William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions dedicated to statistics output and the stats socket |
| 3 | * |
| 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
| 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <pwd.h> |
| 20 | #include <grp.h> |
| 21 | |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 26 | #include <haproxy/api.h> |
Willy Tarreau | 5d9ddc5 | 2021-10-06 19:54:09 +0200 | [diff] [blame] | 27 | #include <haproxy/activity.h> |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 28 | #include <haproxy/applet.h> |
Willy Tarreau | 4980160 | 2020-06-04 22:50:02 +0200 | [diff] [blame] | 29 | #include <haproxy/backend.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 30 | #include <haproxy/base64.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 31 | #include <haproxy/cfgparse.h> |
Willy Tarreau | f1d32c4 | 2020-06-04 21:07:02 +0200 | [diff] [blame] | 32 | #include <haproxy/channel.h> |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 33 | #include <haproxy/check.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 34 | #include <haproxy/cli.h> |
Willy Tarreau | 5554264 | 2021-10-08 09:33:24 +0200 | [diff] [blame] | 35 | #include <haproxy/clock.h> |
Willy Tarreau | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 36 | #include <haproxy/compression.h> |
Willy Tarreau | 2a83d60 | 2020-05-27 16:58:08 +0200 | [diff] [blame] | 37 | #include <haproxy/debug.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 38 | #include <haproxy/errors.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 39 | #include <haproxy/fd.h> |
| 40 | #include <haproxy/freq_ctr.h> |
Willy Tarreau | 762d7a5 | 2020-06-04 11:23:07 +0200 | [diff] [blame] | 41 | #include <haproxy/frontend.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 42 | #include <haproxy/global.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 43 | #include <haproxy/http.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 44 | #include <haproxy/http_ana.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 45 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 46 | #include <haproxy/htx.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 47 | #include <haproxy/list.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 48 | #include <haproxy/listener.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 49 | #include <haproxy/log.h> |
Willy Tarreau | 2cd5809 | 2020-06-04 15:10:43 +0200 | [diff] [blame] | 50 | #include <haproxy/map-t.h> |
Willy Tarreau | 225a90a | 2020-06-04 15:06:28 +0200 | [diff] [blame] | 51 | #include <haproxy/pattern-t.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 52 | #include <haproxy/pipe.h> |
| 53 | #include <haproxy/pool.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 54 | #include <haproxy/proxy.h> |
Emeric Brun | c943799 | 2021-02-12 19:42:55 +0100 | [diff] [blame] | 55 | #include <haproxy/resolvers.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 56 | #include <haproxy/sc_strm.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 57 | #include <haproxy/server.h> |
Willy Tarreau | 48d25b3 | 2020-06-04 18:58:52 +0200 | [diff] [blame] | 58 | #include <haproxy/session.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 59 | #include <haproxy/stats.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 60 | #include <haproxy/stconn.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 61 | #include <haproxy/stream.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 62 | #include <haproxy/task.h> |
Willy Tarreau | c2f7c58 | 2020-06-02 18:15:32 +0200 | [diff] [blame] | 63 | #include <haproxy/ticks.h> |
Willy Tarreau | 92b4f13 | 2020-06-01 11:05:15 +0200 | [diff] [blame] | 64 | #include <haproxy/time.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 65 | #include <haproxy/tools.h> |
Willy Tarreau | 8c42b8a | 2020-06-04 19:27:34 +0200 | [diff] [blame] | 66 | #include <haproxy/uri_auth-t.h> |
Willy Tarreau | d678805 | 2020-05-27 15:59:00 +0200 | [diff] [blame] | 67 | #include <haproxy/version.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 68 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 69 | |
Christopher Faulet | 2b9b678 | 2019-02-27 16:42:58 +0100 | [diff] [blame] | 70 | /* status codes available for the stats admin page (strictly 4 chars length) */ |
| 71 | const char *stat_status_codes[STAT_STATUS_SIZE] = { |
| 72 | [STAT_STATUS_DENY] = "DENY", |
| 73 | [STAT_STATUS_DONE] = "DONE", |
| 74 | [STAT_STATUS_ERRP] = "ERRP", |
| 75 | [STAT_STATUS_EXCD] = "EXCD", |
| 76 | [STAT_STATUS_NONE] = "NONE", |
| 77 | [STAT_STATUS_PART] = "PART", |
| 78 | [STAT_STATUS_UNKN] = "UNKN", |
| 79 | [STAT_STATUS_IVAL] = "IVAL", |
| 80 | }; |
| 81 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 82 | /* These are the field names for each INF_* field position. Please pay attention |
| 83 | * to always use the exact same name except that the strings for new names must |
| 84 | * be lower case or CamelCase while the enum entries must be upper case. |
| 85 | */ |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 86 | const struct name_desc info_fields[INF_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 87 | [INF_NAME] = { .name = "Name", .desc = "Product name" }, |
| 88 | [INF_VERSION] = { .name = "Version", .desc = "Product version" }, |
| 89 | [INF_RELEASE_DATE] = { .name = "Release_date", .desc = "Date of latest source code update" }, |
| 90 | [INF_NBTHREAD] = { .name = "Nbthread", .desc = "Number of started threads (global.nbthread)" }, |
Willy Tarreau | 9135859 | 2021-06-15 08:08:04 +0200 | [diff] [blame] | 91 | [INF_NBPROC] = { .name = "Nbproc", .desc = "Number of started worker processes (historical, always 1)" }, |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 92 | [INF_PROCESS_NUM] = { .name = "Process_num", .desc = "Relative worker process number (1)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 93 | [INF_PID] = { .name = "Pid", .desc = "This worker process identifier for the system" }, |
| 94 | [INF_UPTIME] = { .name = "Uptime", .desc = "How long ago this worker process was started (days+hours+minutes+seconds)" }, |
| 95 | [INF_UPTIME_SEC] = { .name = "Uptime_sec", .desc = "How long ago this worker process was started (seconds)" }, |
William Dauchy | defd156 | 2021-01-15 22:41:38 +0100 | [diff] [blame] | 96 | [INF_START_TIME_SEC] = { .name = "Start_time_sec", .desc = "Start time in seconds" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 97 | [INF_MEMMAX_MB] = { .name = "Memmax_MB", .desc = "Worker process's hard limit on memory usage in MB (-m on command line)" }, |
William Dauchy | a8766cf | 2021-01-15 22:41:37 +0100 | [diff] [blame] | 98 | [INF_MEMMAX_BYTES] = { .name = "Memmax_bytes", .desc = "Worker process's hard limit on memory usage in byes (-m on command line)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 99 | [INF_POOL_ALLOC_MB] = { .name = "PoolAlloc_MB", .desc = "Amount of memory allocated in pools (in MB)" }, |
William Dauchy | a8766cf | 2021-01-15 22:41:37 +0100 | [diff] [blame] | 100 | [INF_POOL_ALLOC_BYTES] = { .name = "PoolAlloc_bytes", .desc = "Amount of memory allocated in pools (in bytes)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 101 | [INF_POOL_USED_MB] = { .name = "PoolUsed_MB", .desc = "Amount of pool memory currently used (in MB)" }, |
William Dauchy | a8766cf | 2021-01-15 22:41:37 +0100 | [diff] [blame] | 102 | [INF_POOL_USED_BYTES] = { .name = "PoolUsed_bytes", .desc = "Amount of pool memory currently used (in bytes)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 103 | [INF_POOL_FAILED] = { .name = "PoolFailed", .desc = "Number of failed pool allocations since this worker was started" }, |
| 104 | [INF_ULIMIT_N] = { .name = "Ulimit-n", .desc = "Hard limit on the number of per-process file descriptors" }, |
| 105 | [INF_MAXSOCK] = { .name = "Maxsock", .desc = "Hard limit on the number of per-process sockets" }, |
| 106 | [INF_MAXCONN] = { .name = "Maxconn", .desc = "Hard limit on the number of per-process connections (configured or imposed by Ulimit-n)" }, |
| 107 | [INF_HARD_MAXCONN] = { .name = "Hard_maxconn", .desc = "Hard limit on the number of per-process connections (imposed by Memmax_MB or Ulimit-n)" }, |
| 108 | [INF_CURR_CONN] = { .name = "CurrConns", .desc = "Current number of connections on this worker process" }, |
| 109 | [INF_CUM_CONN] = { .name = "CumConns", .desc = "Total number of connections on this worker process since started" }, |
| 110 | [INF_CUM_REQ] = { .name = "CumReq", .desc = "Total number of requests on this worker process since started" }, |
| 111 | [INF_MAX_SSL_CONNS] = { .name = "MaxSslConns", .desc = "Hard limit on the number of per-process SSL endpoints (front+back), 0=unlimited" }, |
| 112 | [INF_CURR_SSL_CONNS] = { .name = "CurrSslConns", .desc = "Current number of SSL endpoints on this worker process (front+back)" }, |
| 113 | [INF_CUM_SSL_CONNS] = { .name = "CumSslConns", .desc = "Total number of SSL endpoints on this worker process since started (front+back)" }, |
| 114 | [INF_MAXPIPES] = { .name = "Maxpipes", .desc = "Hard limit on the number of pipes for splicing, 0=unlimited" }, |
| 115 | [INF_PIPES_USED] = { .name = "PipesUsed", .desc = "Current number of pipes in use in this worker process" }, |
| 116 | [INF_PIPES_FREE] = { .name = "PipesFree", .desc = "Current number of allocated and available pipes in this worker process" }, |
| 117 | [INF_CONN_RATE] = { .name = "ConnRate", .desc = "Number of front connections created on this worker process over the last second" }, |
| 118 | [INF_CONN_RATE_LIMIT] = { .name = "ConnRateLimit", .desc = "Hard limit for ConnRate (global.maxconnrate)" }, |
| 119 | [INF_MAX_CONN_RATE] = { .name = "MaxConnRate", .desc = "Highest ConnRate reached on this worker process since started (in connections per second)" }, |
| 120 | [INF_SESS_RATE] = { .name = "SessRate", .desc = "Number of sessions created on this worker process over the last second" }, |
| 121 | [INF_SESS_RATE_LIMIT] = { .name = "SessRateLimit", .desc = "Hard limit for SessRate (global.maxsessrate)" }, |
| 122 | [INF_MAX_SESS_RATE] = { .name = "MaxSessRate", .desc = "Highest SessRate reached on this worker process since started (in sessions per second)" }, |
| 123 | [INF_SSL_RATE] = { .name = "SslRate", .desc = "Number of SSL connections created on this worker process over the last second" }, |
| 124 | [INF_SSL_RATE_LIMIT] = { .name = "SslRateLimit", .desc = "Hard limit for SslRate (global.maxsslrate)" }, |
| 125 | [INF_MAX_SSL_RATE] = { .name = "MaxSslRate", .desc = "Highest SslRate reached on this worker process since started (in connections per second)" }, |
| 126 | [INF_SSL_FRONTEND_KEY_RATE] = { .name = "SslFrontendKeyRate", .desc = "Number of SSL keys created on frontends in this worker process over the last second" }, |
| 127 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = { .name = "SslFrontendMaxKeyRate", .desc = "Highest SslFrontendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 128 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = { .name = "SslFrontendSessionReuse_pct", .desc = "Percent of frontend SSL connections which did not require a new key" }, |
| 129 | [INF_SSL_BACKEND_KEY_RATE] = { .name = "SslBackendKeyRate", .desc = "Number of SSL keys created on backends in this worker process over the last second" }, |
| 130 | [INF_SSL_BACKEND_MAX_KEY_RATE] = { .name = "SslBackendMaxKeyRate", .desc = "Highest SslBackendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 131 | [INF_SSL_CACHE_LOOKUPS] = { .name = "SslCacheLookups", .desc = "Total number of SSL session ID lookups in the SSL session cache on this worker since started" }, |
| 132 | [INF_SSL_CACHE_MISSES] = { .name = "SslCacheMisses", .desc = "Total number of SSL session ID lookups that didn't find a session in the SSL session cache on this worker since started" }, |
| 133 | [INF_COMPRESS_BPS_IN] = { .name = "CompressBpsIn", .desc = "Number of bytes submitted to the HTTP compressor in this worker process over the last second" }, |
| 134 | [INF_COMPRESS_BPS_OUT] = { .name = "CompressBpsOut", .desc = "Number of bytes emitted by the HTTP compressor in this worker process over the last second" }, |
| 135 | [INF_COMPRESS_BPS_RATE_LIM] = { .name = "CompressBpsRateLim", .desc = "Limit of CompressBpsOut beyond which HTTP compression is automatically disabled" }, |
| 136 | [INF_ZLIB_MEM_USAGE] = { .name = "ZlibMemUsage", .desc = "Amount of memory currently used by HTTP compression on the current worker process (in bytes)" }, |
| 137 | [INF_MAX_ZLIB_MEM_USAGE] = { .name = "MaxZlibMemUsage", .desc = "Limit on the amount of memory used by HTTP compression above which it is automatically disabled (in bytes, see global.maxzlibmem)" }, |
| 138 | [INF_TASKS] = { .name = "Tasks", .desc = "Total number of tasks in the current worker process (active + sleeping)" }, |
| 139 | [INF_RUN_QUEUE] = { .name = "Run_queue", .desc = "Total number of active tasks+tasklets in the current worker process" }, |
| 140 | [INF_IDLE_PCT] = { .name = "Idle_pct", .desc = "Percentage of last second spent waiting in the current worker thread" }, |
| 141 | [INF_NODE] = { .name = "node", .desc = "Node name (global.node)" }, |
| 142 | [INF_DESCRIPTION] = { .name = "description", .desc = "Node description (global.description)" }, |
| 143 | [INF_STOPPING] = { .name = "Stopping", .desc = "1 if the worker process is currently stopping, otherwise zero" }, |
| 144 | [INF_JOBS] = { .name = "Jobs", .desc = "Current number of active jobs on the current worker process (frontend connections, master connections, listeners)" }, |
| 145 | [INF_UNSTOPPABLE_JOBS] = { .name = "Unstoppable Jobs", .desc = "Current number of unstoppable jobs on the current worker process (master connections)" }, |
| 146 | [INF_LISTENERS] = { .name = "Listeners", .desc = "Current number of active listeners on the current worker process" }, |
| 147 | [INF_ACTIVE_PEERS] = { .name = "ActivePeers", .desc = "Current number of verified active peers connections on the current worker process" }, |
| 148 | [INF_CONNECTED_PEERS] = { .name = "ConnectedPeers", .desc = "Current number of peers having passed the connection step on the current worker process" }, |
| 149 | [INF_DROPPED_LOGS] = { .name = "DroppedLogs", .desc = "Total number of dropped logs for current worker process since started" }, |
| 150 | [INF_BUSY_POLLING] = { .name = "BusyPolling", .desc = "1 if busy-polling is currently in use on the worker process, otherwise zero (config.busy-polling)" }, |
| 151 | [INF_FAILED_RESOLUTIONS] = { .name = "FailedResolutions", .desc = "Total number of failed DNS resolutions in current worker process since started" }, |
| 152 | [INF_TOTAL_BYTES_OUT] = { .name = "TotalBytesOut", .desc = "Total number of bytes emitted by current worker process since started" }, |
Tim Duesterhus | 0ababda | 2023-03-27 15:23:44 +0200 | [diff] [blame] | 153 | [INF_TOTAL_SPLICED_BYTES_OUT] = { .name = "TotalSplicedBytesOut", .desc = "Total number of bytes emitted by current worker process through a kernel pipe since started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 154 | [INF_BYTES_OUT_RATE] = { .name = "BytesOutRate", .desc = "Number of bytes emitted by current worker process over the last second" }, |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 155 | [INF_DEBUG_COMMANDS_ISSUED] = { .name = "DebugCommandsIssued", .desc = "Number of debug commands issued on this process (anything > 0 is unsafe)" }, |
Emeric Brun | 45c457a | 2020-07-09 23:23:34 +0200 | [diff] [blame] | 156 | [INF_CUM_LOG_MSGS] = { .name = "CumRecvLogs", .desc = "Total number of log messages received by log-forwarding listeners on this worker process since started" }, |
Adis Nezirovic | b62b78b | 2021-01-15 13:12:33 +0100 | [diff] [blame] | 157 | [INF_BUILD_INFO] = { .name = "Build info", .desc = "Build info" }, |
Amaury Denoyelle | 5dfdf3e | 2021-05-05 17:09:12 +0200 | [diff] [blame] | 158 | [INF_TAINTED] = { .name = "Tainted", .desc = "Experimental features used" }, |
Willy Tarreau | 3c4a297 | 2023-05-11 12:02:21 +0200 | [diff] [blame] | 159 | [INF_WARNINGS] = { .name = "TotalWarnings", .desc = "Total warnings issued" }, |
Willy Tarreau | 9615102 | 2023-05-11 13:51:31 +0200 | [diff] [blame] | 160 | [INF_MAXCONN_REACHED] = { .name = "MaxconnReached", .desc = "Number of times an accepted connection resulted in Maxconn being reached" }, |
Willy Tarreau | 5723b38 | 2023-05-17 09:05:20 +0200 | [diff] [blame] | 161 | [INF_BOOTTIME_MS] = { .name = "BootTime_ms", .desc = "How long ago it took to parse and process the config before being ready (milliseconds)" }, |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 162 | }; |
| 163 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 164 | const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 165 | [ST_F_PXNAME] = { .name = "pxname", .desc = "Proxy name" }, |
| 166 | [ST_F_SVNAME] = { .name = "svname", .desc = "Server name" }, |
William Dauchy | eedb9b1 | 2021-02-01 13:11:53 +0100 | [diff] [blame] | 167 | [ST_F_QCUR] = { .name = "qcur", .desc = "Number of current queued connections" }, |
| 168 | [ST_F_QMAX] = { .name = "qmax", .desc = "Highest value of queued connections encountered since process started" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 169 | [ST_F_SCUR] = { .name = "scur", .desc = "Number of current sessions on the frontend, backend or server" }, |
| 170 | [ST_F_SMAX] = { .name = "smax", .desc = "Highest value of current sessions encountered since process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 171 | [ST_F_SLIM] = { .name = "slim", .desc = "Frontend/listener/server's maxconn, backend's fullconn" }, |
| 172 | [ST_F_STOT] = { .name = "stot", .desc = "Total number of sessions since process started" }, |
| 173 | [ST_F_BIN] = { .name = "bin", .desc = "Total number of request bytes since process started" }, |
| 174 | [ST_F_BOUT] = { .name = "bout", .desc = "Total number of response bytes since process started" }, |
| 175 | [ST_F_DREQ] = { .name = "dreq", .desc = "Total number of denied requests since process started" }, |
| 176 | [ST_F_DRESP] = { .name = "dresp", .desc = "Total number of denied responses since process started" }, |
| 177 | [ST_F_EREQ] = { .name = "ereq", .desc = "Total number of invalid requests since process started" }, |
| 178 | [ST_F_ECON] = { .name = "econ", .desc = "Total number of failed connections to server since the worker process started" }, |
| 179 | [ST_F_ERESP] = { .name = "eresp", .desc = "Total number of invalid responses since the worker process started" }, |
| 180 | [ST_F_WRETR] = { .name = "wretr", .desc = "Total number of server connection retries since the worker process started" }, |
| 181 | [ST_F_WREDIS] = { .name = "wredis", .desc = "Total number of server redispatches due to connection failures since the worker process started" }, |
| 182 | [ST_F_STATUS] = { .name = "status", .desc = "Frontend/listen status: OPEN/WAITING/FULL/STOP; backend: UP/DOWN; server: last check status" }, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 183 | [ST_F_WEIGHT] = { .name = "weight", .desc = "Server's effective weight, or sum of active servers' effective weights for a backend" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 184 | [ST_F_ACT] = { .name = "act", .desc = "Total number of active UP servers with a non-zero weight" }, |
| 185 | [ST_F_BCK] = { .name = "bck", .desc = "Total number of backup UP servers with a non-zero weight" }, |
| 186 | [ST_F_CHKFAIL] = { .name = "chkfail", .desc = "Total number of failed individual health checks per server/backend, since the worker process started" }, |
| 187 | [ST_F_CHKDOWN] = { .name = "chkdown", .desc = "Total number of failed checks causing UP to DOWN server transitions, per server/backend, since the worker process started" }, |
| 188 | [ST_F_LASTCHG] = { .name = "lastchg", .desc = "How long ago the last server state changed, in seconds" }, |
| 189 | [ST_F_DOWNTIME] = { .name = "downtime", .desc = "Total time spent in DOWN state, for server or backend" }, |
| 190 | [ST_F_QLIMIT] = { .name = "qlimit", .desc = "Limit on the number of connections in queue, for servers only (maxqueue argument)" }, |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 191 | [ST_F_PID] = { .name = "pid", .desc = "Relative worker process number (1)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 192 | [ST_F_IID] = { .name = "iid", .desc = "Frontend or Backend numeric identifier ('id' setting)" }, |
| 193 | [ST_F_SID] = { .name = "sid", .desc = "Server numeric identifier ('id' setting)" }, |
| 194 | [ST_F_THROTTLE] = { .name = "throttle", .desc = "Throttling ratio applied to a server's maxconn and weight during the slowstart period (0 to 100%)" }, |
| 195 | [ST_F_LBTOT] = { .name = "lbtot", .desc = "Total number of requests routed by load balancing since the worker process started (ignores queue pop and stickiness)" }, |
| 196 | [ST_F_TRACKED] = { .name = "tracked", .desc = "Name of the other server this server tracks for its state" }, |
| 197 | [ST_F_TYPE] = { .name = "type", .desc = "Type of the object (Listener, Frontend, Backend, Server)" }, |
| 198 | [ST_F_RATE] = { .name = "rate", .desc = "Total number of sessions processed by this object over the last second (sessions for listeners/frontends, requests for backends/servers)" }, |
| 199 | [ST_F_RATE_LIM] = { .name = "rate_lim", .desc = "Limit on the number of sessions accepted in a second (frontend only, 'rate-limit sessions' setting)" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 200 | [ST_F_RATE_MAX] = { .name = "rate_max", .desc = "Highest value of sessions per second observed since the worker process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 201 | [ST_F_CHECK_STATUS] = { .name = "check_status", .desc = "Status report of the server's latest health check, prefixed with '*' if a check is currently in progress" }, |
| 202 | [ST_F_CHECK_CODE] = { .name = "check_code", .desc = "HTTP/SMTP/LDAP status code reported by the latest server health check" }, |
| 203 | [ST_F_CHECK_DURATION] = { .name = "check_duration", .desc = "Total duration of the latest server health check, in milliseconds" }, |
| 204 | [ST_F_HRSP_1XX] = { .name = "hrsp_1xx", .desc = "Total number of HTTP responses with status 100-199 returned by this object since the worker process started" }, |
| 205 | [ST_F_HRSP_2XX] = { .name = "hrsp_2xx", .desc = "Total number of HTTP responses with status 200-299 returned by this object since the worker process started" }, |
| 206 | [ST_F_HRSP_3XX] = { .name = "hrsp_3xx", .desc = "Total number of HTTP responses with status 300-399 returned by this object since the worker process started" }, |
| 207 | [ST_F_HRSP_4XX] = { .name = "hrsp_4xx", .desc = "Total number of HTTP responses with status 400-499 returned by this object since the worker process started" }, |
| 208 | [ST_F_HRSP_5XX] = { .name = "hrsp_5xx", .desc = "Total number of HTTP responses with status 500-599 returned by this object since the worker process started" }, |
| 209 | [ST_F_HRSP_OTHER] = { .name = "hrsp_other", .desc = "Total number of HTTP responses with status <100, >599 returned by this object since the worker process started (error -1 included)" }, |
| 210 | [ST_F_HANAFAIL] = { .name = "hanafail", .desc = "Total number of failed checks caused by an 'on-error' directive after an 'observe' condition matched" }, |
| 211 | [ST_F_REQ_RATE] = { .name = "req_rate", .desc = "Number of HTTP requests processed over the last second on this object" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 212 | [ST_F_REQ_RATE_MAX] = { .name = "req_rate_max", .desc = "Highest value of http requests observed since the worker process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 213 | [ST_F_REQ_TOT] = { .name = "req_tot", .desc = "Total number of HTTP requests processed by this object since the worker process started" }, |
| 214 | [ST_F_CLI_ABRT] = { .name = "cli_abrt", .desc = "Total number of requests or connections aborted by the client since the worker process started" }, |
| 215 | [ST_F_SRV_ABRT] = { .name = "srv_abrt", .desc = "Total number of requests or connections aborted by the server since the worker process started" }, |
| 216 | [ST_F_COMP_IN] = { .name = "comp_in", .desc = "Total number of bytes submitted to the HTTP compressor for this object since the worker process started" }, |
| 217 | [ST_F_COMP_OUT] = { .name = "comp_out", .desc = "Total number of bytes emitted by the HTTP compressor for this object since the worker process started" }, |
| 218 | [ST_F_COMP_BYP] = { .name = "comp_byp", .desc = "Total number of bytes that bypassed HTTP compression for this object since the worker process started (CPU/memory/bandwidth limitation)" }, |
| 219 | [ST_F_COMP_RSP] = { .name = "comp_rsp", .desc = "Total number of HTTP responses that were compressed for this object since the worker process started" }, |
| 220 | [ST_F_LASTSESS] = { .name = "lastsess", .desc = "How long ago some traffic was seen on this object on this worker process, in seconds" }, |
| 221 | [ST_F_LAST_CHK] = { .name = "last_chk", .desc = "Short description of the latest health check report for this server (see also check_desc)" }, |
| 222 | [ST_F_LAST_AGT] = { .name = "last_agt", .desc = "Short description of the latest agent check report for this server (see also agent_desc)" }, |
| 223 | [ST_F_QTIME] = { .name = "qtime", .desc = "Time spent in the queue, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 224 | [ST_F_CTIME] = { .name = "ctime", .desc = "Time spent waiting for a connection to complete, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 225 | [ST_F_RTIME] = { .name = "rtime", .desc = "Time spent waiting for a server response, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 226 | [ST_F_TTIME] = { .name = "ttime", .desc = "Total request+response time (request+queue+connect+response+processing), in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 227 | [ST_F_AGENT_STATUS] = { .name = "agent_status", .desc = "Status report of the server's latest agent check, prefixed with '*' if a check is currently in progress" }, |
| 228 | [ST_F_AGENT_CODE] = { .name = "agent_code", .desc = "Status code reported by the latest server agent check" }, |
| 229 | [ST_F_AGENT_DURATION] = { .name = "agent_duration", .desc = "Total duration of the latest server agent check, in milliseconds" }, |
| 230 | [ST_F_CHECK_DESC] = { .name = "check_desc", .desc = "Textual description of the latest health check report for this server" }, |
| 231 | [ST_F_AGENT_DESC] = { .name = "agent_desc", .desc = "Textual description of the latest agent check report for this server" }, |
| 232 | [ST_F_CHECK_RISE] = { .name = "check_rise", .desc = "Number of successful health checks before declaring a server UP (server 'rise' setting)" }, |
| 233 | [ST_F_CHECK_FALL] = { .name = "check_fall", .desc = "Number of failed health checks before declaring a server DOWN (server 'fall' setting)" }, |
| 234 | [ST_F_CHECK_HEALTH] = { .name = "check_health", .desc = "Current server health check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 235 | [ST_F_AGENT_RISE] = { .name = "agent_rise", .desc = "Number of successful agent checks before declaring a server UP (server 'rise' setting)" }, |
| 236 | [ST_F_AGENT_FALL] = { .name = "agent_fall", .desc = "Number of failed agent checks before declaring a server DOWN (server 'fall' setting)" }, |
| 237 | [ST_F_AGENT_HEALTH] = { .name = "agent_health", .desc = "Current server agent check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 238 | [ST_F_ADDR] = { .name = "addr", .desc = "Server's address:port, shown only if show-legends is set, or at levels oper/admin for the CLI" }, |
| 239 | [ST_F_COOKIE] = { .name = "cookie", .desc = "Backend's cookie name or Server's cookie value, shown only if show-legends is set, or at levels oper/admin for the CLI" }, |
| 240 | [ST_F_MODE] = { .name = "mode", .desc = "'mode' setting (tcp/http/health/cli)" }, |
| 241 | [ST_F_ALGO] = { .name = "algo", .desc = "Backend's load balancing algorithm, shown only if show-legends is set, or at levels oper/admin for the CLI" }, |
| 242 | [ST_F_CONN_RATE] = { .name = "conn_rate", .desc = "Number of new connections accepted over the last second on the frontend for this worker process" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 243 | [ST_F_CONN_RATE_MAX] = { .name = "conn_rate_max", .desc = "Highest value of connections per second observed since the worker process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 244 | [ST_F_CONN_TOT] = { .name = "conn_tot", .desc = "Total number of new connections accepted on this frontend since the worker process started" }, |
| 245 | [ST_F_INTERCEPTED] = { .name = "intercepted", .desc = "Total number of HTTP requests intercepted on the frontend (redirects/stats/services) since the worker process started" }, |
| 246 | [ST_F_DCON] = { .name = "dcon", .desc = "Total number of incoming connections blocked on a listener/frontend by a tcp-request connection rule since the worker process started" }, |
| 247 | [ST_F_DSES] = { .name = "dses", .desc = "Total number of incoming sessions blocked on a listener/frontend by a tcp-request connection rule since the worker process started" }, |
| 248 | [ST_F_WREW] = { .name = "wrew", .desc = "Total number of failed HTTP header rewrites since the worker process started" }, |
| 249 | [ST_F_CONNECT] = { .name = "connect", .desc = "Total number of outgoing connection attempts on this backend/server since the worker process started" }, |
| 250 | [ST_F_REUSE] = { .name = "reuse", .desc = "Total number of reused connection on this backend/server since the worker process started" }, |
| 251 | [ST_F_CACHE_LOOKUPS] = { .name = "cache_lookups", .desc = "Total number of HTTP requests looked up in the cache on this frontend/backend since the worker process started" }, |
| 252 | [ST_F_CACHE_HITS] = { .name = "cache_hits", .desc = "Total number of HTTP requests not found in the cache on this frontend/backend since the worker process started" }, |
| 253 | [ST_F_SRV_ICUR] = { .name = "srv_icur", .desc = "Current number of idle connections available for reuse on this server" }, |
| 254 | [ST_F_SRV_ILIM] = { .name = "src_ilim", .desc = "Limit on the number of available idle connections on this server (server 'pool_max_conn' directive)" }, |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 255 | [ST_F_QT_MAX] = { .name = "qtime_max", .desc = "Maximum observed time spent in the queue, in milliseconds (backend/server)" }, |
| 256 | [ST_F_CT_MAX] = { .name = "ctime_max", .desc = "Maximum observed time spent waiting for a connection to complete, in milliseconds (backend/server)" }, |
| 257 | [ST_F_RT_MAX] = { .name = "rtime_max", .desc = "Maximum observed time spent waiting for a server response, in milliseconds (backend/server)" }, |
| 258 | [ST_F_TT_MAX] = { .name = "ttime_max", .desc = "Maximum observed total request+response time (request+queue+connect+response+processing), in milliseconds (backend/server)" }, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 259 | [ST_F_EINT] = { .name = "eint", .desc = "Total number of internal errors since process started"}, |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 260 | [ST_F_IDLE_CONN_CUR] = { .name = "idle_conn_cur", .desc = "Current number of unsafe idle connections"}, |
| 261 | [ST_F_SAFE_CONN_CUR] = { .name = "safe_conn_cur", .desc = "Current number of safe idle connections"}, |
| 262 | [ST_F_USED_CONN_CUR] = { .name = "used_conn_cur", .desc = "Current number of connections in use"}, |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 263 | [ST_F_NEED_CONN_EST] = { .name = "need_conn_est", .desc = "Estimated needed number of connections"}, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 264 | [ST_F_UWEIGHT] = { .name = "uweight", .desc = "Server's user weight, or sum of active servers' user weights for a backend" }, |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 265 | [ST_F_AGG_SRV_CHECK_STATUS] = { .name = "agg_server_check_status", .desc = "[DEPRECATED] Backend's aggregated gauge of servers' status" }, |
| 266 | [ST_F_AGG_SRV_STATUS ] = { .name = "agg_server_status", .desc = "Backend's aggregated gauge of servers' status" }, |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame] | 267 | [ST_F_AGG_CHECK_STATUS] = { .name = "agg_check_status", .desc = "Backend's aggregated gauge of servers' state check status" }, |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 268 | [ST_F_SRID] = { .name = "srid", .desc = "Server id revision, to prevent server id reuse mixups" }, |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 269 | [ST_F_SESS_OTHER] = { .name = "sess_other", .desc = "Total number of sessions other than HTTP since process started" }, |
| 270 | [ST_F_H1SESS] = { .name = "h1sess", .desc = "Total number of HTTP/1 sessions since process started" }, |
| 271 | [ST_F_H2SESS] = { .name = "h2sess", .desc = "Total number of HTTP/2 sessions since process started" }, |
| 272 | [ST_F_H3SESS] = { .name = "h3sess", .desc = "Total number of HTTP/3 sessions since process started" }, |
| 273 | [ST_F_REQ_OTHER] = { .name = "req_other", .desc = "Total number of sessions other than HTTP processed by this object since the worker process started" }, |
| 274 | [ST_F_H1REQ] = { .name = "h1req", .desc = "Total number of HTTP/1 sessions processed by this object since the worker process started" }, |
| 275 | [ST_F_H2REQ] = { .name = "h2req", .desc = "Total number of hTTP/2 sessions processed by this object since the worker process started" }, |
| 276 | [ST_F_H3REQ] = { .name = "h3req", .desc = "Total number of HTTP/3 sessions processed by this object since the worker process started" }, |
Tim Duesterhus | 7a38d47 | 2023-06-01 18:58:08 +0200 | [diff] [blame] | 277 | [ST_F_PROTO] = { .name = "proto", .desc = "Protocol" }, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 278 | }; |
| 279 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 280 | /* one line of info */ |
William Dauchy | 5d9b8f3 | 2021-01-11 20:07:49 +0100 | [diff] [blame] | 281 | THREAD_LOCAL struct field info[INF_TOTAL_FIELDS]; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 282 | |
| 283 | /* description of statistics (static and dynamic) */ |
| 284 | static struct name_desc *stat_f[STATS_DOMAIN_COUNT]; |
| 285 | static size_t stat_count[STATS_DOMAIN_COUNT]; |
| 286 | |
| 287 | /* one line for stats */ |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 288 | THREAD_LOCAL struct field *stat_l[STATS_DOMAIN_COUNT]; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 289 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 290 | /* list of all registered stats module */ |
| 291 | static struct list stats_module_list[STATS_DOMAIN_COUNT] = { |
| 292 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_PROXY]), |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 293 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_RESOLVERS]), |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 294 | }; |
| 295 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 296 | THREAD_LOCAL void *trash_counters; |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 297 | static THREAD_LOCAL struct buffer trash_chunk = BUF_NULL; |
| 298 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 299 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 300 | static inline uint8_t stats_get_domain(uint32_t domain) |
| 301 | { |
| 302 | return domain >> STATS_DOMAIN & STATS_DOMAIN_MASK; |
| 303 | } |
| 304 | |
Amaury Denoyelle | 72b16e5 | 2020-10-05 11:49:38 +0200 | [diff] [blame] | 305 | static inline enum stats_domain_px_cap stats_px_get_cap(uint32_t domain) |
| 306 | { |
| 307 | return domain >> STATS_PX_CAP & STATS_PX_CAP_MASK; |
| 308 | } |
| 309 | |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 310 | static void stats_dump_json_schema(struct buffer *out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 311 | |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 312 | int stats_putchk(struct appctx *appctx, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 313 | { |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 314 | struct stconn *sc = appctx_sc(appctx); |
| 315 | struct channel *chn = sc_ic(sc); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 316 | struct buffer *chk = &trash_chunk; |
| 317 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 318 | if (htx) { |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 319 | if (chk->data >= channel_htx_recv_max(chn, htx)) { |
| 320 | sc_need_room(sc, chk->data); |
Christopher Faulet | 69fc88c | 2019-01-07 14:27:53 +0100 | [diff] [blame] | 321 | return 0; |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 322 | } |
| 323 | if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data))) { |
| 324 | sc_need_room(sc, 0); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 325 | return 0; |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 326 | } |
Christopher Faulet | 5adbeeb | 2019-01-02 14:34:39 +0100 | [diff] [blame] | 327 | channel_add_input(chn, chk->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 328 | chk->data = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 329 | } |
| 330 | else { |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 331 | if (applet_putchk(appctx, chk) == -1) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | return 1; |
| 335 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 336 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 337 | static const char *stats_scope_ptr(struct appctx *appctx, struct stconn *sc) |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 338 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 339 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 340 | struct channel *req = sc_oc(sc); |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 341 | struct htx *htx = htxbuf(&req->buf); |
| 342 | struct htx_blk *blk; |
| 343 | struct ist uri; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 344 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 345 | blk = htx_get_head_blk(htx); |
Christopher Faulet | ea00973 | 2019-11-18 15:50:25 +0100 | [diff] [blame] | 346 | BUG_ON(!blk || htx_get_blk_type(blk) != HTX_BLK_REQ_SL); |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 347 | ALREADY_CHECKED(blk); |
| 348 | uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 349 | return uri.ptr + ctx->scope_str; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 350 | } |
| 351 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 352 | /* |
| 353 | * http_stats_io_handler() |
| 354 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 355 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 356 | * -> stats_dump_json_header() // emits the JSON headers (same as above) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 357 | * -> stats_dump_html_head() // emits the HTML headers |
| 358 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 359 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 360 | * -> stats_dump_html_px_hdr() |
| 361 | * -> stats_dump_fe_stats() |
| 362 | * -> stats_dump_li_stats() |
| 363 | * -> stats_dump_sv_stats() |
| 364 | * -> stats_dump_be_stats() |
| 365 | * -> stats_dump_html_px_end() |
| 366 | * -> stats_dump_html_end() // emits HTML trailer |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 367 | * -> stats_dump_json_end() // emits JSON trailer |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 368 | */ |
| 369 | |
| 370 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 371 | /* Dumps the stats CSV header to the local trash buffer. The caller is |
| 372 | * responsible for clearing it if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 373 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 374 | * so please only append new fields at the end, never in the middle. |
| 375 | */ |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 376 | static void stats_dump_csv_header(enum stats_domain domain) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 377 | { |
| 378 | int field; |
| 379 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 380 | chunk_appendf(&trash_chunk, "# "); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 381 | if (stat_f[domain]) { |
| 382 | for (field = 0; field < stat_count[domain]; ++field) { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 383 | chunk_appendf(&trash_chunk, "%s,", stat_f[domain][field].name); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 384 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 385 | /* print special delimiter on proxy stats to mark end of |
| 386 | static fields */ |
| 387 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 388 | chunk_appendf(&trash_chunk, "-,"); |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 392 | chunk_appendf(&trash_chunk, "\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 393 | } |
| 394 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 395 | /* Emits a stats field without any surrounding element and properly encoded to |
| 396 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 397 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 398 | int stats_emit_raw_data_field(struct buffer *out, const struct field *f) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 399 | { |
| 400 | switch (field_format(f, 0)) { |
| 401 | case FF_EMPTY: return 1; |
| 402 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 403 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 404 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 405 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
Willy Tarreau | 065ba31 | 2021-05-08 10:38:20 +0200 | [diff] [blame] | 406 | case FF_FLT: { |
| 407 | size_t prev_data = out->data; |
| 408 | out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "%f", f->u.flt)); |
| 409 | return out->data; |
| 410 | } |
Emeric Brun | 36e5427 | 2024-01-23 15:44:32 +0100 | [diff] [blame] | 411 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, 2, out) != NULL; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 412 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 413 | } |
| 414 | } |
| 415 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 416 | const char *field_to_html_str(const struct field *f) |
| 417 | { |
| 418 | switch (field_format(f, 0)) { |
| 419 | case FF_S32: return U2H(f->u.s32); |
| 420 | case FF_S64: return U2H(f->u.s64); |
| 421 | case FF_U64: return U2H(f->u.u64); |
| 422 | case FF_U32: return U2H(f->u.u32); |
Willy Tarreau | 6004fb7 | 2021-05-08 07:37:38 +0200 | [diff] [blame] | 423 | case FF_FLT: return F2H(f->u.flt); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 424 | case FF_STR: return field_str(f, 0); |
| 425 | case FF_EMPTY: |
| 426 | default: |
| 427 | return ""; |
| 428 | } |
| 429 | } |
| 430 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 431 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 432 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 433 | * if the buffer is full. |
| 434 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 435 | int stats_emit_typed_data_field(struct buffer *out, const struct field *f) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 436 | { |
| 437 | switch (field_format(f, 0)) { |
| 438 | case FF_EMPTY: return 1; |
| 439 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 440 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 441 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 442 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
Willy Tarreau | 065ba31 | 2021-05-08 10:38:20 +0200 | [diff] [blame] | 443 | case FF_FLT: { |
| 444 | size_t prev_data = out->data; |
| 445 | out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "flt:%f", f->u.flt)); |
| 446 | return out->data; |
| 447 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 448 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 449 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 450 | } |
| 451 | } |
| 452 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 453 | /* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per |
| 454 | * the recommendation for interoperable integers in section 6 of RFC 7159. |
| 455 | */ |
| 456 | #define JSON_INT_MAX ((1ULL << 53) - 1) |
| 457 | #define JSON_INT_MIN (0 - JSON_INT_MAX) |
| 458 | |
| 459 | /* Emits a stats field value and its type in JSON. |
| 460 | * Returns non-zero on success, 0 on error. |
| 461 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 462 | int stats_emit_json_data_field(struct buffer *out, const struct field *f) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 463 | { |
| 464 | int old_len; |
| 465 | char buf[20]; |
| 466 | const char *type, *value = buf, *quote = ""; |
| 467 | |
| 468 | switch (field_format(f, 0)) { |
| 469 | case FF_EMPTY: return 1; |
| 470 | case FF_S32: type = "\"s32\""; |
| 471 | snprintf(buf, sizeof(buf), "%d", f->u.s32); |
| 472 | break; |
| 473 | case FF_U32: type = "\"u32\""; |
| 474 | snprintf(buf, sizeof(buf), "%u", f->u.u32); |
| 475 | break; |
| 476 | case FF_S64: type = "\"s64\""; |
| 477 | if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX) |
| 478 | return 0; |
| 479 | type = "\"s64\""; |
| 480 | snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64); |
| 481 | break; |
| 482 | case FF_U64: if (f->u.u64 > JSON_INT_MAX) |
| 483 | return 0; |
| 484 | type = "\"u64\""; |
| 485 | snprintf(buf, sizeof(buf), "%llu", |
| 486 | (unsigned long long) f->u.u64); |
Christopher Faulet | 52c91bb | 2019-09-28 10:37:31 +0200 | [diff] [blame] | 487 | break; |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 488 | case FF_FLT: type = "\"flt\""; |
Willy Tarreau | 065ba31 | 2021-05-08 10:38:20 +0200 | [diff] [blame] | 489 | flt_trim(buf, 0, snprintf(buf, sizeof(buf), "%f", f->u.flt)); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 490 | break; |
| 491 | case FF_STR: type = "\"str\""; |
| 492 | value = field_str(f, 0); |
| 493 | quote = "\""; |
| 494 | break; |
| 495 | default: snprintf(buf, sizeof(buf), "%u", f->type); |
| 496 | type = buf; |
| 497 | value = "unknown"; |
| 498 | quote = "\""; |
| 499 | break; |
| 500 | } |
| 501 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 502 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 503 | chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}", |
| 504 | type, quote, value, quote); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 505 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 506 | } |
| 507 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 508 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 509 | * Returns non-zero on success, 0 if the buffer is full. |
| 510 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 511 | int stats_emit_field_tags(struct buffer *out, const struct field *f, |
| 512 | char delim) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 513 | { |
| 514 | char origin, nature, scope; |
| 515 | |
| 516 | switch (field_origin(f, 0)) { |
| 517 | case FO_METRIC: origin = 'M'; break; |
| 518 | case FO_STATUS: origin = 'S'; break; |
| 519 | case FO_KEY: origin = 'K'; break; |
| 520 | case FO_CONFIG: origin = 'C'; break; |
| 521 | case FO_PRODUCT: origin = 'P'; break; |
| 522 | default: origin = '?'; break; |
| 523 | } |
| 524 | |
| 525 | switch (field_nature(f, 0)) { |
| 526 | case FN_GAUGE: nature = 'G'; break; |
| 527 | case FN_LIMIT: nature = 'L'; break; |
| 528 | case FN_MIN: nature = 'm'; break; |
| 529 | case FN_MAX: nature = 'M'; break; |
| 530 | case FN_RATE: nature = 'R'; break; |
| 531 | case FN_COUNTER: nature = 'C'; break; |
| 532 | case FN_DURATION: nature = 'D'; break; |
| 533 | case FN_AGE: nature = 'A'; break; |
| 534 | case FN_TIME: nature = 'T'; break; |
| 535 | case FN_NAME: nature = 'N'; break; |
| 536 | case FN_OUTPUT: nature = 'O'; break; |
| 537 | case FN_AVG: nature = 'a'; break; |
| 538 | default: nature = '?'; break; |
| 539 | } |
| 540 | |
| 541 | switch (field_scope(f, 0)) { |
| 542 | case FS_PROCESS: scope = 'P'; break; |
| 543 | case FS_SERVICE: scope = 'S'; break; |
| 544 | case FS_SYSTEM: scope = 's'; break; |
| 545 | case FS_CLUSTER: scope = 'C'; break; |
| 546 | default: scope = '?'; break; |
| 547 | } |
| 548 | |
| 549 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 550 | } |
| 551 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 552 | /* Emits an encoding of the field type as JSON. |
| 553 | * Returns non-zero on success, 0 if the buffer is full. |
| 554 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 555 | int stats_emit_json_field_tags(struct buffer *out, const struct field *f) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 556 | { |
| 557 | const char *origin, *nature, *scope; |
| 558 | int old_len; |
| 559 | |
| 560 | switch (field_origin(f, 0)) { |
| 561 | case FO_METRIC: origin = "Metric"; break; |
| 562 | case FO_STATUS: origin = "Status"; break; |
| 563 | case FO_KEY: origin = "Key"; break; |
| 564 | case FO_CONFIG: origin = "Config"; break; |
| 565 | case FO_PRODUCT: origin = "Product"; break; |
| 566 | default: origin = "Unknown"; break; |
| 567 | } |
| 568 | |
| 569 | switch (field_nature(f, 0)) { |
| 570 | case FN_GAUGE: nature = "Gauge"; break; |
| 571 | case FN_LIMIT: nature = "Limit"; break; |
| 572 | case FN_MIN: nature = "Min"; break; |
| 573 | case FN_MAX: nature = "Max"; break; |
| 574 | case FN_RATE: nature = "Rate"; break; |
| 575 | case FN_COUNTER: nature = "Counter"; break; |
| 576 | case FN_DURATION: nature = "Duration"; break; |
| 577 | case FN_AGE: nature = "Age"; break; |
| 578 | case FN_TIME: nature = "Time"; break; |
| 579 | case FN_NAME: nature = "Name"; break; |
| 580 | case FN_OUTPUT: nature = "Output"; break; |
| 581 | case FN_AVG: nature = "Avg"; break; |
| 582 | default: nature = "Unknown"; break; |
| 583 | } |
| 584 | |
| 585 | switch (field_scope(f, 0)) { |
| 586 | case FS_PROCESS: scope = "Process"; break; |
| 587 | case FS_SERVICE: scope = "Service"; break; |
| 588 | case FS_SYSTEM: scope = "System"; break; |
| 589 | case FS_CLUSTER: scope = "Cluster"; break; |
| 590 | default: scope = "Unknown"; break; |
| 591 | } |
| 592 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 593 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 594 | chunk_appendf(out, "\"tags\":{" |
| 595 | "\"origin\":\"%s\"," |
| 596 | "\"nature\":\"%s\"," |
| 597 | "\"scope\":\"%s\"" |
| 598 | "}", origin, nature, scope); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 599 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 600 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 601 | |
| 602 | /* Dump all fields from <stats> into <out> using CSV format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 603 | static int stats_dump_fields_csv(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 604 | const struct field *stats, size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 605 | struct show_stat_ctx *ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 606 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 607 | int domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 608 | int field; |
| 609 | |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 610 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 611 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 612 | return 0; |
| 613 | if (!chunk_strcat(out, ",")) |
| 614 | return 0; |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 615 | |
| 616 | /* print special delimiter on proxy stats to mark end of |
| 617 | static fields */ |
| 618 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) { |
| 619 | if (!chunk_strcat(out, "-,")) |
| 620 | return 0; |
| 621 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 622 | } |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 623 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 624 | chunk_strcat(out, "\n"); |
| 625 | return 1; |
| 626 | } |
| 627 | |
| 628 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 629 | static int stats_dump_fields_typed(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 630 | const struct field *stats, |
| 631 | size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 632 | struct show_stat_ctx * ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 633 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 634 | int flags = ctx->flags; |
| 635 | int domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 636 | int field; |
| 637 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 638 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 639 | if (!stats[field].type) |
| 640 | continue; |
| 641 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 642 | switch (domain) { |
| 643 | case STATS_DOMAIN_PROXY: |
| 644 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 645 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 646 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 647 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 648 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 649 | '?', |
| 650 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 651 | field, |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 652 | stat_f[domain][field].name, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 653 | stats[ST_F_PID].u.u32); |
| 654 | break; |
| 655 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 656 | case STATS_DOMAIN_RESOLVERS: |
| 657 | chunk_appendf(out, "N.%d.%s:", field, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 658 | stat_f[domain][field].name); |
| 659 | break; |
| 660 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 661 | default: |
| 662 | break; |
| 663 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 664 | |
| 665 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 666 | return 0; |
| 667 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 668 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 669 | |
Willy Tarreau | fc8e438 | 2021-06-17 07:22:27 +0200 | [diff] [blame] | 670 | if (flags & STAT_SHOW_FDESC && |
| 671 | !chunk_appendf(out, ":\"%s\"", stat_f[domain][field].desc)) { |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 672 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 673 | } |
| 674 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 675 | if (!chunk_strcat(out, "\n")) |
| 676 | return 0; |
| 677 | } |
| 678 | return 1; |
| 679 | } |
| 680 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 681 | /* Dump all fields from <stats> into <out> using the "show info json" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 682 | static int stats_dump_json_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 683 | const struct field *info, |
| 684 | struct show_stat_ctx *ctx) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 685 | { |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 686 | int started = (ctx->field) ? 1 : 0; |
| 687 | int ready_data = 0; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 688 | |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 689 | if (!started && !chunk_strcat(out, "[")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 690 | return 0; |
| 691 | |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 692 | for (; ctx->field < INF_TOTAL_FIELDS; ctx->field++) { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 693 | int old_len; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 694 | int field = ctx->field; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 695 | |
| 696 | if (!field_format(info, field)) |
| 697 | continue; |
| 698 | |
| 699 | if (started && !chunk_strcat(out, ",")) |
| 700 | goto err; |
| 701 | started = 1; |
| 702 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 703 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 704 | chunk_appendf(out, |
| 705 | "{\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 706 | "\"processNum\":%u,", |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 707 | field, info_fields[field].name, |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 708 | info[INF_PROCESS_NUM].u.u32); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 709 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 710 | goto err; |
| 711 | |
| 712 | if (!stats_emit_json_field_tags(out, &info[field])) |
| 713 | goto err; |
| 714 | |
| 715 | if (!stats_emit_json_data_field(out, &info[field])) |
| 716 | goto err; |
| 717 | |
| 718 | if (!chunk_strcat(out, "}")) |
| 719 | goto err; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 720 | ready_data = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Willy Tarreau | c6b7a97 | 2022-06-10 15:12:21 +0200 | [diff] [blame] | 723 | if (!chunk_strcat(out, "]\n")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 724 | goto err; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 725 | ctx->field = 0; /* we're done */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 726 | return 1; |
| 727 | |
| 728 | err: |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 729 | if (!ready_data) { |
| 730 | /* not enough buffer space for a single entry.. */ |
| 731 | chunk_reset(out); |
| 732 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}\n"); |
| 733 | return 0; /* hard error */ |
| 734 | } |
| 735 | /* push ready data and wait for a new buffer to complete the dump */ |
| 736 | out->data = ready_data; |
| 737 | return 1; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 738 | } |
| 739 | |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 740 | static void stats_print_proxy_field_json(struct buffer *out, |
| 741 | const struct field *stat, |
| 742 | const char *name, |
| 743 | int pos, |
| 744 | uint32_t field_type, |
| 745 | uint32_t iid, |
| 746 | uint32_t sid, |
| 747 | uint32_t pid) |
| 748 | { |
| 749 | const char *obj_type; |
| 750 | switch (field_type) { |
| 751 | case STATS_TYPE_FE: obj_type = "Frontend"; break; |
| 752 | case STATS_TYPE_BE: obj_type = "Backend"; break; |
| 753 | case STATS_TYPE_SO: obj_type = "Listener"; break; |
| 754 | case STATS_TYPE_SV: obj_type = "Server"; break; |
| 755 | default: obj_type = "Unknown"; break; |
| 756 | } |
| 757 | |
| 758 | chunk_appendf(out, |
| 759 | "{" |
| 760 | "\"objType\":\"%s\"," |
| 761 | "\"proxyId\":%u," |
| 762 | "\"id\":%u," |
| 763 | "\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 764 | "\"processNum\":%u,", |
| 765 | obj_type, iid, sid, pos, name, pid); |
| 766 | } |
| 767 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 768 | static void stats_print_rslv_field_json(struct buffer *out, |
| 769 | const struct field *stat, |
| 770 | const char *name, |
| 771 | int pos) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 772 | { |
| 773 | chunk_appendf(out, |
| 774 | "{" |
| 775 | "\"field\":{\"pos\":%d,\"name\":\"%s\"},", |
| 776 | pos, name); |
| 777 | } |
| 778 | |
| 779 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 780 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 781 | static int stats_dump_fields_json(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 782 | const struct field *stats, size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 783 | struct show_stat_ctx *ctx) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 784 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 785 | int flags = ctx->flags; |
| 786 | int domain = ctx->domain; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 787 | int started = (ctx->field) ? 1 : 0; |
| 788 | int ready_data = 0; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 789 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 790 | if (!started && (flags & STAT_STARTED) && !chunk_strcat(out, ",")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 791 | return 0; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 792 | if (!started && !chunk_strcat(out, "[")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 793 | return 0; |
| 794 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 795 | for (; ctx->field < stats_count; ctx->field++) { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 796 | int old_len; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 797 | int field = ctx->field; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 798 | |
| 799 | if (!stats[field].type) |
| 800 | continue; |
| 801 | |
| 802 | if (started && !chunk_strcat(out, ",")) |
| 803 | goto err; |
| 804 | started = 1; |
| 805 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 806 | old_len = out->data; |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 807 | if (domain == STATS_DOMAIN_PROXY) { |
| 808 | stats_print_proxy_field_json(out, &stats[field], |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 809 | stat_f[domain][field].name, |
| 810 | field, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 811 | stats[ST_F_TYPE].u.u32, |
| 812 | stats[ST_F_IID].u.u32, |
| 813 | stats[ST_F_SID].u.u32, |
| 814 | stats[ST_F_PID].u.u32); |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 815 | } else if (domain == STATS_DOMAIN_RESOLVERS) { |
| 816 | stats_print_rslv_field_json(out, &stats[field], |
| 817 | stat_f[domain][field].name, |
| 818 | field); |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 819 | } |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 820 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 821 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 822 | goto err; |
| 823 | |
| 824 | if (!stats_emit_json_field_tags(out, &stats[field])) |
| 825 | goto err; |
| 826 | |
| 827 | if (!stats_emit_json_data_field(out, &stats[field])) |
| 828 | goto err; |
| 829 | |
| 830 | if (!chunk_strcat(out, "}")) |
| 831 | goto err; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 832 | ready_data = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | if (!chunk_strcat(out, "]")) |
| 836 | goto err; |
| 837 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 838 | ctx->field = 0; /* we're done */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 839 | return 1; |
| 840 | |
| 841 | err: |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 842 | if (!ready_data) { |
| 843 | /* not enough buffer space for a single entry.. */ |
| 844 | chunk_reset(out); |
| 845 | if (ctx->flags & STAT_STARTED) |
| 846 | chunk_strcat(out, ","); |
| 847 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}"); |
| 848 | return 0; /* hard error */ |
| 849 | } |
| 850 | /* push ready data and wait for a new buffer to complete the dump */ |
| 851 | out->data = ready_data; |
| 852 | return 1; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 853 | } |
| 854 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 855 | /* Dump all fields from <stats> into <out> using the HTML format. A column is |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 856 | * reserved for the checkbox is STAT_ADMIN is set in <flags>. Some extra info |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 857 | * are provided if STAT_SHLGNDS is present in <flags>. The statistics from |
| 858 | * extra modules are displayed at the end of the lines if STAT_SHMODULES is |
| 859 | * present in <flags>. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 860 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 861 | static int stats_dump_fields_html(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 862 | const struct field *stats, |
| 863 | struct show_stat_ctx *ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 864 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 865 | struct buffer src; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 866 | struct stats_module *mod; |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 867 | int flags = ctx->flags; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 868 | int i = 0, j = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 869 | |
| 870 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
| 871 | chunk_appendf(out, |
| 872 | /* name, queue */ |
| 873 | "<tr class=\"frontend\">"); |
| 874 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 875 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 876 | /* Column sub-heading for Enable or Disable server */ |
| 877 | chunk_appendf(out, "<td></td>"); |
| 878 | } |
| 879 | |
| 880 | chunk_appendf(out, |
| 881 | "<td class=ac>" |
| 882 | "<a name=\"%s/Frontend\"></a>" |
| 883 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 884 | "<td colspan=3></td>" |
| 885 | "", |
| 886 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 887 | |
| 888 | chunk_appendf(out, |
| 889 | /* sessions rate : current */ |
| 890 | "<td><u>%s<div class=tips><table class=det>" |
| 891 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 892 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 893 | "", |
| 894 | U2H(stats[ST_F_RATE].u.u32), |
| 895 | U2H(stats[ST_F_CONN_RATE].u.u32), |
| 896 | U2H(stats[ST_F_RATE].u.u32)); |
| 897 | |
| 898 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 899 | chunk_appendf(out, |
| 900 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
| 901 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
| 902 | |
| 903 | chunk_appendf(out, |
| 904 | "</table></div></u></td>" |
| 905 | /* sessions rate : max */ |
| 906 | "<td><u>%s<div class=tips><table class=det>" |
| 907 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 908 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 909 | "", |
| 910 | U2H(stats[ST_F_RATE_MAX].u.u32), |
| 911 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
| 912 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 913 | |
| 914 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 915 | chunk_appendf(out, |
| 916 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
| 917 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
| 918 | |
| 919 | chunk_appendf(out, |
| 920 | "</table></div></u></td>" |
| 921 | /* sessions rate : limit */ |
| 922 | "<td>%s</td>", |
| 923 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
| 924 | |
| 925 | chunk_appendf(out, |
| 926 | /* sessions: current, max, limit, total */ |
| 927 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 928 | "<td><u>%s<div class=tips><table class=det>" |
| 929 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 930 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 931 | "", |
| 932 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 933 | U2H(stats[ST_F_STOT].u.u64), |
| 934 | U2H(stats[ST_F_CONN_TOT].u.u64), |
| 935 | U2H(stats[ST_F_STOT].u.u64)); |
| 936 | |
| 937 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 938 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 939 | chunk_appendf(out, |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 940 | "<tr><th>- HTTP/1 sessions:</th><td>%s</td></tr>" |
| 941 | "<tr><th>- HTTP/2 sessions:</th><td>%s</td></tr>" |
| 942 | "<tr><th>- HTTP/3 sessions:</th><td>%s</td></tr>" |
| 943 | "<tr><th>- other sessions:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 944 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 945 | "<tr><th>- HTTP/1 requests:</th><td>%s</td></tr>" |
| 946 | "<tr><th>- HTTP/2 requests:</th><td>%s</td></tr>" |
| 947 | "<tr><th>- HTTP/3 requests:</th><td>%s</td></tr>" |
| 948 | "<tr><th>- other requests:</th><td>%s</td></tr>" |
| 949 | "", |
| 950 | U2H(stats[ST_F_H1SESS].u.u64), |
| 951 | U2H(stats[ST_F_H2SESS].u.u64), |
| 952 | U2H(stats[ST_F_H3SESS].u.u64), |
| 953 | U2H(stats[ST_F_SESS_OTHER].u.u64), |
| 954 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 955 | U2H(stats[ST_F_H1REQ].u.u64), |
| 956 | U2H(stats[ST_F_H2REQ].u.u64), |
| 957 | U2H(stats[ST_F_H3REQ].u.u64), |
| 958 | U2H(stats[ST_F_REQ_OTHER].u.u64)); |
| 959 | |
| 960 | chunk_appendf(out, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 961 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 962 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 963 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 964 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 965 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 966 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 967 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 968 | "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 969 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 970 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 971 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 972 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 973 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 974 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 975 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 976 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 977 | U2H(stats[ST_F_HRSP_OTHER].u.u64)); |
| 978 | |
| 979 | chunk_appendf(out, |
| 980 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 981 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 982 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 983 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
| 984 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
| 985 | "", |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 986 | U2H(stats[ST_F_INTERCEPTED].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 987 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 988 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 989 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 990 | (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 991 | U2H(stats[ST_F_WREW].u.u64), |
| 992 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | chunk_appendf(out, |
| 996 | "</table></div></u></td>" |
| 997 | /* sessions: lbtot, lastsess */ |
| 998 | "<td></td><td></td>" |
| 999 | /* bytes : in */ |
| 1000 | "<td>%s</td>" |
| 1001 | "", |
| 1002 | U2H(stats[ST_F_BIN].u.u64)); |
| 1003 | |
| 1004 | chunk_appendf(out, |
| 1005 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 1006 | "<td>%s%s<div class=tips><table class=det>" |
| 1007 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 1008 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 1009 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1010 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1011 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1012 | "</table></div>%s</td>", |
| 1013 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1014 | U2H(stats[ST_F_BOUT].u.u64), |
| 1015 | U2H(stats[ST_F_BOUT].u.u64), |
| 1016 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1017 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1018 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1019 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1020 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1021 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 1022 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1023 | |
| 1024 | chunk_appendf(out, |
| 1025 | /* denied: req, resp */ |
| 1026 | "<td>%s</td><td>%s</td>" |
| 1027 | /* errors : request, connect, response */ |
| 1028 | "<td>%s</td><td></td><td></td>" |
| 1029 | /* warnings: retries, redispatches */ |
| 1030 | "<td></td><td></td>" |
| 1031 | /* server status : reflect frontend status */ |
| 1032 | "<td class=ac>%s</td>" |
| 1033 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1034 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1035 | "", |
| 1036 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1037 | U2H(stats[ST_F_EREQ].u.u64), |
| 1038 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1039 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1040 | if (flags & STAT_SHMODULES) { |
| 1041 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1042 | chunk_appendf(out, "<td>"); |
| 1043 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1044 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1045 | chunk_appendf(out, |
| 1046 | "<u>%s<div class=tips><table class=det>", |
| 1047 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1048 | for (j = 0; j < mod->stats_count; ++j) { |
| 1049 | chunk_appendf(out, |
| 1050 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1051 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1052 | ++i; |
| 1053 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1054 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1055 | } else { |
| 1056 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1057 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1058 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1059 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1060 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1064 | } |
| 1065 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
| 1066 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1067 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1068 | /* Column sub-heading for Enable or Disable server */ |
| 1069 | chunk_appendf(out, "<td></td>"); |
| 1070 | } |
| 1071 | |
| 1072 | chunk_appendf(out, |
| 1073 | /* frontend name, listener name */ |
| 1074 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 1075 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 1076 | "", |
| 1077 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1078 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1079 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 1080 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1081 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1082 | chunk_appendf(out, "<div class=tips>"); |
| 1083 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 1084 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1085 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 1086 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 1087 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1088 | else if (*field_str(stats, ST_F_ADDR)) |
| 1089 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1090 | |
Willy Tarreau | 4cfb001 | 2023-05-11 14:49:43 +0200 | [diff] [blame] | 1091 | chunk_appendf(out, "proto=%s, ", field_str(stats, ST_F_PROTO)); |
| 1092 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1093 | /* id */ |
| 1094 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
| 1095 | } |
| 1096 | |
| 1097 | chunk_appendf(out, |
| 1098 | /* queue */ |
| 1099 | "%s</td><td colspan=3></td>" |
| 1100 | /* sessions rate: current, max, limit */ |
| 1101 | "<td colspan=3> </td>" |
| 1102 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 1103 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1104 | "<td>%s</td><td> </td><td> </td>" |
| 1105 | /* bytes: in, out */ |
| 1106 | "<td>%s</td><td>%s</td>" |
| 1107 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1108 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1109 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 1110 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 1111 | |
| 1112 | chunk_appendf(out, |
| 1113 | /* denied: req, resp */ |
| 1114 | "<td>%s</td><td>%s</td>" |
| 1115 | /* errors: request, connect, response */ |
| 1116 | "<td>%s</td><td></td><td></td>" |
| 1117 | /* warnings: retries, redispatches */ |
| 1118 | "<td></td><td></td>" |
| 1119 | /* server status: reflect listener status */ |
| 1120 | "<td class=ac>%s</td>" |
| 1121 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1122 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1123 | "", |
| 1124 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1125 | U2H(stats[ST_F_EREQ].u.u64), |
| 1126 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1127 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1128 | if (flags & STAT_SHMODULES) { |
| 1129 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1130 | chunk_appendf(out, "<td>"); |
| 1131 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1132 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1133 | chunk_appendf(out, |
| 1134 | "<u>%s<div class=tips><table class=det>", |
| 1135 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1136 | for (j = 0; j < mod->stats_count; ++j) { |
| 1137 | chunk_appendf(out, |
| 1138 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1139 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1140 | ++i; |
| 1141 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1142 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1143 | } else { |
| 1144 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1145 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1146 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1147 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1148 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1152 | } |
| 1153 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 1154 | const char *style; |
| 1155 | |
| 1156 | /* determine the style to use depending on the server's state, |
| 1157 | * its health and weight. There isn't a 1-to-1 mapping between |
| 1158 | * state and styles for the cases where the server is (still) |
| 1159 | * up. The reason is that we don't want to report nolb and |
| 1160 | * drain with the same color. |
| 1161 | */ |
| 1162 | |
| 1163 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 1164 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 1165 | style = "down"; |
| 1166 | } |
Florian Apolloner | 39272c2 | 2021-03-30 13:28:35 +0200 | [diff] [blame] | 1167 | else if (strncmp(field_str(stats, ST_F_STATUS), "DOWN ", strlen("DOWN ")) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1168 | style = "going_up"; |
| 1169 | } |
Daniel Corbett | b428517 | 2020-03-28 12:35:50 -0400 | [diff] [blame] | 1170 | else if (strcmp(field_str(stats, ST_F_STATUS), "DRAIN") == 0) { |
| 1171 | style = "draining"; |
| 1172 | } |
Florian Apolloner | 39272c2 | 2021-03-30 13:28:35 +0200 | [diff] [blame] | 1173 | else if (strncmp(field_str(stats, ST_F_STATUS), "NOLB ", strlen("NOLB ")) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1174 | style = "going_down"; |
| 1175 | } |
| 1176 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 1177 | style = "nolb"; |
| 1178 | } |
| 1179 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 1180 | style = "no_check"; |
| 1181 | } |
| 1182 | else if (!stats[ST_F_CHKFAIL].type || |
| 1183 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 1184 | /* no check or max health = UP */ |
| 1185 | if (stats[ST_F_WEIGHT].u.u32) |
| 1186 | style = "up"; |
| 1187 | else |
| 1188 | style = "draining"; |
| 1189 | } |
| 1190 | else { |
| 1191 | style = "going_down"; |
| 1192 | } |
| 1193 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1194 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1195 | chunk_appendf(out, "<tr class=\"maintain\">"); |
| 1196 | else |
| 1197 | chunk_appendf(out, |
| 1198 | "<tr class=\"%s_%s\">", |
| 1199 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
| 1200 | |
| 1201 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1202 | if (flags & STAT_ADMIN) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1203 | chunk_appendf(out, |
David Harrigan | d3db35a | 2016-12-30 12:12:49 +0000 | [diff] [blame] | 1204 | "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 1205 | field_str(stats, ST_F_PXNAME), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1206 | field_str(stats, ST_F_SVNAME)); |
| 1207 | |
| 1208 | chunk_appendf(out, |
| 1209 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 1210 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 1211 | "", |
| 1212 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1213 | (flags & STAT_SHLGNDS) ? "<u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1214 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 1215 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1216 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1217 | chunk_appendf(out, "<div class=tips>"); |
| 1218 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 1219 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1220 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 1221 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 1222 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1223 | else if (*field_str(stats, ST_F_ADDR)) |
| 1224 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1225 | |
| 1226 | /* id */ |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 1227 | chunk_appendf(out, "id: %d, rid: %d", stats[ST_F_SID].u.u32, stats[ST_F_SRID].u.u32); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1228 | |
| 1229 | /* cookie */ |
| 1230 | if (stats[ST_F_COOKIE].type) { |
| 1231 | chunk_appendf(out, ", cookie: '"); |
| 1232 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1233 | chunk_htmlencode(out, &src); |
| 1234 | chunk_appendf(out, "'"); |
| 1235 | } |
| 1236 | |
| 1237 | chunk_appendf(out, "</div>"); |
| 1238 | } |
| 1239 | |
| 1240 | chunk_appendf(out, |
| 1241 | /* queue : current, max, limit */ |
| 1242 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 1243 | /* sessions rate : current, max, limit */ |
| 1244 | "<td>%s</td><td>%s</td><td></td>" |
| 1245 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1246 | (flags & STAT_SHLGNDS) ? "</u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1247 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 1248 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1249 | |
| 1250 | chunk_appendf(out, |
| 1251 | /* sessions: current, max, limit, total */ |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1252 | "<td><u>%s<div class=tips>" |
| 1253 | "<table class=det>" |
| 1254 | "<tr><th>Current active connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1255 | "<tr><th>Current used connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1256 | "<tr><th>Current idle connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1257 | "<tr><th>- unsafe:</th><td>%s</td></tr>" |
| 1258 | "<tr><th>- safe:</th><td>%s</td></tr>" |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1259 | "<tr><th>Estimated need of connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1260 | "<tr><th>Active connections limit:</th><td>%s</td></tr>" |
| 1261 | "<tr><th>Idle connections limit:</th><td>%s</td></tr>" |
| 1262 | "</table></div></u>" |
| 1263 | "</td><td>%s</td><td>%s</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1264 | "<td><u>%s<div class=tips><table class=det>" |
| 1265 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1266 | "", |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1267 | U2H(stats[ST_F_SCUR].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1268 | U2H(stats[ST_F_SCUR].u.u32), |
| 1269 | U2H(stats[ST_F_USED_CONN_CUR].u.u32), |
| 1270 | U2H(stats[ST_F_SRV_ICUR].u.u32), |
| 1271 | U2H(stats[ST_F_IDLE_CONN_CUR].u.u32), |
| 1272 | U2H(stats[ST_F_SAFE_CONN_CUR].u.u32), |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1273 | U2H(stats[ST_F_NEED_CONN_EST].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1274 | |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1275 | LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 1276 | stats[ST_F_SRV_ILIM].type ? U2H(stats[ST_F_SRV_ILIM].u.u32) : "-", |
| 1277 | U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1278 | U2H(stats[ST_F_STOT].u.u64), |
| 1279 | U2H(stats[ST_F_STOT].u.u64)); |
| 1280 | |
| 1281 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1282 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1283 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1284 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1285 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1286 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1287 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1288 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1289 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1290 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1291 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1292 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1293 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1294 | "<tr><th>Internal error:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1295 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1296 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1297 | U2H(stats[ST_F_REUSE].u.u64), |
| 1298 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1299 | (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0, |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1300 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1301 | U2H(stats[ST_F_HRSP_1XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1302 | (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1303 | U2H(stats[ST_F_HRSP_2XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1304 | (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1305 | U2H(stats[ST_F_HRSP_3XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1306 | (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1307 | U2H(stats[ST_F_HRSP_4XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1308 | (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1309 | U2H(stats[ST_F_HRSP_5XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1310 | (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1311 | U2H(stats[ST_F_HRSP_OTHER].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1312 | (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1313 | U2H(stats[ST_F_WREW].u.u64), |
| 1314 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1315 | } |
| 1316 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1317 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1318 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1319 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1320 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1321 | U2H(stats[ST_F_CT_MAX].u.u32), U2H(stats[ST_F_CTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1322 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1323 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1324 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1325 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1326 | U2H(stats[ST_F_TT_MAX].u.u32), U2H(stats[ST_F_TTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1327 | |
| 1328 | chunk_appendf(out, |
| 1329 | "</table></div></u></td>" |
| 1330 | /* sessions: lbtot, last */ |
| 1331 | "<td>%s</td><td>%s</td>", |
| 1332 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1333 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
| 1334 | |
| 1335 | chunk_appendf(out, |
| 1336 | /* bytes : in, out */ |
| 1337 | "<td>%s</td><td>%s</td>" |
| 1338 | /* denied: req, resp */ |
| 1339 | "<td></td><td>%s</td>" |
| 1340 | /* errors : request, connect */ |
| 1341 | "<td></td><td>%s</td>" |
| 1342 | /* errors : response */ |
| 1343 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1344 | /* warnings: retries, redispatches */ |
| 1345 | "<td>%lld</td><td>%lld</td>" |
| 1346 | "", |
| 1347 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 1348 | U2H(stats[ST_F_DRESP].u.u64), |
| 1349 | U2H(stats[ST_F_ECON].u.u64), |
| 1350 | U2H(stats[ST_F_ERESP].u.u64), |
| 1351 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1352 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1353 | (long long)stats[ST_F_WRETR].u.u64, |
| 1354 | (long long)stats[ST_F_WREDIS].u.u64); |
| 1355 | |
| 1356 | /* status, last change */ |
| 1357 | chunk_appendf(out, "<td class=ac>"); |
| 1358 | |
| 1359 | /* FIXME!!!! |
| 1360 | * LASTCHG should contain the last change for *this* server and must be computed |
| 1361 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 1362 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 1363 | */ |
| 1364 | |
| 1365 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1366 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1367 | chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); |
| 1368 | } |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1369 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1370 | chunk_strcat(out, "<i>no check</i>"); |
| 1371 | } |
| 1372 | else { |
| 1373 | chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1374 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1375 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
| 1376 | chunk_strcat(out, " ↑"); |
| 1377 | } |
| 1378 | else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) |
| 1379 | chunk_strcat(out, " ↓"); |
| 1380 | } |
| 1381 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1382 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1383 | stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { |
| 1384 | chunk_appendf(out, |
| 1385 | "</td><td class=ac><u> %s", |
| 1386 | field_str(stats, ST_F_AGENT_STATUS)); |
| 1387 | |
| 1388 | if (stats[ST_F_AGENT_CODE].type) |
| 1389 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
| 1390 | |
| 1391 | if (stats[ST_F_AGENT_DURATION].type) |
| 1392 | chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); |
| 1393 | |
| 1394 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC)); |
| 1395 | |
| 1396 | if (*field_str(stats, ST_F_LAST_AGT)) { |
| 1397 | chunk_appendf(out, ": "); |
| 1398 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
| 1399 | chunk_htmlencode(out, &src); |
| 1400 | } |
| 1401 | chunk_appendf(out, "</div></u>"); |
| 1402 | } |
| 1403 | else if (stats[ST_F_CHECK_STATUS].type) { |
| 1404 | chunk_appendf(out, |
| 1405 | "</td><td class=ac><u> %s", |
| 1406 | field_str(stats, ST_F_CHECK_STATUS)); |
| 1407 | |
| 1408 | if (stats[ST_F_CHECK_CODE].type) |
| 1409 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
| 1410 | |
| 1411 | if (stats[ST_F_CHECK_DURATION].type) |
| 1412 | chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); |
| 1413 | |
| 1414 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC)); |
| 1415 | |
| 1416 | if (*field_str(stats, ST_F_LAST_CHK)) { |
| 1417 | chunk_appendf(out, ": "); |
| 1418 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
| 1419 | chunk_htmlencode(out, &src); |
| 1420 | } |
| 1421 | chunk_appendf(out, "</div></u>"); |
| 1422 | } |
| 1423 | else |
| 1424 | chunk_appendf(out, "</td><td>"); |
| 1425 | |
| 1426 | chunk_appendf(out, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1427 | /* weight / uweight */ |
| 1428 | "</td><td class=ac>%d/%d</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1429 | /* act, bck */ |
| 1430 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 1431 | "", |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1432 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1433 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 1434 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 1435 | |
| 1436 | /* check failures: unique, fatal, down time */ |
| 1437 | if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) { |
| 1438 | chunk_appendf(out, "<td class=ac colspan=3>resolution</td>"); |
| 1439 | } |
| 1440 | else if (stats[ST_F_CHKFAIL].type) { |
| 1441 | chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64); |
| 1442 | |
| 1443 | if (stats[ST_F_HANAFAIL].type) |
| 1444 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
| 1445 | |
| 1446 | chunk_appendf(out, |
| 1447 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 1448 | "<td>%lld</td><td>%s</td>" |
| 1449 | "", |
| 1450 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 1451 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 1452 | } |
| 1453 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 1454 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
| 1455 | chunk_appendf(out, |
| 1456 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 1457 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 1458 | } |
| 1459 | else |
| 1460 | chunk_appendf(out, "<td colspan=3></td>"); |
| 1461 | |
| 1462 | /* throttle */ |
| 1463 | if (stats[ST_F_THROTTLE].type) |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1464 | chunk_appendf(out, "<td class=ac>%d %%</td>\n", stats[ST_F_THROTTLE].u.u32); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1465 | else |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1466 | chunk_appendf(out, "<td class=ac>-</td>"); |
| 1467 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1468 | if (flags & STAT_SHMODULES) { |
| 1469 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1470 | chunk_appendf(out, "<td>"); |
| 1471 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1472 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1473 | chunk_appendf(out, |
| 1474 | "<u>%s<div class=tips><table class=det>", |
| 1475 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1476 | for (j = 0; j < mod->stats_count; ++j) { |
| 1477 | chunk_appendf(out, |
| 1478 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1479 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1480 | ++i; |
| 1481 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1482 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1483 | } else { |
| 1484 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1485 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1486 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1487 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1488 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | chunk_appendf(out, "</tr>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1492 | } |
| 1493 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
| 1494 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1495 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1496 | /* Column sub-heading for Enable or Disable server */ |
| 1497 | chunk_appendf(out, "<td></td>"); |
| 1498 | } |
| 1499 | chunk_appendf(out, |
| 1500 | "<td class=ac>" |
| 1501 | /* name */ |
| 1502 | "%s<a name=\"%s/Backend\"></a>" |
| 1503 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 1504 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1505 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1506 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 1507 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1508 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1509 | /* balancing */ |
| 1510 | chunk_appendf(out, "<div class=tips>balancing: %s", |
| 1511 | field_str(stats, ST_F_ALGO)); |
| 1512 | |
| 1513 | /* cookie */ |
| 1514 | if (stats[ST_F_COOKIE].type) { |
| 1515 | chunk_appendf(out, ", cookie: '"); |
| 1516 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1517 | chunk_htmlencode(out, &src); |
| 1518 | chunk_appendf(out, "'"); |
| 1519 | } |
| 1520 | chunk_appendf(out, "</div>"); |
| 1521 | } |
| 1522 | |
| 1523 | chunk_appendf(out, |
| 1524 | "%s</td>" |
| 1525 | /* queue : current, max */ |
| 1526 | "<td>%s</td><td>%s</td><td></td>" |
| 1527 | /* sessions rate : current, max, limit */ |
| 1528 | "<td>%s</td><td>%s</td><td></td>" |
| 1529 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1530 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1531 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 1532 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1533 | |
| 1534 | chunk_appendf(out, |
| 1535 | /* sessions: current, max, limit, total */ |
| 1536 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1537 | "<td><u>%s<div class=tips><table class=det>" |
| 1538 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1539 | "", |
Willy Tarreau | 8e0f175 | 2016-12-12 15:07:29 +0100 | [diff] [blame] | 1540 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1541 | U2H(stats[ST_F_STOT].u.u64), |
| 1542 | U2H(stats[ST_F_STOT].u.u64)); |
| 1543 | |
| 1544 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1545 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 1546 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1547 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1548 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1549 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1550 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1551 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1552 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1553 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1554 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1555 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1556 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1557 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 1558 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1559 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1560 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1561 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1562 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1563 | U2H(stats[ST_F_REUSE].u.u64), |
| 1564 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1565 | (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1566 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1567 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 1568 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 1569 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 1570 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 1571 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 1572 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 1573 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 1574 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Willy Tarreau | feead3a | 2018-12-14 13:48:44 +0100 | [diff] [blame] | 1575 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1576 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 1577 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 1578 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 1579 | (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1580 | U2H(stats[ST_F_WREW].u.u64), |
| 1581 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1582 | } |
| 1583 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1584 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1585 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1586 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1587 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1588 | U2H(stats[ST_F_CT_MAX].u.u32), U2H(stats[ST_F_CTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1589 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1590 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1591 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1592 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1593 | U2H(stats[ST_F_TT_MAX].u.u32), U2H(stats[ST_F_TTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1594 | |
| 1595 | chunk_appendf(out, |
| 1596 | "</table></div></u></td>" |
| 1597 | /* sessions: lbtot, last */ |
| 1598 | "<td>%s</td><td>%s</td>" |
| 1599 | /* bytes: in */ |
| 1600 | "<td>%s</td>" |
| 1601 | "", |
| 1602 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1603 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 1604 | U2H(stats[ST_F_BIN].u.u64)); |
| 1605 | |
| 1606 | chunk_appendf(out, |
| 1607 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 1608 | "<td>%s%s<div class=tips><table class=det>" |
| 1609 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 1610 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 1611 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1612 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1613 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1614 | "</table></div>%s</td>", |
| 1615 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1616 | U2H(stats[ST_F_BOUT].u.u64), |
| 1617 | U2H(stats[ST_F_BOUT].u.u64), |
| 1618 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1619 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1620 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1621 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1622 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1623 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 1624 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1625 | |
| 1626 | chunk_appendf(out, |
| 1627 | /* denied: req, resp */ |
| 1628 | "<td>%s</td><td>%s</td>" |
| 1629 | /* errors : request, connect */ |
| 1630 | "<td></td><td>%s</td>" |
| 1631 | /* errors : response */ |
| 1632 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1633 | /* warnings: retries, redispatches */ |
| 1634 | "<td>%lld</td><td>%lld</td>" |
| 1635 | /* backend status: reflect backend status (up/down): we display UP |
| 1636 | * if the backend has known working servers or if it has no server at |
| 1637 | * all (eg: for stats). Then we display the total weight, number of |
| 1638 | * active and backups. */ |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1639 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d/%d</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1640 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 1641 | "", |
| 1642 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1643 | U2H(stats[ST_F_ECON].u.u64), |
| 1644 | U2H(stats[ST_F_ERESP].u.u64), |
| 1645 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1646 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1647 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 1648 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 1649 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1650 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1651 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 1652 | |
| 1653 | chunk_appendf(out, |
| 1654 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 1655 | "<td class=ac> </td><td>%d</td>" |
| 1656 | "<td>%s</td>" |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1657 | "<td></td>", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1658 | stats[ST_F_CHKDOWN].u.u32, |
| 1659 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1660 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1661 | if (flags & STAT_SHMODULES) { |
| 1662 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1663 | chunk_appendf(out, "<td>"); |
| 1664 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1665 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1666 | chunk_appendf(out, |
| 1667 | "<u>%s<div class=tips><table class=det>", |
| 1668 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1669 | for (j = 0; j < mod->stats_count; ++j) { |
| 1670 | chunk_appendf(out, |
| 1671 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1672 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1673 | ++i; |
| 1674 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1675 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1676 | } else { |
| 1677 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1678 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1679 | |
| 1680 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1681 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1682 | } |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1683 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1684 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1685 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1686 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1687 | return 1; |
| 1688 | } |
| 1689 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 1690 | int stats_dump_one_line(const struct field *stats, size_t stats_count, |
| 1691 | struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1692 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1693 | struct show_stat_ctx *ctx = appctx->svcctx; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1694 | int ret; |
| 1695 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1696 | if (ctx->flags & STAT_FMT_HTML) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1697 | ret = stats_dump_fields_html(&trash_chunk, stats, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1698 | else if (ctx->flags & STAT_FMT_TYPED) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1699 | ret = stats_dump_fields_typed(&trash_chunk, stats, stats_count, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1700 | else if (ctx->flags & STAT_FMT_JSON) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1701 | ret = stats_dump_fields_json(&trash_chunk, stats, stats_count, ctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1702 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1703 | ret = stats_dump_fields_csv(&trash_chunk, stats, stats_count, ctx); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1704 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1705 | return ret; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1706 | } |
| 1707 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1708 | /* Fill <stats> with the frontend statistics. <stats> is preallocated array of |
Christopher Faulet | d808f17 | 2021-01-22 17:33:22 +0100 | [diff] [blame] | 1709 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 1710 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 1711 | * this value, or if the selected field is not implemented for frontends, the |
| 1712 | * function returns 0, otherwise, it returns 1. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1713 | */ |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1714 | int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len, |
| 1715 | enum stat_field *selected_field) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1716 | { |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1717 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1718 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1719 | if (len < ST_F_TOTAL_FIELDS) |
| 1720 | return 0; |
| 1721 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1722 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
Christopher Faulet | 8596bfb | 2021-01-25 15:16:41 +0100 | [diff] [blame] | 1723 | struct field metric = { 0 }; |
| 1724 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1725 | switch (current_field) { |
| 1726 | case ST_F_PXNAME: |
| 1727 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1728 | break; |
| 1729 | case ST_F_SVNAME: |
| 1730 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
| 1731 | break; |
| 1732 | case ST_F_MODE: |
| 1733 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1734 | break; |
| 1735 | case ST_F_SCUR: |
| 1736 | metric = mkf_u32(0, px->feconn); |
| 1737 | break; |
| 1738 | case ST_F_SMAX: |
| 1739 | metric = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 1740 | break; |
| 1741 | case ST_F_SLIM: |
| 1742 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 1743 | break; |
| 1744 | case ST_F_STOT: |
| 1745 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 1746 | break; |
| 1747 | case ST_F_BIN: |
| 1748 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 1749 | break; |
| 1750 | case ST_F_BOUT: |
| 1751 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 1752 | break; |
| 1753 | case ST_F_DREQ: |
| 1754 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 1755 | break; |
| 1756 | case ST_F_DRESP: |
| 1757 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 1758 | break; |
| 1759 | case ST_F_EREQ: |
| 1760 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 1761 | break; |
| 1762 | case ST_F_DCON: |
| 1763 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); |
| 1764 | break; |
| 1765 | case ST_F_DSES: |
| 1766 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); |
| 1767 | break; |
Aurelien DARRAGON | cddec0a | 2022-09-09 15:58:57 +0200 | [diff] [blame] | 1768 | case ST_F_STATUS: { |
| 1769 | const char *state; |
| 1770 | |
| 1771 | if (px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) |
| 1772 | state = "STOP"; |
| 1773 | else if (px->flags & PR_FL_PAUSED) |
| 1774 | state = "PAUSED"; |
| 1775 | else |
| 1776 | state = "OPEN"; |
| 1777 | metric = mkf_str(FO_STATUS, state); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1778 | break; |
Aurelien DARRAGON | cddec0a | 2022-09-09 15:58:57 +0200 | [diff] [blame] | 1779 | } |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1780 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 1781 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1782 | break; |
| 1783 | case ST_F_IID: |
| 1784 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1785 | break; |
| 1786 | case ST_F_SID: |
| 1787 | metric = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 1788 | break; |
| 1789 | case ST_F_TYPE: |
| 1790 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 1791 | break; |
| 1792 | case ST_F_RATE: |
| 1793 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 1794 | break; |
| 1795 | case ST_F_RATE_LIM: |
| 1796 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 1797 | break; |
| 1798 | case ST_F_RATE_MAX: |
| 1799 | metric = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 1800 | break; |
| 1801 | case ST_F_WREW: |
| 1802 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites); |
| 1803 | break; |
| 1804 | case ST_F_EINT: |
| 1805 | metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors); |
| 1806 | break; |
| 1807 | case ST_F_HRSP_1XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1808 | if (px->mode == PR_MODE_HTTP) |
| 1809 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1810 | break; |
| 1811 | case ST_F_HRSP_2XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1812 | if (px->mode == PR_MODE_HTTP) |
| 1813 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1814 | break; |
| 1815 | case ST_F_HRSP_3XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1816 | if (px->mode == PR_MODE_HTTP) |
| 1817 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1818 | break; |
| 1819 | case ST_F_HRSP_4XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1820 | if (px->mode == PR_MODE_HTTP) |
| 1821 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1822 | break; |
| 1823 | case ST_F_HRSP_5XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1824 | if (px->mode == PR_MODE_HTTP) |
| 1825 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1826 | break; |
| 1827 | case ST_F_HRSP_OTHER: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1828 | if (px->mode == PR_MODE_HTTP) |
| 1829 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1830 | break; |
| 1831 | case ST_F_INTERCEPTED: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1832 | if (px->mode == PR_MODE_HTTP) |
| 1833 | metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1834 | break; |
| 1835 | case ST_F_CACHE_LOOKUPS: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1836 | if (px->mode == PR_MODE_HTTP) |
| 1837 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1838 | break; |
| 1839 | case ST_F_CACHE_HITS: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1840 | if (px->mode == PR_MODE_HTTP) |
| 1841 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1842 | break; |
| 1843 | case ST_F_REQ_RATE: |
| 1844 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 1845 | break; |
| 1846 | case ST_F_REQ_RATE_MAX: |
| 1847 | metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 1848 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1849 | case ST_F_REQ_TOT: { |
| 1850 | int i; |
| 1851 | uint64_t total_req; |
| 1852 | size_t nb_reqs = |
| 1853 | sizeof(px->fe_counters.p.http.cum_req) / sizeof(*px->fe_counters.p.http.cum_req); |
| 1854 | |
| 1855 | total_req = 0; |
| 1856 | for (i = 0; i < nb_reqs; i++) |
| 1857 | total_req += px->fe_counters.p.http.cum_req[i]; |
| 1858 | metric = mkf_u64(FN_COUNTER, total_req); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1859 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1860 | } |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1861 | case ST_F_COMP_IN: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 1862 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in[COMP_DIR_RES]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1863 | break; |
| 1864 | case ST_F_COMP_OUT: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 1865 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out[COMP_DIR_RES]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1866 | break; |
| 1867 | case ST_F_COMP_BYP: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 1868 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp[COMP_DIR_RES]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1869 | break; |
| 1870 | case ST_F_COMP_RSP: |
| 1871 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 1872 | break; |
| 1873 | case ST_F_CONN_RATE: |
| 1874 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 1875 | break; |
| 1876 | case ST_F_CONN_RATE_MAX: |
| 1877 | metric = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 1878 | break; |
| 1879 | case ST_F_CONN_TOT: |
| 1880 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 1881 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1882 | case ST_F_SESS_OTHER: { |
| 1883 | int i; |
| 1884 | uint64_t total_sess; |
| 1885 | size_t nb_sess = |
| 1886 | sizeof(px->fe_counters.cum_sess_ver) / sizeof(*px->fe_counters.cum_sess_ver); |
| 1887 | |
| 1888 | total_sess = px->fe_counters.cum_sess; |
| 1889 | for (i = 0; i < nb_sess; i++) |
| 1890 | total_sess -= px->fe_counters.cum_sess_ver[i]; |
Frédéric Lécaille | d97d1d7 | 2023-02-06 09:23:56 +0100 | [diff] [blame] | 1891 | total_sess = (int64_t)total_sess < 0 ? 0 : total_sess; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1892 | metric = mkf_u64(FN_COUNTER, total_sess); |
| 1893 | break; |
| 1894 | } |
| 1895 | case ST_F_H1SESS: |
| 1896 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[0]); |
| 1897 | break; |
| 1898 | case ST_F_H2SESS: |
| 1899 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[1]); |
| 1900 | break; |
| 1901 | case ST_F_H3SESS: |
| 1902 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[2]); |
| 1903 | break; |
| 1904 | case ST_F_REQ_OTHER: |
| 1905 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[0]); |
| 1906 | break; |
| 1907 | case ST_F_H1REQ: |
| 1908 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[1]); |
| 1909 | break; |
| 1910 | case ST_F_H2REQ: |
| 1911 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[2]); |
| 1912 | break; |
| 1913 | case ST_F_H3REQ: |
| 1914 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[3]); |
| 1915 | break; |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1916 | default: |
Christopher Faulet | d808f17 | 2021-01-22 17:33:22 +0100 | [diff] [blame] | 1917 | /* not used for frontends. If a specific metric |
| 1918 | * is requested, return an error. Otherwise continue. |
| 1919 | */ |
| 1920 | if (selected_field != NULL) |
| 1921 | return 0; |
| 1922 | continue; |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1923 | } |
| 1924 | stats[current_field] = metric; |
| 1925 | if (selected_field != NULL) |
| 1926 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1927 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1928 | return 1; |
| 1929 | } |
| 1930 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1931 | /* Dumps a frontend's line to the local trash buffer for the current proxy <px> |
| 1932 | * and uses the state from stream connector <sc>. The caller is responsible for |
| 1933 | * clearing the local trash buffer if needed. Returns non-zero if it emits |
| 1934 | * anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1935 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 1936 | static int stats_dump_fe_stats(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1937 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 1938 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1939 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1940 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 1941 | struct stats_module *mod; |
| 1942 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1943 | |
| 1944 | if (!(px->cap & PR_CAP_FE)) |
| 1945 | return 0; |
| 1946 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1947 | if ((ctx->flags & STAT_BOUND) && !(ctx->type & (1 << STATS_TYPE_FE))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1948 | return 0; |
| 1949 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1950 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 1951 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1952 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1953 | return 0; |
| 1954 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1955 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 1956 | void *counters; |
| 1957 | |
| 1958 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE)) { |
| 1959 | stats_count += mod->stats_count; |
| 1960 | continue; |
| 1961 | } |
| 1962 | |
| 1963 | counters = EXTRA_COUNTERS_GET(px->extra_counters_fe, mod); |
| 1964 | mod->fill_stats(counters, stats + stats_count); |
| 1965 | stats_count += mod->stats_count; |
| 1966 | } |
| 1967 | |
| 1968 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1971 | /* Fill <stats> with the listener statistics. <stats> is preallocated array of |
| 1972 | * length <len>. The length of the array must be at least ST_F_TOTAL_FIELDS. If |
| 1973 | * this length is less then this value, the function returns 0, otherwise, it |
| 1974 | * returns 1. If selected_field is != NULL, only fill this one. <flags> can |
| 1975 | * take the value STAT_SHLGNDS. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1976 | */ |
| 1977 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1978 | struct field *stats, int len, enum stat_field *selected_field) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1979 | { |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1980 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 1981 | struct buffer *out = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1982 | |
| 1983 | if (len < ST_F_TOTAL_FIELDS) |
| 1984 | return 0; |
| 1985 | |
| 1986 | if (!l->counters) |
| 1987 | return 0; |
| 1988 | |
| 1989 | chunk_reset(out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1990 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1991 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 1992 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1993 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1994 | switch (current_field) { |
| 1995 | case ST_F_PXNAME: |
| 1996 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1997 | break; |
| 1998 | case ST_F_SVNAME: |
| 1999 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name); |
| 2000 | break; |
| 2001 | case ST_F_MODE: |
| 2002 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 2003 | break; |
| 2004 | case ST_F_SCUR: |
| 2005 | metric = mkf_u32(0, l->nbconn); |
| 2006 | break; |
| 2007 | case ST_F_SMAX: |
| 2008 | metric = mkf_u32(FN_MAX, l->counters->conn_max); |
| 2009 | break; |
| 2010 | case ST_F_SLIM: |
Willy Tarreau | 758c69d | 2023-01-12 18:59:37 +0100 | [diff] [blame] | 2011 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, l->bind_conf->maxconn); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2012 | break; |
| 2013 | case ST_F_STOT: |
| 2014 | metric = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 2015 | break; |
| 2016 | case ST_F_BIN: |
| 2017 | metric = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 2018 | break; |
| 2019 | case ST_F_BOUT: |
| 2020 | metric = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 2021 | break; |
| 2022 | case ST_F_DREQ: |
| 2023 | metric = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 2024 | break; |
| 2025 | case ST_F_DRESP: |
| 2026 | metric = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 2027 | break; |
| 2028 | case ST_F_EREQ: |
| 2029 | metric = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 2030 | break; |
| 2031 | case ST_F_DCON: |
| 2032 | metric = mkf_u64(FN_COUNTER, l->counters->denied_conn); |
| 2033 | break; |
| 2034 | case ST_F_DSES: |
| 2035 | metric = mkf_u64(FN_COUNTER, l->counters->denied_sess); |
| 2036 | break; |
| 2037 | case ST_F_STATUS: |
William Dauchy | 3679d0c | 2021-02-14 23:22:55 +0100 | [diff] [blame] | 2038 | metric = mkf_str(FO_STATUS, li_status_st[get_li_status(l)]); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2039 | break; |
| 2040 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2041 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2042 | break; |
| 2043 | case ST_F_IID: |
| 2044 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2045 | break; |
| 2046 | case ST_F_SID: |
| 2047 | metric = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 2048 | break; |
| 2049 | case ST_F_TYPE: |
| 2050 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 2051 | break; |
| 2052 | case ST_F_WREW: |
| 2053 | metric = mkf_u64(FN_COUNTER, l->counters->failed_rewrites); |
| 2054 | break; |
| 2055 | case ST_F_EINT: |
| 2056 | metric = mkf_u64(FN_COUNTER, l->counters->internal_errors); |
| 2057 | break; |
| 2058 | case ST_F_ADDR: |
| 2059 | if (flags & STAT_SHLGNDS) { |
| 2060 | char str[INET6_ADDRSTRLEN]; |
| 2061 | int port; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2062 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2063 | port = get_host_port(&l->rx.addr); |
| 2064 | switch (addr_to_str(&l->rx.addr, str, sizeof(str))) { |
| 2065 | case AF_INET: |
| 2066 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2067 | chunk_appendf(out, "%s:%d", str, port); |
| 2068 | break; |
| 2069 | case AF_INET6: |
| 2070 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2071 | chunk_appendf(out, "[%s]:%d", str, port); |
| 2072 | break; |
| 2073 | case AF_UNIX: |
| 2074 | metric = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 2075 | break; |
| 2076 | case -1: |
| 2077 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2078 | chunk_strcat(out, strerror(errno)); |
| 2079 | break; |
| 2080 | default: /* address family not supported */ |
| 2081 | break; |
| 2082 | } |
| 2083 | } |
| 2084 | break; |
Willy Tarreau | 4cfb001 | 2023-05-11 14:49:43 +0200 | [diff] [blame] | 2085 | case ST_F_PROTO: |
| 2086 | metric = mkf_str(FO_STATUS, l->rx.proto->name); |
| 2087 | break; |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2088 | default: |
| 2089 | /* not used for listen. If a specific metric |
| 2090 | * is requested, return an error. Otherwise continue. |
| 2091 | */ |
| 2092 | if (selected_field != NULL) |
| 2093 | return 0; |
| 2094 | continue; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2095 | } |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2096 | stats[current_field] = metric; |
| 2097 | if (selected_field != NULL) |
| 2098 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2099 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2100 | return 1; |
| 2101 | } |
| 2102 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2103 | /* Dumps a line for listener <l> and proxy <px> to the local trash buffer and |
| 2104 | * uses the state from stream connector <sc>. The caller is responsible for |
| 2105 | * clearing the local trash buffer if needed. Returns non-zero if it emits |
| 2106 | * anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2107 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2108 | static int stats_dump_li_stats(struct stconn *sc, struct proxy *px, struct listener *l) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2109 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2110 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2111 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2112 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2113 | struct stats_module *mod; |
| 2114 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 2115 | |
| 2116 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2117 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2118 | if (!stats_fill_li_stats(px, l, ctx->flags, stats, |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2119 | ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2120 | return 0; |
| 2121 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2122 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2123 | void *counters; |
| 2124 | |
| 2125 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI)) { |
| 2126 | stats_count += mod->stats_count; |
| 2127 | continue; |
| 2128 | } |
| 2129 | |
| 2130 | counters = EXTRA_COUNTERS_GET(l->extra_counters, mod); |
| 2131 | mod->fill_stats(counters, stats + stats_count); |
| 2132 | stats_count += mod->stats_count; |
| 2133 | } |
| 2134 | |
| 2135 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | enum srv_stats_state { |
| 2139 | SRV_STATS_STATE_DOWN = 0, |
| 2140 | SRV_STATS_STATE_DOWN_AGENT, |
| 2141 | SRV_STATS_STATE_GOING_UP, |
| 2142 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 2143 | SRV_STATS_STATE_UP, |
| 2144 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 2145 | SRV_STATS_STATE_NOLB, |
| 2146 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 2147 | SRV_STATS_STATE_DRAIN, |
| 2148 | SRV_STATS_STATE_DRAIN_AGENT, |
| 2149 | SRV_STATS_STATE_NO_CHECK, |
| 2150 | |
| 2151 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 2152 | }; |
| 2153 | |
| 2154 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 2155 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 2156 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 2157 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 2158 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 2159 | [SRV_STATS_STATE_UP] = "UP", |
| 2160 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 2161 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 2162 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 2163 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 2164 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 2165 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 2166 | }; |
| 2167 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2168 | /* Compute server state helper |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2169 | */ |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2170 | static void stats_fill_sv_stats_computestate(struct server *sv, struct server *ref, |
| 2171 | enum srv_stats_state *state) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2172 | { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2173 | if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2174 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 2175 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2176 | *state = SRV_STATS_STATE_UP_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2177 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2178 | *state = SRV_STATS_STATE_UP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2179 | } |
| 2180 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2181 | if (sv->cur_admin & SRV_ADMF_DRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2182 | if (ref->agent.state & CHK_ST_ENABLED) |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2183 | *state = SRV_STATS_STATE_DRAIN_AGENT; |
| 2184 | else if (*state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 2185 | *state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2186 | else |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2187 | *state = SRV_STATS_STATE_DRAIN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2188 | } |
| 2189 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2190 | if (*state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 2191 | *state = SRV_STATS_STATE_NO_CHECK; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2192 | } |
| 2193 | } |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2194 | else if (sv->cur_state == SRV_ST_STOPPING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2195 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 2196 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2197 | *state = SRV_STATS_STATE_NOLB; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2198 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2199 | *state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2200 | } |
| 2201 | } |
| 2202 | else { /* stopped */ |
| 2203 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2204 | *state = SRV_STATS_STATE_DOWN_AGENT; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2205 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2206 | *state = SRV_STATS_STATE_DOWN; /* DOWN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2207 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2208 | *state = SRV_STATS_STATE_GOING_UP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2209 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2210 | *state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2211 | } |
| 2212 | } |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2213 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2214 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2215 | /* Fill <stats> with the backend statistics. <stats> is preallocated array of |
| 2216 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 2217 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 2218 | * this value, or if the selected field is not implemented for servers, the |
| 2219 | * function returns 0, otherwise, it returns 1. <flags> can take the value |
| 2220 | * STAT_SHLGNDS. |
| 2221 | */ |
| 2222 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 2223 | struct field *stats, int len, |
| 2224 | enum stat_field *selected_field) |
| 2225 | { |
| 2226 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
| 2227 | struct server *via = sv->track ? sv->track : sv; |
| 2228 | struct server *ref = via; |
| 2229 | enum srv_stats_state state = 0; |
| 2230 | char str[INET6_ADDRSTRLEN]; |
| 2231 | struct buffer *out = get_trash_chunk(); |
| 2232 | char *fld_status; |
| 2233 | long long srv_samples_counter; |
| 2234 | unsigned int srv_samples_window = TIME_STATS_SAMPLES; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2235 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2236 | if (len < ST_F_TOTAL_FIELDS) |
| 2237 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2238 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2239 | chunk_reset(out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2240 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2241 | /* compute state for later use */ |
| 2242 | if (selected_field == NULL || *selected_field == ST_F_STATUS || |
| 2243 | *selected_field == ST_F_CHECK_RISE || *selected_field == ST_F_CHECK_FALL || |
| 2244 | *selected_field == ST_F_CHECK_HEALTH || *selected_field == ST_F_HANAFAIL) { |
| 2245 | /* we have "via" which is the tracked server as described in the configuration, |
| 2246 | * and "ref" which is the checked server and the end of the chain. |
| 2247 | */ |
| 2248 | while (ref->track) |
| 2249 | ref = ref->track; |
| 2250 | stats_fill_sv_stats_computestate(sv, ref, &state); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2251 | } |
| 2252 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2253 | /* compue time values for later use */ |
| 2254 | if (selected_field == NULL || *selected_field == ST_F_QTIME || |
| 2255 | *selected_field == ST_F_CTIME || *selected_field == ST_F_RTIME || |
| 2256 | *selected_field == ST_F_TTIME) { |
| 2257 | srv_samples_counter = (px->mode == PR_MODE_HTTP) ? sv->counters.p.http.cum_req : sv->counters.cum_lbconn; |
| 2258 | if (srv_samples_counter < TIME_STATS_SAMPLES && srv_samples_counter > 0) |
| 2259 | srv_samples_window = srv_samples_counter; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2260 | } |
| 2261 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2262 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 2263 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2264 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2265 | switch (current_field) { |
| 2266 | case ST_F_PXNAME: |
| 2267 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 2268 | break; |
| 2269 | case ST_F_SVNAME: |
| 2270 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id); |
| 2271 | break; |
| 2272 | case ST_F_MODE: |
| 2273 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Christopher Faulet | 3888b8c | 2021-01-27 13:32:25 +0100 | [diff] [blame] | 2274 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2275 | case ST_F_QCUR: |
Willy Tarreau | a057045 | 2021-06-18 09:30:30 +0200 | [diff] [blame] | 2276 | metric = mkf_u32(0, sv->queue.length); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2277 | break; |
| 2278 | case ST_F_QMAX: |
| 2279 | metric = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 2280 | break; |
| 2281 | case ST_F_SCUR: |
| 2282 | metric = mkf_u32(0, sv->cur_sess); |
| 2283 | break; |
| 2284 | case ST_F_SMAX: |
| 2285 | metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 2286 | break; |
| 2287 | case ST_F_SLIM: |
| 2288 | if (sv->maxconn) |
| 2289 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 2290 | break; |
| 2291 | case ST_F_SRV_ICUR: |
| 2292 | metric = mkf_u32(0, sv->curr_idle_conns); |
| 2293 | break; |
| 2294 | case ST_F_SRV_ILIM: |
| 2295 | if (sv->max_idle_conns != -1) |
| 2296 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->max_idle_conns); |
| 2297 | break; |
| 2298 | case ST_F_STOT: |
| 2299 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 2300 | break; |
| 2301 | case ST_F_BIN: |
| 2302 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 2303 | break; |
| 2304 | case ST_F_BOUT: |
| 2305 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 2306 | break; |
| 2307 | case ST_F_DRESP: |
| 2308 | metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp); |
| 2309 | break; |
| 2310 | case ST_F_ECON: |
| 2311 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 2312 | break; |
| 2313 | case ST_F_ERESP: |
| 2314 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 2315 | break; |
| 2316 | case ST_F_WRETR: |
| 2317 | metric = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 2318 | break; |
| 2319 | case ST_F_WREDIS: |
| 2320 | metric = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 2321 | break; |
| 2322 | case ST_F_WREW: |
| 2323 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites); |
| 2324 | break; |
| 2325 | case ST_F_EINT: |
| 2326 | metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors); |
| 2327 | break; |
| 2328 | case ST_F_CONNECT: |
| 2329 | metric = mkf_u64(FN_COUNTER, sv->counters.connect); |
| 2330 | break; |
| 2331 | case ST_F_REUSE: |
| 2332 | metric = mkf_u64(FN_COUNTER, sv->counters.reuse); |
| 2333 | break; |
| 2334 | case ST_F_IDLE_CONN_CUR: |
| 2335 | metric = mkf_u32(0, sv->curr_idle_nb); |
| 2336 | break; |
| 2337 | case ST_F_SAFE_CONN_CUR: |
| 2338 | metric = mkf_u32(0, sv->curr_safe_nb); |
| 2339 | break; |
| 2340 | case ST_F_USED_CONN_CUR: |
| 2341 | metric = mkf_u32(0, sv->curr_used_conns); |
| 2342 | break; |
| 2343 | case ST_F_NEED_CONN_EST: |
| 2344 | metric = mkf_u32(0, sv->est_need_conns); |
| 2345 | break; |
| 2346 | case ST_F_STATUS: |
| 2347 | fld_status = chunk_newstr(out); |
| 2348 | if (sv->cur_admin & SRV_ADMF_RMAINT) |
| 2349 | chunk_appendf(out, "MAINT (resolution)"); |
| 2350 | else if (sv->cur_admin & SRV_ADMF_IMAINT) |
| 2351 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 2352 | else if (sv->cur_admin & SRV_ADMF_MAINT) |
| 2353 | chunk_appendf(out, "MAINT"); |
| 2354 | else |
| 2355 | chunk_appendf(out, |
| 2356 | srv_hlt_st[state], |
| 2357 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2358 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2359 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2360 | metric = mkf_str(FO_STATUS, fld_status); |
| 2361 | break; |
| 2362 | case ST_F_LASTCHG: |
Willy Tarreau | 69530f5 | 2023-04-28 09:16:15 +0200 | [diff] [blame] | 2363 | metric = mkf_u32(FN_AGE, ns_to_sec(now_ns) - sv->last_change); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2364 | break; |
| 2365 | case ST_F_WEIGHT: |
| 2366 | metric = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 2367 | break; |
| 2368 | case ST_F_UWEIGHT: |
| 2369 | metric = mkf_u32(FN_AVG, sv->uweight); |
| 2370 | break; |
| 2371 | case ST_F_ACT: |
| 2372 | metric = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 2373 | break; |
| 2374 | case ST_F_BCK: |
| 2375 | metric = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
| 2376 | break; |
| 2377 | case ST_F_CHKFAIL: |
| 2378 | if (sv->check.state & CHK_ST_ENABLED) |
| 2379 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 2380 | break; |
| 2381 | case ST_F_CHKDOWN: |
| 2382 | if (sv->check.state & CHK_ST_ENABLED) |
| 2383 | metric = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 2384 | break; |
| 2385 | case ST_F_DOWNTIME: |
| 2386 | if (sv->check.state & CHK_ST_ENABLED) |
| 2387 | metric = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 2388 | break; |
| 2389 | case ST_F_QLIMIT: |
| 2390 | if (sv->maxqueue) |
| 2391 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
| 2392 | break; |
| 2393 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2394 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2395 | break; |
| 2396 | case ST_F_IID: |
| 2397 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2398 | break; |
| 2399 | case ST_F_SID: |
| 2400 | metric = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
| 2401 | break; |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 2402 | case ST_F_SRID: |
| 2403 | metric = mkf_u32(FN_COUNTER, sv->rid); |
| 2404 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2405 | case ST_F_THROTTLE: |
| 2406 | if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 2407 | metric = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
| 2408 | break; |
| 2409 | case ST_F_LBTOT: |
| 2410 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
| 2411 | break; |
| 2412 | case ST_F_TRACKED: |
| 2413 | if (sv->track) { |
| 2414 | char *fld_track = chunk_newstr(out); |
| 2415 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 2416 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 2417 | } |
| 2418 | break; |
| 2419 | case ST_F_TYPE: |
| 2420 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 2421 | break; |
| 2422 | case ST_F_RATE: |
| 2423 | metric = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 2424 | break; |
| 2425 | case ST_F_RATE_MAX: |
| 2426 | metric = mkf_u32(FN_MAX, sv->counters.sps_max); |
| 2427 | break; |
| 2428 | case ST_F_CHECK_STATUS: |
| 2429 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2430 | const char *fld_chksts; |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 2431 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2432 | fld_chksts = chunk_newstr(out); |
| 2433 | chunk_strcat(out, "* "); // for check in progress |
| 2434 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 2435 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 2436 | fld_chksts += 2; // skip "* " |
Willy Tarreau | 973a937 | 2021-05-12 17:29:14 +0200 | [diff] [blame] | 2437 | metric = mkf_str(FN_OUTPUT, fld_chksts); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2438 | } |
| 2439 | break; |
| 2440 | case ST_F_CHECK_CODE: |
| 2441 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2442 | sv->check.status >= HCHK_STATUS_L57DATA) |
| 2443 | metric = mkf_u32(FN_OUTPUT, sv->check.code); |
| 2444 | break; |
| 2445 | case ST_F_CHECK_DURATION: |
| 2446 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2447 | sv->check.status >= HCHK_STATUS_CHECKED) |
Aurelien DARRAGON | b118f2f | 2022-12-07 14:52:10 +0100 | [diff] [blame] | 2448 | metric = mkf_u64(FN_DURATION, MAX(sv->check.duration, 0)); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2449 | break; |
| 2450 | case ST_F_CHECK_DESC: |
| 2451 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2452 | metric = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 2453 | break; |
| 2454 | case ST_F_LAST_CHK: |
| 2455 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2456 | metric = mkf_str(FN_OUTPUT, sv->check.desc); |
| 2457 | break; |
| 2458 | case ST_F_CHECK_RISE: |
| 2459 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2460 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 2461 | break; |
| 2462 | case ST_F_CHECK_FALL: |
| 2463 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2464 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 2465 | break; |
| 2466 | case ST_F_CHECK_HEALTH: |
| 2467 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2468 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 2469 | break; |
Christopher Faulet | 59bab61 | 2021-07-22 08:04:38 +0200 | [diff] [blame] | 2470 | case ST_F_AGENT_STATUS: |
| 2471 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2472 | const char *fld_chksts; |
| 2473 | |
| 2474 | fld_chksts = chunk_newstr(out); |
| 2475 | chunk_strcat(out, "* "); // for check in progress |
| 2476 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 2477 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 2478 | fld_chksts += 2; // skip "* " |
| 2479 | metric = mkf_str(FN_OUTPUT, fld_chksts); |
| 2480 | } |
| 2481 | break; |
| 2482 | case ST_F_AGENT_CODE: |
| 2483 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2484 | (sv->agent.status >= HCHK_STATUS_L57DATA)) |
| 2485 | metric = mkf_u32(FN_OUTPUT, sv->agent.code); |
| 2486 | break; |
| 2487 | case ST_F_AGENT_DURATION: |
| 2488 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2489 | metric = mkf_u64(FN_DURATION, sv->agent.duration); |
| 2490 | break; |
| 2491 | case ST_F_AGENT_DESC: |
| 2492 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2493 | metric = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 2494 | break; |
| 2495 | case ST_F_LAST_AGT: |
| 2496 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2497 | metric = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 2498 | break; |
| 2499 | case ST_F_AGENT_RISE: |
| 2500 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2501 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 2502 | break; |
| 2503 | case ST_F_AGENT_FALL: |
| 2504 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2505 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 2506 | break; |
| 2507 | case ST_F_AGENT_HEALTH: |
| 2508 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2509 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 2510 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2511 | case ST_F_REQ_TOT: |
| 2512 | if (px->mode == PR_MODE_HTTP) |
| 2513 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req); |
| 2514 | break; |
| 2515 | case ST_F_HRSP_1XX: |
| 2516 | if (px->mode == PR_MODE_HTTP) |
| 2517 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 2518 | break; |
| 2519 | case ST_F_HRSP_2XX: |
| 2520 | if (px->mode == PR_MODE_HTTP) |
| 2521 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 2522 | break; |
| 2523 | case ST_F_HRSP_3XX: |
| 2524 | if (px->mode == PR_MODE_HTTP) |
| 2525 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 2526 | break; |
| 2527 | case ST_F_HRSP_4XX: |
| 2528 | if (px->mode == PR_MODE_HTTP) |
| 2529 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 2530 | break; |
| 2531 | case ST_F_HRSP_5XX: |
| 2532 | if (px->mode == PR_MODE_HTTP) |
| 2533 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 2534 | break; |
| 2535 | case ST_F_HRSP_OTHER: |
| 2536 | if (px->mode == PR_MODE_HTTP) |
| 2537 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 2538 | break; |
| 2539 | case ST_F_HANAFAIL: |
| 2540 | if (ref->observe) |
| 2541 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
| 2542 | break; |
| 2543 | case ST_F_CLI_ABRT: |
| 2544 | metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 2545 | break; |
| 2546 | case ST_F_SRV_ABRT: |
| 2547 | metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 2548 | break; |
| 2549 | case ST_F_LASTSESS: |
| 2550 | metric = mkf_s32(FN_AGE, srv_lastsession(sv)); |
| 2551 | break; |
| 2552 | case ST_F_QTIME: |
| 2553 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, srv_samples_window)); |
| 2554 | break; |
| 2555 | case ST_F_CTIME: |
| 2556 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, srv_samples_window)); |
| 2557 | break; |
| 2558 | case ST_F_RTIME: |
| 2559 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, srv_samples_window)); |
| 2560 | break; |
| 2561 | case ST_F_TTIME: |
| 2562 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, srv_samples_window)); |
| 2563 | break; |
| 2564 | case ST_F_QT_MAX: |
| 2565 | metric = mkf_u32(FN_MAX, sv->counters.qtime_max); |
| 2566 | break; |
| 2567 | case ST_F_CT_MAX: |
| 2568 | metric = mkf_u32(FN_MAX, sv->counters.ctime_max); |
| 2569 | break; |
| 2570 | case ST_F_RT_MAX: |
| 2571 | metric = mkf_u32(FN_MAX, sv->counters.dtime_max); |
| 2572 | break; |
| 2573 | case ST_F_TT_MAX: |
| 2574 | metric = mkf_u32(FN_MAX, sv->counters.ttime_max); |
| 2575 | break; |
| 2576 | case ST_F_ADDR: |
| 2577 | if (flags & STAT_SHLGNDS) { |
| 2578 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2579 | case AF_INET: |
| 2580 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2581 | chunk_appendf(out, "%s:%d", str, sv->svc_port); |
| 2582 | break; |
| 2583 | case AF_INET6: |
| 2584 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2585 | chunk_appendf(out, "[%s]:%d", str, sv->svc_port); |
| 2586 | break; |
| 2587 | case AF_UNIX: |
| 2588 | metric = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 2589 | break; |
| 2590 | case -1: |
| 2591 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2592 | chunk_strcat(out, strerror(errno)); |
| 2593 | break; |
| 2594 | default: /* address family not supported */ |
| 2595 | break; |
| 2596 | } |
| 2597 | } |
| 2598 | break; |
| 2599 | case ST_F_COOKIE: |
| 2600 | if (flags & STAT_SHLGNDS && sv->cookie) |
| 2601 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 2602 | break; |
| 2603 | default: |
| 2604 | /* not used for servers. If a specific metric |
| 2605 | * is requested, return an error. Otherwise continue. |
| 2606 | */ |
| 2607 | if (selected_field != NULL) |
| 2608 | return 0; |
| 2609 | continue; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2610 | } |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2611 | stats[current_field] = metric; |
| 2612 | if (selected_field != NULL) |
| 2613 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2614 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2615 | return 1; |
| 2616 | } |
| 2617 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2618 | /* Dumps a line for server <sv> and proxy <px> to the local trash vbuffer and |
| 2619 | * uses the state from stream connector <sc>, and server state <state>. The |
| 2620 | * caller is responsible for clearing the local trash buffer if needed. Returns |
| 2621 | * non-zero if it emits anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2622 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2623 | static int stats_dump_sv_stats(struct stconn *sc, struct proxy *px, struct server *sv) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2624 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2625 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2626 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2627 | struct stats_module *mod; |
| 2628 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2629 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 2630 | |
| 2631 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2632 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2633 | if (!stats_fill_sv_stats(px, sv, ctx->flags, stats, |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2634 | ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2635 | return 0; |
| 2636 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2637 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2638 | void *counters; |
| 2639 | |
| 2640 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2641 | continue; |
| 2642 | |
| 2643 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV)) { |
| 2644 | stats_count += mod->stats_count; |
| 2645 | continue; |
| 2646 | } |
| 2647 | |
| 2648 | counters = EXTRA_COUNTERS_GET(sv->extra_counters, mod); |
| 2649 | mod->fill_stats(counters, stats + stats_count); |
| 2650 | stats_count += mod->stats_count; |
| 2651 | } |
| 2652 | |
| 2653 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2656 | /* Helper to compute srv values for a given backend |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2657 | */ |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2658 | static void stats_fill_be_stats_computesrv(struct proxy *px, int *nbup, int *nbsrv, int *totuw) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2659 | { |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2660 | int nbup_tmp, nbsrv_tmp, totuw_tmp; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2661 | const struct server *srv; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2662 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2663 | nbup_tmp = nbsrv_tmp = totuw_tmp = 0; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2664 | for (srv = px->srv; srv; srv = srv->next) { |
| 2665 | if (srv->cur_state != SRV_ST_STOPPED) { |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2666 | nbup_tmp++; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2667 | if (srv_currently_usable(srv) && |
| 2668 | (!px->srv_act ^ !(srv->flags & SRV_F_BACKUP))) |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2669 | totuw_tmp += srv->uweight; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2670 | } |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2671 | nbsrv_tmp++; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2672 | } |
| 2673 | |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2674 | HA_RWLOCK_RDLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2675 | if (!px->srv_act && px->lbprm.fbck) |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2676 | totuw_tmp = px->lbprm.fbck->uweight; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2677 | HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2678 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2679 | /* use tmp variable then assign result to make gcc happy */ |
| 2680 | *nbup = nbup_tmp; |
| 2681 | *nbsrv = nbsrv_tmp; |
| 2682 | *totuw = totuw_tmp; |
| 2683 | } |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2684 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2685 | /* Fill <stats> with the backend statistics. <stats> is preallocated array of |
| 2686 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 2687 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 2688 | * this value, or if the selected field is not implemented for backends, the |
| 2689 | * function returns 0, otherwise, it returns 1. <flags> can take the value |
| 2690 | * STAT_SHLGNDS. |
| 2691 | */ |
| 2692 | int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len, |
| 2693 | enum stat_field *selected_field) |
| 2694 | { |
| 2695 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
| 2696 | long long be_samples_counter; |
| 2697 | unsigned int be_samples_window = TIME_STATS_SAMPLES; |
| 2698 | struct buffer *out = get_trash_chunk(); |
| 2699 | int nbup, nbsrv, totuw; |
| 2700 | char *fld; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2701 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2702 | if (len < ST_F_TOTAL_FIELDS) |
| 2703 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2704 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2705 | nbup = nbsrv = totuw = 0; |
| 2706 | /* some srv values compute for later if we either select all fields or |
| 2707 | * need them for one of the mentioned ones */ |
| 2708 | if (selected_field == NULL || *selected_field == ST_F_STATUS || |
| 2709 | *selected_field == ST_F_UWEIGHT) |
| 2710 | stats_fill_be_stats_computesrv(px, &nbup, &nbsrv, &totuw); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2711 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2712 | /* same here but specific to time fields */ |
| 2713 | if (selected_field == NULL || *selected_field == ST_F_QTIME || |
| 2714 | *selected_field == ST_F_CTIME || *selected_field == ST_F_RTIME || |
| 2715 | *selected_field == ST_F_TTIME) { |
| 2716 | be_samples_counter = (px->mode == PR_MODE_HTTP) ? px->be_counters.p.http.cum_req : px->be_counters.cum_lbconn; |
| 2717 | if (be_samples_counter < TIME_STATS_SAMPLES && be_samples_counter > 0) |
| 2718 | be_samples_window = be_samples_counter; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2719 | } |
| 2720 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2721 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 2722 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2723 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2724 | switch (current_field) { |
| 2725 | case ST_F_PXNAME: |
| 2726 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 2727 | break; |
| 2728 | case ST_F_SVNAME: |
| 2729 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND"); |
| 2730 | break; |
| 2731 | case ST_F_MODE: |
| 2732 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 2733 | break; |
| 2734 | case ST_F_QCUR: |
Willy Tarreau | 7f3c1df | 2021-06-18 09:22:21 +0200 | [diff] [blame] | 2735 | metric = mkf_u32(0, px->queue.length); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2736 | break; |
| 2737 | case ST_F_QMAX: |
| 2738 | metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 2739 | break; |
| 2740 | case ST_F_SCUR: |
| 2741 | metric = mkf_u32(0, px->beconn); |
| 2742 | break; |
| 2743 | case ST_F_SMAX: |
| 2744 | metric = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 2745 | break; |
| 2746 | case ST_F_SLIM: |
| 2747 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 2748 | break; |
| 2749 | case ST_F_STOT: |
Amaury Denoyelle | 1c8372b | 2024-04-04 18:08:46 +0200 | [diff] [blame] | 2750 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_sess); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2751 | break; |
| 2752 | case ST_F_BIN: |
| 2753 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 2754 | break; |
| 2755 | case ST_F_BOUT: |
| 2756 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 2757 | break; |
| 2758 | case ST_F_DREQ: |
| 2759 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 2760 | break; |
| 2761 | case ST_F_DRESP: |
| 2762 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 2763 | break; |
| 2764 | case ST_F_ECON: |
| 2765 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 2766 | break; |
| 2767 | case ST_F_ERESP: |
| 2768 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 2769 | break; |
| 2770 | case ST_F_WRETR: |
| 2771 | metric = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 2772 | break; |
| 2773 | case ST_F_WREDIS: |
| 2774 | metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 2775 | break; |
| 2776 | case ST_F_WREW: |
| 2777 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites); |
| 2778 | break; |
| 2779 | case ST_F_EINT: |
| 2780 | metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors); |
| 2781 | break; |
| 2782 | case ST_F_CONNECT: |
| 2783 | metric = mkf_u64(FN_COUNTER, px->be_counters.connect); |
| 2784 | break; |
| 2785 | case ST_F_REUSE: |
| 2786 | metric = mkf_u64(FN_COUNTER, px->be_counters.reuse); |
| 2787 | break; |
| 2788 | case ST_F_STATUS: |
| 2789 | fld = chunk_newstr(out); |
| 2790 | chunk_appendf(out, "%s", (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 2791 | if (flags & (STAT_HIDE_MAINT|STAT_HIDE_DOWN)) |
| 2792 | chunk_appendf(out, " (%d/%d)", nbup, nbsrv); |
| 2793 | metric = mkf_str(FO_STATUS, fld); |
| 2794 | break; |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 2795 | case ST_F_AGG_SRV_CHECK_STATUS: // DEPRECATED |
| 2796 | case ST_F_AGG_SRV_STATUS: |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 2797 | metric = mkf_u32(FN_GAUGE, 0); |
| 2798 | break; |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame] | 2799 | case ST_F_AGG_CHECK_STATUS: |
| 2800 | metric = mkf_u32(FN_GAUGE, 0); |
| 2801 | break; |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2802 | case ST_F_WEIGHT: |
| 2803 | metric = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 2804 | break; |
| 2805 | case ST_F_UWEIGHT: |
| 2806 | metric = mkf_u32(FN_AVG, totuw); |
| 2807 | break; |
| 2808 | case ST_F_ACT: |
| 2809 | metric = mkf_u32(0, px->srv_act); |
| 2810 | break; |
| 2811 | case ST_F_BCK: |
| 2812 | metric = mkf_u32(0, px->srv_bck); |
| 2813 | break; |
| 2814 | case ST_F_CHKDOWN: |
| 2815 | metric = mkf_u64(FN_COUNTER, px->down_trans); |
| 2816 | break; |
| 2817 | case ST_F_LASTCHG: |
Willy Tarreau | 69530f5 | 2023-04-28 09:16:15 +0200 | [diff] [blame] | 2818 | metric = mkf_u32(FN_AGE, ns_to_sec(now_ns) - px->last_change); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2819 | break; |
| 2820 | case ST_F_DOWNTIME: |
| 2821 | if (px->srv) |
| 2822 | metric = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 2823 | break; |
| 2824 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2825 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2826 | break; |
| 2827 | case ST_F_IID: |
| 2828 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2829 | break; |
| 2830 | case ST_F_SID: |
| 2831 | metric = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 2832 | break; |
| 2833 | case ST_F_LBTOT: |
| 2834 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 2835 | break; |
| 2836 | case ST_F_TYPE: |
| 2837 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 2838 | break; |
| 2839 | case ST_F_RATE: |
| 2840 | metric = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 2841 | break; |
| 2842 | case ST_F_RATE_MAX: |
| 2843 | metric = mkf_u32(0, px->be_counters.sps_max); |
| 2844 | break; |
| 2845 | case ST_F_COOKIE: |
| 2846 | if (flags & STAT_SHLGNDS && px->cookie_name) |
| 2847 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name); |
| 2848 | break; |
| 2849 | case ST_F_ALGO: |
| 2850 | if (flags & STAT_SHLGNDS) |
| 2851 | metric = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2852 | break; |
| 2853 | case ST_F_REQ_TOT: |
| 2854 | if (px->mode == PR_MODE_HTTP) |
| 2855 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 2856 | break; |
| 2857 | case ST_F_HRSP_1XX: |
| 2858 | if (px->mode == PR_MODE_HTTP) |
| 2859 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 2860 | break; |
| 2861 | case ST_F_HRSP_2XX: |
| 2862 | if (px->mode == PR_MODE_HTTP) |
| 2863 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 2864 | break; |
| 2865 | case ST_F_HRSP_3XX: |
| 2866 | if (px->mode == PR_MODE_HTTP) |
| 2867 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 2868 | break; |
| 2869 | case ST_F_HRSP_4XX: |
| 2870 | if (px->mode == PR_MODE_HTTP) |
| 2871 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 2872 | break; |
| 2873 | case ST_F_HRSP_5XX: |
| 2874 | if (px->mode == PR_MODE_HTTP) |
| 2875 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 2876 | break; |
| 2877 | case ST_F_HRSP_OTHER: |
| 2878 | if (px->mode == PR_MODE_HTTP) |
| 2879 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
| 2880 | break; |
| 2881 | case ST_F_CACHE_LOOKUPS: |
| 2882 | if (px->mode == PR_MODE_HTTP) |
| 2883 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups); |
| 2884 | break; |
| 2885 | case ST_F_CACHE_HITS: |
| 2886 | if (px->mode == PR_MODE_HTTP) |
| 2887 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits); |
| 2888 | break; |
| 2889 | case ST_F_CLI_ABRT: |
| 2890 | metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 2891 | break; |
| 2892 | case ST_F_SRV_ABRT: |
| 2893 | metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 2894 | break; |
| 2895 | case ST_F_COMP_IN: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 2896 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in[COMP_DIR_RES]); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2897 | break; |
| 2898 | case ST_F_COMP_OUT: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 2899 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out[COMP_DIR_RES]); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2900 | break; |
| 2901 | case ST_F_COMP_BYP: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 2902 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp[COMP_DIR_RES]); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2903 | break; |
| 2904 | case ST_F_COMP_RSP: |
| 2905 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 2906 | break; |
| 2907 | case ST_F_LASTSESS: |
| 2908 | metric = mkf_s32(FN_AGE, be_lastsession(px)); |
| 2909 | break; |
| 2910 | case ST_F_QTIME: |
| 2911 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, be_samples_window)); |
| 2912 | break; |
| 2913 | case ST_F_CTIME: |
| 2914 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, be_samples_window)); |
| 2915 | break; |
| 2916 | case ST_F_RTIME: |
| 2917 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, be_samples_window)); |
| 2918 | break; |
| 2919 | case ST_F_TTIME: |
| 2920 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, be_samples_window)); |
| 2921 | break; |
| 2922 | case ST_F_QT_MAX: |
| 2923 | metric = mkf_u32(FN_MAX, px->be_counters.qtime_max); |
| 2924 | break; |
| 2925 | case ST_F_CT_MAX: |
| 2926 | metric = mkf_u32(FN_MAX, px->be_counters.ctime_max); |
| 2927 | break; |
| 2928 | case ST_F_RT_MAX: |
| 2929 | metric = mkf_u32(FN_MAX, px->be_counters.dtime_max); |
| 2930 | break; |
| 2931 | case ST_F_TT_MAX: |
| 2932 | metric = mkf_u32(FN_MAX, px->be_counters.ttime_max); |
| 2933 | break; |
| 2934 | default: |
| 2935 | /* not used for backends. If a specific metric |
| 2936 | * is requested, return an error. Otherwise continue. |
| 2937 | */ |
| 2938 | if (selected_field != NULL) |
| 2939 | return 0; |
| 2940 | continue; |
| 2941 | } |
| 2942 | stats[current_field] = metric; |
| 2943 | if (selected_field != NULL) |
| 2944 | break; |
| 2945 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2946 | return 1; |
| 2947 | } |
| 2948 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2949 | /* Dumps a line for backend <px> to the local trash buffer for and uses the |
| 2950 | * state from stream interface <si>. The caller is responsible for clearing the |
| 2951 | * local trash buffer if needed. Returns non-zero if it emits anything, zero |
| 2952 | * otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2953 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2954 | static int stats_dump_be_stats(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2955 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2956 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2957 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2958 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2959 | struct stats_module *mod; |
| 2960 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2961 | |
| 2962 | if (!(px->cap & PR_CAP_BE)) |
| 2963 | return 0; |
| 2964 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2965 | if ((ctx->flags & STAT_BOUND) && !(ctx->type & (1 << STATS_TYPE_BE))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2966 | return 0; |
| 2967 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2968 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 2969 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2970 | if (!stats_fill_be_stats(px, ctx->flags, stats, ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2971 | return 0; |
| 2972 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2973 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2974 | struct extra_counters *counters; |
| 2975 | |
| 2976 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2977 | continue; |
| 2978 | |
| 2979 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE)) { |
| 2980 | stats_count += mod->stats_count; |
| 2981 | continue; |
| 2982 | } |
| 2983 | |
| 2984 | counters = EXTRA_COUNTERS_GET(px->extra_counters_be, mod); |
| 2985 | mod->fill_stats(counters, stats + stats_count); |
| 2986 | stats_count += mod->stats_count; |
| 2987 | } |
| 2988 | |
| 2989 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2990 | } |
| 2991 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2992 | /* Dumps the HTML table header for proxy <px> to the local trash buffer for and |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 2993 | * uses the state from stream connector <sc>. The caller is responsible for |
| 2994 | * clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2995 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2996 | static void stats_dump_html_px_hdr(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2997 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2998 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2999 | struct show_stat_ctx *ctx = appctx->svcctx; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3000 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 3001 | struct stats_module *mod; |
| 3002 | int stats_module_len = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3003 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3004 | if (px->cap & PR_CAP_BE && px->srv && (ctx->flags & STAT_ADMIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3005 | /* A form to enable/disable this proxy servers */ |
| 3006 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3007 | /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3008 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3009 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3010 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3011 | |
Willy Tarreau | fc458ec | 2023-04-07 18:11:39 +0200 | [diff] [blame] | 3012 | strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3013 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 3014 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3015 | } |
| 3016 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3017 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3018 | "<form method=\"post\">"); |
| 3019 | } |
| 3020 | |
| 3021 | /* print a new table */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3022 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3023 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3024 | "<tr class=\"titre\">" |
| 3025 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3026 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3027 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3028 | "<a name=\"%s\"></a>%s" |
| 3029 | "<a class=px href=\"#%s\">%s</a>", |
| 3030 | px->id, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3031 | (ctx->flags & STAT_SHLGNDS) ? "<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3032 | px->id, px->id); |
| 3033 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3034 | if (ctx->flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3035 | /* cap, mode, id */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3036 | chunk_appendf(&trash_chunk, "<div class=tips>cap: %s, mode: %s, id: %d", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3037 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3038 | px->uuid); |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3039 | chunk_appendf(&trash_chunk, "</div>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3040 | } |
| 3041 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3042 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3043 | "%s</th>" |
| 3044 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3045 | "</tr>\n" |
| 3046 | "</table>\n" |
| 3047 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3048 | "<tr class=\"titre\">", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3049 | (ctx->flags & STAT_SHLGNDS) ? "</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3050 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3051 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3052 | if (ctx->flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3053 | /* Column heading for Enable or Disable server */ |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 3054 | if ((px->cap & PR_CAP_BE) && px->srv) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3055 | chunk_appendf(&trash_chunk, |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 3056 | "<th rowspan=2 width=1><input type=\"checkbox\" " |
| 3057 | "onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) " |
| 3058 | "document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>", |
| 3059 | px->id, |
| 3060 | px->id); |
| 3061 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3062 | chunk_appendf(&trash_chunk, "<th rowspan=2></th>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3063 | } |
| 3064 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3065 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3066 | "<th rowspan=2></th>" |
| 3067 | "<th colspan=3>Queue</th>" |
| 3068 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
| 3069 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3070 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3071 | "<th colspan=9>Server</th>"); |
| 3072 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3073 | if (ctx->flags & STAT_SHMODULES) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3074 | // calculate the count of module for colspan attribute |
| 3075 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 3076 | ++stats_module_len; |
| 3077 | } |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3078 | chunk_appendf(&trash_chunk, "<th colspan=%d>Extra modules</th>", |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3079 | stats_module_len); |
| 3080 | } |
| 3081 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3082 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3083 | "</tr>\n" |
| 3084 | "<tr class=\"titre\">" |
| 3085 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3086 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 3087 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>" |
| 3088 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3089 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3090 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3091 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3092 | "<th>Thrtle</th>\n"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 3093 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3094 | if (ctx->flags & STAT_SHMODULES) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3095 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3096 | chunk_appendf(&trash_chunk, "<th>%s</th>", mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3097 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 3098 | } |
| 3099 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3100 | chunk_appendf(&trash_chunk, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3101 | } |
| 3102 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3103 | /* Dumps the HTML table trailer for proxy <px> to the local trash buffer for and |
| 3104 | * uses the state from stream connector <sc>. The caller is responsible for |
| 3105 | * clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3106 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3107 | static void stats_dump_html_px_end(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3108 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3109 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3110 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | 693b23b | 2022-02-28 09:09:05 +0100 | [diff] [blame] | 3111 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3112 | chunk_appendf(&trash_chunk, "</table>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3113 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3114 | if ((px->cap & PR_CAP_BE) && px->srv && (ctx->flags & STAT_ADMIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3115 | /* close the form used to enable/disable this proxy servers */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3116 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3117 | "Choose the action to perform on the checked servers : " |
| 3118 | "<select name=action>" |
| 3119 | "<option value=\"\"></option>" |
| 3120 | "<option value=\"ready\">Set state to READY</option>" |
| 3121 | "<option value=\"drain\">Set state to DRAIN</option>" |
| 3122 | "<option value=\"maint\">Set state to MAINT</option>" |
| 3123 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3124 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3125 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3126 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3127 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3128 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3129 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3130 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3131 | "<option value=\"adown\">Agent: force DOWN</option>" |
| 3132 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3133 | "</select>" |
| 3134 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3135 | " <input type=\"submit\" value=\"Apply\">" |
| 3136 | "</form>", |
| 3137 | px->uuid); |
| 3138 | } |
| 3139 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3140 | chunk_appendf(&trash_chunk, "<p>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | /* |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 3144 | * Dumps statistics for a proxy. The output is sent to the stream connector's |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3145 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3146 | * buffer space, or non-zero if everything completed. This function is used |
| 3147 | * both by the CLI and the HTTP entry points, and is able to dump the output |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3148 | * in HTML or CSV formats. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3149 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3150 | int stats_dump_proxy_to_buffer(struct stconn *sc, struct htx *htx, |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3151 | struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3152 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3153 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3154 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3155 | struct channel *rep = sc_ic(sc); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3156 | struct server *sv, *svs; /* server and server-state, server-state=server or server->track */ |
| 3157 | struct listener *l; |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3158 | struct uri_auth *uri = NULL; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3159 | int current_field; |
Aurelien DARRAGON | 99a8d0f | 2023-01-31 09:51:32 +0100 | [diff] [blame] | 3160 | int px_st = ctx->px_st; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3161 | |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3162 | if (ctx->http_px) |
| 3163 | uri = ctx->http_px->uri_auth; |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3164 | chunk_reset(&trash_chunk); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3165 | more: |
| 3166 | current_field = ctx->field; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3167 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3168 | switch (ctx->px_st) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3169 | case STAT_PX_ST_INIT: |
| 3170 | /* we are on a new proxy */ |
| 3171 | if (uri && uri->scope) { |
| 3172 | /* we have a limited scope, we have to check the proxy name */ |
| 3173 | struct stat_scope *scope; |
| 3174 | int len; |
| 3175 | |
| 3176 | len = strlen(px->id); |
| 3177 | scope = uri->scope; |
| 3178 | |
| 3179 | while (scope) { |
| 3180 | /* match exact proxy name */ |
| 3181 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3182 | break; |
| 3183 | |
| 3184 | /* match '.' which means 'self' proxy */ |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3185 | if (strcmp(scope->px_id, ".") == 0 && px == ctx->http_px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3186 | break; |
| 3187 | scope = scope->next; |
| 3188 | } |
| 3189 | |
| 3190 | /* proxy name not found : don't dump anything */ |
| 3191 | if (scope == NULL) |
| 3192 | return 1; |
| 3193 | } |
| 3194 | |
| 3195 | /* if the user has requested a limited output and the proxy |
| 3196 | * name does not match, skip it. |
| 3197 | */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3198 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3199 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3200 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3201 | if (strnistr(px->id, strlen(px->id), scope_ptr, ctx->scope_len) == NULL) |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3202 | return 1; |
| 3203 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3204 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3205 | if ((ctx->flags & STAT_BOUND) && |
| 3206 | (ctx->iid != -1) && |
| 3207 | (px->uuid != ctx->iid)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3208 | return 1; |
| 3209 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3210 | ctx->px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3211 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3212 | |
| 3213 | case STAT_PX_ST_TH: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3214 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3215 | stats_dump_html_px_hdr(sc, px); |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3216 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3217 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3218 | } |
| 3219 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3220 | ctx->px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3221 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3222 | |
| 3223 | case STAT_PX_ST_FE: |
| 3224 | /* print the frontend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3225 | if (stats_dump_fe_stats(sc, px)) { |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3226 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3227 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3228 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3229 | if (ctx->field) |
| 3230 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3231 | } |
| 3232 | |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3233 | current_field = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3234 | ctx->obj2 = px->conf.listeners.n; |
| 3235 | ctx->px_st = STAT_PX_ST_LI; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3236 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3237 | |
| 3238 | case STAT_PX_ST_LI: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 3239 | /* obj2 points to listeners list as initialized above */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3240 | for (; ctx->obj2 != &px->conf.listeners; ctx->obj2 = l->by_fe.n) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3241 | if (htx) { |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3242 | if (htx_almost_full(htx)) { |
| 3243 | sc_need_room(sc, htx->size / 2); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3244 | goto full; |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3245 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3246 | } |
| 3247 | else { |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3248 | if (buffer_almost_full(&rep->buf)) { |
| 3249 | sc_need_room(sc, b_size(&rep->buf) / 2); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3250 | goto full; |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3251 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3252 | } |
| 3253 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3254 | l = LIST_ELEM(ctx->obj2, struct listener *, by_fe); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3255 | if (!l->counters) |
| 3256 | continue; |
| 3257 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3258 | if (ctx->flags & STAT_BOUND) { |
| 3259 | if (!(ctx->type & (1 << STATS_TYPE_SO))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3260 | break; |
| 3261 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3262 | if (ctx->sid != -1 && l->luid != ctx->sid) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3263 | continue; |
| 3264 | } |
| 3265 | |
| 3266 | /* print the frontend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3267 | if (stats_dump_li_stats(sc, px, l)) { |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3268 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3269 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3270 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3271 | if (ctx->field) |
| 3272 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3273 | } |
Aurelien DARRAGON | 9b07d4f | 2023-02-03 11:43:05 +0100 | [diff] [blame] | 3274 | current_field = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3275 | } |
| 3276 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3277 | ctx->obj2 = px->srv; /* may be NULL */ |
| 3278 | ctx->px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3279 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3280 | |
| 3281 | case STAT_PX_ST_SV: |
Aurelien DARRAGON | 99a8d0f | 2023-01-31 09:51:32 +0100 | [diff] [blame] | 3282 | /* check for dump resumption */ |
| 3283 | if (px_st == STAT_PX_ST_SV) { |
| 3284 | struct server *cur = ctx->obj2; |
| 3285 | |
| 3286 | /* re-entrant dump */ |
| 3287 | BUG_ON(!cur); |
| 3288 | if (cur->flags & SRV_F_DELETED) { |
| 3289 | /* the server could have been marked as deleted |
| 3290 | * between two dumping attempts, skip it. |
| 3291 | */ |
| 3292 | cur = cur->next; |
| 3293 | } |
| 3294 | srv_drop(ctx->obj2); /* drop old srv taken on last dumping attempt */ |
| 3295 | ctx->obj2 = cur; /* could be NULL */ |
| 3296 | /* back to normal */ |
| 3297 | } |
| 3298 | |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3299 | /* obj2 points to servers list as initialized above. |
| 3300 | * |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3301 | * A server may be removed during the stats dumping. |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3302 | * Temporarily increment its refcount to prevent its |
Aurelien DARRAGON | 99a8d0f | 2023-01-31 09:51:32 +0100 | [diff] [blame] | 3303 | * anticipated cleaning. Call srv_drop() to release it. |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3304 | */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3305 | for (; ctx->obj2 != NULL; |
| 3306 | ctx->obj2 = srv_drop(sv)) { |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3307 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3308 | sv = ctx->obj2; |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3309 | srv_take(sv); |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3310 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3311 | if (htx) { |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3312 | if (htx_almost_full(htx)) { |
| 3313 | sc_need_room(sc, htx->size / 2); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3314 | goto full; |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3315 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3316 | } |
| 3317 | else { |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3318 | if (buffer_almost_full(&rep->buf)) { |
| 3319 | sc_need_room(sc, b_size(&rep->buf) / 2); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3320 | goto full; |
Christopher Faulet | a236c58 | 2023-05-09 16:31:01 +0200 | [diff] [blame] | 3321 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3322 | } |
| 3323 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3324 | if (ctx->flags & STAT_BOUND) { |
| 3325 | if (!(ctx->type & (1 << STATS_TYPE_SV))) { |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3326 | srv_drop(sv); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3327 | break; |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3328 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3329 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3330 | if (ctx->sid != -1 && sv->puid != ctx->sid) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3331 | continue; |
| 3332 | } |
| 3333 | |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 3334 | /* do not report disabled servers */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3335 | if (ctx->flags & STAT_HIDE_MAINT && |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 3336 | sv->cur_admin & SRV_ADMF_MAINT) { |
| 3337 | continue; |
| 3338 | } |
| 3339 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3340 | svs = sv; |
| 3341 | while (svs->track) |
| 3342 | svs = svs->track; |
| 3343 | |
| 3344 | /* do not report servers which are DOWN and not changing state */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3345 | if ((ctx->flags & STAT_HIDE_DOWN) && |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 3346 | ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 3347 | (sv->cur_state == SRV_ST_STOPPED && /* server is down */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3348 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 3349 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 3350 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
| 3351 | continue; |
| 3352 | } |
| 3353 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3354 | if (stats_dump_sv_stats(sc, px, sv)) { |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3355 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3356 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3357 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 28a2361 | 2023-02-02 18:13:30 +0100 | [diff] [blame] | 3358 | if (ctx->field) |
| 3359 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3360 | } |
Aurelien DARRAGON | 28a2361 | 2023-02-02 18:13:30 +0100 | [diff] [blame] | 3361 | current_field = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3362 | } /* for sv */ |
| 3363 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3364 | ctx->px_st = STAT_PX_ST_BE; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3365 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3366 | |
| 3367 | case STAT_PX_ST_BE: |
| 3368 | /* print the backend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3369 | if (stats_dump_be_stats(sc, px)) { |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3370 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3371 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3372 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3373 | if (ctx->field) |
| 3374 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3375 | } |
| 3376 | |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3377 | current_field = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3378 | ctx->px_st = STAT_PX_ST_END; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3379 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3380 | |
| 3381 | case STAT_PX_ST_END: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3382 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3383 | stats_dump_html_px_end(sc, px); |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3384 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3385 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3386 | } |
| 3387 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3388 | ctx->px_st = STAT_PX_ST_FIN; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3389 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3390 | |
| 3391 | case STAT_PX_ST_FIN: |
| 3392 | return 1; |
| 3393 | |
| 3394 | default: |
| 3395 | /* unknown state, we should put an abort() here ! */ |
| 3396 | return 1; |
| 3397 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3398 | |
| 3399 | full: |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3400 | /* restore previous field */ |
| 3401 | ctx->field = current_field; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3402 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3403 | } |
| 3404 | |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3405 | /* Dumps the HTTP stats head block to the local trash buffer and uses the |
| 3406 | * per-uri parameters from the parent proxy. The caller is responsible for |
| 3407 | * clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3408 | */ |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3409 | static void stats_dump_html_head(struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3410 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3411 | struct show_stat_ctx *ctx = appctx->svcctx; |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3412 | struct uri_auth *uri; |
| 3413 | |
| 3414 | BUG_ON(!ctx->http_px); |
| 3415 | uri = ctx->http_px->uri_auth; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3416 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3417 | /* WARNING! This must fit in the first buffer !!! */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3418 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3419 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3420 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3421 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
Thierry Fournier | b6b1cde | 2021-09-24 00:03:07 +0200 | [diff] [blame] | 3422 | "<link rel=\"icon\" href=\"data:,\">\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3423 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3424 | "<style type=\"text/css\"><!--\n" |
| 3425 | "body {" |
| 3426 | " font-family: arial, helvetica, sans-serif;" |
| 3427 | " font-size: 12px;" |
| 3428 | " font-weight: normal;" |
| 3429 | " color: black;" |
| 3430 | " background: white;" |
| 3431 | "}\n" |
| 3432 | "th,td {" |
| 3433 | " font-size: 10px;" |
| 3434 | "}\n" |
| 3435 | "h1 {" |
| 3436 | " font-size: x-large;" |
| 3437 | " margin-bottom: 0.5em;" |
| 3438 | "}\n" |
| 3439 | "h2 {" |
| 3440 | " font-family: helvetica, arial;" |
| 3441 | " font-size: x-large;" |
| 3442 | " font-weight: bold;" |
| 3443 | " font-style: italic;" |
| 3444 | " color: #6020a0;" |
| 3445 | " margin-top: 0em;" |
| 3446 | " margin-bottom: 0em;" |
| 3447 | "}\n" |
| 3448 | "h3 {" |
| 3449 | " font-family: helvetica, arial;" |
| 3450 | " font-size: 16px;" |
| 3451 | " font-weight: bold;" |
| 3452 | " color: #b00040;" |
| 3453 | " background: #e8e8d0;" |
| 3454 | " margin-top: 0em;" |
| 3455 | " margin-bottom: 0em;" |
| 3456 | "}\n" |
| 3457 | "li {" |
| 3458 | " margin-top: 0.25em;" |
| 3459 | " margin-right: 2em;" |
| 3460 | "}\n" |
| 3461 | ".hr {margin-top: 0.25em;" |
| 3462 | " border-color: black;" |
| 3463 | " border-bottom-style: solid;" |
| 3464 | "}\n" |
| 3465 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3466 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3467 | ".frontend {background: #e8e8d0;}\n" |
| 3468 | ".socket {background: #d0d0d0;}\n" |
| 3469 | ".backend {background: #e8e8d0;}\n" |
| 3470 | ".active_down {background: #ff9090;}\n" |
| 3471 | ".active_going_up {background: #ffd020;}\n" |
| 3472 | ".active_going_down {background: #ffffa0;}\n" |
| 3473 | ".active_up {background: #c0ffc0;}\n" |
| 3474 | ".active_nolb {background: #20a0ff;}\n" |
| 3475 | ".active_draining {background: #20a0FF;}\n" |
| 3476 | ".active_no_check {background: #e0e0e0;}\n" |
| 3477 | ".backup_down {background: #ff9090;}\n" |
| 3478 | ".backup_going_up {background: #ff80ff;}\n" |
| 3479 | ".backup_going_down {background: #c060ff;}\n" |
| 3480 | ".backup_up {background: #b0d0ff;}\n" |
| 3481 | ".backup_nolb {background: #90b0e0;}\n" |
| 3482 | ".backup_draining {background: #cc9900;}\n" |
| 3483 | ".backup_no_check {background: #e0e0e0;}\n" |
| 3484 | ".maintain {background: #c07820;}\n" |
| 3485 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3486 | "\n" |
| 3487 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3488 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3489 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3490 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3491 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3492 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3493 | "\n" |
| 3494 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3495 | "table.tbl td { text-align: right; border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray; white-space: nowrap;}\n" |
| 3496 | "table.tbl td.ac { text-align: center;}\n" |
| 3497 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3498 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3499 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3500 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3501 | "\n" |
| 3502 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3503 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3504 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 3505 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3506 | "table.det th { text-align: left; border-width: 0px; padding: 0px 1px 0px 0px; font-style:normal;font-size:11px;font-weight:bold;font-family: sans-serif;}\n" |
| 3507 | "table.det td { text-align: right; border-width: 0px; padding: 0px 0px 0px 4px; white-space: nowrap; font-style:normal;font-size:11px;font-weight:normal;}\n" |
| 3508 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Thierry Fournier | b6b1cde | 2021-09-24 00:03:07 +0200 | [diff] [blame] | 3509 | "div.tips {\n" |
| 3510 | " display:block;\n" |
| 3511 | " visibility:hidden;\n" |
| 3512 | " z-index:2147483647;\n" |
| 3513 | " position:absolute;\n" |
| 3514 | " padding:2px 4px 3px;\n" |
| 3515 | " background:#f0f060; color:#000000;\n" |
| 3516 | " border:1px solid #7040c0;\n" |
| 3517 | " white-space:nowrap;\n" |
| 3518 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3519 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3520 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3521 | "}\n" |
| 3522 | "u:hover div.tips {visibility:visible;}\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3523 | "@media (prefers-color-scheme: dark) {\n" |
| 3524 | " body { font-family: arial, helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #e8e6e3; background: #131516;}\n" |
| 3525 | " h1 { color: #a265e0!important; }\n" |
| 3526 | " h2 { color: #a265e0; }\n" |
| 3527 | " h3 { color: #ff5190; background-color: #3e3e1f; }\n" |
| 3528 | " a { color: #3391ff; }\n" |
| 3529 | " input { background-color: #2f3437; }\n" |
| 3530 | " .hr { border-color: #8c8273; }\n" |
| 3531 | " .titre { background-color: #1aa6a6; color: #e8e6e3; }\n" |
| 3532 | " .frontend {background: #2f3437;}\n" |
Marno Krahmer | a690b73 | 2022-03-08 13:45:09 +0100 | [diff] [blame] | 3533 | " .socket {background: #2a2d2f;}\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3534 | " .backend {background: #2f3437;}\n" |
| 3535 | " .active_down {background: #760000;}\n" |
| 3536 | " .active_going_up {background: #b99200;}\n" |
| 3537 | " .active_going_down {background: #6c6c00;}\n" |
| 3538 | " .active_up {background: #165900;}\n" |
| 3539 | " .active_nolb {background: #006ab9;}\n" |
| 3540 | " .active_draining {background: #006ab9;}\n" |
| 3541 | " .active_no_check {background: #2a2d2f;}\n" |
| 3542 | " .backup_down {background: #760000;}\n" |
| 3543 | " .backup_going_up {background: #7f007f;}\n" |
| 3544 | " .backup_going_down {background: #580092;}\n" |
| 3545 | " .backup_up {background: #2e3234;}\n" |
| 3546 | " .backup_nolb {background: #1e3c6a;}\n" |
| 3547 | " .backup_draining {background: #a37a00;}\n" |
| 3548 | " .backup_no_check {background: #2a2d2f;}\n" |
| 3549 | " .maintain {background: #9a601a;}\n" |
| 3550 | " a.px:link {color: #d8d83b; text-decoration: none;}\n" |
| 3551 | " a.px:visited {color: #d8d83b; text-decoration: none;}\n" |
| 3552 | " a.px:hover {color: #ffffff; text-decoration: none;}\n" |
| 3553 | " a.lfsb:link {color: #e8e6e3; text-decoration: none;}\n" |
| 3554 | " a.lfsb:visited {color: #e8e6e3; text-decoration: none;}\n" |
| 3555 | " a.lfsb:hover {color: #b5afa6; text-decoration: none;}\n" |
| 3556 | " table.tbl th.empty { background-color: #181a1b; }\n" |
Willy Tarreau | 00147f7 | 2022-04-11 07:59:27 +0200 | [diff] [blame] | 3557 | " table.tbl th.desc { background: #181a1b; }\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3558 | " table.tbl th.pxname { background-color: #8d0033; color: #ffff46; }\n" |
| 3559 | " table.tbl th { border-color: #808080; }\n" |
| 3560 | " table.tbl td { border-color: #808080; }\n" |
| 3561 | " u {text-decoration:none; border-bottom: 1px dotted #e8e6e3;}\n" |
| 3562 | " div.tips {\n" |
| 3563 | " background:#8e8e0d;\n" |
| 3564 | " color:#e8e6e3;\n" |
| 3565 | " border-color: #4e2c86;\n" |
| 3566 | " -moz-box-shadow: #60686c 2px 2px 3px;\n" |
| 3567 | " -webkit-box-shadow: #60686c 2px 2px 3px;\n" |
| 3568 | " box-shadow: #60686c 2px 2px 3px;\n" |
| 3569 | " }\n" |
| 3570 | "}\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3571 | "-->\n" |
| 3572 | "</style></head>\n", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3573 | (ctx->flags & STAT_SHNODE) ? " on " : "", |
| 3574 | (ctx->flags & STAT_SHNODE) ? (uri && uri->node ? uri->node : global.node) : "" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3575 | ); |
| 3576 | } |
| 3577 | |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3578 | /* Dumps the HTML stats information block to the local trash buffer and uses |
| 3579 | * the state from stream connector <sc> and per-uri parameter from the parent |
| 3580 | * proxy. The caller is responsible for clearing the local trash buffer if |
| 3581 | * needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3582 | */ |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3583 | static void stats_dump_html_info(struct stconn *sc) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3584 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3585 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3586 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c05d30e | 2023-04-28 14:50:29 +0200 | [diff] [blame] | 3587 | unsigned int up = ns_to_sec(now_ns - start_time_ns); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3588 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3589 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3590 | struct uri_auth *uri; |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 3591 | unsigned long long bps; |
| 3592 | int thr; |
| 3593 | |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3594 | BUG_ON(!ctx->http_px); |
| 3595 | uri = ctx->http_px->uri_auth; |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 3596 | for (bps = thr = 0; thr < global.nbthread; thr++) |
| 3597 | bps += 32ULL * read_freq_ctr(&ha_thread_ctx[thr].out_32bps); |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 3598 | |
| 3599 | /* Turn the bytes per second to bits per second and take care of the |
| 3600 | * usual ethernet overhead in order to help figure how far we are from |
| 3601 | * interface saturation since it's the only case which usually matters. |
| 3602 | * For this we count the total size of an Ethernet frame on the wire |
| 3603 | * including preamble and IFG (1538) for the largest TCP segment it |
| 3604 | * transports (1448 with TCP timestamps). This is not valid for smaller |
| 3605 | * packets (under-estimated), but it gives a reasonably accurate |
| 3606 | * estimation of how far we are from uplink saturation. |
| 3607 | */ |
| 3608 | bps = bps * 8 * 1538 / 1448; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3609 | |
| 3610 | /* WARNING! this has to fit the first packet too. |
| 3611 | * We are around 3.5 kB, add adding entries will |
| 3612 | * become tricky if we want to support 4kB buffers ! |
| 3613 | */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3614 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3615 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3616 | PRODUCT_NAME "%s</a></h1>\n" |
| 3617 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3618 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3619 | "<h3>> General process information</h3>\n" |
| 3620 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 3621 | "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n" |
Willy Tarreau | 3c4a297 | 2023-05-11 12:02:21 +0200 | [diff] [blame] | 3622 | "<b>uptime = </b> %dd %dh%02dm%02ds; warnings = %u<br>\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3623 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
Willy Tarreau | 9615102 | 2023-05-11 13:51:31 +0200 | [diff] [blame] | 3624 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>reached = </b> %llu; <b>maxpipes = </b> %d<br>\n" |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 3625 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec; bit rate = %.3f %cbps<br>\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3626 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3627 | "</td><td align=\"center\" nowrap>\n" |
| 3628 | "<table class=\"lgd\"><tr>\n" |
| 3629 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 3630 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
| 3631 | "</tr><tr>\n" |
| 3632 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3633 | "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3634 | "</tr><tr>\n" |
| 3635 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3636 | "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3637 | "</tr><tr>\n" |
| 3638 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 3639 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
| 3640 | "</tr><tr>\n" |
| 3641 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
| 3642 | "</tr><tr>\n" |
| 3643 | "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance </td>" |
| 3644 | "</tr></table>\n" |
| 3645 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
| 3646 | "</td>" |
| 3647 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3648 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3649 | "", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3650 | (ctx->flags & STAT_HIDEVER) ? "" : (stats_version_string), |
| 3651 | pid, (ctx->flags & STAT_SHNODE) ? " on " : "", |
| 3652 | (ctx->flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3653 | (ctx->flags & STAT_SHDESC) ? ": " : "", |
| 3654 | (ctx->flags & STAT_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 3655 | pid, 1, 1, global.nbthread, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3656 | up / 86400, (up % 86400) / 3600, |
| 3657 | (up % 3600) / 60, (up % 60), |
Willy Tarreau | 3c4a297 | 2023-05-11 12:02:21 +0200 | [diff] [blame] | 3658 | HA_ATOMIC_LOAD(&tot_warnings), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3659 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3660 | global.rlimit_memmax ? " MB" : "", |
| 3661 | global.rlimit_nofile, |
Willy Tarreau | 9615102 | 2023-05-11 13:51:31 +0200 | [diff] [blame] | 3662 | global.maxsock, global.maxconn, HA_ATOMIC_LOAD(&maxconn_reached), global.maxpipes, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3663 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 3664 | bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0), |
| 3665 | bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k', |
Willy Tarreau | f9d5e10 | 2021-10-08 10:43:59 +0200 | [diff] [blame] | 3666 | total_run_queues(), total_allocated_tasks(), clock_report_idle() |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3667 | ); |
| 3668 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3669 | /* scope_txt = search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3670 | memcpy(scope_txt, scope_ptr, ctx->scope_len); |
| 3671 | scope_txt[ctx->scope_len] = '\0'; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3672 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3673 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3674 | "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3675 | (ctx->scope_len > 0) ? scope_txt : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3676 | STAT_SCOPE_TXT_MAXLEN); |
| 3677 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3678 | /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3679 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3680 | if (ctx->scope_len) { |
Willy Tarreau | fc458ec | 2023-04-07 18:11:39 +0200 | [diff] [blame] | 3681 | strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3682 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 3683 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3684 | } |
| 3685 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3686 | if (ctx->flags & STAT_HIDE_DOWN) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3687 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3688 | "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n", |
| 3689 | uri->uri_prefix, |
| 3690 | "", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3691 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3692 | scope_txt); |
| 3693 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3694 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3695 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 3696 | uri->uri_prefix, |
| 3697 | ";up", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3698 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3699 | scope_txt); |
| 3700 | |
| 3701 | if (uri->refresh > 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3702 | if (ctx->flags & STAT_NO_REFRESH) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3703 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3704 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
| 3705 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3706 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3707 | "", |
| 3708 | scope_txt); |
| 3709 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3710 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3711 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
| 3712 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3713 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3714 | ";norefresh", |
| 3715 | scope_txt); |
| 3716 | } |
| 3717 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3718 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3719 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
| 3720 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3721 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3722 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3723 | scope_txt); |
| 3724 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3725 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3726 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
| 3727 | uri->uri_prefix, |
| 3728 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3729 | scope_txt); |
| 3730 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3731 | chunk_appendf(&trash_chunk, |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3732 | "<li><a href=\"%s;json%s%s\">JSON export</a> (<a href=\"%s;json-schema\">schema</a>)<br>\n", |
| 3733 | uri->uri_prefix, |
| 3734 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3735 | scope_txt, uri->uri_prefix); |
| 3736 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3737 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3738 | "</ul></td>" |
| 3739 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3740 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3741 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3742 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3743 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3744 | "</ul>" |
| 3745 | "</td>" |
| 3746 | "</tr></table>\n" |
| 3747 | "" |
| 3748 | ); |
| 3749 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3750 | if (ctx->st_code) { |
| 3751 | switch (ctx->st_code) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3752 | case STAT_STATUS_DONE: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3753 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3754 | "<p><div class=active_up>" |
| 3755 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3756 | "Action processed successfully." |
| 3757 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3758 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3759 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3760 | scope_txt); |
| 3761 | break; |
| 3762 | case STAT_STATUS_NONE: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3763 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3764 | "<p><div class=active_going_down>" |
| 3765 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3766 | "Nothing has changed." |
| 3767 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3768 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3769 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3770 | scope_txt); |
| 3771 | break; |
| 3772 | case STAT_STATUS_PART: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3773 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3774 | "<p><div class=active_going_down>" |
| 3775 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3776 | "Action partially processed.<br>" |
| 3777 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
| 3778 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3779 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3780 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3781 | scope_txt); |
| 3782 | break; |
| 3783 | case STAT_STATUS_ERRP: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3784 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3785 | "<p><div class=active_down>" |
| 3786 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3787 | "Action not processed because of invalid parameters." |
| 3788 | "<ul>" |
| 3789 | "<li>The action is maybe unknown.</li>" |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 3790 | "<li>Invalid key parameter (empty or too long).</li>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3791 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3792 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3793 | "</ul>" |
| 3794 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3795 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3796 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3797 | scope_txt); |
| 3798 | break; |
| 3799 | case STAT_STATUS_EXCD: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3800 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3801 | "<p><div class=active_down>" |
| 3802 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3803 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3804 | "You should retry with less servers at a time.</b>" |
| 3805 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3806 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3807 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3808 | scope_txt); |
| 3809 | break; |
| 3810 | case STAT_STATUS_DENY: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3811 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3812 | "<p><div class=active_down>" |
| 3813 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3814 | "<b>Action denied.</b>" |
| 3815 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3816 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3817 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3818 | scope_txt); |
| 3819 | break; |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3820 | case STAT_STATUS_IVAL: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3821 | chunk_appendf(&trash_chunk, |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3822 | "<p><div class=active_down>" |
| 3823 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3824 | "<b>Invalid requests (unsupported method or chunked encoded request).</b>" |
| 3825 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3826 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3827 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3828 | scope_txt); |
| 3829 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3830 | default: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3831 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3832 | "<p><div class=active_no_check>" |
| 3833 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3834 | "Unexpected result." |
| 3835 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3836 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3837 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3838 | scope_txt); |
| 3839 | } |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3840 | chunk_appendf(&trash_chunk, "<p>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3844 | /* Dumps the HTML stats trailer block to the local trash buffer. The caller is |
| 3845 | * responsible for clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3846 | */ |
| 3847 | static void stats_dump_html_end() |
| 3848 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3849 | chunk_appendf(&trash_chunk, "</body></html>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3850 | } |
| 3851 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3852 | /* Dumps the stats JSON header to the local trash buffer buffer which. The |
| 3853 | * caller is responsible for clearing it if needed. |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3854 | */ |
| 3855 | static void stats_dump_json_header() |
| 3856 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3857 | chunk_strcat(&trash_chunk, "["); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3858 | } |
| 3859 | |
| 3860 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3861 | /* Dumps the JSON stats trailer block to the local trash buffer. The caller is |
| 3862 | * responsible for clearing the local trash buffer if needed. |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3863 | */ |
| 3864 | static void stats_dump_json_end() |
| 3865 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3866 | chunk_strcat(&trash_chunk, "]\n"); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3867 | } |
| 3868 | |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3869 | /* Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as |
| 3870 | * a pointer to the current server/listener. |
| 3871 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3872 | static int stats_dump_proxies(struct stconn *sc, |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3873 | struct htx *htx) |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3874 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3875 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3876 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3877 | struct channel *rep = sc_ic(sc); |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3878 | struct proxy *px; |
| 3879 | |
| 3880 | /* dump proxies */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3881 | while (ctx->obj1) { |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3882 | if (htx) { |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 3883 | if (htx_almost_full(htx)) { |
| 3884 | sc_need_room(sc, htx->size / 2); |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3885 | goto full; |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 3886 | } |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3887 | } |
| 3888 | else { |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 3889 | if (buffer_almost_full(&rep->buf)) { |
| 3890 | sc_need_room(sc, b_size(&rep->buf) / 2); |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3891 | goto full; |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 3892 | } |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3893 | } |
| 3894 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3895 | px = ctx->obj1; |
Marno Krahmer | 07954fb | 2021-06-24 16:51:08 +0200 | [diff] [blame] | 3896 | /* Skip the global frontend proxies and non-networked ones. |
William Lallemand | 85a16b2 | 2021-08-03 13:18:11 +0200 | [diff] [blame] | 3897 | * Also skip proxies that were disabled in the configuration |
Marno Krahmer | 07954fb | 2021-06-24 16:51:08 +0200 | [diff] [blame] | 3898 | * This change allows retrieving stats from "old" proxies after a reload. |
| 3899 | */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 3900 | if (!(px->flags & PR_FL_DISABLED) && px->uuid > 0 && |
William Lallemand | e7f7462 | 2021-07-28 17:45:18 +0200 | [diff] [blame] | 3901 | (px->cap & (PR_CAP_FE | PR_CAP_BE)) && !(px->cap & PR_CAP_INT)) { |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3902 | if (stats_dump_proxy_to_buffer(sc, htx, px) == 0) |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3903 | return 0; |
| 3904 | } |
| 3905 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3906 | ctx->obj1 = px->next; |
| 3907 | ctx->px_st = STAT_PX_ST_INIT; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3908 | ctx->field = 0; |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3909 | } |
| 3910 | |
| 3911 | return 1; |
| 3912 | |
| 3913 | full: |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3914 | return 0; |
| 3915 | } |
| 3916 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 3917 | /* This function dumps statistics onto the stream connector's read buffer in |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3918 | * either CSV or HTML format. It returns 0 if it had to stop writing data and |
| 3919 | * an I/O is needed, 1 if the dump is finished and the stream must be closed, |
| 3920 | * or -1 in case of any error. This function is used by both the CLI and the |
| 3921 | * HTTP handlers. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3922 | */ |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3923 | static int stats_dump_stat_to_buffer(struct stconn *sc, struct htx *htx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3924 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3925 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3926 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3927 | enum stats_domain domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3928 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3929 | chunk_reset(&trash_chunk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3930 | |
Willy Tarreau | 41f8852 | 2022-05-03 18:39:27 +0200 | [diff] [blame] | 3931 | switch (ctx->state) { |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3932 | case STAT_STATE_INIT: |
| 3933 | ctx->state = STAT_STATE_HEAD; /* let's start producing data */ |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3934 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3935 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3936 | case STAT_STATE_HEAD: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3937 | if (ctx->flags & STAT_FMT_HTML) |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3938 | stats_dump_html_head(appctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3939 | else if (ctx->flags & STAT_JSON_SCHM) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3940 | stats_dump_json_schema(&trash_chunk); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3941 | else if (ctx->flags & STAT_FMT_JSON) |
Willy Tarreau | 9d7fb63 | 2017-04-11 07:53:04 +0200 | [diff] [blame] | 3942 | stats_dump_json_header(); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3943 | else if (!(ctx->flags & STAT_FMT_TYPED)) |
| 3944 | stats_dump_csv_header(ctx->domain); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3945 | |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3946 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3947 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3948 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3949 | if (ctx->flags & STAT_JSON_SCHM) { |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3950 | ctx->state = STAT_STATE_FIN; |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3951 | return 1; |
| 3952 | } |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3953 | ctx->state = STAT_STATE_INFO; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3954 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3955 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3956 | case STAT_STATE_INFO: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3957 | if (ctx->flags & STAT_FMT_HTML) { |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3958 | stats_dump_html_info(sc); |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3959 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3960 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3961 | } |
| 3962 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3963 | if (domain == STATS_DOMAIN_PROXY) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3964 | ctx->obj1 = proxies_list; |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3965 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3966 | ctx->px_st = STAT_PX_ST_INIT; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3967 | ctx->field = 0; |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3968 | ctx->state = STAT_STATE_LIST; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3969 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3970 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3971 | case STAT_STATE_LIST: |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3972 | switch (domain) { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 3973 | case STATS_DOMAIN_RESOLVERS: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3974 | if (!stats_dump_resolvers(sc, stat_l[domain], |
Emeric Brun | d3b4495 | 2021-01-06 16:01:02 +0100 | [diff] [blame] | 3975 | stat_count[domain], |
| 3976 | &stats_module_list[domain])) { |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3977 | return 0; |
| 3978 | } |
| 3979 | break; |
| 3980 | |
| 3981 | case STATS_DOMAIN_PROXY: |
| 3982 | default: |
| 3983 | /* dump proxies */ |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 3984 | if (!stats_dump_proxies(sc, htx)) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3985 | return 0; |
| 3986 | break; |
| 3987 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3988 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3989 | ctx->state = STAT_STATE_END; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3990 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3991 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3992 | case STAT_STATE_END: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3993 | if (ctx->flags & (STAT_FMT_HTML|STAT_FMT_JSON)) { |
| 3994 | if (ctx->flags & STAT_FMT_HTML) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3995 | stats_dump_html_end(); |
| 3996 | else |
| 3997 | stats_dump_json_end(); |
Christopher Faulet | f4258bd | 2023-05-05 10:59:39 +0200 | [diff] [blame] | 3998 | if (!stats_putchk(appctx, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3999 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4000 | } |
| 4001 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 4002 | ctx->state = STAT_STATE_FIN; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 4003 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4004 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 4005 | case STAT_STATE_FIN: |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4006 | return 1; |
| 4007 | |
| 4008 | default: |
| 4009 | /* unknown state ! */ |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 4010 | ctx->state = STAT_STATE_FIN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4011 | return -1; |
| 4012 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4013 | |
| 4014 | full: |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4015 | return 0; |
| 4016 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | /* We reached the stats page through a POST request. The appctx is |
| 4020 | * expected to have already been allocated by the caller. |
| 4021 | * Parse the posted data and enable/disable servers if necessary. |
| 4022 | * Returns 1 if request was parsed or zero if it needs more data. |
| 4023 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4024 | static int stats_process_http_post(struct stconn *sc) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4025 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4026 | struct stream *s = __sc_strm(sc); |
| 4027 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4028 | struct show_stat_ctx *ctx = appctx->svcctx; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4029 | |
| 4030 | struct proxy *px = NULL; |
| 4031 | struct server *sv = NULL; |
| 4032 | |
| 4033 | char key[LINESIZE]; |
| 4034 | int action = ST_ADM_ACTION_NONE; |
| 4035 | int reprocess = 0; |
| 4036 | |
| 4037 | int total_servers = 0; |
| 4038 | int altered_servers = 0; |
| 4039 | |
| 4040 | char *first_param, *cur_param, *next_param, *end_params; |
| 4041 | char *st_cur_param = NULL; |
| 4042 | char *st_next_param = NULL; |
| 4043 | |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4044 | struct buffer *temp = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4045 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4046 | struct htx *htx = htxbuf(&s->req.buf); |
| 4047 | struct htx_blk *blk; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4048 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4049 | /* we need more data */ |
| 4050 | if (s->txn->req.msg_state < HTTP_MSG_DONE) { |
| 4051 | /* check if we can receive more */ |
| 4052 | if (htx_free_data_space(htx) <= global.tune.maxrewrite) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4053 | ctx->st_code = STAT_STATUS_EXCD; |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4054 | goto out; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4055 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4056 | goto wait; |
| 4057 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4058 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4059 | /* The request was fully received. Copy data */ |
| 4060 | blk = htx_get_head_blk(htx); |
| 4061 | while (blk) { |
| 4062 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4063 | |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 4064 | if (type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4065 | break; |
| 4066 | if (type == HTX_BLK_DATA) { |
| 4067 | struct ist v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4068 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4069 | if (!chunk_memcat(temp, v.ptr, v.len)) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4070 | ctx->st_code = STAT_STATUS_EXCD; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4071 | goto out; |
| 4072 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4073 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4074 | blk = htx_get_next_blk(htx, blk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4075 | } |
| 4076 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4077 | first_param = temp->area; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4078 | end_params = temp->area + temp->data; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4079 | cur_param = next_param = end_params; |
| 4080 | *end_params = '\0'; |
| 4081 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4082 | ctx->st_code = STAT_STATUS_NONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4083 | |
| 4084 | /* |
| 4085 | * Parse the parameters in reverse order to only store the last value. |
| 4086 | * From the html form, the backend and the action are at the end. |
| 4087 | */ |
| 4088 | while (cur_param > first_param) { |
| 4089 | char *value; |
| 4090 | int poffset, plen; |
| 4091 | |
| 4092 | cur_param--; |
| 4093 | |
| 4094 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4095 | reprocess_servers: |
| 4096 | /* Parse the key */ |
| 4097 | poffset = (cur_param != first_param ? 1 : 0); |
| 4098 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4099 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4100 | strncpy(key, cur_param + poffset, plen); |
| 4101 | key[plen - 1] = '\0'; |
| 4102 | } else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4103 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4104 | goto out; |
| 4105 | } |
| 4106 | |
| 4107 | /* Parse the value */ |
| 4108 | value = key; |
| 4109 | while (*value != '\0' && *value != '=') { |
| 4110 | value++; |
| 4111 | } |
| 4112 | if (*value == '=') { |
| 4113 | /* Ok, a value is found, we can mark the end of the key */ |
| 4114 | *value++ = '\0'; |
| 4115 | } |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 4116 | if (url_decode(key, 1) < 0 || url_decode(value, 1) < 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4117 | break; |
| 4118 | |
| 4119 | /* Now we can check the key to see what to do */ |
| 4120 | if (!px && (strcmp(key, "b") == 0)) { |
| 4121 | if ((px = proxy_be_by_name(value)) == NULL) { |
| 4122 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4123 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4124 | goto out; |
| 4125 | } |
| 4126 | } |
| 4127 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4128 | if (strcmp(value, "ready") == 0) { |
| 4129 | action = ST_ADM_ACTION_READY; |
| 4130 | } |
| 4131 | else if (strcmp(value, "drain") == 0) { |
| 4132 | action = ST_ADM_ACTION_DRAIN; |
| 4133 | } |
| 4134 | else if (strcmp(value, "maint") == 0) { |
| 4135 | action = ST_ADM_ACTION_MAINT; |
| 4136 | } |
| 4137 | else if (strcmp(value, "shutdown") == 0) { |
| 4138 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4139 | } |
| 4140 | else if (strcmp(value, "dhlth") == 0) { |
| 4141 | action = ST_ADM_ACTION_DHLTH; |
| 4142 | } |
| 4143 | else if (strcmp(value, "ehlth") == 0) { |
| 4144 | action = ST_ADM_ACTION_EHLTH; |
| 4145 | } |
| 4146 | else if (strcmp(value, "hrunn") == 0) { |
| 4147 | action = ST_ADM_ACTION_HRUNN; |
| 4148 | } |
| 4149 | else if (strcmp(value, "hnolb") == 0) { |
| 4150 | action = ST_ADM_ACTION_HNOLB; |
| 4151 | } |
| 4152 | else if (strcmp(value, "hdown") == 0) { |
| 4153 | action = ST_ADM_ACTION_HDOWN; |
| 4154 | } |
| 4155 | else if (strcmp(value, "dagent") == 0) { |
| 4156 | action = ST_ADM_ACTION_DAGENT; |
| 4157 | } |
| 4158 | else if (strcmp(value, "eagent") == 0) { |
| 4159 | action = ST_ADM_ACTION_EAGENT; |
| 4160 | } |
| 4161 | else if (strcmp(value, "arunn") == 0) { |
| 4162 | action = ST_ADM_ACTION_ARUNN; |
| 4163 | } |
| 4164 | else if (strcmp(value, "adown") == 0) { |
| 4165 | action = ST_ADM_ACTION_ADOWN; |
| 4166 | } |
| 4167 | /* else these are the old supported methods */ |
| 4168 | else if (strcmp(value, "disable") == 0) { |
| 4169 | action = ST_ADM_ACTION_DISABLE; |
| 4170 | } |
| 4171 | else if (strcmp(value, "enable") == 0) { |
| 4172 | action = ST_ADM_ACTION_ENABLE; |
| 4173 | } |
| 4174 | else if (strcmp(value, "stop") == 0) { |
| 4175 | action = ST_ADM_ACTION_STOP; |
| 4176 | } |
| 4177 | else if (strcmp(value, "start") == 0) { |
| 4178 | action = ST_ADM_ACTION_START; |
| 4179 | } |
| 4180 | else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4181 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4182 | goto out; |
| 4183 | } |
| 4184 | } |
| 4185 | else if (strcmp(key, "s") == 0) { |
| 4186 | if (!(px && action)) { |
| 4187 | /* |
| 4188 | * Indicates that we'll need to reprocess the parameters |
| 4189 | * as soon as backend and action are known |
| 4190 | */ |
| 4191 | if (!reprocess) { |
| 4192 | st_cur_param = cur_param; |
| 4193 | st_next_param = next_param; |
| 4194 | } |
| 4195 | reprocess = 1; |
| 4196 | } |
| 4197 | else if ((sv = findserver(px, value)) != NULL) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4198 | HA_SPIN_LOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4199 | switch (action) { |
| 4200 | case ST_ADM_ACTION_DISABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4201 | if (!(sv->cur_admin & SRV_ADMF_FMAINT)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4202 | altered_servers++; |
| 4203 | total_servers++; |
Aurelien DARRAGON | 9b1ccd7 | 2023-04-03 17:40:28 +0200 | [diff] [blame] | 4204 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT, SRV_ADM_STCHGC_STATS_DISABLE); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4205 | } |
| 4206 | break; |
| 4207 | case ST_ADM_ACTION_ENABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4208 | if (sv->cur_admin & SRV_ADMF_FMAINT) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4209 | altered_servers++; |
| 4210 | total_servers++; |
| 4211 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
| 4212 | } |
| 4213 | break; |
| 4214 | case ST_ADM_ACTION_STOP: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4215 | if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) { |
Aurelien DARRAGON | 9b1ccd7 | 2023-04-03 17:40:28 +0200 | [diff] [blame] | 4216 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, SRV_ADM_STCHGC_STATS_STOP); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4217 | altered_servers++; |
| 4218 | total_servers++; |
| 4219 | } |
| 4220 | break; |
| 4221 | case ST_ADM_ACTION_START: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4222 | if (sv->cur_admin & SRV_ADMF_FDRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4223 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4224 | altered_servers++; |
| 4225 | total_servers++; |
| 4226 | } |
| 4227 | break; |
| 4228 | case ST_ADM_ACTION_DHLTH: |
| 4229 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4230 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4231 | altered_servers++; |
| 4232 | total_servers++; |
| 4233 | } |
| 4234 | break; |
| 4235 | case ST_ADM_ACTION_EHLTH: |
| 4236 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4237 | sv->check.state |= CHK_ST_ENABLED; |
| 4238 | altered_servers++; |
| 4239 | total_servers++; |
| 4240 | } |
| 4241 | break; |
| 4242 | case ST_ADM_ACTION_HRUNN: |
| 4243 | if (!(sv->track)) { |
| 4244 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Aurelien DARRAGON | 1746b56 | 2023-04-04 10:17:40 +0200 | [diff] [blame] | 4245 | srv_set_running(sv, SRV_OP_STCHGC_STATS_WEB); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4246 | altered_servers++; |
| 4247 | total_servers++; |
| 4248 | } |
| 4249 | break; |
| 4250 | case ST_ADM_ACTION_HNOLB: |
| 4251 | if (!(sv->track)) { |
| 4252 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Aurelien DARRAGON | 1746b56 | 2023-04-04 10:17:40 +0200 | [diff] [blame] | 4253 | srv_set_stopping(sv, SRV_OP_STCHGC_STATS_WEB); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4254 | altered_servers++; |
| 4255 | total_servers++; |
| 4256 | } |
| 4257 | break; |
| 4258 | case ST_ADM_ACTION_HDOWN: |
| 4259 | if (!(sv->track)) { |
| 4260 | sv->check.health = 0; |
Aurelien DARRAGON | 1746b56 | 2023-04-04 10:17:40 +0200 | [diff] [blame] | 4261 | srv_set_stopped(sv, SRV_OP_STCHGC_STATS_WEB); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4262 | altered_servers++; |
| 4263 | total_servers++; |
| 4264 | } |
| 4265 | break; |
| 4266 | case ST_ADM_ACTION_DAGENT: |
| 4267 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4268 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4269 | altered_servers++; |
| 4270 | total_servers++; |
| 4271 | } |
| 4272 | break; |
| 4273 | case ST_ADM_ACTION_EAGENT: |
| 4274 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4275 | sv->agent.state |= CHK_ST_ENABLED; |
| 4276 | altered_servers++; |
| 4277 | total_servers++; |
| 4278 | } |
| 4279 | break; |
| 4280 | case ST_ADM_ACTION_ARUNN: |
| 4281 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4282 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
Aurelien DARRAGON | 1746b56 | 2023-04-04 10:17:40 +0200 | [diff] [blame] | 4283 | srv_set_running(sv, SRV_OP_STCHGC_STATS_WEB); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4284 | altered_servers++; |
| 4285 | total_servers++; |
| 4286 | } |
| 4287 | break; |
| 4288 | case ST_ADM_ACTION_ADOWN: |
| 4289 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4290 | sv->agent.health = 0; |
Aurelien DARRAGON | 1746b56 | 2023-04-04 10:17:40 +0200 | [diff] [blame] | 4291 | srv_set_stopped(sv, SRV_OP_STCHGC_STATS_WEB); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4292 | altered_servers++; |
| 4293 | total_servers++; |
| 4294 | } |
| 4295 | break; |
| 4296 | case ST_ADM_ACTION_READY: |
| 4297 | srv_adm_set_ready(sv); |
| 4298 | altered_servers++; |
| 4299 | total_servers++; |
| 4300 | break; |
| 4301 | case ST_ADM_ACTION_DRAIN: |
| 4302 | srv_adm_set_drain(sv); |
| 4303 | altered_servers++; |
| 4304 | total_servers++; |
| 4305 | break; |
| 4306 | case ST_ADM_ACTION_MAINT: |
| 4307 | srv_adm_set_maint(sv); |
| 4308 | altered_servers++; |
| 4309 | total_servers++; |
| 4310 | break; |
| 4311 | case ST_ADM_ACTION_SHUTDOWN: |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 4312 | if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) { |
Willy Tarreau | af7ea81 | 2019-11-14 16:42:04 +0100 | [diff] [blame] | 4313 | srv_shutdown_streams(sv, SF_ERR_KILLED); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4314 | altered_servers++; |
| 4315 | total_servers++; |
| 4316 | } |
| 4317 | break; |
| 4318 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4319 | HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4320 | } else { |
| 4321 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4322 | total_servers++; |
| 4323 | } |
| 4324 | } |
| 4325 | if (reprocess && px && action) { |
| 4326 | /* Now, we know the backend and the action chosen by the user. |
| 4327 | * We can safely restart from the first server parameter |
| 4328 | * to reprocess them |
| 4329 | */ |
| 4330 | cur_param = st_cur_param; |
| 4331 | next_param = st_next_param; |
| 4332 | reprocess = 0; |
| 4333 | goto reprocess_servers; |
| 4334 | } |
| 4335 | |
| 4336 | next_param = cur_param; |
| 4337 | } |
| 4338 | } |
| 4339 | |
| 4340 | if (total_servers == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4341 | ctx->st_code = STAT_STATUS_NONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4342 | } |
| 4343 | else if (altered_servers == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4344 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4345 | } |
| 4346 | else if (altered_servers == total_servers) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4347 | ctx->st_code = STAT_STATUS_DONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4348 | } |
| 4349 | else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4350 | ctx->st_code = STAT_STATUS_PART; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4351 | } |
| 4352 | out: |
| 4353 | return 1; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4354 | wait: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4355 | ctx->st_code = STAT_STATUS_NONE; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4356 | return 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4360 | static int stats_send_http_headers(struct stconn *sc, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4361 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4362 | struct stream *s = __sc_strm(sc); |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 4363 | struct uri_auth *uri; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4364 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4365 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4366 | struct htx_sl *sl; |
| 4367 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4368 | |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 4369 | BUG_ON(!ctx->http_px); |
| 4370 | uri = ctx->http_px->uri_auth; |
| 4371 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4372 | flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_ENC|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK); |
| 4373 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 4374 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4375 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4376 | sl->info.res.status = 200; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4377 | |
Christopher Faulet | b829f4c | 2019-03-29 16:13:55 +0100 | [diff] [blame] | 4378 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache"))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4379 | goto full; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4380 | if (ctx->flags & STAT_FMT_HTML) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4381 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/html"))) |
| 4382 | goto full; |
| 4383 | } |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4384 | else if (ctx->flags & (STAT_FMT_JSON|STAT_JSON_SCHM)) { |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 4385 | if (!htx_add_header(htx, ist("Content-Type"), ist("application/json"))) |
| 4386 | goto full; |
| 4387 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4388 | else { |
| 4389 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain"))) |
| 4390 | goto full; |
| 4391 | } |
| 4392 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4393 | if (uri->refresh > 0 && !(ctx->flags & STAT_NO_REFRESH)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4394 | const char *refresh = U2A(uri->refresh); |
Tim Duesterhus | dcf753a | 2021-03-04 17:31:47 +0100 | [diff] [blame] | 4395 | if (!htx_add_header(htx, ist("Refresh"), ist(refresh))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4396 | goto full; |
| 4397 | } |
| 4398 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4399 | if (ctx->flags & STAT_CHUNKED) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4400 | if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked"))) |
| 4401 | goto full; |
| 4402 | } |
| 4403 | |
| 4404 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 4405 | goto full; |
| 4406 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 4407 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4408 | return 1; |
| 4409 | |
| 4410 | full: |
| 4411 | htx_reset(htx); |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 4412 | sc_need_room(sc, 0); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4413 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4414 | } |
| 4415 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4416 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4417 | static int stats_send_http_redirect(struct stconn *sc, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4418 | { |
| 4419 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4420 | struct stream *s = __sc_strm(sc); |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 4421 | struct uri_auth *uri; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4422 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4423 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4424 | struct htx_sl *sl; |
| 4425 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4426 | |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 4427 | BUG_ON(!ctx->http_px); |
| 4428 | uri = ctx->http_px->uri_auth; |
| 4429 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4430 | /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4431 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4432 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4433 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 4434 | |
Willy Tarreau | fc458ec | 2023-04-07 18:11:39 +0200 | [diff] [blame] | 4435 | strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4436 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 4437 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | /* We don't want to land on the posted stats page because a refresh will |
| 4441 | * repost the data. We don't want this to happen on accident so we redirect |
| 4442 | * the browse to the stats page with a GET. |
| 4443 | */ |
| 4444 | chunk_printf(&trash, "%s;st=%s%s%s%s", |
| 4445 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4446 | ((ctx->st_code > STAT_STATUS_INIT) && |
| 4447 | (ctx->st_code < STAT_STATUS_SIZE) && |
| 4448 | stat_status_codes[ctx->st_code]) ? |
| 4449 | stat_status_codes[ctx->st_code] : |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4450 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4451 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4452 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4453 | scope_txt); |
| 4454 | |
Christopher Faulet | ea0a9a6 | 2024-05-17 15:42:46 +0200 | [diff] [blame] | 4455 | flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CLEN|HTX_SL_F_BODYLESS); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4456 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other")); |
| 4457 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4458 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4459 | sl->info.res.status = 303; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4460 | |
| 4461 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4462 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) || |
| 4463 | !htx_add_header(htx, ist("Content-Length"), ist("0")) || |
| 4464 | !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data))) |
| 4465 | goto full; |
| 4466 | |
| 4467 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 4468 | goto full; |
| 4469 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 4470 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4471 | return 1; |
| 4472 | |
| 4473 | full: |
| 4474 | htx_reset(htx); |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 4475 | sc_need_room(sc, 0); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4476 | return 0; |
| 4477 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4478 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 4479 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4480 | /* This I/O handler runs as an applet embedded in a stream connector. It is |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4481 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 4482 | * appctx->st0 contains the operation in progress (dump, done). The handler |
| 4483 | * automatically unregisters itself once transfer is complete. |
| 4484 | */ |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4485 | static void http_stats_io_handler(struct appctx *appctx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4486 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4487 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 4488 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4489 | struct stream *s = __sc_strm(sc); |
| 4490 | struct channel *req = sc_oc(sc); |
| 4491 | struct channel *res = sc_ic(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4492 | struct htx *req_htx, *res_htx; |
| 4493 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4494 | /* only proxy stats are available via http */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4495 | ctx->domain = STATS_DOMAIN_PROXY; |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4496 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4497 | res_htx = htx_from_buf(&res->buf); |
| 4498 | |
Christopher Faulet | 9837bd8 | 2023-04-11 07:41:30 +0200 | [diff] [blame] | 4499 | if (unlikely(se_fl_test(appctx->sedesc, (SE_FL_EOS|SE_FL_ERROR|SE_FL_SHR|SE_FL_SHW)))) { |
| 4500 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4501 | goto out; |
Christopher Faulet | 9837bd8 | 2023-04-11 07:41:30 +0200 | [diff] [blame] | 4502 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4503 | |
Ilya Shipitsin | 856aabc | 2020-04-16 23:51:34 +0500 | [diff] [blame] | 4504 | /* Check if the input buffer is available. */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4505 | if (!b_size(&res->buf)) { |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 4506 | sc_need_room(sc, 0); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4507 | goto out; |
| 4508 | } |
| 4509 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4510 | /* all states are processed in sequence */ |
| 4511 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4512 | if (stats_send_http_headers(sc, res_htx)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4513 | if (s->txn->meth == HTTP_METH_HEAD) |
| 4514 | appctx->st0 = STAT_HTTP_DONE; |
| 4515 | else |
| 4516 | appctx->st0 = STAT_HTTP_DUMP; |
| 4517 | } |
| 4518 | } |
| 4519 | |
| 4520 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Aurelien DARRAGON | 1465684 | 2023-02-03 08:31:42 +0100 | [diff] [blame] | 4521 | trash_chunk = b_make(trash.area, res->buf.size, 0, 0); |
Aurelien DARRAGON | 5e7ecbe | 2023-02-02 15:03:12 +0100 | [diff] [blame] | 4522 | /* adjust buffer size to take htx overhead into account, |
| 4523 | * make sure to perform this call on an empty buffer |
| 4524 | */ |
| 4525 | trash_chunk.size = buf_room_for_htx_data(&trash_chunk); |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 4526 | if (stats_dump_stat_to_buffer(sc, res_htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4527 | appctx->st0 = STAT_HTTP_DONE; |
| 4528 | } |
| 4529 | |
| 4530 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4531 | if (stats_process_http_post(sc)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4532 | appctx->st0 = STAT_HTTP_LAST; |
Christopher Faulet | ca5309a | 2023-04-17 16:17:32 +0200 | [diff] [blame] | 4533 | else if (s->scf->flags & (SC_FL_EOS|SC_FL_ABRT_DONE)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4534 | appctx->st0 = STAT_HTTP_DONE; |
| 4535 | } |
| 4536 | |
| 4537 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4538 | if (stats_send_http_redirect(sc, res_htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4539 | appctx->st0 = STAT_HTTP_DONE; |
| 4540 | } |
| 4541 | |
| 4542 | if (appctx->st0 == STAT_HTTP_DONE) { |
Christopher Faulet | 08b45cb | 2022-04-07 09:25:13 +0200 | [diff] [blame] | 4543 | /* no more data are expected. If the response buffer is empty, |
| 4544 | * be sure to add something (EOT block in this case) to have |
| 4545 | * something to send. It is important to be sure the EOM flags |
| 4546 | * will be handled by the endpoint. |
| 4547 | */ |
| 4548 | if (htx_is_empty(res_htx)) { |
| 4549 | if (!htx_add_endof(res_htx, HTX_BLK_EOT)) { |
Christopher Faulet | 7b3d38a | 2023-05-05 11:28:45 +0200 | [diff] [blame] | 4550 | sc_need_room(sc, sizeof(struct htx_blk) + 1); |
Christopher Faulet | 08b45cb | 2022-04-07 09:25:13 +0200 | [diff] [blame] | 4551 | goto out; |
| 4552 | } |
| 4553 | channel_add_input(res, 1); |
| 4554 | } |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 4555 | res_htx->flags |= HTX_FL_EOM; |
Willy Tarreau | d869e13 | 2022-05-17 18:05:31 +0200 | [diff] [blame] | 4556 | se_fl_set(appctx->sedesc, SE_FL_EOI); |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4557 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4558 | } |
| 4559 | |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4560 | if (appctx->st0 == STAT_HTTP_END) { |
Christopher Faulet | df15a5d | 2023-03-31 11:28:22 +0200 | [diff] [blame] | 4561 | se_fl_set(appctx->sedesc, SE_FL_EOS); |
Christopher Faulet | c2c043e | 2023-03-22 09:30:40 +0100 | [diff] [blame] | 4562 | applet_will_consume(appctx); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4563 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4564 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4565 | out: |
| 4566 | /* we have left the request in the buffer for the case where we |
| 4567 | * process a POST, and this automatically re-enables activity on |
| 4568 | * read. It's better to indicate that we want to stop reading when |
| 4569 | * we're sending, so that we know there's at most one direction |
| 4570 | * deciding to wake the applet up. It saves it from looping when |
| 4571 | * emitting large blocks into small TCP windows. |
| 4572 | */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 4573 | htx_to_buf(res_htx, &res->buf); |
Christopher Faulet | c2c043e | 2023-03-22 09:30:40 +0100 | [diff] [blame] | 4574 | if (appctx->st0 == STAT_HTTP_END) { |
| 4575 | /* eat the whole request */ |
| 4576 | if (co_data(req)) { |
| 4577 | req_htx = htx_from_buf(&req->buf); |
| 4578 | co_htx_skip(req, req_htx, co_data(req)); |
| 4579 | htx_to_buf(req_htx, &req->buf); |
| 4580 | } |
| 4581 | } |
| 4582 | else if (!channel_is_empty(res)) |
Willy Tarreau | 75a8f8e | 2022-05-25 18:12:11 +0200 | [diff] [blame] | 4583 | applet_wont_consume(appctx); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4584 | } |
| 4585 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4586 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4587 | static int stats_dump_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4588 | const struct field *info, |
| 4589 | struct show_stat_ctx *ctx) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4590 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4591 | int flags = ctx->flags; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4592 | int field; |
| 4593 | |
| 4594 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 4595 | if (!field_format(info, field)) |
| 4596 | continue; |
| 4597 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 4598 | if (!chunk_appendf(out, "%s: ", info_fields[field].name)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4599 | return 0; |
| 4600 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 4601 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 4602 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 4603 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4604 | if (!chunk_strcat(out, "\n")) |
| 4605 | return 0; |
| 4606 | } |
| 4607 | return 1; |
| 4608 | } |
| 4609 | |
| 4610 | /* Dump all fields from <info> into <out> using the "show info typed" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4611 | static int stats_dump_typed_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4612 | const struct field *info, |
| 4613 | struct show_stat_ctx *ctx) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4614 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4615 | int flags = ctx->flags; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4616 | int field; |
| 4617 | |
| 4618 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 4619 | if (!field_format(info, field)) |
| 4620 | continue; |
| 4621 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 4622 | if (!chunk_appendf(out, "%d.%s.%u:", field, info_fields[field].name, info[INF_PROCESS_NUM].u.u32)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4623 | return 0; |
| 4624 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 4625 | return 0; |
| 4626 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 4627 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 4628 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 4629 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4630 | if (!chunk_strcat(out, "\n")) |
| 4631 | return 0; |
| 4632 | } |
| 4633 | return 1; |
| 4634 | } |
| 4635 | |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 4636 | /* Fill <info> with HAProxy global info. <info> is preallocated array of length |
| 4637 | * <len>. The length of the array must be INF_TOTAL_FIELDS. If this length is |
| 4638 | * less then this value, the function returns 0, otherwise, it returns 1. Some |
| 4639 | * fields' presence or precision may depend on some of the STAT_* flags present |
| 4640 | * in <flags>. |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4641 | */ |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 4642 | int stats_fill_info(struct field *info, int len, uint flags) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4643 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4644 | struct buffer *out = get_trash_chunk(); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4645 | uint64_t glob_out_bytes, glob_spl_bytes, glob_out_b32; |
Willy Tarreau | 563efe6 | 2023-04-27 14:41:37 +0200 | [diff] [blame] | 4646 | uint up_sec, up_usec; |
| 4647 | ullong up; |
Willy Tarreau | 5723b38 | 2023-05-17 09:05:20 +0200 | [diff] [blame] | 4648 | ulong boot; |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4649 | int thr; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4650 | |
| 4651 | #ifdef USE_OPENSSL |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4652 | double ssl_sess_rate = read_freq_ctr_flt(&global.ssl_per_sec); |
| 4653 | double ssl_key_rate = read_freq_ctr_flt(&global.ssl_fe_keys_per_sec); |
| 4654 | double ssl_reuse = 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4655 | |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4656 | if (ssl_key_rate < ssl_sess_rate) |
| 4657 | ssl_reuse = 100.0 * (1.0 - ssl_key_rate / ssl_sess_rate); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4658 | #endif |
| 4659 | |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4660 | /* sum certain per-thread totals (mostly byte counts) */ |
| 4661 | glob_out_bytes = glob_spl_bytes = glob_out_b32 = 0; |
| 4662 | for (thr = 0; thr < global.nbthread; thr++) { |
| 4663 | glob_out_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].out_bytes); |
| 4664 | glob_spl_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].spliced_out_bytes); |
| 4665 | glob_out_b32 += read_freq_ctr(&ha_thread_ctx[thr].out_32bps); |
| 4666 | } |
| 4667 | glob_out_b32 *= 32; // values are 32-byte units |
| 4668 | |
Willy Tarreau | c05d30e | 2023-04-28 14:50:29 +0200 | [diff] [blame] | 4669 | up = now_ns - start_time_ns; |
Willy Tarreau | 563efe6 | 2023-04-27 14:41:37 +0200 | [diff] [blame] | 4670 | up_sec = ns_to_sec(up); |
| 4671 | up_usec = (up / 1000U) % 1000000U; |
Willy Tarreau | d37e26e | 2021-05-08 07:40:52 +0200 | [diff] [blame] | 4672 | |
Willy Tarreau | 5723b38 | 2023-05-17 09:05:20 +0200 | [diff] [blame] | 4673 | boot = tv_ms_remain(&start_date, &ready_date); |
| 4674 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4675 | if (len < INF_TOTAL_FIELDS) |
| 4676 | return 0; |
| 4677 | |
| 4678 | chunk_reset(out); |
| 4679 | memset(info, 0, sizeof(*info) * len); |
| 4680 | |
| 4681 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
Willy Tarreau | 909b9d8 | 2019-01-04 18:20:32 +0100 | [diff] [blame] | 4682 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version); |
Adis Nezirovic | b62b78b | 2021-01-15 13:12:33 +0100 | [diff] [blame] | 4683 | info[INF_BUILD_INFO] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version); |
Willy Tarreau | 909b9d8 | 2019-01-04 18:20:32 +0100 | [diff] [blame] | 4684 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_date); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4685 | |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 4686 | info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread); |
Willy Tarreau | 9135859 | 2021-06-15 08:08:04 +0200 | [diff] [blame] | 4687 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, 1); |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 4688 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, 1); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4689 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 4690 | |
| 4691 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
Willy Tarreau | 563efe6 | 2023-04-27 14:41:37 +0200 | [diff] [blame] | 4692 | chunk_appendf(out, "%ud %uh%02um%02us", up_sec / 86400, (up_sec % 86400) / 3600, (up_sec % 3600) / 60, (up_sec % 60)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4693 | |
Willy Tarreau | 563efe6 | 2023-04-27 14:41:37 +0200 | [diff] [blame] | 4694 | info[INF_UPTIME_SEC] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, up_sec + up_usec / 1000000.0) : mkf_u32(FN_DURATION, up_sec); |
Willy Tarreau | 7222db7 | 2023-04-28 15:57:18 +0200 | [diff] [blame] | 4695 | info[INF_START_TIME_SEC] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, start_date.tv_sec + start_date.tv_usec / 1000000.0) : mkf_u32(FN_DURATION, start_date.tv_sec); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4696 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
William Dauchy | a8766cf | 2021-01-15 22:41:37 +0100 | [diff] [blame] | 4697 | info[INF_MEMMAX_BYTES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4698 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
Christopher Faulet | c960a3b | 2022-12-22 11:05:48 +0100 | [diff] [blame] | 4699 | info[INF_POOL_ALLOC_BYTES] = mkf_u64(0, pool_total_allocated()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4700 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
Christopher Faulet | c960a3b | 2022-12-22 11:05:48 +0100 | [diff] [blame] | 4701 | info[INF_POOL_USED_BYTES] = mkf_u64(0, pool_total_used()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4702 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 4703 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 4704 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 4705 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 4706 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 4707 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 4708 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 4709 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 4710 | #ifdef USE_OPENSSL |
| 4711 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
Willy Tarreau | 82531f6 | 2021-10-06 12:15:18 +0200 | [diff] [blame] | 4712 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, global.sslconns); |
| 4713 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, global.totalsslconns); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4714 | #endif |
| 4715 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 4716 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 4717 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4718 | info[INF_CONN_RATE] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, read_freq_ctr_flt(&global.conn_per_sec)) : mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4719 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 4720 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4721 | info[INF_SESS_RATE] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, read_freq_ctr_flt(&global.sess_per_sec)) : mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4722 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 4723 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 4724 | |
| 4725 | #ifdef USE_OPENSSL |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4726 | info[INF_SSL_RATE] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, ssl_sess_rate) : mkf_u32(FN_RATE, ssl_sess_rate); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4727 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 4728 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4729 | info[INF_SSL_FRONTEND_KEY_RATE] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, ssl_key_rate) : mkf_u32(0, ssl_key_rate); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4730 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4731 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, ssl_reuse) : mkf_u32(0, ssl_reuse); |
| 4732 | info[INF_SSL_BACKEND_KEY_RATE] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, read_freq_ctr_flt(&global.ssl_be_keys_per_sec)) : mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4733 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 4734 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 4735 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 4736 | #endif |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4737 | info[INF_COMPRESS_BPS_IN] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, read_freq_ctr_flt(&global.comp_bps_in)) : mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 4738 | info[INF_COMPRESS_BPS_OUT] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, read_freq_ctr_flt(&global.comp_bps_out)) : mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4739 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 4740 | #ifdef USE_ZLIB |
| 4741 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 4742 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 4743 | #endif |
Willy Tarreau | 955a11e | 2021-02-24 17:03:30 +0100 | [diff] [blame] | 4744 | info[INF_TASKS] = mkf_u32(0, total_allocated_tasks()); |
Willy Tarreau | 9c7b808 | 2021-02-24 15:10:07 +0100 | [diff] [blame] | 4745 | info[INF_RUN_QUEUE] = mkf_u32(0, total_run_queues()); |
Willy Tarreau | f9d5e10 | 2021-10-08 10:43:59 +0200 | [diff] [blame] | 4746 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, clock_report_idle()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4747 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 4748 | if (global.desc) |
| 4749 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 4750 | info[INF_STOPPING] = mkf_u32(0, stopping); |
| 4751 | info[INF_JOBS] = mkf_u32(0, jobs); |
William Lallemand | a719926 | 2018-11-16 16:57:20 +0100 | [diff] [blame] | 4752 | info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs); |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 4753 | info[INF_LISTENERS] = mkf_u32(0, listeners); |
Willy Tarreau | 199ad24 | 2018-11-05 16:31:22 +0100 | [diff] [blame] | 4754 | info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers); |
Willy Tarreau | 2d372c2 | 2018-11-05 17:12:27 +0100 | [diff] [blame] | 4755 | info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers); |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 4756 | info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs); |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 4757 | info[INF_BUSY_POLLING] = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING)); |
Emeric Brun | d30e9a1 | 2020-12-23 18:49:16 +0100 | [diff] [blame] | 4758 | info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, resolv_failed_resolutions); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4759 | info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, glob_out_bytes); |
| 4760 | info[INF_TOTAL_SPLICED_BYTES_OUT] = mkf_u64(0, glob_spl_bytes); |
| 4761 | info[INF_BYTES_OUT_RATE] = mkf_u64(FN_RATE, glob_out_b32); |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 4762 | info[INF_DEBUG_COMMANDS_ISSUED] = mkf_u32(0, debug_commands_issued); |
Emeric Brun | 45c457a | 2020-07-09 23:23:34 +0200 | [diff] [blame] | 4763 | info[INF_CUM_LOG_MSGS] = mkf_u32(FN_COUNTER, cum_log_messages); |
Amaury Denoyelle | 5dfdf3e | 2021-05-05 17:09:12 +0200 | [diff] [blame] | 4764 | |
| 4765 | info[INF_TAINTED] = mkf_str(FO_STATUS, chunk_newstr(out)); |
Willy Tarreau | 52fd879 | 2023-05-17 08:43:15 +0200 | [diff] [blame] | 4766 | chunk_appendf(out, "%#x", get_tainted()); |
Willy Tarreau | 3c4a297 | 2023-05-11 12:02:21 +0200 | [diff] [blame] | 4767 | info[INF_WARNINGS] = mkf_u32(FN_COUNTER, HA_ATOMIC_LOAD(&tot_warnings)); |
Willy Tarreau | 9615102 | 2023-05-11 13:51:31 +0200 | [diff] [blame] | 4768 | info[INF_MAXCONN_REACHED] = mkf_u32(FN_COUNTER, HA_ATOMIC_LOAD(&maxconn_reached)); |
Willy Tarreau | 5723b38 | 2023-05-17 09:05:20 +0200 | [diff] [blame] | 4769 | info[INF_BOOTTIME_MS] = mkf_u32(FN_DURATION, boot); |
Amaury Denoyelle | 5dfdf3e | 2021-05-05 17:09:12 +0200 | [diff] [blame] | 4770 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4771 | return 1; |
| 4772 | } |
| 4773 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4774 | /* This function dumps information onto the stream connector's read buffer. |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4775 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4776 | * No state is used. |
| 4777 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4778 | static int stats_dump_info_to_buffer(struct stconn *sc) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4779 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4780 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4781 | struct show_stat_ctx *ctx = appctx->svcctx; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4782 | int ret; |
| 4783 | int current_field; |
Christopher Faulet | 2da02ae | 2022-02-24 13:45:27 +0100 | [diff] [blame] | 4784 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4785 | if (!stats_fill_info(info, INF_TOTAL_FIELDS, ctx->flags)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4786 | return 0; |
| 4787 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4788 | chunk_reset(&trash_chunk); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4789 | more: |
| 4790 | current_field = ctx->field; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4791 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4792 | if (ctx->flags & STAT_FMT_TYPED) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4793 | ret = stats_dump_typed_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4794 | else if (ctx->flags & STAT_FMT_JSON) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4795 | ret = stats_dump_json_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4796 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4797 | ret = stats_dump_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4798 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4799 | if (applet_putchk(appctx, &trash_chunk) == -1) { |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4800 | /* restore previous field */ |
| 4801 | ctx->field = current_field; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4802 | return 0; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4803 | } |
| 4804 | if (ret && ctx->field) { |
| 4805 | /* partial dump */ |
| 4806 | goto more; |
| 4807 | } |
| 4808 | ctx->field = 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4809 | return 1; |
| 4810 | } |
| 4811 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4812 | /* This function dumps the schema onto the stream connector's read buffer. |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4813 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4814 | * No state is used. |
| 4815 | * |
Ilya Shipitsin | f38a018 | 2020-12-21 01:16:17 +0500 | [diff] [blame] | 4816 | * Integer values bounded to the range [-(2**53)+1, (2**53)-1] as |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4817 | * per the recommendation for interoperable integers in section 6 of RFC 7159. |
| 4818 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4819 | static void stats_dump_json_schema(struct buffer *out) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4820 | { |
| 4821 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4822 | int old_len = out->data; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4823 | |
| 4824 | chunk_strcat(out, |
| 4825 | "{" |
| 4826 | "\"$schema\":\"http://json-schema.org/draft-04/schema#\"," |
| 4827 | "\"oneOf\":[" |
| 4828 | "{" |
| 4829 | "\"title\":\"Info\"," |
| 4830 | "\"type\":\"array\"," |
| 4831 | "\"items\":{" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 4832 | "\"title\":\"InfoItem\"," |
| 4833 | "\"type\":\"object\"," |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4834 | "\"properties\":{" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4835 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 4836 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 4837 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 4838 | "\"value\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 4839 | "}," |
| 4840 | "\"required\":[\"field\",\"processNum\",\"tags\"," |
| 4841 | "\"value\"]" |
| 4842 | "}" |
| 4843 | "}," |
| 4844 | "{" |
| 4845 | "\"title\":\"Stat\"," |
| 4846 | "\"type\":\"array\"," |
| 4847 | "\"items\":{" |
| 4848 | "\"title\":\"InfoItem\"," |
| 4849 | "\"type\":\"object\"," |
| 4850 | "\"properties\":{" |
| 4851 | "\"objType\":{" |
| 4852 | "\"enum\":[\"Frontend\",\"Backend\",\"Listener\"," |
| 4853 | "\"Server\",\"Unknown\"]" |
| 4854 | "}," |
| 4855 | "\"proxyId\":{" |
| 4856 | "\"type\":\"integer\"," |
| 4857 | "\"minimum\":0" |
| 4858 | "}," |
| 4859 | "\"id\":{" |
| 4860 | "\"type\":\"integer\"," |
| 4861 | "\"minimum\":0" |
| 4862 | "}," |
| 4863 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 4864 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 4865 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 4866 | "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 4867 | "}," |
| 4868 | "\"required\":[\"objType\",\"proxyId\",\"id\"," |
| 4869 | "\"field\",\"processNum\",\"tags\"," |
| 4870 | "\"value\"]" |
| 4871 | "}" |
| 4872 | "}," |
| 4873 | "{" |
| 4874 | "\"title\":\"Error\"," |
| 4875 | "\"type\":\"object\"," |
| 4876 | "\"properties\":{" |
| 4877 | "\"errorStr\":{" |
| 4878 | "\"type\":\"string\"" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 4879 | "}" |
| 4880 | "}," |
| 4881 | "\"required\":[\"errorStr\"]" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4882 | "}" |
| 4883 | "]," |
| 4884 | "\"definitions\":{" |
| 4885 | "\"field\":{" |
| 4886 | "\"type\":\"object\"," |
| 4887 | "\"pos\":{" |
| 4888 | "\"type\":\"integer\"," |
| 4889 | "\"minimum\":0" |
| 4890 | "}," |
| 4891 | "\"name\":{" |
| 4892 | "\"type\":\"string\"" |
| 4893 | "}," |
| 4894 | "\"required\":[\"pos\",\"name\"]" |
| 4895 | "}," |
| 4896 | "\"processNum\":{" |
| 4897 | "\"type\":\"integer\"," |
| 4898 | "\"minimum\":1" |
| 4899 | "}," |
| 4900 | "\"tags\":{" |
| 4901 | "\"type\":\"object\"," |
| 4902 | "\"origin\":{" |
| 4903 | "\"type\":\"string\"," |
| 4904 | "\"enum\":[\"Metric\",\"Status\",\"Key\"," |
| 4905 | "\"Config\",\"Product\",\"Unknown\"]" |
| 4906 | "}," |
| 4907 | "\"nature\":{" |
| 4908 | "\"type\":\"string\"," |
| 4909 | "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\"," |
| 4910 | "\"Rate\",\"Counter\",\"Duration\"," |
| 4911 | "\"Age\",\"Time\",\"Name\",\"Output\"," |
| 4912 | "\"Avg\", \"Unknown\"]" |
| 4913 | "}," |
| 4914 | "\"scope\":{" |
| 4915 | "\"type\":\"string\"," |
| 4916 | "\"enum\":[\"Cluster\",\"Process\",\"Service\"," |
| 4917 | "\"System\",\"Unknown\"]" |
| 4918 | "}," |
| 4919 | "\"required\":[\"origin\",\"nature\",\"scope\"]" |
| 4920 | "}," |
| 4921 | "\"typedValue\":{" |
| 4922 | "\"type\":\"object\"," |
| 4923 | "\"oneOf\":[" |
| 4924 | "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"}," |
| 4925 | "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"}," |
| 4926 | "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"}," |
| 4927 | "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"}," |
| 4928 | "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}" |
| 4929 | "]," |
| 4930 | "\"definitions\":{" |
| 4931 | "\"s32Value\":{" |
| 4932 | "\"properties\":{" |
| 4933 | "\"type\":{" |
| 4934 | "\"type\":\"string\"," |
| 4935 | "\"enum\":[\"s32\"]" |
| 4936 | "}," |
| 4937 | "\"value\":{" |
| 4938 | "\"type\":\"integer\"," |
| 4939 | "\"minimum\":-2147483648," |
| 4940 | "\"maximum\":2147483647" |
| 4941 | "}" |
| 4942 | "}," |
| 4943 | "\"required\":[\"type\",\"value\"]" |
| 4944 | "}," |
| 4945 | "\"s64Value\":{" |
| 4946 | "\"properties\":{" |
| 4947 | "\"type\":{" |
| 4948 | "\"type\":\"string\"," |
| 4949 | "\"enum\":[\"s64\"]" |
| 4950 | "}," |
| 4951 | "\"value\":{" |
| 4952 | "\"type\":\"integer\"," |
| 4953 | "\"minimum\":-9007199254740991," |
| 4954 | "\"maximum\":9007199254740991" |
| 4955 | "}" |
| 4956 | "}," |
| 4957 | "\"required\":[\"type\",\"value\"]" |
| 4958 | "}," |
| 4959 | "\"u32Value\":{" |
| 4960 | "\"properties\":{" |
| 4961 | "\"type\":{" |
| 4962 | "\"type\":\"string\"," |
| 4963 | "\"enum\":[\"u32\"]" |
| 4964 | "}," |
| 4965 | "\"value\":{" |
| 4966 | "\"type\":\"integer\"," |
| 4967 | "\"minimum\":0," |
| 4968 | "\"maximum\":4294967295" |
| 4969 | "}" |
| 4970 | "}," |
| 4971 | "\"required\":[\"type\",\"value\"]" |
| 4972 | "}," |
| 4973 | "\"u64Value\":{" |
| 4974 | "\"properties\":{" |
| 4975 | "\"type\":{" |
| 4976 | "\"type\":\"string\"," |
| 4977 | "\"enum\":[\"u64\"]" |
| 4978 | "}," |
| 4979 | "\"value\":{" |
| 4980 | "\"type\":\"integer\"," |
| 4981 | "\"minimum\":0," |
| 4982 | "\"maximum\":9007199254740991" |
| 4983 | "}" |
| 4984 | "}," |
| 4985 | "\"required\":[\"type\",\"value\"]" |
| 4986 | "}," |
| 4987 | "\"strValue\":{" |
| 4988 | "\"properties\":{" |
| 4989 | "\"type\":{" |
| 4990 | "\"type\":\"string\"," |
| 4991 | "\"enum\":[\"str\"]" |
| 4992 | "}," |
| 4993 | "\"value\":{\"type\":\"string\"}" |
| 4994 | "}," |
| 4995 | "\"required\":[\"type\",\"value\"]" |
| 4996 | "}," |
| 4997 | "\"unknownValue\":{" |
| 4998 | "\"properties\":{" |
| 4999 | "\"type\":{" |
| 5000 | "\"type\":\"integer\"," |
| 5001 | "\"minimum\":0" |
| 5002 | "}," |
| 5003 | "\"value\":{" |
| 5004 | "\"type\":\"string\"," |
| 5005 | "\"enum\":[\"unknown\"]" |
| 5006 | "}" |
| 5007 | "}," |
| 5008 | "\"required\":[\"type\",\"value\"]" |
| 5009 | "}" |
| 5010 | "}" |
| 5011 | "}" |
| 5012 | "}" |
| 5013 | "}"); |
| 5014 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 5015 | if (old_len == out->data) { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5016 | chunk_reset(out); |
| 5017 | chunk_appendf(out, |
| 5018 | "{\"errorStr\":\"output buffer too short\"}"); |
| 5019 | } |
Willy Tarreau | 5a0e7ca | 2022-06-10 09:21:22 +0200 | [diff] [blame] | 5020 | chunk_appendf(out, "\n"); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5021 | } |
| 5022 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 5023 | /* This function dumps the schema onto the stream connector's read buffer. |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5024 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 5025 | * No state is used. |
| 5026 | */ |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5027 | static int stats_dump_json_schema_to_buffer(struct appctx *appctx) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5028 | { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5029 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5030 | chunk_reset(&trash_chunk); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5031 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5032 | stats_dump_json_schema(&trash_chunk); |
| 5033 | |
| 5034 | if (applet_putchk(appctx, &trash_chunk) == -1) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5035 | return 0; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5036 | |
| 5037 | return 1; |
| 5038 | } |
| 5039 | |
Amaury Denoyelle | f618dbc | 2024-02-22 14:13:45 +0100 | [diff] [blame] | 5040 | static void http_stats_release(struct appctx *appctx) |
| 5041 | { |
| 5042 | struct show_stat_ctx *ctx = appctx->svcctx; |
| 5043 | |
| 5044 | if (ctx->px_st == STAT_PX_ST_SV) |
| 5045 | srv_drop(ctx->obj2); |
| 5046 | } |
| 5047 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 5048 | static int cli_parse_clear_counters(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5049 | { |
| 5050 | struct proxy *px; |
| 5051 | struct server *sv; |
| 5052 | struct listener *li; |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 5053 | struct stats_module *mod; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5054 | int clrall = 0; |
| 5055 | |
| 5056 | if (strcmp(args[2], "all") == 0) |
| 5057 | clrall = 1; |
| 5058 | |
| 5059 | /* check permissions */ |
| 5060 | if (!cli_has_level(appctx, ACCESS_LVL_OPER) || |
| 5061 | (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN))) |
| 5062 | return 1; |
| 5063 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 5064 | for (px = proxies_list; px; px = px->next) { |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5065 | if (clrall) { |
| 5066 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 5067 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 5068 | } |
| 5069 | else { |
| 5070 | px->be_counters.conn_max = 0; |
| 5071 | px->be_counters.p.http.rps_max = 0; |
| 5072 | px->be_counters.sps_max = 0; |
| 5073 | px->be_counters.cps_max = 0; |
| 5074 | px->be_counters.nbpend_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 5075 | px->be_counters.qtime_max = 0; |
| 5076 | px->be_counters.ctime_max = 0; |
| 5077 | px->be_counters.dtime_max = 0; |
| 5078 | px->be_counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5079 | |
| 5080 | px->fe_counters.conn_max = 0; |
| 5081 | px->fe_counters.p.http.rps_max = 0; |
| 5082 | px->fe_counters.sps_max = 0; |
| 5083 | px->fe_counters.cps_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | for (sv = px->srv; sv; sv = sv->next) |
| 5087 | if (clrall) |
| 5088 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 5089 | else { |
| 5090 | sv->counters.cur_sess_max = 0; |
| 5091 | sv->counters.nbpend_max = 0; |
| 5092 | sv->counters.sps_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 5093 | sv->counters.qtime_max = 0; |
| 5094 | sv->counters.ctime_max = 0; |
| 5095 | sv->counters.dtime_max = 0; |
| 5096 | sv->counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
| 5100 | if (li->counters) { |
| 5101 | if (clrall) |
| 5102 | memset(li->counters, 0, sizeof(*li->counters)); |
| 5103 | else |
| 5104 | li->counters->conn_max = 0; |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | global.cps_max = 0; |
| 5109 | global.sps_max = 0; |
Olivier Houchard | 00bc3cb | 2017-10-17 19:23:25 +0200 | [diff] [blame] | 5110 | global.ssl_max = 0; |
| 5111 | global.ssl_fe_keys_max = 0; |
| 5112 | global.ssl_be_keys_max = 0; |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 5113 | |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 5114 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5115 | if (!mod->clearable && !clrall) |
| 5116 | continue; |
| 5117 | |
| 5118 | for (px = proxies_list; px; px = px->next) { |
| 5119 | enum stats_domain_px_cap mod_cap = stats_px_get_cap(mod->domain_flags); |
| 5120 | |
| 5121 | if (px->cap & PR_CAP_FE && mod_cap & STATS_PX_CAP_FE) { |
| 5122 | EXTRA_COUNTERS_INIT(px->extra_counters_fe, |
| 5123 | mod, |
| 5124 | mod->counters, |
| 5125 | mod->counters_size); |
| 5126 | } |
| 5127 | |
| 5128 | if (px->cap & PR_CAP_BE && mod_cap & STATS_PX_CAP_BE) { |
| 5129 | EXTRA_COUNTERS_INIT(px->extra_counters_be, |
| 5130 | mod, |
| 5131 | mod->counters, |
| 5132 | mod->counters_size); |
| 5133 | } |
| 5134 | |
| 5135 | if (mod_cap & STATS_PX_CAP_SRV) { |
| 5136 | for (sv = px->srv; sv; sv = sv->next) { |
| 5137 | EXTRA_COUNTERS_INIT(sv->extra_counters, |
| 5138 | mod, |
| 5139 | mod->counters, |
| 5140 | mod->counters_size); |
| 5141 | } |
| 5142 | } |
| 5143 | |
| 5144 | if (mod_cap & STATS_PX_CAP_LI) { |
| 5145 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 5146 | EXTRA_COUNTERS_INIT(li->extra_counters, |
| 5147 | mod, |
| 5148 | mod->counters, |
| 5149 | mod->counters_size); |
| 5150 | } |
| 5151 | } |
| 5152 | } |
| 5153 | } |
| 5154 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5155 | resolv_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_RESOLVERS]); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5156 | |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 5157 | memset(activity, 0, sizeof(activity)); |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5158 | return 1; |
| 5159 | } |
| 5160 | |
| 5161 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 5162 | static int cli_parse_show_info(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5163 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5164 | struct show_stat_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5165 | int arg = 2; |
| 5166 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5167 | ctx->scope_str = 0; |
| 5168 | ctx->scope_len = 0; |
| 5169 | ctx->flags = 0; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 5170 | ctx->field = 0; /* explicit default value */ |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 5171 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5172 | while (*args[arg]) { |
| 5173 | if (strcmp(args[arg], "typed") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5174 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5175 | else if (strcmp(args[arg], "json") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5176 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5177 | else if (strcmp(args[arg], "desc") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5178 | ctx->flags |= STAT_SHOW_FDESC; |
Willy Tarreau | 2745620 | 2021-05-08 07:54:24 +0200 | [diff] [blame] | 5179 | else if (strcmp(args[arg], "float") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5180 | ctx->flags |= STAT_USE_FLOAT; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5181 | arg++; |
| 5182 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5183 | return 0; |
| 5184 | } |
| 5185 | |
| 5186 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 5187 | static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5188 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5189 | struct show_stat_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5190 | int arg = 2; |
| 5191 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5192 | ctx->scope_str = 0; |
| 5193 | ctx->scope_len = 0; |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 5194 | ctx->http_px = NULL; // not under http context |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5195 | ctx->flags = STAT_SHNODE | STAT_SHDESC; |
Willy Tarreau | 578d6e4 | 2019-10-09 11:00:22 +0200 | [diff] [blame] | 5196 | |
Willy Tarreau | 0698c80 | 2022-05-11 14:09:57 +0200 | [diff] [blame] | 5197 | if ((strm_li(appctx_strm(appctx))->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5198 | ctx->flags |= STAT_SHLGNDS; |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 5199 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5200 | /* proxy is the default domain */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5201 | ctx->domain = STATS_DOMAIN_PROXY; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 5202 | if (strcmp(args[arg], "domain") == 0) { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5203 | ++args; |
| 5204 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 5205 | if (strcmp(args[arg], "proxy") == 0) { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5206 | ++args; |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5207 | } else if (strcmp(args[arg], "resolvers") == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5208 | ctx->domain = STATS_DOMAIN_RESOLVERS; |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5209 | ++args; |
| 5210 | } else { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5211 | return cli_err(appctx, "Invalid statistics domain.\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5212 | } |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5213 | } |
| 5214 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5215 | if (ctx->domain == STATS_DOMAIN_PROXY |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5216 | && *args[arg] && *args[arg+1] && *args[arg+2]) { |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5217 | struct proxy *px; |
| 5218 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5219 | px = proxy_find_by_name(args[arg], 0, 0); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5220 | if (px) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5221 | ctx->iid = px->uuid; |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5222 | else |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5223 | ctx->iid = atoi(args[arg]); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5224 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5225 | if (!ctx->iid) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5226 | return cli_err(appctx, "No such proxy.\n"); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5227 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5228 | ctx->flags |= STAT_BOUND; |
| 5229 | ctx->type = atoi(args[arg+1]); |
| 5230 | ctx->sid = atoi(args[arg+2]); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5231 | arg += 3; |
| 5232 | } |
| 5233 | |
| 5234 | while (*args[arg]) { |
| 5235 | if (strcmp(args[arg], "typed") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5236 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5237 | else if (strcmp(args[arg], "json") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5238 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5239 | else if (strcmp(args[arg], "desc") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5240 | ctx->flags |= STAT_SHOW_FDESC; |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 5241 | else if (strcmp(args[arg], "no-maint") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5242 | ctx->flags |= STAT_HIDE_MAINT; |
Willy Tarreau | 65141ff | 2020-10-23 17:19:48 +0200 | [diff] [blame] | 5243 | else if (strcmp(args[arg], "up") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5244 | ctx->flags |= STAT_HIDE_DOWN; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5245 | arg++; |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5246 | } |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5247 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5248 | return 0; |
| 5249 | } |
| 5250 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5251 | static int cli_io_handler_dump_info(struct appctx *appctx) |
| 5252 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5253 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5254 | return stats_dump_info_to_buffer(appctx_sc(appctx)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5255 | } |
| 5256 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 5257 | /* This I/O handler runs as an applet embedded in a stream connector. It is |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5258 | * used to send raw stats over a socket. |
| 5259 | */ |
| 5260 | static int cli_io_handler_dump_stat(struct appctx *appctx) |
| 5261 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5262 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Aurelien DARRAGON | 40f8802 | 2023-12-05 19:49:13 +0100 | [diff] [blame] | 5263 | return stats_dump_stat_to_buffer(appctx_sc(appctx), NULL); |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5264 | } |
| 5265 | |
Amaury Denoyelle | f618dbc | 2024-02-22 14:13:45 +0100 | [diff] [blame] | 5266 | static void cli_io_handler_release_stat(struct appctx *appctx) |
| 5267 | { |
| 5268 | struct show_stat_ctx *ctx = appctx->svcctx; |
| 5269 | |
| 5270 | if (ctx->px_st == STAT_PX_ST_SV) |
| 5271 | srv_drop(ctx->obj2); |
| 5272 | } |
| 5273 | |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5274 | static int cli_io_handler_dump_json_schema(struct appctx *appctx) |
| 5275 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5276 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5277 | return stats_dump_json_schema_to_buffer(appctx); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5278 | } |
| 5279 | |
Amaury Denoyelle | 216a1ce | 2021-03-18 15:48:14 +0100 | [diff] [blame] | 5280 | int stats_allocate_proxy_counters_internal(struct extra_counters **counters, |
| 5281 | int type, int px_cap) |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5282 | { |
| 5283 | struct stats_module *mod; |
| 5284 | |
| 5285 | EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed); |
| 5286 | |
| 5287 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5288 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 5289 | continue; |
| 5290 | |
| 5291 | EXTRA_COUNTERS_ADD(mod, *counters, mod->counters, mod->counters_size); |
| 5292 | } |
| 5293 | |
| 5294 | EXTRA_COUNTERS_ALLOC(*counters, alloc_failed); |
| 5295 | |
| 5296 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5297 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 5298 | continue; |
| 5299 | |
| 5300 | EXTRA_COUNTERS_INIT(*counters, mod, mod->counters, mod->counters_size); |
| 5301 | } |
| 5302 | |
| 5303 | return 1; |
| 5304 | |
| 5305 | alloc_failed: |
| 5306 | return 0; |
| 5307 | } |
| 5308 | |
| 5309 | /* Initialize and allocate all extra counters for a proxy and its attached |
| 5310 | * servers/listeners with all already registered stats module |
| 5311 | */ |
| 5312 | int stats_allocate_proxy_counters(struct proxy *px) |
| 5313 | { |
| 5314 | struct server *sv; |
| 5315 | struct listener *li; |
| 5316 | |
| 5317 | if (px->cap & PR_CAP_FE) { |
| 5318 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_fe, |
| 5319 | COUNTERS_FE, |
| 5320 | STATS_PX_CAP_FE)) { |
| 5321 | return 0; |
| 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | if (px->cap & PR_CAP_BE) { |
| 5326 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be, |
| 5327 | COUNTERS_BE, |
| 5328 | STATS_PX_CAP_BE)) { |
| 5329 | return 0; |
| 5330 | } |
| 5331 | } |
| 5332 | |
| 5333 | for (sv = px->srv; sv; sv = sv->next) { |
| 5334 | if (!stats_allocate_proxy_counters_internal(&sv->extra_counters, |
| 5335 | COUNTERS_SV, |
| 5336 | STATS_PX_CAP_SRV)) { |
| 5337 | return 0; |
| 5338 | } |
| 5339 | } |
| 5340 | |
| 5341 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 5342 | if (!stats_allocate_proxy_counters_internal(&li->extra_counters, |
| 5343 | COUNTERS_LI, |
| 5344 | STATS_PX_CAP_LI)) { |
| 5345 | return 0; |
| 5346 | } |
| 5347 | } |
| 5348 | |
| 5349 | return 1; |
| 5350 | } |
| 5351 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 5352 | void stats_register_module(struct stats_module *m) |
| 5353 | { |
| 5354 | const uint8_t domain = stats_get_domain(m->domain_flags); |
| 5355 | |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 5356 | LIST_APPEND(&stats_module_list[domain], &m->list); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5357 | stat_count[domain] += m->stats_count; |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 5358 | } |
| 5359 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5360 | static int allocate_stats_px_postcheck(void) |
| 5361 | { |
| 5362 | struct stats_module *mod; |
| 5363 | size_t i = ST_F_TOTAL_FIELDS; |
| 5364 | int err_code = 0; |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 5365 | struct proxy *px; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5366 | |
| 5367 | stat_count[STATS_DOMAIN_PROXY] += ST_F_TOTAL_FIELDS; |
| 5368 | |
| 5369 | stat_f[STATS_DOMAIN_PROXY] = malloc(stat_count[STATS_DOMAIN_PROXY] * sizeof(struct name_desc)); |
| 5370 | if (!stat_f[STATS_DOMAIN_PROXY]) { |
| 5371 | ha_alert("stats: cannot allocate all fields for proxy statistics\n"); |
| 5372 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5373 | return err_code; |
| 5374 | } |
| 5375 | |
| 5376 | memcpy(stat_f[STATS_DOMAIN_PROXY], stat_fields, |
| 5377 | ST_F_TOTAL_FIELDS * sizeof(struct name_desc)); |
| 5378 | |
| 5379 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5380 | memcpy(stat_f[STATS_DOMAIN_PROXY] + i, |
| 5381 | mod->stats, |
| 5382 | mod->stats_count * sizeof(struct name_desc)); |
| 5383 | i += mod->stats_count; |
| 5384 | } |
| 5385 | |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 5386 | for (px = proxies_list; px; px = px->next) { |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5387 | if (!stats_allocate_proxy_counters(px)) { |
| 5388 | ha_alert("stats: cannot allocate all counters for proxy statistics\n"); |
| 5389 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5390 | return err_code; |
| 5391 | } |
| 5392 | } |
| 5393 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5394 | /* wait per-thread alloc to perform corresponding stat_l allocation */ |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5395 | |
| 5396 | return err_code; |
| 5397 | } |
| 5398 | |
| 5399 | REGISTER_CONFIG_POSTPARSER("allocate-stats-px", allocate_stats_px_postcheck); |
| 5400 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5401 | static int allocate_stats_rslv_postcheck(void) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5402 | { |
| 5403 | struct stats_module *mod; |
| 5404 | size_t i = 0; |
| 5405 | int err_code = 0; |
| 5406 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5407 | stat_f[STATS_DOMAIN_RESOLVERS] = malloc(stat_count[STATS_DOMAIN_RESOLVERS] * sizeof(struct name_desc)); |
| 5408 | if (!stat_f[STATS_DOMAIN_RESOLVERS]) { |
| 5409 | ha_alert("stats: cannot allocate all fields for resolver statistics\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5410 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5411 | return err_code; |
| 5412 | } |
| 5413 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5414 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_RESOLVERS], list) { |
| 5415 | memcpy(stat_f[STATS_DOMAIN_RESOLVERS] + i, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5416 | mod->stats, |
| 5417 | mod->stats_count * sizeof(struct name_desc)); |
| 5418 | i += mod->stats_count; |
| 5419 | } |
| 5420 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5421 | if (!resolv_allocate_counters(&stats_module_list[STATS_DOMAIN_RESOLVERS])) { |
| 5422 | ha_alert("stats: cannot allocate all counters for resolver statistics\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5423 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5424 | return err_code; |
| 5425 | } |
| 5426 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5427 | /* wait per-thread alloc to perform corresponding stat_l allocation */ |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5428 | |
| 5429 | return err_code; |
| 5430 | } |
| 5431 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5432 | REGISTER_CONFIG_POSTPARSER("allocate-stats-resolver", allocate_stats_rslv_postcheck); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5433 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5434 | static int allocate_stat_lines_per_thread(void) |
| 5435 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5436 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5437 | |
| 5438 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5439 | const int domain = domains[i]; |
| 5440 | |
| 5441 | stat_l[domain] = malloc(stat_count[domain] * sizeof(struct field)); |
| 5442 | if (!stat_l[domain]) |
| 5443 | return 0; |
| 5444 | } |
| 5445 | return 1; |
| 5446 | } |
| 5447 | |
| 5448 | REGISTER_PER_THREAD_ALLOC(allocate_stat_lines_per_thread); |
| 5449 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5450 | static int allocate_trash_counters(void) |
| 5451 | { |
| 5452 | struct stats_module *mod; |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5453 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5454 | size_t max_counters_size = 0; |
| 5455 | |
| 5456 | /* calculate the greatest counters used by any stats modules */ |
| 5457 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5458 | list_for_each_entry(mod, &stats_module_list[domains[i]], list) { |
| 5459 | max_counters_size = mod->counters_size > max_counters_size ? |
| 5460 | mod->counters_size : max_counters_size; |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | /* allocate the trash with the size of the greatest counters */ |
| 5465 | if (max_counters_size) { |
| 5466 | trash_counters = malloc(max_counters_size); |
| 5467 | if (!trash_counters) { |
| 5468 | ha_alert("stats: cannot allocate trash counters for statistics\n"); |
| 5469 | return 0; |
| 5470 | } |
| 5471 | } |
| 5472 | |
| 5473 | return 1; |
| 5474 | } |
| 5475 | |
| 5476 | REGISTER_PER_THREAD_ALLOC(allocate_trash_counters); |
| 5477 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5478 | static void deinit_stat_lines_per_thread(void) |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5479 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5480 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5481 | |
| 5482 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5483 | const int domain = domains[i]; |
| 5484 | |
Willy Tarreau | 61cfdf4 | 2021-02-20 10:46:51 +0100 | [diff] [blame] | 5485 | ha_free(&stat_l[domain]); |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5486 | } |
| 5487 | } |
| 5488 | |
| 5489 | |
| 5490 | REGISTER_PER_THREAD_FREE(deinit_stat_lines_per_thread); |
| 5491 | |
| 5492 | static void deinit_stats(void) |
| 5493 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5494 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5495 | |
| 5496 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5497 | const int domain = domains[i]; |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5498 | |
| 5499 | if (stat_f[domain]) |
| 5500 | free(stat_f[domain]); |
| 5501 | } |
| 5502 | } |
| 5503 | |
| 5504 | REGISTER_POST_DEINIT(deinit_stats); |
| 5505 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5506 | static void free_trash_counters(void) |
| 5507 | { |
| 5508 | if (trash_counters) |
| 5509 | free(trash_counters); |
| 5510 | } |
| 5511 | |
| 5512 | REGISTER_PER_THREAD_FREE(free_trash_counters); |
| 5513 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5514 | /* register cli keywords */ |
| 5515 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5516 | { { "clear", "counters", NULL }, "clear counters [all] : clear max statistics counters (or all counters)", cli_parse_clear_counters, NULL, NULL }, |
Willy Tarreau | 2745620 | 2021-05-08 07:54:24 +0200 | [diff] [blame] | 5517 | { { "show", "info", NULL }, "show info [desc|json|typed|float]* : report information about the running process", cli_parse_show_info, cli_io_handler_dump_info, NULL }, |
Amaury Denoyelle | f618dbc | 2024-02-22 14:13:45 +0100 | [diff] [blame] | 5518 | { { "show", "stat", NULL }, "show stat [desc|json|no-maint|typed|up]*: report counters for each proxy and server", cli_parse_show_stat, cli_io_handler_dump_stat, cli_io_handler_release_stat }, |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5519 | { { "show", "schema", "json", NULL }, "show schema json : report schema used for stats", NULL, cli_io_handler_dump_json_schema, NULL }, |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5520 | {{},} |
| 5521 | }}; |
| 5522 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5523 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 5524 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 5525 | struct applet http_stats_applet = { |
| 5526 | .obj_type = OBJ_TYPE_APPLET, |
| 5527 | .name = "<STATS>", /* used for logging */ |
| 5528 | .fct = http_stats_io_handler, |
Amaury Denoyelle | f618dbc | 2024-02-22 14:13:45 +0100 | [diff] [blame] | 5529 | .release = http_stats_release, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 5530 | }; |
| 5531 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 5532 | /* |
| 5533 | * Local variables: |
| 5534 | * c-indent-level: 8 |
| 5535 | * c-basic-offset: 8 |
| 5536 | * End: |
| 5537 | */ |