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> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
| 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 27 | #include <haproxy/api.h> |
Willy Tarreau | 3f0f82e | 2020-06-04 19:42:41 +0200 | [diff] [blame] | 28 | #include <haproxy/applet-t.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 | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 35 | #include <haproxy/compression.h> |
Willy Tarreau | 2a83d60 | 2020-05-27 16:58:08 +0200 | [diff] [blame] | 36 | #include <haproxy/debug.h> |
Willy Tarreau | eb92deb | 2020-06-04 10:53:16 +0200 | [diff] [blame] | 37 | #include <haproxy/dns.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 | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 44 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 45 | #include <haproxy/htx.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 46 | #include <haproxy/list.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 47 | #include <haproxy/listener.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 48 | #include <haproxy/log.h> |
Willy Tarreau | 2cd5809 | 2020-06-04 15:10:43 +0200 | [diff] [blame] | 49 | #include <haproxy/map-t.h> |
Willy Tarreau | 225a90a | 2020-06-04 15:06:28 +0200 | [diff] [blame] | 50 | #include <haproxy/pattern-t.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 51 | #include <haproxy/pipe.h> |
| 52 | #include <haproxy/pool.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 53 | #include <haproxy/proxy.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 54 | #include <haproxy/server.h> |
Willy Tarreau | 48d25b3 | 2020-06-04 18:58:52 +0200 | [diff] [blame] | 55 | #include <haproxy/session.h> |
Willy Tarreau | 209108d | 2020-06-04 20:30:20 +0200 | [diff] [blame] | 56 | #include <haproxy/ssl_sock.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 57 | #include <haproxy/stats.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 58 | #include <haproxy/stream.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 59 | #include <haproxy/stream_interface.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 60 | #include <haproxy/task.h> |
Willy Tarreau | c2f7c58 | 2020-06-02 18:15:32 +0200 | [diff] [blame] | 61 | #include <haproxy/ticks.h> |
Willy Tarreau | 92b4f13 | 2020-06-01 11:05:15 +0200 | [diff] [blame] | 62 | #include <haproxy/time.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 63 | #include <haproxy/tools.h> |
Willy Tarreau | 8c42b8a | 2020-06-04 19:27:34 +0200 | [diff] [blame] | 64 | #include <haproxy/uri_auth-t.h> |
Willy Tarreau | d678805 | 2020-05-27 15:59:00 +0200 | [diff] [blame] | 65 | #include <haproxy/version.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 66 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 67 | |
Christopher Faulet | 2b9b678 | 2019-02-27 16:42:58 +0100 | [diff] [blame] | 68 | /* status codes available for the stats admin page (strictly 4 chars length) */ |
| 69 | const char *stat_status_codes[STAT_STATUS_SIZE] = { |
| 70 | [STAT_STATUS_DENY] = "DENY", |
| 71 | [STAT_STATUS_DONE] = "DONE", |
| 72 | [STAT_STATUS_ERRP] = "ERRP", |
| 73 | [STAT_STATUS_EXCD] = "EXCD", |
| 74 | [STAT_STATUS_NONE] = "NONE", |
| 75 | [STAT_STATUS_PART] = "PART", |
| 76 | [STAT_STATUS_UNKN] = "UNKN", |
| 77 | [STAT_STATUS_IVAL] = "IVAL", |
| 78 | }; |
| 79 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 80 | /* These are the field names for each INF_* field position. Please pay attention |
| 81 | * to always use the exact same name except that the strings for new names must |
| 82 | * be lower case or CamelCase while the enum entries must be upper case. |
| 83 | */ |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 84 | const struct name_desc info_fields[INF_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 85 | [INF_NAME] = { .name = "Name", .desc = "Product name" }, |
| 86 | [INF_VERSION] = { .name = "Version", .desc = "Product version" }, |
| 87 | [INF_RELEASE_DATE] = { .name = "Release_date", .desc = "Date of latest source code update" }, |
| 88 | [INF_NBTHREAD] = { .name = "Nbthread", .desc = "Number of started threads (global.nbthread)" }, |
| 89 | [INF_NBPROC] = { .name = "Nbproc", .desc = "Number of started worker processes (global.nbproc)" }, |
| 90 | [INF_PROCESS_NUM] = { .name = "Process_num", .desc = "Relative worker process number (1..Nbproc)" }, |
| 91 | [INF_PID] = { .name = "Pid", .desc = "This worker process identifier for the system" }, |
| 92 | [INF_UPTIME] = { .name = "Uptime", .desc = "How long ago this worker process was started (days+hours+minutes+seconds)" }, |
| 93 | [INF_UPTIME_SEC] = { .name = "Uptime_sec", .desc = "How long ago this worker process was started (seconds)" }, |
| 94 | [INF_MEMMAX_MB] = { .name = "Memmax_MB", .desc = "Worker process's hard limit on memory usage in MB (-m on command line)" }, |
| 95 | [INF_POOL_ALLOC_MB] = { .name = "PoolAlloc_MB", .desc = "Amount of memory allocated in pools (in MB)" }, |
| 96 | [INF_POOL_USED_MB] = { .name = "PoolUsed_MB", .desc = "Amount of pool memory currently used (in MB)" }, |
| 97 | [INF_POOL_FAILED] = { .name = "PoolFailed", .desc = "Number of failed pool allocations since this worker was started" }, |
| 98 | [INF_ULIMIT_N] = { .name = "Ulimit-n", .desc = "Hard limit on the number of per-process file descriptors" }, |
| 99 | [INF_MAXSOCK] = { .name = "Maxsock", .desc = "Hard limit on the number of per-process sockets" }, |
| 100 | [INF_MAXCONN] = { .name = "Maxconn", .desc = "Hard limit on the number of per-process connections (configured or imposed by Ulimit-n)" }, |
| 101 | [INF_HARD_MAXCONN] = { .name = "Hard_maxconn", .desc = "Hard limit on the number of per-process connections (imposed by Memmax_MB or Ulimit-n)" }, |
| 102 | [INF_CURR_CONN] = { .name = "CurrConns", .desc = "Current number of connections on this worker process" }, |
| 103 | [INF_CUM_CONN] = { .name = "CumConns", .desc = "Total number of connections on this worker process since started" }, |
| 104 | [INF_CUM_REQ] = { .name = "CumReq", .desc = "Total number of requests on this worker process since started" }, |
| 105 | [INF_MAX_SSL_CONNS] = { .name = "MaxSslConns", .desc = "Hard limit on the number of per-process SSL endpoints (front+back), 0=unlimited" }, |
| 106 | [INF_CURR_SSL_CONNS] = { .name = "CurrSslConns", .desc = "Current number of SSL endpoints on this worker process (front+back)" }, |
| 107 | [INF_CUM_SSL_CONNS] = { .name = "CumSslConns", .desc = "Total number of SSL endpoints on this worker process since started (front+back)" }, |
| 108 | [INF_MAXPIPES] = { .name = "Maxpipes", .desc = "Hard limit on the number of pipes for splicing, 0=unlimited" }, |
| 109 | [INF_PIPES_USED] = { .name = "PipesUsed", .desc = "Current number of pipes in use in this worker process" }, |
| 110 | [INF_PIPES_FREE] = { .name = "PipesFree", .desc = "Current number of allocated and available pipes in this worker process" }, |
| 111 | [INF_CONN_RATE] = { .name = "ConnRate", .desc = "Number of front connections created on this worker process over the last second" }, |
| 112 | [INF_CONN_RATE_LIMIT] = { .name = "ConnRateLimit", .desc = "Hard limit for ConnRate (global.maxconnrate)" }, |
| 113 | [INF_MAX_CONN_RATE] = { .name = "MaxConnRate", .desc = "Highest ConnRate reached on this worker process since started (in connections per second)" }, |
| 114 | [INF_SESS_RATE] = { .name = "SessRate", .desc = "Number of sessions created on this worker process over the last second" }, |
| 115 | [INF_SESS_RATE_LIMIT] = { .name = "SessRateLimit", .desc = "Hard limit for SessRate (global.maxsessrate)" }, |
| 116 | [INF_MAX_SESS_RATE] = { .name = "MaxSessRate", .desc = "Highest SessRate reached on this worker process since started (in sessions per second)" }, |
| 117 | [INF_SSL_RATE] = { .name = "SslRate", .desc = "Number of SSL connections created on this worker process over the last second" }, |
| 118 | [INF_SSL_RATE_LIMIT] = { .name = "SslRateLimit", .desc = "Hard limit for SslRate (global.maxsslrate)" }, |
| 119 | [INF_MAX_SSL_RATE] = { .name = "MaxSslRate", .desc = "Highest SslRate reached on this worker process since started (in connections per second)" }, |
| 120 | [INF_SSL_FRONTEND_KEY_RATE] = { .name = "SslFrontendKeyRate", .desc = "Number of SSL keys created on frontends in this worker process over the last second" }, |
| 121 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = { .name = "SslFrontendMaxKeyRate", .desc = "Highest SslFrontendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 122 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = { .name = "SslFrontendSessionReuse_pct", .desc = "Percent of frontend SSL connections which did not require a new key" }, |
| 123 | [INF_SSL_BACKEND_KEY_RATE] = { .name = "SslBackendKeyRate", .desc = "Number of SSL keys created on backends in this worker process over the last second" }, |
| 124 | [INF_SSL_BACKEND_MAX_KEY_RATE] = { .name = "SslBackendMaxKeyRate", .desc = "Highest SslBackendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 125 | [INF_SSL_CACHE_LOOKUPS] = { .name = "SslCacheLookups", .desc = "Total number of SSL session ID lookups in the SSL session cache on this worker since started" }, |
| 126 | [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" }, |
| 127 | [INF_COMPRESS_BPS_IN] = { .name = "CompressBpsIn", .desc = "Number of bytes submitted to the HTTP compressor in this worker process over the last second" }, |
| 128 | [INF_COMPRESS_BPS_OUT] = { .name = "CompressBpsOut", .desc = "Number of bytes emitted by the HTTP compressor in this worker process over the last second" }, |
| 129 | [INF_COMPRESS_BPS_RATE_LIM] = { .name = "CompressBpsRateLim", .desc = "Limit of CompressBpsOut beyond which HTTP compression is automatically disabled" }, |
| 130 | [INF_ZLIB_MEM_USAGE] = { .name = "ZlibMemUsage", .desc = "Amount of memory currently used by HTTP compression on the current worker process (in bytes)" }, |
| 131 | [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)" }, |
| 132 | [INF_TASKS] = { .name = "Tasks", .desc = "Total number of tasks in the current worker process (active + sleeping)" }, |
| 133 | [INF_RUN_QUEUE] = { .name = "Run_queue", .desc = "Total number of active tasks+tasklets in the current worker process" }, |
| 134 | [INF_IDLE_PCT] = { .name = "Idle_pct", .desc = "Percentage of last second spent waiting in the current worker thread" }, |
| 135 | [INF_NODE] = { .name = "node", .desc = "Node name (global.node)" }, |
| 136 | [INF_DESCRIPTION] = { .name = "description", .desc = "Node description (global.description)" }, |
| 137 | [INF_STOPPING] = { .name = "Stopping", .desc = "1 if the worker process is currently stopping, otherwise zero" }, |
| 138 | [INF_JOBS] = { .name = "Jobs", .desc = "Current number of active jobs on the current worker process (frontend connections, master connections, listeners)" }, |
| 139 | [INF_UNSTOPPABLE_JOBS] = { .name = "Unstoppable Jobs", .desc = "Current number of unstoppable jobs on the current worker process (master connections)" }, |
| 140 | [INF_LISTENERS] = { .name = "Listeners", .desc = "Current number of active listeners on the current worker process" }, |
| 141 | [INF_ACTIVE_PEERS] = { .name = "ActivePeers", .desc = "Current number of verified active peers connections on the current worker process" }, |
| 142 | [INF_CONNECTED_PEERS] = { .name = "ConnectedPeers", .desc = "Current number of peers having passed the connection step on the current worker process" }, |
| 143 | [INF_DROPPED_LOGS] = { .name = "DroppedLogs", .desc = "Total number of dropped logs for current worker process since started" }, |
| 144 | [INF_BUSY_POLLING] = { .name = "BusyPolling", .desc = "1 if busy-polling is currently in use on the worker process, otherwise zero (config.busy-polling)" }, |
| 145 | [INF_FAILED_RESOLUTIONS] = { .name = "FailedResolutions", .desc = "Total number of failed DNS resolutions in current worker process since started" }, |
| 146 | [INF_TOTAL_BYTES_OUT] = { .name = "TotalBytesOut", .desc = "Total number of bytes emitted by current worker process since started" }, |
Christopher Faulet | aaa7085 | 2020-07-10 13:56:30 +0200 | [diff] [blame] | 147 | [INF_TOTAL_SPLICED_BYTES_OUT] = { .name = "TotalSplicdedBytesOut", .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] | 148 | [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] | 149 | [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] | 150 | [INF_CUM_LOG_MSGS] = { .name = "CumRecvLogs", .desc = "Total number of log messages received by log-forwarding listeners on this worker process since started" }, |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 151 | }; |
| 152 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 153 | const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 154 | [ST_F_PXNAME] = { .name = "pxname", .desc = "Proxy name" }, |
| 155 | [ST_F_SVNAME] = { .name = "svname", .desc = "Server name" }, |
| 156 | [ST_F_QCUR] = { .name = "qcur", .desc = "Current number of connections waiting in the server of backend queue" }, |
| 157 | [ST_F_QMAX] = { .name = "qmax", .desc = "Highest value of qcur encountered since process started" }, |
| 158 | [ST_F_SCUR] = { .name = "scur", .desc = "Current number of sessions on the frontend, backend or server" }, |
| 159 | [ST_F_SMAX] = { .name = "smax", .desc = "Highest value of scur encountered since process started" }, |
| 160 | [ST_F_SLIM] = { .name = "slim", .desc = "Frontend/listener/server's maxconn, backend's fullconn" }, |
| 161 | [ST_F_STOT] = { .name = "stot", .desc = "Total number of sessions since process started" }, |
| 162 | [ST_F_BIN] = { .name = "bin", .desc = "Total number of request bytes since process started" }, |
| 163 | [ST_F_BOUT] = { .name = "bout", .desc = "Total number of response bytes since process started" }, |
| 164 | [ST_F_DREQ] = { .name = "dreq", .desc = "Total number of denied requests since process started" }, |
| 165 | [ST_F_DRESP] = { .name = "dresp", .desc = "Total number of denied responses since process started" }, |
| 166 | [ST_F_EREQ] = { .name = "ereq", .desc = "Total number of invalid requests since process started" }, |
| 167 | [ST_F_ECON] = { .name = "econ", .desc = "Total number of failed connections to server since the worker process started" }, |
| 168 | [ST_F_ERESP] = { .name = "eresp", .desc = "Total number of invalid responses since the worker process started" }, |
| 169 | [ST_F_WRETR] = { .name = "wretr", .desc = "Total number of server connection retries since the worker process started" }, |
| 170 | [ST_F_WREDIS] = { .name = "wredis", .desc = "Total number of server redispatches due to connection failures since the worker process started" }, |
| 171 | [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] | 172 | [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] | 173 | [ST_F_ACT] = { .name = "act", .desc = "Total number of active UP servers with a non-zero weight" }, |
| 174 | [ST_F_BCK] = { .name = "bck", .desc = "Total number of backup UP servers with a non-zero weight" }, |
| 175 | [ST_F_CHKFAIL] = { .name = "chkfail", .desc = "Total number of failed individual health checks per server/backend, since the worker process started" }, |
| 176 | [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" }, |
| 177 | [ST_F_LASTCHG] = { .name = "lastchg", .desc = "How long ago the last server state changed, in seconds" }, |
| 178 | [ST_F_DOWNTIME] = { .name = "downtime", .desc = "Total time spent in DOWN state, for server or backend" }, |
| 179 | [ST_F_QLIMIT] = { .name = "qlimit", .desc = "Limit on the number of connections in queue, for servers only (maxqueue argument)" }, |
| 180 | [ST_F_PID] = { .name = "pid", .desc = "Relative worker process number (1..nbproc)" }, |
| 181 | [ST_F_IID] = { .name = "iid", .desc = "Frontend or Backend numeric identifier ('id' setting)" }, |
| 182 | [ST_F_SID] = { .name = "sid", .desc = "Server numeric identifier ('id' setting)" }, |
| 183 | [ST_F_THROTTLE] = { .name = "throttle", .desc = "Throttling ratio applied to a server's maxconn and weight during the slowstart period (0 to 100%)" }, |
| 184 | [ST_F_LBTOT] = { .name = "lbtot", .desc = "Total number of requests routed by load balancing since the worker process started (ignores queue pop and stickiness)" }, |
| 185 | [ST_F_TRACKED] = { .name = "tracked", .desc = "Name of the other server this server tracks for its state" }, |
| 186 | [ST_F_TYPE] = { .name = "type", .desc = "Type of the object (Listener, Frontend, Backend, Server)" }, |
| 187 | [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)" }, |
| 188 | [ST_F_RATE_LIM] = { .name = "rate_lim", .desc = "Limit on the number of sessions accepted in a second (frontend only, 'rate-limit sessions' setting)" }, |
| 189 | [ST_F_RATE_MAX] = { .name = "rate_max", .desc = "Highest value of 'rate' observed since the worker process started" }, |
| 190 | [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" }, |
| 191 | [ST_F_CHECK_CODE] = { .name = "check_code", .desc = "HTTP/SMTP/LDAP status code reported by the latest server health check" }, |
| 192 | [ST_F_CHECK_DURATION] = { .name = "check_duration", .desc = "Total duration of the latest server health check, in milliseconds" }, |
| 193 | [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" }, |
| 194 | [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" }, |
| 195 | [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" }, |
| 196 | [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" }, |
| 197 | [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" }, |
| 198 | [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)" }, |
| 199 | [ST_F_HANAFAIL] = { .name = "hanafail", .desc = "Total number of failed checks caused by an 'on-error' directive after an 'observe' condition matched" }, |
| 200 | [ST_F_REQ_RATE] = { .name = "req_rate", .desc = "Number of HTTP requests processed over the last second on this object" }, |
| 201 | [ST_F_REQ_RATE_MAX] = { .name = "req_rate_max", .desc = "Highest value of 'req_rate' observed since the worker process started" }, |
| 202 | [ST_F_REQ_TOT] = { .name = "req_tot", .desc = "Total number of HTTP requests processed by this object since the worker process started" }, |
| 203 | [ST_F_CLI_ABRT] = { .name = "cli_abrt", .desc = "Total number of requests or connections aborted by the client since the worker process started" }, |
| 204 | [ST_F_SRV_ABRT] = { .name = "srv_abrt", .desc = "Total number of requests or connections aborted by the server since the worker process started" }, |
| 205 | [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" }, |
| 206 | [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" }, |
| 207 | [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)" }, |
| 208 | [ST_F_COMP_RSP] = { .name = "comp_rsp", .desc = "Total number of HTTP responses that were compressed for this object since the worker process started" }, |
| 209 | [ST_F_LASTSESS] = { .name = "lastsess", .desc = "How long ago some traffic was seen on this object on this worker process, in seconds" }, |
| 210 | [ST_F_LAST_CHK] = { .name = "last_chk", .desc = "Short description of the latest health check report for this server (see also check_desc)" }, |
| 211 | [ST_F_LAST_AGT] = { .name = "last_agt", .desc = "Short description of the latest agent check report for this server (see also agent_desc)" }, |
| 212 | [ST_F_QTIME] = { .name = "qtime", .desc = "Time spent in the queue, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 213 | [ST_F_CTIME] = { .name = "ctime", .desc = "Time spent waiting for a connection to complete, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 214 | [ST_F_RTIME] = { .name = "rtime", .desc = "Time spent waiting for a server response, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 215 | [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)" }, |
| 216 | [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" }, |
| 217 | [ST_F_AGENT_CODE] = { .name = "agent_code", .desc = "Status code reported by the latest server agent check" }, |
| 218 | [ST_F_AGENT_DURATION] = { .name = "agent_duration", .desc = "Total duration of the latest server agent check, in milliseconds" }, |
| 219 | [ST_F_CHECK_DESC] = { .name = "check_desc", .desc = "Textual description of the latest health check report for this server" }, |
| 220 | [ST_F_AGENT_DESC] = { .name = "agent_desc", .desc = "Textual description of the latest agent check report for this server" }, |
| 221 | [ST_F_CHECK_RISE] = { .name = "check_rise", .desc = "Number of successful health checks before declaring a server UP (server 'rise' setting)" }, |
| 222 | [ST_F_CHECK_FALL] = { .name = "check_fall", .desc = "Number of failed health checks before declaring a server DOWN (server 'fall' setting)" }, |
| 223 | [ST_F_CHECK_HEALTH] = { .name = "check_health", .desc = "Current server health check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 224 | [ST_F_AGENT_RISE] = { .name = "agent_rise", .desc = "Number of successful agent checks before declaring a server UP (server 'rise' setting)" }, |
| 225 | [ST_F_AGENT_FALL] = { .name = "agent_fall", .desc = "Number of failed agent checks before declaring a server DOWN (server 'fall' setting)" }, |
| 226 | [ST_F_AGENT_HEALTH] = { .name = "agent_health", .desc = "Current server agent check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 227 | [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" }, |
| 228 | [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" }, |
| 229 | [ST_F_MODE] = { .name = "mode", .desc = "'mode' setting (tcp/http/health/cli)" }, |
| 230 | [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" }, |
| 231 | [ST_F_CONN_RATE] = { .name = "conn_rate", .desc = "Number of new connections accepted over the last second on the frontend for this worker process" }, |
| 232 | [ST_F_CONN_RATE_MAX] = { .name = "conn_rate_max", .desc = "Highest value of 'conn_rate' observed since the worker process started" }, |
| 233 | [ST_F_CONN_TOT] = { .name = "conn_tot", .desc = "Total number of new connections accepted on this frontend since the worker process started" }, |
| 234 | [ST_F_INTERCEPTED] = { .name = "intercepted", .desc = "Total number of HTTP requests intercepted on the frontend (redirects/stats/services) since the worker process started" }, |
| 235 | [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" }, |
| 236 | [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" }, |
| 237 | [ST_F_WREW] = { .name = "wrew", .desc = "Total number of failed HTTP header rewrites since the worker process started" }, |
| 238 | [ST_F_CONNECT] = { .name = "connect", .desc = "Total number of outgoing connection attempts on this backend/server since the worker process started" }, |
| 239 | [ST_F_REUSE] = { .name = "reuse", .desc = "Total number of reused connection on this backend/server since the worker process started" }, |
| 240 | [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" }, |
| 241 | [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" }, |
| 242 | [ST_F_SRV_ICUR] = { .name = "srv_icur", .desc = "Current number of idle connections available for reuse on this server" }, |
| 243 | [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] | 244 | [ST_F_QT_MAX] = { .name = "qtime_max", .desc = "Maximum observed time spent in the queue, in milliseconds (backend/server)" }, |
| 245 | [ST_F_CT_MAX] = { .name = "ctime_max", .desc = "Maximum observed time spent waiting for a connection to complete, in milliseconds (backend/server)" }, |
| 246 | [ST_F_RT_MAX] = { .name = "rtime_max", .desc = "Maximum observed time spent waiting for a server response, in milliseconds (backend/server)" }, |
| 247 | [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] | 248 | [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] | 249 | [ST_F_IDLE_CONN_CUR] = { .name = "idle_conn_cur", .desc = "Current number of unsafe idle connections"}, |
| 250 | [ST_F_SAFE_CONN_CUR] = { .name = "safe_conn_cur", .desc = "Current number of safe idle connections"}, |
| 251 | [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] | 252 | [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] | 253 | [ST_F_UWEIGHT] = { .name = "uweight", .desc = "Server's user weight, or sum of active servers' user weights for a backend" }, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 254 | }; |
| 255 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 256 | /* one line of info */ |
Christopher Faulet | 1bc04c7 | 2017-10-29 20:14:08 +0100 | [diff] [blame] | 257 | static THREAD_LOCAL struct field info[INF_TOTAL_FIELDS]; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 258 | |
| 259 | /* description of statistics (static and dynamic) */ |
| 260 | static struct name_desc *stat_f[STATS_DOMAIN_COUNT]; |
| 261 | static size_t stat_count[STATS_DOMAIN_COUNT]; |
| 262 | |
| 263 | /* one line for stats */ |
| 264 | static struct field *stat_l[STATS_DOMAIN_COUNT]; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 265 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 266 | /* list of all registered stats module */ |
| 267 | static struct list stats_module_list[STATS_DOMAIN_COUNT] = { |
| 268 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_PROXY]), |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 269 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_DNS]), |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 270 | }; |
| 271 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 272 | THREAD_LOCAL void *trash_counters; |
| 273 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 274 | static inline uint8_t stats_get_domain(uint32_t domain) |
| 275 | { |
| 276 | return domain >> STATS_DOMAIN & STATS_DOMAIN_MASK; |
| 277 | } |
| 278 | |
Amaury Denoyelle | 72b16e5 | 2020-10-05 11:49:38 +0200 | [diff] [blame] | 279 | static inline enum stats_domain_px_cap stats_px_get_cap(uint32_t domain) |
| 280 | { |
| 281 | return domain >> STATS_PX_CAP & STATS_PX_CAP_MASK; |
| 282 | } |
| 283 | |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 284 | static void stats_dump_json_schema(struct buffer *out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 285 | |
Amaury Denoyelle | 3ca927e | 2020-10-02 18:32:00 +0200 | [diff] [blame] | 286 | int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 287 | { |
| 288 | if (htx) { |
Christopher Faulet | 69fc88c | 2019-01-07 14:27:53 +0100 | [diff] [blame] | 289 | if (chk->data >= channel_htx_recv_max(chn, htx)) |
| 290 | return 0; |
Willy Tarreau | 0a7ef02 | 2019-05-28 10:30:11 +0200 | [diff] [blame] | 291 | if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 292 | return 0; |
Christopher Faulet | 5adbeeb | 2019-01-02 14:34:39 +0100 | [diff] [blame] | 293 | channel_add_input(chn, chk->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 294 | chk->data = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 295 | } |
| 296 | else { |
| 297 | if (ci_putchk(chn, chk) == -1) |
| 298 | return 0; |
| 299 | } |
| 300 | return 1; |
| 301 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 302 | |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 303 | static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interface *si) |
| 304 | { |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 305 | struct channel *req = si_oc(si); |
| 306 | struct htx *htx = htxbuf(&req->buf); |
| 307 | struct htx_blk *blk; |
| 308 | struct ist uri; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 309 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 310 | blk = htx_get_head_blk(htx); |
Christopher Faulet | ea00973 | 2019-11-18 15:50:25 +0100 | [diff] [blame] | 311 | BUG_ON(!blk || htx_get_blk_type(blk) != HTX_BLK_REQ_SL); |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 312 | ALREADY_CHECKED(blk); |
| 313 | uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk)); |
| 314 | return uri.ptr + appctx->ctx.stats.scope_str; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 315 | } |
| 316 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 317 | /* |
| 318 | * http_stats_io_handler() |
| 319 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 320 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 321 | * -> stats_dump_json_header() // emits the JSON headers (same as above) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 322 | * -> stats_dump_html_head() // emits the HTML headers |
| 323 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 324 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 325 | * -> stats_dump_html_px_hdr() |
| 326 | * -> stats_dump_fe_stats() |
| 327 | * -> stats_dump_li_stats() |
| 328 | * -> stats_dump_sv_stats() |
| 329 | * -> stats_dump_be_stats() |
| 330 | * -> stats_dump_html_px_end() |
| 331 | * -> stats_dump_html_end() // emits HTML trailer |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 332 | * -> stats_dump_json_end() // emits JSON trailer |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 333 | */ |
| 334 | |
| 335 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 336 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 337 | * for clearing it if needed. |
| 338 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 339 | * so please only append new fields at the end, never in the middle. |
| 340 | */ |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 341 | static void stats_dump_csv_header(enum stats_domain domain) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 342 | { |
| 343 | int field; |
| 344 | |
| 345 | chunk_appendf(&trash, "# "); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 346 | if (stat_f[domain]) { |
| 347 | for (field = 0; field < stat_count[domain]; ++field) { |
| 348 | chunk_appendf(&trash, "%s,", stat_f[domain][field].name); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 349 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 350 | /* print special delimiter on proxy stats to mark end of |
| 351 | static fields */ |
| 352 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) |
| 353 | chunk_appendf(&trash, "-,"); |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 357 | chunk_appendf(&trash, "\n"); |
| 358 | } |
| 359 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 360 | /* Emits a stats field without any surrounding element and properly encoded to |
| 361 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 362 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 363 | 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] | 364 | { |
| 365 | switch (field_format(f, 0)) { |
| 366 | case FF_EMPTY: return 1; |
| 367 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 368 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 369 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 370 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 371 | case FF_FLT: return chunk_appendf(out, "%f", f->u.flt); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 372 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 373 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 374 | } |
| 375 | } |
| 376 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 377 | const char *field_to_html_str(const struct field *f) |
| 378 | { |
| 379 | switch (field_format(f, 0)) { |
| 380 | case FF_S32: return U2H(f->u.s32); |
| 381 | case FF_S64: return U2H(f->u.s64); |
| 382 | case FF_U64: return U2H(f->u.u64); |
| 383 | case FF_U32: return U2H(f->u.u32); |
| 384 | case FF_STR: return field_str(f, 0); |
| 385 | case FF_EMPTY: |
| 386 | default: |
| 387 | return ""; |
| 388 | } |
| 389 | } |
| 390 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 391 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 392 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 393 | * if the buffer is full. |
| 394 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 395 | 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] | 396 | { |
| 397 | switch (field_format(f, 0)) { |
| 398 | case FF_EMPTY: return 1; |
| 399 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 400 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 401 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 402 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 403 | case FF_FLT: return chunk_appendf(out, "flt:%f", f->u.flt); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 404 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 405 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 406 | } |
| 407 | } |
| 408 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 409 | /* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per |
| 410 | * the recommendation for interoperable integers in section 6 of RFC 7159. |
| 411 | */ |
| 412 | #define JSON_INT_MAX ((1ULL << 53) - 1) |
| 413 | #define JSON_INT_MIN (0 - JSON_INT_MAX) |
| 414 | |
| 415 | /* Emits a stats field value and its type in JSON. |
| 416 | * Returns non-zero on success, 0 on error. |
| 417 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 418 | 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] | 419 | { |
| 420 | int old_len; |
| 421 | char buf[20]; |
| 422 | const char *type, *value = buf, *quote = ""; |
| 423 | |
| 424 | switch (field_format(f, 0)) { |
| 425 | case FF_EMPTY: return 1; |
| 426 | case FF_S32: type = "\"s32\""; |
| 427 | snprintf(buf, sizeof(buf), "%d", f->u.s32); |
| 428 | break; |
| 429 | case FF_U32: type = "\"u32\""; |
| 430 | snprintf(buf, sizeof(buf), "%u", f->u.u32); |
| 431 | break; |
| 432 | case FF_S64: type = "\"s64\""; |
| 433 | if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX) |
| 434 | return 0; |
| 435 | type = "\"s64\""; |
| 436 | snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64); |
| 437 | break; |
| 438 | case FF_U64: if (f->u.u64 > JSON_INT_MAX) |
| 439 | return 0; |
| 440 | type = "\"u64\""; |
| 441 | snprintf(buf, sizeof(buf), "%llu", |
| 442 | (unsigned long long) f->u.u64); |
Christopher Faulet | 52c91bb | 2019-09-28 10:37:31 +0200 | [diff] [blame] | 443 | break; |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 444 | case FF_FLT: type = "\"flt\""; |
| 445 | snprintf(buf, sizeof(buf), "%f", f->u.flt); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 446 | break; |
| 447 | case FF_STR: type = "\"str\""; |
| 448 | value = field_str(f, 0); |
| 449 | quote = "\""; |
| 450 | break; |
| 451 | default: snprintf(buf, sizeof(buf), "%u", f->type); |
| 452 | type = buf; |
| 453 | value = "unknown"; |
| 454 | quote = "\""; |
| 455 | break; |
| 456 | } |
| 457 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 458 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 459 | chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}", |
| 460 | type, quote, value, quote); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 461 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 462 | } |
| 463 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 464 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 465 | * Returns non-zero on success, 0 if the buffer is full. |
| 466 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 467 | int stats_emit_field_tags(struct buffer *out, const struct field *f, |
| 468 | char delim) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 469 | { |
| 470 | char origin, nature, scope; |
| 471 | |
| 472 | switch (field_origin(f, 0)) { |
| 473 | case FO_METRIC: origin = 'M'; break; |
| 474 | case FO_STATUS: origin = 'S'; break; |
| 475 | case FO_KEY: origin = 'K'; break; |
| 476 | case FO_CONFIG: origin = 'C'; break; |
| 477 | case FO_PRODUCT: origin = 'P'; break; |
| 478 | default: origin = '?'; break; |
| 479 | } |
| 480 | |
| 481 | switch (field_nature(f, 0)) { |
| 482 | case FN_GAUGE: nature = 'G'; break; |
| 483 | case FN_LIMIT: nature = 'L'; break; |
| 484 | case FN_MIN: nature = 'm'; break; |
| 485 | case FN_MAX: nature = 'M'; break; |
| 486 | case FN_RATE: nature = 'R'; break; |
| 487 | case FN_COUNTER: nature = 'C'; break; |
| 488 | case FN_DURATION: nature = 'D'; break; |
| 489 | case FN_AGE: nature = 'A'; break; |
| 490 | case FN_TIME: nature = 'T'; break; |
| 491 | case FN_NAME: nature = 'N'; break; |
| 492 | case FN_OUTPUT: nature = 'O'; break; |
| 493 | case FN_AVG: nature = 'a'; break; |
| 494 | default: nature = '?'; break; |
| 495 | } |
| 496 | |
| 497 | switch (field_scope(f, 0)) { |
| 498 | case FS_PROCESS: scope = 'P'; break; |
| 499 | case FS_SERVICE: scope = 'S'; break; |
| 500 | case FS_SYSTEM: scope = 's'; break; |
| 501 | case FS_CLUSTER: scope = 'C'; break; |
| 502 | default: scope = '?'; break; |
| 503 | } |
| 504 | |
| 505 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 506 | } |
| 507 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 508 | /* Emits an encoding of the field type as JSON. |
| 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_json_field_tags(struct buffer *out, const struct field *f) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 512 | { |
| 513 | const char *origin, *nature, *scope; |
| 514 | int old_len; |
| 515 | |
| 516 | switch (field_origin(f, 0)) { |
| 517 | case FO_METRIC: origin = "Metric"; break; |
| 518 | case FO_STATUS: origin = "Status"; break; |
| 519 | case FO_KEY: origin = "Key"; break; |
| 520 | case FO_CONFIG: origin = "Config"; break; |
| 521 | case FO_PRODUCT: origin = "Product"; break; |
| 522 | default: origin = "Unknown"; break; |
| 523 | } |
| 524 | |
| 525 | switch (field_nature(f, 0)) { |
| 526 | case FN_GAUGE: nature = "Gauge"; break; |
| 527 | case FN_LIMIT: nature = "Limit"; break; |
| 528 | case FN_MIN: nature = "Min"; break; |
| 529 | case FN_MAX: nature = "Max"; break; |
| 530 | case FN_RATE: nature = "Rate"; break; |
| 531 | case FN_COUNTER: nature = "Counter"; break; |
| 532 | case FN_DURATION: nature = "Duration"; break; |
| 533 | case FN_AGE: nature = "Age"; break; |
| 534 | case FN_TIME: nature = "Time"; break; |
| 535 | case FN_NAME: nature = "Name"; break; |
| 536 | case FN_OUTPUT: nature = "Output"; break; |
| 537 | case FN_AVG: nature = "Avg"; break; |
| 538 | default: nature = "Unknown"; break; |
| 539 | } |
| 540 | |
| 541 | switch (field_scope(f, 0)) { |
| 542 | case FS_PROCESS: scope = "Process"; break; |
| 543 | case FS_SERVICE: scope = "Service"; break; |
| 544 | case FS_SYSTEM: scope = "System"; break; |
| 545 | case FS_CLUSTER: scope = "Cluster"; break; |
| 546 | default: scope = "Unknown"; break; |
| 547 | } |
| 548 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 549 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 550 | chunk_appendf(out, "\"tags\":{" |
| 551 | "\"origin\":\"%s\"," |
| 552 | "\"nature\":\"%s\"," |
| 553 | "\"scope\":\"%s\"" |
| 554 | "}", origin, nature, scope); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 555 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 556 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 557 | |
| 558 | /* Dump all fields from <stats> into <out> using CSV format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 559 | static int stats_dump_fields_csv(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 560 | const struct field *stats, size_t stats_count, |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 561 | unsigned int flags, |
| 562 | enum stats_domain domain) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 563 | { |
| 564 | int field; |
| 565 | |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 566 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 567 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 568 | return 0; |
| 569 | if (!chunk_strcat(out, ",")) |
| 570 | return 0; |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 571 | |
| 572 | /* print special delimiter on proxy stats to mark end of |
| 573 | static fields */ |
| 574 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) { |
| 575 | if (!chunk_strcat(out, "-,")) |
| 576 | return 0; |
| 577 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 578 | } |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 579 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 580 | chunk_strcat(out, "\n"); |
| 581 | return 1; |
| 582 | } |
| 583 | |
| 584 | /* 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] | 585 | static int stats_dump_fields_typed(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 586 | const struct field *stats, |
| 587 | size_t stats_count, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 588 | unsigned int flags, |
| 589 | enum stats_domain domain) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 590 | { |
| 591 | int field; |
| 592 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 593 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 594 | if (!stats[field].type) |
| 595 | continue; |
| 596 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 597 | switch (domain) { |
| 598 | case STATS_DOMAIN_PROXY: |
| 599 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 600 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 601 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 602 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 603 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 604 | '?', |
| 605 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 606 | field, |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 607 | stat_f[domain][field].name, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 608 | stats[ST_F_PID].u.u32); |
| 609 | break; |
| 610 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 611 | case STATS_DOMAIN_DNS: |
| 612 | chunk_appendf(out, "D.%d.%s:", field, |
| 613 | stat_f[domain][field].name); |
| 614 | break; |
| 615 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 616 | default: |
| 617 | break; |
| 618 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 619 | |
| 620 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 621 | return 0; |
| 622 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 623 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 624 | |
| 625 | if (flags & STAT_SHOW_FDESC |
| 626 | && !chunk_appendf(out, ":\"%s\"", stat_f[domain][field].name)) { |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 627 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 628 | } |
| 629 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 630 | if (!chunk_strcat(out, "\n")) |
| 631 | return 0; |
| 632 | } |
| 633 | return 1; |
| 634 | } |
| 635 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 636 | /* 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] | 637 | static int stats_dump_json_info_fields(struct buffer *out, |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 638 | const struct field *info, unsigned int flags) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 639 | { |
| 640 | int field; |
| 641 | int started = 0; |
| 642 | |
| 643 | if (!chunk_strcat(out, "[")) |
| 644 | return 0; |
| 645 | |
| 646 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 647 | int old_len; |
| 648 | |
| 649 | if (!field_format(info, field)) |
| 650 | continue; |
| 651 | |
| 652 | if (started && !chunk_strcat(out, ",")) |
| 653 | goto err; |
| 654 | started = 1; |
| 655 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 656 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 657 | chunk_appendf(out, |
| 658 | "{\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 659 | "\"processNum\":%u,", |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 660 | field, info_fields[field].name, |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 661 | info[INF_PROCESS_NUM].u.u32); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 662 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 663 | goto err; |
| 664 | |
| 665 | if (!stats_emit_json_field_tags(out, &info[field])) |
| 666 | goto err; |
| 667 | |
| 668 | if (!stats_emit_json_data_field(out, &info[field])) |
| 669 | goto err; |
| 670 | |
| 671 | if (!chunk_strcat(out, "}")) |
| 672 | goto err; |
| 673 | } |
| 674 | |
| 675 | if (!chunk_strcat(out, "]")) |
| 676 | goto err; |
| 677 | return 1; |
| 678 | |
| 679 | err: |
| 680 | chunk_reset(out); |
| 681 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}"); |
| 682 | return 0; |
| 683 | } |
| 684 | |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 685 | static void stats_print_proxy_field_json(struct buffer *out, |
| 686 | const struct field *stat, |
| 687 | const char *name, |
| 688 | int pos, |
| 689 | uint32_t field_type, |
| 690 | uint32_t iid, |
| 691 | uint32_t sid, |
| 692 | uint32_t pid) |
| 693 | { |
| 694 | const char *obj_type; |
| 695 | switch (field_type) { |
| 696 | case STATS_TYPE_FE: obj_type = "Frontend"; break; |
| 697 | case STATS_TYPE_BE: obj_type = "Backend"; break; |
| 698 | case STATS_TYPE_SO: obj_type = "Listener"; break; |
| 699 | case STATS_TYPE_SV: obj_type = "Server"; break; |
| 700 | default: obj_type = "Unknown"; break; |
| 701 | } |
| 702 | |
| 703 | chunk_appendf(out, |
| 704 | "{" |
| 705 | "\"objType\":\"%s\"," |
| 706 | "\"proxyId\":%u," |
| 707 | "\"id\":%u," |
| 708 | "\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 709 | "\"processNum\":%u,", |
| 710 | obj_type, iid, sid, pos, name, pid); |
| 711 | } |
| 712 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 713 | static void stats_print_dns_field_json(struct buffer *out, |
| 714 | const struct field *stat, |
| 715 | const char *name, |
| 716 | int pos) |
| 717 | { |
| 718 | chunk_appendf(out, |
| 719 | "{" |
| 720 | "\"field\":{\"pos\":%d,\"name\":\"%s\"},", |
| 721 | pos, name); |
| 722 | } |
| 723 | |
| 724 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 725 | /* 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] | 726 | static int stats_dump_fields_json(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 727 | const struct field *stats, size_t stats_count, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 728 | unsigned int flags, |
| 729 | enum stats_domain domain) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 730 | { |
| 731 | int field; |
| 732 | int started = 0; |
| 733 | |
Willy Tarreau | b0ce3ad | 2019-10-09 11:19:29 +0200 | [diff] [blame] | 734 | if ((flags & STAT_STARTED) && !chunk_strcat(out, ",")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 735 | return 0; |
| 736 | if (!chunk_strcat(out, "[")) |
| 737 | return 0; |
| 738 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 739 | for (field = 0; field < stats_count; field++) { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 740 | int old_len; |
| 741 | |
| 742 | if (!stats[field].type) |
| 743 | continue; |
| 744 | |
| 745 | if (started && !chunk_strcat(out, ",")) |
| 746 | goto err; |
| 747 | started = 1; |
| 748 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 749 | old_len = out->data; |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 750 | if (domain == STATS_DOMAIN_PROXY) { |
| 751 | stats_print_proxy_field_json(out, &stats[field], |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 752 | stat_f[domain][field].name, |
| 753 | field, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 754 | stats[ST_F_TYPE].u.u32, |
| 755 | stats[ST_F_IID].u.u32, |
| 756 | stats[ST_F_SID].u.u32, |
| 757 | stats[ST_F_PID].u.u32); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 758 | } else if (domain == STATS_DOMAIN_DNS) { |
| 759 | stats_print_dns_field_json(out, &stats[field], |
| 760 | stat_f[domain][field].name, |
| 761 | field); |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 762 | } |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 763 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 764 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 765 | goto err; |
| 766 | |
| 767 | if (!stats_emit_json_field_tags(out, &stats[field])) |
| 768 | goto err; |
| 769 | |
| 770 | if (!stats_emit_json_data_field(out, &stats[field])) |
| 771 | goto err; |
| 772 | |
| 773 | if (!chunk_strcat(out, "}")) |
| 774 | goto err; |
| 775 | } |
| 776 | |
| 777 | if (!chunk_strcat(out, "]")) |
| 778 | goto err; |
| 779 | |
| 780 | return 1; |
| 781 | |
| 782 | err: |
| 783 | chunk_reset(out); |
Willy Tarreau | b0ce3ad | 2019-10-09 11:19:29 +0200 | [diff] [blame] | 784 | if (flags & STAT_STARTED) |
| 785 | chunk_strcat(out, ","); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 786 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}"); |
| 787 | return 0; |
| 788 | } |
| 789 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 790 | /* 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] | 791 | * 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] | 792 | * are provided if STAT_SHLGNDS is present in <flags>. The statistics from |
| 793 | * extra modules are displayed at the end of the lines if STAT_SHMODULES is |
| 794 | * present in <flags>. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 795 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 796 | static int stats_dump_fields_html(struct buffer *out, |
| 797 | const struct field *stats, |
| 798 | unsigned int flags) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 799 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 800 | struct buffer src; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 801 | struct stats_module *mod; |
| 802 | int i = 0, j = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 803 | |
| 804 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
| 805 | chunk_appendf(out, |
| 806 | /* name, queue */ |
| 807 | "<tr class=\"frontend\">"); |
| 808 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 809 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 810 | /* Column sub-heading for Enable or Disable server */ |
| 811 | chunk_appendf(out, "<td></td>"); |
| 812 | } |
| 813 | |
| 814 | chunk_appendf(out, |
| 815 | "<td class=ac>" |
| 816 | "<a name=\"%s/Frontend\"></a>" |
| 817 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 818 | "<td colspan=3></td>" |
| 819 | "", |
| 820 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 821 | |
| 822 | chunk_appendf(out, |
| 823 | /* sessions rate : current */ |
| 824 | "<td><u>%s<div class=tips><table class=det>" |
| 825 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 826 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 827 | "", |
| 828 | U2H(stats[ST_F_RATE].u.u32), |
| 829 | U2H(stats[ST_F_CONN_RATE].u.u32), |
| 830 | U2H(stats[ST_F_RATE].u.u32)); |
| 831 | |
| 832 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 833 | chunk_appendf(out, |
| 834 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
| 835 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
| 836 | |
| 837 | chunk_appendf(out, |
| 838 | "</table></div></u></td>" |
| 839 | /* sessions rate : max */ |
| 840 | "<td><u>%s<div class=tips><table class=det>" |
| 841 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 842 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 843 | "", |
| 844 | U2H(stats[ST_F_RATE_MAX].u.u32), |
| 845 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
| 846 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 847 | |
| 848 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 849 | chunk_appendf(out, |
| 850 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
| 851 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
| 852 | |
| 853 | chunk_appendf(out, |
| 854 | "</table></div></u></td>" |
| 855 | /* sessions rate : limit */ |
| 856 | "<td>%s</td>", |
| 857 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
| 858 | |
| 859 | chunk_appendf(out, |
| 860 | /* sessions: current, max, limit, total */ |
| 861 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 862 | "<td><u>%s<div class=tips><table class=det>" |
| 863 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 864 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 865 | "", |
| 866 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 867 | U2H(stats[ST_F_STOT].u.u64), |
| 868 | U2H(stats[ST_F_CONN_TOT].u.u64), |
| 869 | U2H(stats[ST_F_STOT].u.u64)); |
| 870 | |
| 871 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 872 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 873 | chunk_appendf(out, |
| 874 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 875 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 876 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 877 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 878 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 879 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 880 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 881 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 882 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 883 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 884 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 885 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 886 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 887 | "", |
| 888 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 889 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 890 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 891 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 892 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 893 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 894 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 895 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 896 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 897 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 898 | U2H(stats[ST_F_INTERCEPTED].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 899 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 900 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 901 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 902 | (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] | 903 | U2H(stats[ST_F_WREW].u.u64), |
| 904 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | chunk_appendf(out, |
| 908 | "</table></div></u></td>" |
| 909 | /* sessions: lbtot, lastsess */ |
| 910 | "<td></td><td></td>" |
| 911 | /* bytes : in */ |
| 912 | "<td>%s</td>" |
| 913 | "", |
| 914 | U2H(stats[ST_F_BIN].u.u64)); |
| 915 | |
| 916 | chunk_appendf(out, |
| 917 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 918 | "<td>%s%s<div class=tips><table class=det>" |
| 919 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 920 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 921 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 922 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 923 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 924 | "</table></div>%s</td>", |
| 925 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 926 | U2H(stats[ST_F_BOUT].u.u64), |
| 927 | U2H(stats[ST_F_BOUT].u.u64), |
| 928 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 929 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 930 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 931 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 932 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 933 | 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, |
| 934 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 935 | |
| 936 | chunk_appendf(out, |
| 937 | /* denied: req, resp */ |
| 938 | "<td>%s</td><td>%s</td>" |
| 939 | /* errors : request, connect, response */ |
| 940 | "<td>%s</td><td></td><td></td>" |
| 941 | /* warnings: retries, redispatches */ |
| 942 | "<td></td><td></td>" |
| 943 | /* server status : reflect frontend status */ |
| 944 | "<td class=ac>%s</td>" |
| 945 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 946 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 947 | "", |
| 948 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 949 | U2H(stats[ST_F_EREQ].u.u64), |
| 950 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 951 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 952 | if (flags & STAT_SHMODULES) { |
| 953 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 954 | chunk_appendf(out, "<td>"); |
| 955 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 956 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 957 | chunk_appendf(out, |
| 958 | "<u>%s<div class=tips><table class=det>", |
| 959 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 960 | for (j = 0; j < mod->stats_count; ++j) { |
| 961 | chunk_appendf(out, |
| 962 | "<tr><th>%s</th><td>%s</td></tr>", |
| 963 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 964 | ++i; |
| 965 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 966 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 967 | } else { |
| 968 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 969 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 970 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 971 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 972 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 976 | } |
| 977 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
| 978 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 979 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 980 | /* Column sub-heading for Enable or Disable server */ |
| 981 | chunk_appendf(out, "<td></td>"); |
| 982 | } |
| 983 | |
| 984 | chunk_appendf(out, |
| 985 | /* frontend name, listener name */ |
| 986 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 987 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 988 | "", |
| 989 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 990 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 991 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 992 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 993 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 994 | chunk_appendf(out, "<div class=tips>"); |
| 995 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 996 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 997 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 998 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 999 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1000 | else if (*field_str(stats, ST_F_ADDR)) |
| 1001 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1002 | |
| 1003 | /* id */ |
| 1004 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
| 1005 | } |
| 1006 | |
| 1007 | chunk_appendf(out, |
| 1008 | /* queue */ |
| 1009 | "%s</td><td colspan=3></td>" |
| 1010 | /* sessions rate: current, max, limit */ |
| 1011 | "<td colspan=3> </td>" |
| 1012 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 1013 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1014 | "<td>%s</td><td> </td><td> </td>" |
| 1015 | /* bytes: in, out */ |
| 1016 | "<td>%s</td><td>%s</td>" |
| 1017 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1018 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1019 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 1020 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 1021 | |
| 1022 | chunk_appendf(out, |
| 1023 | /* denied: req, resp */ |
| 1024 | "<td>%s</td><td>%s</td>" |
| 1025 | /* errors: request, connect, response */ |
| 1026 | "<td>%s</td><td></td><td></td>" |
| 1027 | /* warnings: retries, redispatches */ |
| 1028 | "<td></td><td></td>" |
| 1029 | /* server status: reflect listener status */ |
| 1030 | "<td class=ac>%s</td>" |
| 1031 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1032 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1033 | "", |
| 1034 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1035 | U2H(stats[ST_F_EREQ].u.u64), |
| 1036 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1037 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1038 | if (flags & STAT_SHMODULES) { |
| 1039 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1040 | chunk_appendf(out, "<td>"); |
| 1041 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1042 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1043 | chunk_appendf(out, |
| 1044 | "<u>%s<div class=tips><table class=det>", |
| 1045 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1046 | for (j = 0; j < mod->stats_count; ++j) { |
| 1047 | chunk_appendf(out, |
| 1048 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1049 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1050 | ++i; |
| 1051 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1052 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1053 | } else { |
| 1054 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1055 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1056 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1057 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1058 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1062 | } |
| 1063 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 1064 | const char *style; |
| 1065 | |
| 1066 | /* determine the style to use depending on the server's state, |
| 1067 | * its health and weight. There isn't a 1-to-1 mapping between |
| 1068 | * state and styles for the cases where the server is (still) |
| 1069 | * up. The reason is that we don't want to report nolb and |
| 1070 | * drain with the same color. |
| 1071 | */ |
| 1072 | |
| 1073 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 1074 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 1075 | style = "down"; |
| 1076 | } |
| 1077 | else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) { |
| 1078 | style = "going_up"; |
| 1079 | } |
Daniel Corbett | b428517 | 2020-03-28 12:35:50 -0400 | [diff] [blame] | 1080 | else if (strcmp(field_str(stats, ST_F_STATUS), "DRAIN") == 0) { |
| 1081 | style = "draining"; |
| 1082 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1083 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) { |
| 1084 | style = "going_down"; |
| 1085 | } |
| 1086 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 1087 | style = "nolb"; |
| 1088 | } |
| 1089 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 1090 | style = "no_check"; |
| 1091 | } |
| 1092 | else if (!stats[ST_F_CHKFAIL].type || |
| 1093 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 1094 | /* no check or max health = UP */ |
| 1095 | if (stats[ST_F_WEIGHT].u.u32) |
| 1096 | style = "up"; |
| 1097 | else |
| 1098 | style = "draining"; |
| 1099 | } |
| 1100 | else { |
| 1101 | style = "going_down"; |
| 1102 | } |
| 1103 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1104 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1105 | chunk_appendf(out, "<tr class=\"maintain\">"); |
| 1106 | else |
| 1107 | chunk_appendf(out, |
| 1108 | "<tr class=\"%s_%s\">", |
| 1109 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
| 1110 | |
| 1111 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1112 | if (flags & STAT_ADMIN) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1113 | chunk_appendf(out, |
David Harrigan | d3db35a | 2016-12-30 12:12:49 +0000 | [diff] [blame] | 1114 | "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 1115 | field_str(stats, ST_F_PXNAME), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1116 | field_str(stats, ST_F_SVNAME)); |
| 1117 | |
| 1118 | chunk_appendf(out, |
| 1119 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 1120 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 1121 | "", |
| 1122 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1123 | (flags & STAT_SHLGNDS) ? "<u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1124 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 1125 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1126 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1127 | chunk_appendf(out, "<div class=tips>"); |
| 1128 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 1129 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1130 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 1131 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 1132 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1133 | else if (*field_str(stats, ST_F_ADDR)) |
| 1134 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1135 | |
| 1136 | /* id */ |
| 1137 | chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); |
| 1138 | |
| 1139 | /* cookie */ |
| 1140 | if (stats[ST_F_COOKIE].type) { |
| 1141 | chunk_appendf(out, ", cookie: '"); |
| 1142 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1143 | chunk_htmlencode(out, &src); |
| 1144 | chunk_appendf(out, "'"); |
| 1145 | } |
| 1146 | |
| 1147 | chunk_appendf(out, "</div>"); |
| 1148 | } |
| 1149 | |
| 1150 | chunk_appendf(out, |
| 1151 | /* queue : current, max, limit */ |
| 1152 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 1153 | /* sessions rate : current, max, limit */ |
| 1154 | "<td>%s</td><td>%s</td><td></td>" |
| 1155 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1156 | (flags & STAT_SHLGNDS) ? "</u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1157 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 1158 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1159 | |
| 1160 | chunk_appendf(out, |
| 1161 | /* sessions: current, max, limit, total */ |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1162 | "<td><u>%s<div class=tips>" |
| 1163 | "<table class=det>" |
| 1164 | "<tr><th>Current active connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1165 | "<tr><th>Current used connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1166 | "<tr><th>Current idle connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1167 | "<tr><th>- unsafe:</th><td>%s</td></tr>" |
| 1168 | "<tr><th>- safe:</th><td>%s</td></tr>" |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1169 | "<tr><th>Estimated need of connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1170 | "<tr><th>Active connections limit:</th><td>%s</td></tr>" |
| 1171 | "<tr><th>Idle connections limit:</th><td>%s</td></tr>" |
| 1172 | "</table></div></u>" |
| 1173 | "</td><td>%s</td><td>%s</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1174 | "<td><u>%s<div class=tips><table class=det>" |
| 1175 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1176 | "", |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1177 | U2H(stats[ST_F_SCUR].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1178 | U2H(stats[ST_F_SCUR].u.u32), |
| 1179 | U2H(stats[ST_F_USED_CONN_CUR].u.u32), |
| 1180 | U2H(stats[ST_F_SRV_ICUR].u.u32), |
| 1181 | U2H(stats[ST_F_IDLE_CONN_CUR].u.u32), |
| 1182 | U2H(stats[ST_F_SAFE_CONN_CUR].u.u32), |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1183 | U2H(stats[ST_F_NEED_CONN_EST].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1184 | |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1185 | LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 1186 | stats[ST_F_SRV_ILIM].type ? U2H(stats[ST_F_SRV_ILIM].u.u32) : "-", |
| 1187 | 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] | 1188 | U2H(stats[ST_F_STOT].u.u64), |
| 1189 | U2H(stats[ST_F_STOT].u.u64)); |
| 1190 | |
| 1191 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1192 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1193 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1194 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1195 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1196 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1197 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1198 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1199 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1200 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1201 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1202 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1203 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1204 | "<tr><th>Internal error:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1205 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1206 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1207 | U2H(stats[ST_F_REUSE].u.u64), |
| 1208 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1209 | (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] | 1210 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1211 | U2H(stats[ST_F_HRSP_1XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1212 | (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1213 | U2H(stats[ST_F_HRSP_2XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1214 | (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1215 | U2H(stats[ST_F_HRSP_3XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1216 | (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1217 | U2H(stats[ST_F_HRSP_4XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1218 | (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1219 | U2H(stats[ST_F_HRSP_5XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1220 | (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1221 | U2H(stats[ST_F_HRSP_OTHER].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1222 | (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] | 1223 | U2H(stats[ST_F_WREW].u.u64), |
| 1224 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1225 | } |
| 1226 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1227 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1228 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1229 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1230 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1231 | 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] | 1232 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1233 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1234 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1235 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1236 | 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] | 1237 | |
| 1238 | chunk_appendf(out, |
| 1239 | "</table></div></u></td>" |
| 1240 | /* sessions: lbtot, last */ |
| 1241 | "<td>%s</td><td>%s</td>", |
| 1242 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1243 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
| 1244 | |
| 1245 | chunk_appendf(out, |
| 1246 | /* bytes : in, out */ |
| 1247 | "<td>%s</td><td>%s</td>" |
| 1248 | /* denied: req, resp */ |
| 1249 | "<td></td><td>%s</td>" |
| 1250 | /* errors : request, connect */ |
| 1251 | "<td></td><td>%s</td>" |
| 1252 | /* errors : response */ |
| 1253 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1254 | /* warnings: retries, redispatches */ |
| 1255 | "<td>%lld</td><td>%lld</td>" |
| 1256 | "", |
| 1257 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 1258 | U2H(stats[ST_F_DRESP].u.u64), |
| 1259 | U2H(stats[ST_F_ECON].u.u64), |
| 1260 | U2H(stats[ST_F_ERESP].u.u64), |
| 1261 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1262 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1263 | (long long)stats[ST_F_WRETR].u.u64, |
| 1264 | (long long)stats[ST_F_WREDIS].u.u64); |
| 1265 | |
| 1266 | /* status, last change */ |
| 1267 | chunk_appendf(out, "<td class=ac>"); |
| 1268 | |
| 1269 | /* FIXME!!!! |
| 1270 | * LASTCHG should contain the last change for *this* server and must be computed |
| 1271 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 1272 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 1273 | */ |
| 1274 | |
| 1275 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1276 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1277 | chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); |
| 1278 | } |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1279 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1280 | chunk_strcat(out, "<i>no check</i>"); |
| 1281 | } |
| 1282 | else { |
| 1283 | 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] | 1284 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1285 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
| 1286 | chunk_strcat(out, " ↑"); |
| 1287 | } |
| 1288 | else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) |
| 1289 | chunk_strcat(out, " ↓"); |
| 1290 | } |
| 1291 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1292 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1293 | stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { |
| 1294 | chunk_appendf(out, |
| 1295 | "</td><td class=ac><u> %s", |
| 1296 | field_str(stats, ST_F_AGENT_STATUS)); |
| 1297 | |
| 1298 | if (stats[ST_F_AGENT_CODE].type) |
| 1299 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
| 1300 | |
| 1301 | if (stats[ST_F_AGENT_DURATION].type) |
| 1302 | chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); |
| 1303 | |
| 1304 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC)); |
| 1305 | |
| 1306 | if (*field_str(stats, ST_F_LAST_AGT)) { |
| 1307 | chunk_appendf(out, ": "); |
| 1308 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
| 1309 | chunk_htmlencode(out, &src); |
| 1310 | } |
| 1311 | chunk_appendf(out, "</div></u>"); |
| 1312 | } |
| 1313 | else if (stats[ST_F_CHECK_STATUS].type) { |
| 1314 | chunk_appendf(out, |
| 1315 | "</td><td class=ac><u> %s", |
| 1316 | field_str(stats, ST_F_CHECK_STATUS)); |
| 1317 | |
| 1318 | if (stats[ST_F_CHECK_CODE].type) |
| 1319 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
| 1320 | |
| 1321 | if (stats[ST_F_CHECK_DURATION].type) |
| 1322 | chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); |
| 1323 | |
| 1324 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC)); |
| 1325 | |
| 1326 | if (*field_str(stats, ST_F_LAST_CHK)) { |
| 1327 | chunk_appendf(out, ": "); |
| 1328 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
| 1329 | chunk_htmlencode(out, &src); |
| 1330 | } |
| 1331 | chunk_appendf(out, "</div></u>"); |
| 1332 | } |
| 1333 | else |
| 1334 | chunk_appendf(out, "</td><td>"); |
| 1335 | |
| 1336 | chunk_appendf(out, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1337 | /* weight / uweight */ |
| 1338 | "</td><td class=ac>%d/%d</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1339 | /* act, bck */ |
| 1340 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 1341 | "", |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1342 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1343 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 1344 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 1345 | |
| 1346 | /* check failures: unique, fatal, down time */ |
| 1347 | if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) { |
| 1348 | chunk_appendf(out, "<td class=ac colspan=3>resolution</td>"); |
| 1349 | } |
| 1350 | else if (stats[ST_F_CHKFAIL].type) { |
| 1351 | chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64); |
| 1352 | |
| 1353 | if (stats[ST_F_HANAFAIL].type) |
| 1354 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
| 1355 | |
| 1356 | chunk_appendf(out, |
| 1357 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 1358 | "<td>%lld</td><td>%s</td>" |
| 1359 | "", |
| 1360 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 1361 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 1362 | } |
| 1363 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 1364 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
| 1365 | chunk_appendf(out, |
| 1366 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 1367 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 1368 | } |
| 1369 | else |
| 1370 | chunk_appendf(out, "<td colspan=3></td>"); |
| 1371 | |
| 1372 | /* throttle */ |
| 1373 | if (stats[ST_F_THROTTLE].type) |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1374 | 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] | 1375 | else |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1376 | chunk_appendf(out, "<td class=ac>-</td>"); |
| 1377 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1378 | if (flags & STAT_SHMODULES) { |
| 1379 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1380 | chunk_appendf(out, "<td>"); |
| 1381 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1382 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1383 | chunk_appendf(out, |
| 1384 | "<u>%s<div class=tips><table class=det>", |
| 1385 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1386 | for (j = 0; j < mod->stats_count; ++j) { |
| 1387 | chunk_appendf(out, |
| 1388 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1389 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1390 | ++i; |
| 1391 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1392 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1393 | } else { |
| 1394 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1395 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1396 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1397 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1398 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | chunk_appendf(out, "</tr>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1402 | } |
| 1403 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
| 1404 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1405 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1406 | /* Column sub-heading for Enable or Disable server */ |
| 1407 | chunk_appendf(out, "<td></td>"); |
| 1408 | } |
| 1409 | chunk_appendf(out, |
| 1410 | "<td class=ac>" |
| 1411 | /* name */ |
| 1412 | "%s<a name=\"%s/Backend\"></a>" |
| 1413 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 1414 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1415 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1416 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 1417 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1418 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1419 | /* balancing */ |
| 1420 | chunk_appendf(out, "<div class=tips>balancing: %s", |
| 1421 | field_str(stats, ST_F_ALGO)); |
| 1422 | |
| 1423 | /* cookie */ |
| 1424 | if (stats[ST_F_COOKIE].type) { |
| 1425 | chunk_appendf(out, ", cookie: '"); |
| 1426 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1427 | chunk_htmlencode(out, &src); |
| 1428 | chunk_appendf(out, "'"); |
| 1429 | } |
| 1430 | chunk_appendf(out, "</div>"); |
| 1431 | } |
| 1432 | |
| 1433 | chunk_appendf(out, |
| 1434 | "%s</td>" |
| 1435 | /* queue : current, max */ |
| 1436 | "<td>%s</td><td>%s</td><td></td>" |
| 1437 | /* sessions rate : current, max, limit */ |
| 1438 | "<td>%s</td><td>%s</td><td></td>" |
| 1439 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1440 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1441 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 1442 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1443 | |
| 1444 | chunk_appendf(out, |
| 1445 | /* sessions: current, max, limit, total */ |
| 1446 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1447 | "<td><u>%s<div class=tips><table class=det>" |
| 1448 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1449 | "", |
Willy Tarreau | 8e0f175 | 2016-12-12 15:07:29 +0100 | [diff] [blame] | 1450 | 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] | 1451 | U2H(stats[ST_F_STOT].u.u64), |
| 1452 | U2H(stats[ST_F_STOT].u.u64)); |
| 1453 | |
| 1454 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1455 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 1456 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1457 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1458 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1459 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1460 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1461 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1462 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1463 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1464 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1465 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1466 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1467 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 1468 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1469 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1470 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1471 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1472 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1473 | U2H(stats[ST_F_REUSE].u.u64), |
| 1474 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1475 | (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] | 1476 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1477 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 1478 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 1479 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 1480 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 1481 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 1482 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 1483 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 1484 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Willy Tarreau | feead3a | 2018-12-14 13:48:44 +0100 | [diff] [blame] | 1485 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1486 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 1487 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 1488 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 1489 | (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] | 1490 | U2H(stats[ST_F_WREW].u.u64), |
| 1491 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1492 | } |
| 1493 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1494 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1495 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1496 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1497 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1498 | 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] | 1499 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1500 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1501 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1502 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1503 | 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] | 1504 | |
| 1505 | chunk_appendf(out, |
| 1506 | "</table></div></u></td>" |
| 1507 | /* sessions: lbtot, last */ |
| 1508 | "<td>%s</td><td>%s</td>" |
| 1509 | /* bytes: in */ |
| 1510 | "<td>%s</td>" |
| 1511 | "", |
| 1512 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1513 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 1514 | U2H(stats[ST_F_BIN].u.u64)); |
| 1515 | |
| 1516 | chunk_appendf(out, |
| 1517 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 1518 | "<td>%s%s<div class=tips><table class=det>" |
| 1519 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 1520 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 1521 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1522 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1523 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1524 | "</table></div>%s</td>", |
| 1525 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1526 | U2H(stats[ST_F_BOUT].u.u64), |
| 1527 | U2H(stats[ST_F_BOUT].u.u64), |
| 1528 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1529 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1530 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1531 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1532 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1533 | 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, |
| 1534 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1535 | |
| 1536 | chunk_appendf(out, |
| 1537 | /* denied: req, resp */ |
| 1538 | "<td>%s</td><td>%s</td>" |
| 1539 | /* errors : request, connect */ |
| 1540 | "<td></td><td>%s</td>" |
| 1541 | /* errors : response */ |
| 1542 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1543 | /* warnings: retries, redispatches */ |
| 1544 | "<td>%lld</td><td>%lld</td>" |
| 1545 | /* backend status: reflect backend status (up/down): we display UP |
| 1546 | * if the backend has known working servers or if it has no server at |
| 1547 | * all (eg: for stats). Then we display the total weight, number of |
| 1548 | * active and backups. */ |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1549 | "<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] | 1550 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 1551 | "", |
| 1552 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1553 | U2H(stats[ST_F_ECON].u.u64), |
| 1554 | U2H(stats[ST_F_ERESP].u.u64), |
| 1555 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1556 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1557 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 1558 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 1559 | 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] | 1560 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1561 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 1562 | |
| 1563 | chunk_appendf(out, |
| 1564 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 1565 | "<td class=ac> </td><td>%d</td>" |
| 1566 | "<td>%s</td>" |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1567 | "<td></td>", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1568 | stats[ST_F_CHKDOWN].u.u32, |
| 1569 | 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] | 1570 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1571 | if (flags & STAT_SHMODULES) { |
| 1572 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1573 | chunk_appendf(out, "<td>"); |
| 1574 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1575 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1576 | chunk_appendf(out, |
| 1577 | "<u>%s<div class=tips><table class=det>", |
| 1578 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1579 | for (j = 0; j < mod->stats_count; ++j) { |
| 1580 | chunk_appendf(out, |
| 1581 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1582 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1583 | ++i; |
| 1584 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1585 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1586 | } else { |
| 1587 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1588 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1589 | |
| 1590 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1591 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1592 | } |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1593 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1594 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1595 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1596 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1597 | return 1; |
| 1598 | } |
| 1599 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 1600 | int stats_dump_one_line(const struct field *stats, size_t stats_count, |
| 1601 | struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1602 | { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1603 | int ret; |
| 1604 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1605 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 1606 | ret = stats_dump_fields_html(&trash, stats, appctx->ctx.stats.flags); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1607 | else if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 1608 | ret = stats_dump_fields_typed(&trash, stats, stats_count, appctx->ctx.stats.flags, appctx->ctx.stats.domain); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1609 | else if (appctx->ctx.stats.flags & STAT_FMT_JSON) |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 1610 | ret = stats_dump_fields_json(&trash, stats, stats_count, appctx->ctx.stats.flags, appctx->ctx.stats.domain); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1611 | else |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 1612 | ret = stats_dump_fields_csv(&trash, stats, stats_count, appctx->ctx.stats.flags, appctx->ctx.stats.domain); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1613 | |
| 1614 | if (ret) |
| 1615 | appctx->ctx.stats.flags |= STAT_STARTED; |
| 1616 | |
| 1617 | return ret; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | /* Fill <stats> with the frontend statistics. <stats> is |
| 1621 | * preallocated array of length <len>. The length of the array |
| 1622 | * must be at least ST_F_TOTAL_FIELDS. If this length is less then |
| 1623 | * this value, the function returns 0, otherwise, it returns 1. |
| 1624 | */ |
| 1625 | int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len) |
| 1626 | { |
| 1627 | if (len < ST_F_TOTAL_FIELDS) |
| 1628 | return 0; |
| 1629 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1630 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1631 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
| 1632 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1633 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 1634 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 1635 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 1636 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 1637 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 1638 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 1639 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 1640 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 1641 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 1642 | stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); |
| 1643 | stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1644 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->disabled ? "STOP" : "OPEN"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1645 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 1646 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1647 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 1648 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 1649 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 1650 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 1651 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 1652 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites); |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1653 | stats[ST_F_EINT] = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1654 | |
| 1655 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1656 | if (px->mode == PR_MODE_HTTP) { |
| 1657 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 1658 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 1659 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 1660 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 1661 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 1662 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
| 1663 | stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1664 | stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups); |
| 1665 | stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1669 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 1670 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 1671 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 1672 | |
| 1673 | /* compression: in, out, bypassed, responses */ |
| 1674 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 1675 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 1676 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 1677 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 1678 | |
| 1679 | /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */ |
| 1680 | stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 1681 | stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 1682 | stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 1683 | |
| 1684 | return 1; |
| 1685 | } |
| 1686 | |
| 1687 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1688 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1689 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 1690 | */ |
| 1691 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
| 1692 | { |
| 1693 | struct appctx *appctx = __objt_appctx(si->end); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1694 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 1695 | struct stats_module *mod; |
| 1696 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1697 | |
| 1698 | if (!(px->cap & PR_CAP_FE)) |
| 1699 | return 0; |
| 1700 | |
| 1701 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 1702 | return 0; |
| 1703 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1704 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 1705 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1706 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS)) |
| 1707 | return 0; |
| 1708 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1709 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 1710 | void *counters; |
| 1711 | |
| 1712 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE)) { |
| 1713 | stats_count += mod->stats_count; |
| 1714 | continue; |
| 1715 | } |
| 1716 | |
| 1717 | counters = EXTRA_COUNTERS_GET(px->extra_counters_fe, mod); |
| 1718 | mod->fill_stats(counters, stats + stats_count); |
| 1719 | stats_count += mod->stats_count; |
| 1720 | } |
| 1721 | |
| 1722 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | /* Fill <stats> with the listener statistics. <stats> is |
| 1726 | * preallocated array of length <len>. The length of the array |
| 1727 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 1728 | * then this value, the function returns 0, otherwise, it |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1729 | * returns 1. <flags> can take the value STAT_SHLGNDS. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1730 | */ |
| 1731 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
| 1732 | struct field *stats, int len) |
| 1733 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 1734 | struct buffer *out = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1735 | |
| 1736 | if (len < ST_F_TOTAL_FIELDS) |
| 1737 | return 0; |
| 1738 | |
| 1739 | if (!l->counters) |
| 1740 | return 0; |
| 1741 | |
| 1742 | chunk_reset(out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1743 | |
| 1744 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1745 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name); |
| 1746 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1747 | stats[ST_F_SCUR] = mkf_u32(0, l->nbconn); |
| 1748 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max); |
| 1749 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn); |
| 1750 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 1751 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 1752 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 1753 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 1754 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 1755 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 1756 | stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn); |
| 1757 | stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess); |
Willy Tarreau | a8cf66b | 2019-02-27 16:49:00 +0100 | [diff] [blame] | 1758 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (!l->maxconn || l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1759 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 1760 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1761 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 1762 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 1763 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, l->counters->failed_rewrites); |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1764 | stats[ST_F_EINT] = mkf_u64(FN_COUNTER, l->counters->internal_errors); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1765 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1766 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1767 | char str[INET6_ADDRSTRLEN]; |
| 1768 | int port; |
| 1769 | |
Willy Tarreau | 3715906 | 2020-08-27 07:48:42 +0200 | [diff] [blame] | 1770 | port = get_host_port(&l->rx.addr); |
| 1771 | switch (addr_to_str(&l->rx.addr, str, sizeof(str))) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1772 | case AF_INET: |
| 1773 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 1774 | chunk_appendf(out, "%s:%d", str, port); |
| 1775 | break; |
| 1776 | case AF_INET6: |
| 1777 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 1778 | chunk_appendf(out, "[%s]:%d", str, port); |
| 1779 | break; |
| 1780 | case AF_UNIX: |
| 1781 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 1782 | break; |
| 1783 | case -1: |
| 1784 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 1785 | chunk_strcat(out, strerror(errno)); |
| 1786 | break; |
| 1787 | default: /* address family not supported */ |
| 1788 | break; |
| 1789 | } |
| 1790 | } |
| 1791 | |
| 1792 | return 1; |
| 1793 | } |
| 1794 | |
| 1795 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 1796 | * from stream interface <si>. The caller is responsible for clearing the trash |
| 1797 | * if needed. Returns non-zero if it emits anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1798 | */ |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 1799 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1800 | { |
| 1801 | struct appctx *appctx = __objt_appctx(si->end); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1802 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 1803 | struct stats_module *mod; |
| 1804 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 1805 | |
| 1806 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1807 | |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 1808 | if (!stats_fill_li_stats(px, l, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1809 | return 0; |
| 1810 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1811 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 1812 | void *counters; |
| 1813 | |
| 1814 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI)) { |
| 1815 | stats_count += mod->stats_count; |
| 1816 | continue; |
| 1817 | } |
| 1818 | |
| 1819 | counters = EXTRA_COUNTERS_GET(l->extra_counters, mod); |
| 1820 | mod->fill_stats(counters, stats + stats_count); |
| 1821 | stats_count += mod->stats_count; |
| 1822 | } |
| 1823 | |
| 1824 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | enum srv_stats_state { |
| 1828 | SRV_STATS_STATE_DOWN = 0, |
| 1829 | SRV_STATS_STATE_DOWN_AGENT, |
| 1830 | SRV_STATS_STATE_GOING_UP, |
| 1831 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 1832 | SRV_STATS_STATE_UP, |
| 1833 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 1834 | SRV_STATS_STATE_NOLB, |
| 1835 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 1836 | SRV_STATS_STATE_DRAIN, |
| 1837 | SRV_STATS_STATE_DRAIN_AGENT, |
| 1838 | SRV_STATS_STATE_NO_CHECK, |
| 1839 | |
| 1840 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 1841 | }; |
| 1842 | |
| 1843 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 1844 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 1845 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 1846 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 1847 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 1848 | [SRV_STATS_STATE_UP] = "UP", |
| 1849 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 1850 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 1851 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 1852 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 1853 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 1854 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 1855 | }; |
| 1856 | |
| 1857 | /* Fill <stats> with the server statistics. <stats> is |
| 1858 | * preallocated array of length <len>. The length of the array |
| 1859 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 1860 | * then this value, the function returns 0, otherwise, it |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1861 | * returns 1. <flags> can take the value STAT_SHLGNDS. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1862 | */ |
| 1863 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 1864 | struct field *stats, int len) |
| 1865 | { |
| 1866 | struct server *via, *ref; |
| 1867 | char str[INET6_ADDRSTRLEN]; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 1868 | struct buffer *out = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1869 | enum srv_stats_state state; |
| 1870 | char *fld_status; |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 1871 | long long srv_samples_counter; |
| 1872 | unsigned int srv_samples_window = TIME_STATS_SAMPLES; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1873 | |
| 1874 | if (len < ST_F_TOTAL_FIELDS) |
| 1875 | return 0; |
| 1876 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1877 | /* we have "via" which is the tracked server as described in the configuration, |
| 1878 | * and "ref" which is the checked server and the end of the chain. |
| 1879 | */ |
| 1880 | via = sv->track ? sv->track : sv; |
| 1881 | ref = via; |
| 1882 | while (ref->track) |
| 1883 | ref = ref->track; |
| 1884 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1885 | 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] | 1886 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 1887 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
| 1888 | state = SRV_STATS_STATE_UP_GOING_DOWN; |
| 1889 | } else { |
| 1890 | state = SRV_STATS_STATE_UP; |
| 1891 | } |
| 1892 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1893 | if (sv->cur_admin & SRV_ADMF_DRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1894 | if (ref->agent.state & CHK_ST_ENABLED) |
| 1895 | state = SRV_STATS_STATE_DRAIN_AGENT; |
| 1896 | else if (state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 1897 | state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
| 1898 | else |
| 1899 | state = SRV_STATS_STATE_DRAIN; |
| 1900 | } |
| 1901 | |
| 1902 | if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 1903 | state = SRV_STATS_STATE_NO_CHECK; |
| 1904 | } |
| 1905 | } |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1906 | else if (sv->cur_state == SRV_ST_STOPPING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1907 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 1908 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
| 1909 | state = SRV_STATS_STATE_NOLB; |
| 1910 | } else { |
| 1911 | state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
| 1912 | } |
| 1913 | } |
| 1914 | else { /* stopped */ |
| 1915 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
| 1916 | state = SRV_STATS_STATE_DOWN_AGENT; |
| 1917 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
| 1918 | state = SRV_STATS_STATE_DOWN; /* DOWN */ |
| 1919 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
| 1920 | state = SRV_STATS_STATE_GOING_UP; |
| 1921 | } else { |
| 1922 | state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
| 1923 | } |
| 1924 | } |
| 1925 | |
| 1926 | chunk_reset(out); |
| 1927 | |
| 1928 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1929 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id); |
| 1930 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1931 | stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend); |
| 1932 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 1933 | stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess); |
| 1934 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 1935 | |
| 1936 | if (sv->maxconn) |
| 1937 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 1938 | |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1939 | stats[ST_F_SRV_ICUR] = mkf_u32(0, sv->curr_idle_conns); |
| 1940 | if (sv->max_idle_conns != -1) |
| 1941 | stats[ST_F_SRV_ILIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->max_idle_conns); |
| 1942 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1943 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 1944 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 1945 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
Christopher Faulet | a08546b | 2019-12-16 16:07:34 +0100 | [diff] [blame] | 1946 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.denied_resp); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1947 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 1948 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 1949 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 1950 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 1951 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites); |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1952 | stats[ST_F_EINT] = mkf_u64(FN_COUNTER, sv->counters.internal_errors); |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1953 | stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, sv->counters.connect); |
| 1954 | stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, sv->counters.reuse); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1955 | |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1956 | stats[ST_F_IDLE_CONN_CUR] = mkf_u32(0, sv->curr_idle_nb); |
| 1957 | stats[ST_F_SAFE_CONN_CUR] = mkf_u32(0, sv->curr_safe_nb); |
| 1958 | stats[ST_F_USED_CONN_CUR] = mkf_u32(0, sv->curr_used_conns); |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1959 | stats[ST_F_NEED_CONN_EST] = mkf_u32(0, sv->est_need_conns); |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1960 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1961 | /* status */ |
| 1962 | fld_status = chunk_newstr(out); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1963 | if (sv->cur_admin & SRV_ADMF_RMAINT) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1964 | chunk_appendf(out, "MAINT (resolution)"); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1965 | else if (sv->cur_admin & SRV_ADMF_IMAINT) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1966 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1967 | else if (sv->cur_admin & SRV_ADMF_MAINT) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1968 | chunk_appendf(out, "MAINT"); |
| 1969 | else |
| 1970 | chunk_appendf(out, |
| 1971 | srv_hlt_st[state], |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1972 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 1973 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1974 | |
| 1975 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status); |
| 1976 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1977 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1978 | stats[ST_F_UWEIGHT] = mkf_u32(FN_AVG, sv->uweight); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1979 | stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 1980 | stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
| 1981 | |
| 1982 | /* check failures: unique, fatal; last change, total downtime */ |
| 1983 | if (sv->check.state & CHK_ST_ENABLED) { |
| 1984 | stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 1985 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 1986 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 1987 | } |
| 1988 | |
| 1989 | if (sv->maxqueue) |
| 1990 | stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
| 1991 | |
| 1992 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 1993 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1994 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
| 1995 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1996 | if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1997 | stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
| 1998 | |
| 1999 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
| 2000 | |
| 2001 | if (sv->track) { |
| 2002 | char *fld_track = chunk_newstr(out); |
| 2003 | |
| 2004 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 2005 | stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 2006 | } |
| 2007 | |
| 2008 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 2009 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 2010 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max); |
| 2011 | |
| 2012 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2013 | const char *fld_chksts; |
| 2014 | |
| 2015 | fld_chksts = chunk_newstr(out); |
| 2016 | chunk_strcat(out, "* "); // for check in progress |
| 2017 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 2018 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 2019 | fld_chksts += 2; // skip "* " |
| 2020 | stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
| 2021 | |
| 2022 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 2023 | stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code); |
| 2024 | |
| 2025 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 2026 | stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); |
| 2027 | |
| 2028 | stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 2029 | stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc); |
| 2030 | stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 2031 | stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 2032 | stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 2033 | } |
| 2034 | |
| 2035 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2036 | const char *fld_chksts; |
| 2037 | |
| 2038 | fld_chksts = chunk_newstr(out); |
| 2039 | chunk_strcat(out, "* "); // for check in progress |
| 2040 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 2041 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 2042 | fld_chksts += 2; // skip "* " |
| 2043 | stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
| 2044 | |
| 2045 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 2046 | stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); |
| 2047 | |
| 2048 | if (sv->agent.status >= HCHK_STATUS_CHECKED) |
| 2049 | stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); |
| 2050 | |
| 2051 | stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 2052 | stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 2053 | stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 2054 | stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 2055 | stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 2056 | } |
| 2057 | |
| 2058 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2059 | if (px->mode == PR_MODE_HTTP) { |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 2060 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2061 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 2062 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 2063 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 2064 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 2065 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 2066 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 2067 | } |
| 2068 | |
| 2069 | if (ref->observe) |
| 2070 | stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
| 2071 | |
| 2072 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 2073 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 2074 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv)); |
| 2075 | |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 2076 | srv_samples_counter = (px->mode == PR_MODE_HTTP) ? sv->counters.p.http.cum_req : sv->counters.cum_lbconn; |
| 2077 | if (srv_samples_counter < TIME_STATS_SAMPLES && srv_samples_counter > 0) |
| 2078 | srv_samples_window = srv_samples_counter; |
| 2079 | |
| 2080 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, srv_samples_window)); |
| 2081 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, srv_samples_window)); |
| 2082 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, srv_samples_window)); |
| 2083 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, srv_samples_window)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2084 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 2085 | stats[ST_F_QT_MAX] = mkf_u32(FN_MAX, sv->counters.qtime_max); |
| 2086 | stats[ST_F_CT_MAX] = mkf_u32(FN_MAX, sv->counters.ctime_max); |
| 2087 | stats[ST_F_RT_MAX] = mkf_u32(FN_MAX, sv->counters.dtime_max); |
| 2088 | stats[ST_F_TT_MAX] = mkf_u32(FN_MAX, sv->counters.ttime_max); |
| 2089 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 2090 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2091 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2092 | case AF_INET: |
| 2093 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
Willy Tarreau | 04276f3 | 2017-01-06 17:41:29 +0100 | [diff] [blame] | 2094 | chunk_appendf(out, "%s:%d", str, sv->svc_port); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2095 | break; |
| 2096 | case AF_INET6: |
| 2097 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
Willy Tarreau | 04276f3 | 2017-01-06 17:41:29 +0100 | [diff] [blame] | 2098 | chunk_appendf(out, "[%s]:%d", str, sv->svc_port); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2099 | break; |
| 2100 | case AF_UNIX: |
| 2101 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 2102 | break; |
| 2103 | case -1: |
| 2104 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2105 | chunk_strcat(out, strerror(errno)); |
| 2106 | break; |
| 2107 | default: /* address family not supported */ |
| 2108 | break; |
| 2109 | } |
| 2110 | |
| 2111 | if (sv->cookie) |
| 2112 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 2113 | } |
| 2114 | |
| 2115 | return 1; |
| 2116 | } |
| 2117 | |
| 2118 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2119 | * from stream interface <si>, and server state <state>. The caller is |
| 2120 | * responsible for clearing the trash if needed. Returns non-zero if it emits |
| 2121 | * anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2122 | */ |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2123 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, struct server *sv) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2124 | { |
| 2125 | struct appctx *appctx = __objt_appctx(si->end); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2126 | struct stats_module *mod; |
| 2127 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2128 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 2129 | |
| 2130 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2131 | |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2132 | if (!stats_fill_sv_stats(px, sv, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2133 | return 0; |
| 2134 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2135 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2136 | void *counters; |
| 2137 | |
| 2138 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2139 | continue; |
| 2140 | |
| 2141 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV)) { |
| 2142 | stats_count += mod->stats_count; |
| 2143 | continue; |
| 2144 | } |
| 2145 | |
| 2146 | counters = EXTRA_COUNTERS_GET(sv->extra_counters, mod); |
| 2147 | mod->fill_stats(counters, stats + stats_count); |
| 2148 | stats_count += mod->stats_count; |
| 2149 | } |
| 2150 | |
| 2151 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2152 | } |
| 2153 | |
| 2154 | /* Fill <stats> with the backend statistics. <stats> is |
| 2155 | * preallocated array of length <len>. The length of the array |
| 2156 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 2157 | * then this value, the function returns 0, otherwise, it |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 2158 | * returns 1. <flags> can take the value STAT_SHLGNDS. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2159 | */ |
| 2160 | int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len) |
| 2161 | { |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 2162 | long long be_samples_counter; |
| 2163 | unsigned int be_samples_window = TIME_STATS_SAMPLES; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2164 | struct buffer *out = get_trash_chunk(); |
| 2165 | const struct server *srv; |
| 2166 | int nbup, nbsrv; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2167 | int totuw; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2168 | char *fld; |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 2169 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2170 | if (len < ST_F_TOTAL_FIELDS) |
| 2171 | return 0; |
| 2172 | |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2173 | totuw = 0; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2174 | nbup = nbsrv = 0; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2175 | for (srv = px->srv; srv; srv = srv->next) { |
| 2176 | if (srv->cur_state != SRV_ST_STOPPED) { |
| 2177 | nbup++; |
| 2178 | if (srv_currently_usable(srv) && |
| 2179 | (!px->srv_act ^ !(srv->flags & SRV_F_BACKUP))) |
| 2180 | totuw += srv->uweight; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2181 | } |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2182 | nbsrv++; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2183 | } |
| 2184 | |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2185 | HA_RWLOCK_RDLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2186 | if (!px->srv_act && px->lbprm.fbck) |
| 2187 | totuw = px->lbprm.fbck->uweight; |
| 2188 | HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2189 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2190 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 2191 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND"); |
| 2192 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 2193 | stats[ST_F_QCUR] = mkf_u32(0, px->nbpend); |
| 2194 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
Thierry FOURNIER | 0ff98a4 | 2016-12-19 16:50:42 +0100 | [diff] [blame] | 2195 | stats[ST_F_SCUR] = mkf_u32(0, px->beconn); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2196 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 2197 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 2198 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 2199 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 2200 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 2201 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 2202 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 2203 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 2204 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 2205 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 2206 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 2207 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites); |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 2208 | stats[ST_F_EINT] = mkf_u64(FN_COUNTER, px->be_counters.internal_errors); |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 2209 | stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, px->be_counters.connect); |
| 2210 | stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, px->be_counters.reuse); |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2211 | |
| 2212 | fld = chunk_newstr(out); |
| 2213 | chunk_appendf(out, "%s", (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 2214 | if (flags & (STAT_HIDE_MAINT|STAT_HIDE_DOWN)) |
| 2215 | chunk_appendf(out, " (%d/%d)", nbup, nbsrv); |
| 2216 | |
| 2217 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2218 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2219 | stats[ST_F_UWEIGHT] = mkf_u32(FN_AVG, totuw); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2220 | stats[ST_F_ACT] = mkf_u32(0, px->srv_act); |
| 2221 | stats[ST_F_BCK] = mkf_u32(0, px->srv_bck); |
| 2222 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans); |
| 2223 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change); |
| 2224 | if (px->srv) |
| 2225 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 2226 | |
| 2227 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 2228 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2229 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 2230 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 2231 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 2232 | stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 2233 | stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max); |
| 2234 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 2235 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2236 | if (px->cookie_name) |
| 2237 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name); |
| 2238 | stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2239 | } |
| 2240 | |
| 2241 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 2242 | if (px->mode == PR_MODE_HTTP) { |
| 2243 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 2244 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 2245 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 2246 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 2247 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 2248 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 2249 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 2250 | stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups); |
| 2251 | stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 2255 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 2256 | |
| 2257 | /* compression: in, out, bypassed, responses */ |
| 2258 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 2259 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 2260 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 2261 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 2262 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px)); |
| 2263 | |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 2264 | be_samples_counter = (px->mode == PR_MODE_HTTP) ? px->be_counters.p.http.cum_req : px->be_counters.cum_lbconn; |
| 2265 | if (be_samples_counter < TIME_STATS_SAMPLES && be_samples_counter > 0) |
| 2266 | be_samples_window = be_samples_counter; |
| 2267 | |
| 2268 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, be_samples_window)); |
| 2269 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, be_samples_window)); |
| 2270 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, be_samples_window)); |
| 2271 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, be_samples_window)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2272 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 2273 | stats[ST_F_QT_MAX] = mkf_u32(FN_MAX, px->be_counters.qtime_max); |
| 2274 | stats[ST_F_CT_MAX] = mkf_u32(FN_MAX, px->be_counters.ctime_max); |
| 2275 | stats[ST_F_RT_MAX] = mkf_u32(FN_MAX, px->be_counters.dtime_max); |
| 2276 | stats[ST_F_TT_MAX] = mkf_u32(FN_MAX, px->be_counters.ttime_max); |
| 2277 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2278 | return 1; |
| 2279 | } |
| 2280 | |
| 2281 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2282 | * interface <si>. The caller is responsible for clearing the trash if needed. |
| 2283 | * Returns non-zero if it emits anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2284 | */ |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2285 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2286 | { |
| 2287 | struct appctx *appctx = __objt_appctx(si->end); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2288 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2289 | struct stats_module *mod; |
| 2290 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2291 | |
| 2292 | if (!(px->cap & PR_CAP_BE)) |
| 2293 | return 0; |
| 2294 | |
| 2295 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 2296 | return 0; |
| 2297 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2298 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 2299 | |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2300 | if (!stats_fill_be_stats(px, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2301 | return 0; |
| 2302 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2303 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2304 | struct extra_counters *counters; |
| 2305 | |
| 2306 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2307 | continue; |
| 2308 | |
| 2309 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE)) { |
| 2310 | stats_count += mod->stats_count; |
| 2311 | continue; |
| 2312 | } |
| 2313 | |
| 2314 | counters = EXTRA_COUNTERS_GET(px->extra_counters_be, mod); |
| 2315 | mod->fill_stats(counters, stats + stats_count); |
| 2316 | stats_count += mod->stats_count; |
| 2317 | } |
| 2318 | |
| 2319 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | /* Dumps the HTML table header for proxy <px> to the trash for and uses the state from |
| 2323 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
| 2324 | * for clearing the trash if needed. |
| 2325 | */ |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2326 | static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2327 | { |
| 2328 | struct appctx *appctx = __objt_appctx(si->end); |
| 2329 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 2330 | struct stats_module *mod; |
| 2331 | int stats_module_len = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2332 | |
| 2333 | if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
| 2334 | /* A form to enable/disable this proxy servers */ |
| 2335 | |
| 2336 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 2337 | scope_txt[0] = 0; |
| 2338 | if (appctx->ctx.stats.scope_len) { |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2339 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
| 2340 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2341 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2342 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2343 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
| 2344 | } |
| 2345 | |
| 2346 | chunk_appendf(&trash, |
| 2347 | "<form method=\"post\">"); |
| 2348 | } |
| 2349 | |
| 2350 | /* print a new table */ |
| 2351 | chunk_appendf(&trash, |
| 2352 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2353 | "<tr class=\"titre\">" |
| 2354 | "<th class=\"pxname\" width=\"10%%\">"); |
| 2355 | |
| 2356 | chunk_appendf(&trash, |
| 2357 | "<a name=\"%s\"></a>%s" |
| 2358 | "<a class=px href=\"#%s\">%s</a>", |
| 2359 | px->id, |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2360 | (appctx->ctx.stats.flags & STAT_SHLGNDS) ? "<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2361 | px->id, px->id); |
| 2362 | |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2363 | if (appctx->ctx.stats.flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2364 | /* cap, mode, id */ |
| 2365 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
| 2366 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 2367 | px->uuid); |
| 2368 | chunk_appendf(&trash, "</div>"); |
| 2369 | } |
| 2370 | |
| 2371 | chunk_appendf(&trash, |
| 2372 | "%s</th>" |
| 2373 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 2374 | "</tr>\n" |
| 2375 | "</table>\n" |
| 2376 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 2377 | "<tr class=\"titre\">", |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2378 | (appctx->ctx.stats.flags & STAT_SHLGNDS) ? "</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2379 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 2380 | |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 2381 | if (appctx->ctx.stats.flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2382 | /* Column heading for Enable or Disable server */ |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 2383 | if ((px->cap & PR_CAP_BE) && px->srv) |
| 2384 | chunk_appendf(&trash, |
| 2385 | "<th rowspan=2 width=1><input type=\"checkbox\" " |
| 2386 | "onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) " |
| 2387 | "document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>", |
| 2388 | px->id, |
| 2389 | px->id); |
| 2390 | else |
| 2391 | chunk_appendf(&trash, "<th rowspan=2></th>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | chunk_appendf(&trash, |
| 2395 | "<th rowspan=2></th>" |
| 2396 | "<th colspan=3>Queue</th>" |
| 2397 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
| 2398 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2399 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 2400 | "<th colspan=9>Server</th>"); |
| 2401 | |
| 2402 | if (appctx->ctx.stats.flags & STAT_SHMODULES) { |
| 2403 | // calculate the count of module for colspan attribute |
| 2404 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2405 | ++stats_module_len; |
| 2406 | } |
| 2407 | chunk_appendf(&trash, "<th colspan=%d>Extra modules</th>", |
| 2408 | stats_module_len); |
| 2409 | } |
| 2410 | |
| 2411 | chunk_appendf(&trash, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2412 | "</tr>\n" |
| 2413 | "<tr class=\"titre\">" |
| 2414 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2415 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2416 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>" |
| 2417 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2418 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2419 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2420 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 2421 | "<th>Thrtle</th>\n"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 2422 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 2423 | if (appctx->ctx.stats.flags & STAT_SHMODULES) { |
| 2424 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2425 | chunk_appendf(&trash, "<th>%s</th>", mod->name); |
| 2426 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | chunk_appendf(&trash, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | /* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from |
| 2433 | * stream interface <si>. The caller is responsible for clearing the trash if needed. |
| 2434 | */ |
| 2435 | static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px) |
| 2436 | { |
| 2437 | struct appctx *appctx = __objt_appctx(si->end); |
| 2438 | chunk_appendf(&trash, "</table>"); |
| 2439 | |
| 2440 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
| 2441 | /* close the form used to enable/disable this proxy servers */ |
| 2442 | chunk_appendf(&trash, |
| 2443 | "Choose the action to perform on the checked servers : " |
| 2444 | "<select name=action>" |
| 2445 | "<option value=\"\"></option>" |
| 2446 | "<option value=\"ready\">Set state to READY</option>" |
| 2447 | "<option value=\"drain\">Set state to DRAIN</option>" |
| 2448 | "<option value=\"maint\">Set state to MAINT</option>" |
| 2449 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 2450 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 2451 | "<option value=\"hrunn\">Health: force UP</option>" |
| 2452 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 2453 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 2454 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 2455 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 2456 | "<option value=\"arunn\">Agent: force UP</option>" |
| 2457 | "<option value=\"adown\">Agent: force DOWN</option>" |
| 2458 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2459 | "</select>" |
| 2460 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2461 | " <input type=\"submit\" value=\"Apply\">" |
| 2462 | "</form>", |
| 2463 | px->uuid); |
| 2464 | } |
| 2465 | |
| 2466 | chunk_appendf(&trash, "<p>\n"); |
| 2467 | } |
| 2468 | |
| 2469 | /* |
| 2470 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2471 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2472 | * buffer space, or non-zero if everything completed. This function is used |
| 2473 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2474 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
| 2475 | */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2476 | int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx, |
| 2477 | struct proxy *px, struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2478 | { |
| 2479 | struct appctx *appctx = __objt_appctx(si->end); |
| 2480 | struct stream *s = si_strm(si); |
| 2481 | struct channel *rep = si_ic(si); |
| 2482 | struct server *sv, *svs; /* server and server-state, server-state=server or server->track */ |
| 2483 | struct listener *l; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2484 | |
| 2485 | chunk_reset(&trash); |
| 2486 | |
| 2487 | switch (appctx->ctx.stats.px_st) { |
| 2488 | case STAT_PX_ST_INIT: |
| 2489 | /* we are on a new proxy */ |
| 2490 | if (uri && uri->scope) { |
| 2491 | /* we have a limited scope, we have to check the proxy name */ |
| 2492 | struct stat_scope *scope; |
| 2493 | int len; |
| 2494 | |
| 2495 | len = strlen(px->id); |
| 2496 | scope = uri->scope; |
| 2497 | |
| 2498 | while (scope) { |
| 2499 | /* match exact proxy name */ |
| 2500 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2501 | break; |
| 2502 | |
| 2503 | /* match '.' which means 'self' proxy */ |
| 2504 | if (!strcmp(scope->px_id, ".") && px == s->be) |
| 2505 | break; |
| 2506 | scope = scope->next; |
| 2507 | } |
| 2508 | |
| 2509 | /* proxy name not found : don't dump anything */ |
| 2510 | if (scope == NULL) |
| 2511 | return 1; |
| 2512 | } |
| 2513 | |
| 2514 | /* if the user has requested a limited output and the proxy |
| 2515 | * name does not match, skip it. |
| 2516 | */ |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2517 | if (appctx->ctx.stats.scope_len) { |
| 2518 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
| 2519 | |
| 2520 | if (strnistr(px->id, strlen(px->id), scope_ptr, appctx->ctx.stats.scope_len) == NULL) |
| 2521 | return 1; |
| 2522 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2523 | |
| 2524 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 2525 | (appctx->ctx.stats.iid != -1) && |
| 2526 | (px->uuid != appctx->ctx.stats.iid)) |
| 2527 | return 1; |
| 2528 | |
| 2529 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
| 2530 | /* fall through */ |
| 2531 | |
| 2532 | case STAT_PX_ST_TH: |
| 2533 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2534 | stats_dump_html_px_hdr(si, px); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2535 | if (!stats_putchk(rep, htx, &trash)) |
| 2536 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
| 2540 | /* fall through */ |
| 2541 | |
| 2542 | case STAT_PX_ST_FE: |
| 2543 | /* print the frontend */ |
| 2544 | if (stats_dump_fe_stats(si, px)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2545 | if (!stats_putchk(rep, htx, &trash)) |
| 2546 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2547 | } |
| 2548 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2549 | appctx->ctx.stats.obj2 = px->conf.listeners.n; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2550 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
| 2551 | /* fall through */ |
| 2552 | |
| 2553 | case STAT_PX_ST_LI: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2554 | /* obj2 points to listeners list as initialized above */ |
| 2555 | for (; appctx->ctx.stats.obj2 != &px->conf.listeners; appctx->ctx.stats.obj2 = l->by_fe.n) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2556 | if (htx) { |
| 2557 | if (htx_almost_full(htx)) |
| 2558 | goto full; |
| 2559 | } |
| 2560 | else { |
| 2561 | if (buffer_almost_full(&rep->buf)) |
| 2562 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2563 | } |
| 2564 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2565 | l = LIST_ELEM(appctx->ctx.stats.obj2, struct listener *, by_fe); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2566 | if (!l->counters) |
| 2567 | continue; |
| 2568 | |
| 2569 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 2570 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
| 2571 | break; |
| 2572 | |
| 2573 | if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid) |
| 2574 | continue; |
| 2575 | } |
| 2576 | |
| 2577 | /* print the frontend */ |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2578 | if (stats_dump_li_stats(si, px, l)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2579 | if (!stats_putchk(rep, htx, &trash)) |
| 2580 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2581 | } |
| 2582 | } |
| 2583 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2584 | appctx->ctx.stats.obj2 = px->srv; /* may be NULL */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2585 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
| 2586 | /* fall through */ |
| 2587 | |
| 2588 | case STAT_PX_ST_SV: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2589 | /* obj2 points to servers list as initialized above */ |
| 2590 | for (; appctx->ctx.stats.obj2 != NULL; appctx->ctx.stats.obj2 = sv->next) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2591 | if (htx) { |
| 2592 | if (htx_almost_full(htx)) |
| 2593 | goto full; |
| 2594 | } |
| 2595 | else { |
| 2596 | if (buffer_almost_full(&rep->buf)) |
| 2597 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2598 | } |
| 2599 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2600 | sv = appctx->ctx.stats.obj2; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2601 | |
| 2602 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 2603 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
| 2604 | break; |
| 2605 | |
| 2606 | if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid) |
| 2607 | continue; |
| 2608 | } |
| 2609 | |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 2610 | /* do not report disabled servers */ |
| 2611 | if (appctx->ctx.stats.flags & STAT_HIDE_MAINT && |
| 2612 | sv->cur_admin & SRV_ADMF_MAINT) { |
| 2613 | continue; |
| 2614 | } |
| 2615 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2616 | svs = sv; |
| 2617 | while (svs->track) |
| 2618 | svs = svs->track; |
| 2619 | |
| 2620 | /* do not report servers which are DOWN and not changing state */ |
| 2621 | if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) && |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2622 | ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 2623 | (sv->cur_state == SRV_ST_STOPPED && /* server is down */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2624 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 2625 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 2626 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
| 2627 | continue; |
| 2628 | } |
| 2629 | |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2630 | if (stats_dump_sv_stats(si, px, sv)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2631 | if (!stats_putchk(rep, htx, &trash)) |
| 2632 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2633 | } |
| 2634 | } /* for sv */ |
| 2635 | |
| 2636 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
| 2637 | /* fall through */ |
| 2638 | |
| 2639 | case STAT_PX_ST_BE: |
| 2640 | /* print the backend */ |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 2641 | if (stats_dump_be_stats(si, px)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2642 | if (!stats_putchk(rep, htx, &trash)) |
| 2643 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
| 2647 | /* fall through */ |
| 2648 | |
| 2649 | case STAT_PX_ST_END: |
| 2650 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
| 2651 | stats_dump_html_px_end(si, px); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2652 | if (!stats_putchk(rep, htx, &trash)) |
| 2653 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
| 2657 | /* fall through */ |
| 2658 | |
| 2659 | case STAT_PX_ST_FIN: |
| 2660 | return 1; |
| 2661 | |
| 2662 | default: |
| 2663 | /* unknown state, we should put an abort() here ! */ |
| 2664 | return 1; |
| 2665 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2666 | |
| 2667 | full: |
| 2668 | si_rx_room_blk(si); |
| 2669 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 2673 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
| 2674 | */ |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2675 | static void stats_dump_html_head(struct appctx *appctx, struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2676 | { |
| 2677 | /* WARNING! This must fit in the first buffer !!! */ |
| 2678 | chunk_appendf(&trash, |
| 2679 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 2680 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 2681 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
zurikus | 6d59993 | 2020-08-18 11:16:05 +0300 | [diff] [blame] | 2682 | "<link rel=\"icon\" href=\"data:,\">\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2683 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 2684 | "<style type=\"text/css\"><!--\n" |
| 2685 | "body {" |
| 2686 | " font-family: arial, helvetica, sans-serif;" |
| 2687 | " font-size: 12px;" |
| 2688 | " font-weight: normal;" |
| 2689 | " color: black;" |
| 2690 | " background: white;" |
| 2691 | "}\n" |
| 2692 | "th,td {" |
| 2693 | " font-size: 10px;" |
| 2694 | "}\n" |
| 2695 | "h1 {" |
| 2696 | " font-size: x-large;" |
| 2697 | " margin-bottom: 0.5em;" |
| 2698 | "}\n" |
| 2699 | "h2 {" |
| 2700 | " font-family: helvetica, arial;" |
| 2701 | " font-size: x-large;" |
| 2702 | " font-weight: bold;" |
| 2703 | " font-style: italic;" |
| 2704 | " color: #6020a0;" |
| 2705 | " margin-top: 0em;" |
| 2706 | " margin-bottom: 0em;" |
| 2707 | "}\n" |
| 2708 | "h3 {" |
| 2709 | " font-family: helvetica, arial;" |
| 2710 | " font-size: 16px;" |
| 2711 | " font-weight: bold;" |
| 2712 | " color: #b00040;" |
| 2713 | " background: #e8e8d0;" |
| 2714 | " margin-top: 0em;" |
| 2715 | " margin-bottom: 0em;" |
| 2716 | "}\n" |
| 2717 | "li {" |
| 2718 | " margin-top: 0.25em;" |
| 2719 | " margin-right: 2em;" |
| 2720 | "}\n" |
| 2721 | ".hr {margin-top: 0.25em;" |
| 2722 | " border-color: black;" |
| 2723 | " border-bottom-style: solid;" |
| 2724 | "}\n" |
| 2725 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 2726 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 2727 | ".frontend {background: #e8e8d0;}\n" |
| 2728 | ".socket {background: #d0d0d0;}\n" |
| 2729 | ".backend {background: #e8e8d0;}\n" |
| 2730 | ".active_down {background: #ff9090;}\n" |
| 2731 | ".active_going_up {background: #ffd020;}\n" |
| 2732 | ".active_going_down {background: #ffffa0;}\n" |
| 2733 | ".active_up {background: #c0ffc0;}\n" |
| 2734 | ".active_nolb {background: #20a0ff;}\n" |
| 2735 | ".active_draining {background: #20a0FF;}\n" |
| 2736 | ".active_no_check {background: #e0e0e0;}\n" |
| 2737 | ".backup_down {background: #ff9090;}\n" |
| 2738 | ".backup_going_up {background: #ff80ff;}\n" |
| 2739 | ".backup_going_down {background: #c060ff;}\n" |
| 2740 | ".backup_up {background: #b0d0ff;}\n" |
| 2741 | ".backup_nolb {background: #90b0e0;}\n" |
| 2742 | ".backup_draining {background: #cc9900;}\n" |
| 2743 | ".backup_no_check {background: #e0e0e0;}\n" |
| 2744 | ".maintain {background: #c07820;}\n" |
| 2745 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 2746 | "\n" |
| 2747 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 2748 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 2749 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 2750 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 2751 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 2752 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 2753 | "\n" |
| 2754 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 2755 | "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" |
| 2756 | "table.tbl td.ac { text-align: center;}\n" |
| 2757 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 2758 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 2759 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 2760 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 2761 | "\n" |
| 2762 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 2763 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 2764 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 2765 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 2766 | "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" |
| 2767 | "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" |
| 2768 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
| 2769 | "div.tips {\n" |
| 2770 | " display:block;\n" |
| 2771 | " visibility:hidden;\n" |
| 2772 | " z-index:2147483647;\n" |
| 2773 | " position:absolute;\n" |
| 2774 | " padding:2px 4px 3px;\n" |
| 2775 | " background:#f0f060; color:#000000;\n" |
| 2776 | " border:1px solid #7040c0;\n" |
| 2777 | " white-space:nowrap;\n" |
| 2778 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 2779 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 2780 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 2781 | "}\n" |
| 2782 | "u:hover div.tips {visibility:visible;}\n" |
| 2783 | "-->\n" |
| 2784 | "</style></head>\n", |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2785 | (appctx->ctx.stats.flags & STAT_SHNODE) ? " on " : "", |
Willy Tarreau | 027d206 | 2020-01-23 11:47:13 +0100 | [diff] [blame] | 2786 | (appctx->ctx.stats.flags & STAT_SHNODE) ? (uri && uri->node ? uri->node : global.node) : "" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2787 | ); |
| 2788 | } |
| 2789 | |
| 2790 | /* Dumps the HTML stats information block to the trash for and uses the state from |
| 2791 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
| 2792 | * for clearing the trash if needed. |
| 2793 | */ |
| 2794 | static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri) |
| 2795 | { |
| 2796 | struct appctx *appctx = __objt_appctx(si->end); |
| 2797 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2798 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2799 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 2800 | unsigned long long bps = (unsigned long long)read_freq_ctr(&global.out_32bps) * 32; |
| 2801 | |
| 2802 | /* Turn the bytes per second to bits per second and take care of the |
| 2803 | * usual ethernet overhead in order to help figure how far we are from |
| 2804 | * interface saturation since it's the only case which usually matters. |
| 2805 | * For this we count the total size of an Ethernet frame on the wire |
| 2806 | * including preamble and IFG (1538) for the largest TCP segment it |
| 2807 | * transports (1448 with TCP timestamps). This is not valid for smaller |
| 2808 | * packets (under-estimated), but it gives a reasonably accurate |
| 2809 | * estimation of how far we are from uplink saturation. |
| 2810 | */ |
| 2811 | bps = bps * 8 * 1538 / 1448; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2812 | |
| 2813 | /* WARNING! this has to fit the first packet too. |
| 2814 | * We are around 3.5 kB, add adding entries will |
| 2815 | * become tricky if we want to support 4kB buffers ! |
| 2816 | */ |
| 2817 | chunk_appendf(&trash, |
| 2818 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 2819 | PRODUCT_NAME "%s</a></h1>\n" |
| 2820 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 2821 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 2822 | "<h3>> General process information</h3>\n" |
| 2823 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 2824 | "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2825 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 2826 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 2827 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 2828 | "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] | 2829 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 2830 | "</td><td align=\"center\" nowrap>\n" |
| 2831 | "<table class=\"lgd\"><tr>\n" |
| 2832 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 2833 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
| 2834 | "</tr><tr>\n" |
| 2835 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 2836 | "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 2837 | "</tr><tr>\n" |
| 2838 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 2839 | "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 2840 | "</tr><tr>\n" |
| 2841 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 2842 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
| 2843 | "</tr><tr>\n" |
| 2844 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
| 2845 | "</tr><tr>\n" |
| 2846 | "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance </td>" |
| 2847 | "</tr></table>\n" |
| 2848 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
| 2849 | "</td>" |
| 2850 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 2851 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 2852 | "", |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 2853 | (appctx->ctx.stats.flags & STAT_HIDEVER) ? "" : (stats_version_string), |
| 2854 | pid, (appctx->ctx.stats.flags & STAT_SHNODE) ? " on " : "", |
| 2855 | (appctx->ctx.stats.flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 2856 | (appctx->ctx.stats.flags & STAT_SHDESC) ? ": " : "", |
| 2857 | (appctx->ctx.stats.flags & STAT_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 2858 | pid, relative_pid, global.nbproc, global.nbthread, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2859 | up / 86400, (up % 86400) / 3600, |
| 2860 | (up % 3600) / 60, (up % 60), |
| 2861 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 2862 | global.rlimit_memmax ? " MB" : "", |
| 2863 | global.rlimit_nofile, |
| 2864 | global.maxsock, global.maxconn, global.maxpipes, |
| 2865 | 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] | 2866 | bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0), |
| 2867 | bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k', |
Willy Tarreau | 81036f2 | 2019-05-20 19:24:50 +0200 | [diff] [blame] | 2868 | tasks_run_queue_cur, nb_tasks_cur, ti->idle_pct |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2869 | ); |
| 2870 | |
| 2871 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2872 | memcpy(scope_txt, scope_ptr, appctx->ctx.stats.scope_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2873 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
| 2874 | |
| 2875 | chunk_appendf(&trash, |
| 2876 | "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
| 2877 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
| 2878 | STAT_SCOPE_TXT_MAXLEN); |
| 2879 | |
| 2880 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 2881 | scope_txt[0] = 0; |
| 2882 | if (appctx->ctx.stats.scope_len) { |
| 2883 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2884 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2885 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
| 2886 | } |
| 2887 | |
| 2888 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
| 2889 | chunk_appendf(&trash, |
| 2890 | "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n", |
| 2891 | uri->uri_prefix, |
| 2892 | "", |
| 2893 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2894 | scope_txt); |
| 2895 | else |
| 2896 | chunk_appendf(&trash, |
| 2897 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 2898 | uri->uri_prefix, |
| 2899 | ";up", |
| 2900 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2901 | scope_txt); |
| 2902 | |
| 2903 | if (uri->refresh > 0) { |
| 2904 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
| 2905 | chunk_appendf(&trash, |
| 2906 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
| 2907 | uri->uri_prefix, |
| 2908 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2909 | "", |
| 2910 | scope_txt); |
| 2911 | else |
| 2912 | chunk_appendf(&trash, |
| 2913 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
| 2914 | uri->uri_prefix, |
| 2915 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2916 | ";norefresh", |
| 2917 | scope_txt); |
| 2918 | } |
| 2919 | |
| 2920 | chunk_appendf(&trash, |
| 2921 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
| 2922 | uri->uri_prefix, |
| 2923 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2924 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2925 | scope_txt); |
| 2926 | |
| 2927 | chunk_appendf(&trash, |
| 2928 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
| 2929 | uri->uri_prefix, |
| 2930 | (uri->refresh > 0) ? ";norefresh" : "", |
| 2931 | scope_txt); |
| 2932 | |
| 2933 | chunk_appendf(&trash, |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 2934 | "<li><a href=\"%s;json%s%s\">JSON export</a> (<a href=\"%s;json-schema\">schema</a>)<br>\n", |
| 2935 | uri->uri_prefix, |
| 2936 | (uri->refresh > 0) ? ";norefresh" : "", |
| 2937 | scope_txt, uri->uri_prefix); |
| 2938 | |
| 2939 | chunk_appendf(&trash, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2940 | "</ul></td>" |
| 2941 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 2942 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 2943 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 2944 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 2945 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 2946 | "</ul>" |
| 2947 | "</td>" |
| 2948 | "</tr></table>\n" |
| 2949 | "" |
| 2950 | ); |
| 2951 | |
| 2952 | if (appctx->ctx.stats.st_code) { |
| 2953 | switch (appctx->ctx.stats.st_code) { |
| 2954 | case STAT_STATUS_DONE: |
| 2955 | chunk_appendf(&trash, |
| 2956 | "<p><div class=active_up>" |
| 2957 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2958 | "Action processed successfully." |
| 2959 | "</div>\n", uri->uri_prefix, |
| 2960 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2961 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2962 | scope_txt); |
| 2963 | break; |
| 2964 | case STAT_STATUS_NONE: |
| 2965 | chunk_appendf(&trash, |
| 2966 | "<p><div class=active_going_down>" |
| 2967 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2968 | "Nothing has changed." |
| 2969 | "</div>\n", uri->uri_prefix, |
| 2970 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2971 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2972 | scope_txt); |
| 2973 | break; |
| 2974 | case STAT_STATUS_PART: |
| 2975 | chunk_appendf(&trash, |
| 2976 | "<p><div class=active_going_down>" |
| 2977 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2978 | "Action partially processed.<br>" |
| 2979 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
| 2980 | "</div>\n", uri->uri_prefix, |
| 2981 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2982 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2983 | scope_txt); |
| 2984 | break; |
| 2985 | case STAT_STATUS_ERRP: |
| 2986 | chunk_appendf(&trash, |
| 2987 | "<p><div class=active_down>" |
| 2988 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2989 | "Action not processed because of invalid parameters." |
| 2990 | "<ul>" |
| 2991 | "<li>The action is maybe unknown.</li>" |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2992 | "<li>Invalid key parameter (empty or too long).</li>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2993 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 2994 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 2995 | "</ul>" |
| 2996 | "</div>\n", uri->uri_prefix, |
| 2997 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2998 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2999 | scope_txt); |
| 3000 | break; |
| 3001 | case STAT_STATUS_EXCD: |
| 3002 | chunk_appendf(&trash, |
| 3003 | "<p><div class=active_down>" |
| 3004 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3005 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3006 | "You should retry with less servers at a time.</b>" |
| 3007 | "</div>\n", uri->uri_prefix, |
| 3008 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3009 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3010 | scope_txt); |
| 3011 | break; |
| 3012 | case STAT_STATUS_DENY: |
| 3013 | chunk_appendf(&trash, |
| 3014 | "<p><div class=active_down>" |
| 3015 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3016 | "<b>Action denied.</b>" |
| 3017 | "</div>\n", uri->uri_prefix, |
| 3018 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3019 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3020 | scope_txt); |
| 3021 | break; |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3022 | case STAT_STATUS_IVAL: |
| 3023 | chunk_appendf(&trash, |
| 3024 | "<p><div class=active_down>" |
| 3025 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3026 | "<b>Invalid requests (unsupported method or chunked encoded request).</b>" |
| 3027 | "</div>\n", uri->uri_prefix, |
| 3028 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3029 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3030 | scope_txt); |
| 3031 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3032 | default: |
| 3033 | chunk_appendf(&trash, |
| 3034 | "<p><div class=active_no_check>" |
| 3035 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3036 | "Unexpected result." |
| 3037 | "</div>\n", uri->uri_prefix, |
| 3038 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3039 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3040 | scope_txt); |
| 3041 | } |
| 3042 | chunk_appendf(&trash, "<p>\n"); |
| 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 3047 | * for clearing the trash if needed. |
| 3048 | */ |
| 3049 | static void stats_dump_html_end() |
| 3050 | { |
| 3051 | chunk_appendf(&trash, "</body></html>\n"); |
| 3052 | } |
| 3053 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3054 | /* Dumps the stats JSON header to the trash buffer which. The caller is responsible |
| 3055 | * for clearing it if needed. |
| 3056 | */ |
| 3057 | static void stats_dump_json_header() |
| 3058 | { |
| 3059 | chunk_strcat(&trash, "["); |
| 3060 | } |
| 3061 | |
| 3062 | |
| 3063 | /* Dumps the JSON stats trailer block to the trash. The caller is responsible |
| 3064 | * for clearing the trash if needed. |
| 3065 | */ |
| 3066 | static void stats_dump_json_end() |
| 3067 | { |
| 3068 | chunk_strcat(&trash, "]"); |
| 3069 | } |
| 3070 | |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3071 | /* Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as |
| 3072 | * a pointer to the current server/listener. |
| 3073 | */ |
| 3074 | static int stats_dump_proxies(struct stream_interface *si, |
| 3075 | struct htx *htx, |
| 3076 | struct uri_auth *uri) |
| 3077 | { |
| 3078 | struct appctx *appctx = __objt_appctx(si->end); |
| 3079 | struct channel *rep = si_ic(si); |
| 3080 | struct proxy *px; |
| 3081 | |
| 3082 | /* dump proxies */ |
| 3083 | while (appctx->ctx.stats.obj1) { |
| 3084 | if (htx) { |
| 3085 | if (htx_almost_full(htx)) |
| 3086 | goto full; |
| 3087 | } |
| 3088 | else { |
| 3089 | if (buffer_almost_full(&rep->buf)) |
| 3090 | goto full; |
| 3091 | } |
| 3092 | |
| 3093 | px = appctx->ctx.stats.obj1; |
| 3094 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 3095 | if (!px->disabled && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE))) { |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3096 | if (stats_dump_proxy_to_buffer(si, htx, px, uri) == 0) |
| 3097 | return 0; |
| 3098 | } |
| 3099 | |
| 3100 | appctx->ctx.stats.obj1 = px->next; |
| 3101 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3102 | } |
| 3103 | |
| 3104 | return 1; |
| 3105 | |
| 3106 | full: |
| 3107 | si_rx_room_blk(si); |
| 3108 | return 0; |
| 3109 | } |
| 3110 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3111 | /* This function dumps statistics onto the stream interface's read buffer in |
| 3112 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
| 3113 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3114 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3115 | * and the stream must be closed, or -1 in case of any error. This function is |
| 3116 | * used by both the CLI and the HTTP handlers. |
| 3117 | */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3118 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct htx *htx, |
| 3119 | struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3120 | { |
| 3121 | struct appctx *appctx = __objt_appctx(si->end); |
| 3122 | struct channel *rep = si_ic(si); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3123 | enum stats_domain domain = appctx->ctx.stats.domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3124 | |
| 3125 | chunk_reset(&trash); |
| 3126 | |
| 3127 | switch (appctx->st2) { |
| 3128 | case STAT_ST_INIT: |
| 3129 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
| 3130 | /* fall through */ |
| 3131 | |
| 3132 | case STAT_ST_HEAD: |
| 3133 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 3134 | stats_dump_html_head(appctx, uri); |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3135 | else if (appctx->ctx.stats.flags & STAT_JSON_SCHM) |
| 3136 | stats_dump_json_schema(&trash); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3137 | else if (appctx->ctx.stats.flags & STAT_FMT_JSON) |
Willy Tarreau | 9d7fb63 | 2017-04-11 07:53:04 +0200 | [diff] [blame] | 3138 | stats_dump_json_header(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3139 | else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED)) |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 3140 | stats_dump_csv_header(appctx->ctx.stats.domain); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3141 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3142 | if (!stats_putchk(rep, htx, &trash)) |
| 3143 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3144 | |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3145 | if (appctx->ctx.stats.flags & STAT_JSON_SCHM) { |
| 3146 | appctx->st2 = STAT_ST_FIN; |
| 3147 | return 1; |
| 3148 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3149 | appctx->st2 = STAT_ST_INFO; |
| 3150 | /* fall through */ |
| 3151 | |
| 3152 | case STAT_ST_INFO: |
| 3153 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
| 3154 | stats_dump_html_info(si, uri); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3155 | if (!stats_putchk(rep, htx, &trash)) |
| 3156 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3157 | } |
| 3158 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3159 | if (domain == STATS_DOMAIN_PROXY) |
| 3160 | appctx->ctx.stats.obj1 = proxies_list; |
| 3161 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3162 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 3163 | appctx->st2 = STAT_ST_LIST; |
| 3164 | /* fall through */ |
| 3165 | |
| 3166 | case STAT_ST_LIST: |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3167 | switch (domain) { |
| 3168 | case STATS_DOMAIN_DNS: |
| 3169 | if (!stats_dump_dns(si, stat_l[domain], |
| 3170 | stat_count[domain], |
| 3171 | &stats_module_list[domain])) { |
| 3172 | return 0; |
| 3173 | } |
| 3174 | break; |
| 3175 | |
| 3176 | case STATS_DOMAIN_PROXY: |
| 3177 | default: |
| 3178 | /* dump proxies */ |
| 3179 | if (!stats_dump_proxies(si, htx, uri)) |
| 3180 | return 0; |
| 3181 | break; |
| 3182 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3183 | |
| 3184 | appctx->st2 = STAT_ST_END; |
| 3185 | /* fall through */ |
| 3186 | |
| 3187 | case STAT_ST_END: |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3188 | if (appctx->ctx.stats.flags & (STAT_FMT_HTML|STAT_FMT_JSON)) { |
| 3189 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
| 3190 | stats_dump_html_end(); |
| 3191 | else |
| 3192 | stats_dump_json_end(); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3193 | if (!stats_putchk(rep, htx, &trash)) |
| 3194 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3195 | } |
| 3196 | |
| 3197 | appctx->st2 = STAT_ST_FIN; |
| 3198 | /* fall through */ |
| 3199 | |
| 3200 | case STAT_ST_FIN: |
| 3201 | return 1; |
| 3202 | |
| 3203 | default: |
| 3204 | /* unknown state ! */ |
| 3205 | appctx->st2 = STAT_ST_FIN; |
| 3206 | return -1; |
| 3207 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3208 | |
| 3209 | full: |
| 3210 | si_rx_room_blk(si); |
| 3211 | return 0; |
| 3212 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | /* We reached the stats page through a POST request. The appctx is |
| 3216 | * expected to have already been allocated by the caller. |
| 3217 | * Parse the posted data and enable/disable servers if necessary. |
| 3218 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3219 | */ |
| 3220 | static int stats_process_http_post(struct stream_interface *si) |
| 3221 | { |
| 3222 | struct stream *s = si_strm(si); |
| 3223 | struct appctx *appctx = objt_appctx(si->end); |
| 3224 | |
| 3225 | struct proxy *px = NULL; |
| 3226 | struct server *sv = NULL; |
| 3227 | |
| 3228 | char key[LINESIZE]; |
| 3229 | int action = ST_ADM_ACTION_NONE; |
| 3230 | int reprocess = 0; |
| 3231 | |
| 3232 | int total_servers = 0; |
| 3233 | int altered_servers = 0; |
| 3234 | |
| 3235 | char *first_param, *cur_param, *next_param, *end_params; |
| 3236 | char *st_cur_param = NULL; |
| 3237 | char *st_next_param = NULL; |
| 3238 | |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3239 | struct buffer *temp = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3240 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3241 | struct htx *htx = htxbuf(&s->req.buf); |
| 3242 | struct htx_blk *blk; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3243 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3244 | /* we need more data */ |
| 3245 | if (s->txn->req.msg_state < HTTP_MSG_DONE) { |
| 3246 | /* check if we can receive more */ |
| 3247 | if (htx_free_data_space(htx) <= global.tune.maxrewrite) { |
| 3248 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
| 3249 | goto out; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3250 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3251 | goto wait; |
| 3252 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3253 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3254 | /* The request was fully received. Copy data */ |
| 3255 | blk = htx_get_head_blk(htx); |
| 3256 | while (blk) { |
| 3257 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3258 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3259 | if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
| 3260 | break; |
| 3261 | if (type == HTX_BLK_DATA) { |
| 3262 | struct ist v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3263 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3264 | if (!chunk_memcat(temp, v.ptr, v.len)) { |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 3265 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
| 3266 | goto out; |
| 3267 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3268 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3269 | blk = htx_get_next_blk(htx, blk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3270 | } |
| 3271 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 3272 | first_param = temp->area; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3273 | end_params = temp->area + temp->data; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3274 | cur_param = next_param = end_params; |
| 3275 | *end_params = '\0'; |
| 3276 | |
| 3277 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
| 3278 | |
| 3279 | /* |
| 3280 | * Parse the parameters in reverse order to only store the last value. |
| 3281 | * From the html form, the backend and the action are at the end. |
| 3282 | */ |
| 3283 | while (cur_param > first_param) { |
| 3284 | char *value; |
| 3285 | int poffset, plen; |
| 3286 | |
| 3287 | cur_param--; |
| 3288 | |
| 3289 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 3290 | reprocess_servers: |
| 3291 | /* Parse the key */ |
| 3292 | poffset = (cur_param != first_param ? 1 : 0); |
| 3293 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 3294 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 3295 | strncpy(key, cur_param + poffset, plen); |
| 3296 | key[plen - 1] = '\0'; |
| 3297 | } else { |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 3298 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3299 | goto out; |
| 3300 | } |
| 3301 | |
| 3302 | /* Parse the value */ |
| 3303 | value = key; |
| 3304 | while (*value != '\0' && *value != '=') { |
| 3305 | value++; |
| 3306 | } |
| 3307 | if (*value == '=') { |
| 3308 | /* Ok, a value is found, we can mark the end of the key */ |
| 3309 | *value++ = '\0'; |
| 3310 | } |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 3311 | if (url_decode(key, 1) < 0 || url_decode(value, 1) < 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3312 | break; |
| 3313 | |
| 3314 | /* Now we can check the key to see what to do */ |
| 3315 | if (!px && (strcmp(key, "b") == 0)) { |
| 3316 | if ((px = proxy_be_by_name(value)) == NULL) { |
| 3317 | /* the backend name is unknown or ambiguous (duplicate names) */ |
| 3318 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
| 3319 | goto out; |
| 3320 | } |
| 3321 | } |
| 3322 | else if (!action && (strcmp(key, "action") == 0)) { |
| 3323 | if (strcmp(value, "ready") == 0) { |
| 3324 | action = ST_ADM_ACTION_READY; |
| 3325 | } |
| 3326 | else if (strcmp(value, "drain") == 0) { |
| 3327 | action = ST_ADM_ACTION_DRAIN; |
| 3328 | } |
| 3329 | else if (strcmp(value, "maint") == 0) { |
| 3330 | action = ST_ADM_ACTION_MAINT; |
| 3331 | } |
| 3332 | else if (strcmp(value, "shutdown") == 0) { |
| 3333 | action = ST_ADM_ACTION_SHUTDOWN; |
| 3334 | } |
| 3335 | else if (strcmp(value, "dhlth") == 0) { |
| 3336 | action = ST_ADM_ACTION_DHLTH; |
| 3337 | } |
| 3338 | else if (strcmp(value, "ehlth") == 0) { |
| 3339 | action = ST_ADM_ACTION_EHLTH; |
| 3340 | } |
| 3341 | else if (strcmp(value, "hrunn") == 0) { |
| 3342 | action = ST_ADM_ACTION_HRUNN; |
| 3343 | } |
| 3344 | else if (strcmp(value, "hnolb") == 0) { |
| 3345 | action = ST_ADM_ACTION_HNOLB; |
| 3346 | } |
| 3347 | else if (strcmp(value, "hdown") == 0) { |
| 3348 | action = ST_ADM_ACTION_HDOWN; |
| 3349 | } |
| 3350 | else if (strcmp(value, "dagent") == 0) { |
| 3351 | action = ST_ADM_ACTION_DAGENT; |
| 3352 | } |
| 3353 | else if (strcmp(value, "eagent") == 0) { |
| 3354 | action = ST_ADM_ACTION_EAGENT; |
| 3355 | } |
| 3356 | else if (strcmp(value, "arunn") == 0) { |
| 3357 | action = ST_ADM_ACTION_ARUNN; |
| 3358 | } |
| 3359 | else if (strcmp(value, "adown") == 0) { |
| 3360 | action = ST_ADM_ACTION_ADOWN; |
| 3361 | } |
| 3362 | /* else these are the old supported methods */ |
| 3363 | else if (strcmp(value, "disable") == 0) { |
| 3364 | action = ST_ADM_ACTION_DISABLE; |
| 3365 | } |
| 3366 | else if (strcmp(value, "enable") == 0) { |
| 3367 | action = ST_ADM_ACTION_ENABLE; |
| 3368 | } |
| 3369 | else if (strcmp(value, "stop") == 0) { |
| 3370 | action = ST_ADM_ACTION_STOP; |
| 3371 | } |
| 3372 | else if (strcmp(value, "start") == 0) { |
| 3373 | action = ST_ADM_ACTION_START; |
| 3374 | } |
| 3375 | else { |
| 3376 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
| 3377 | goto out; |
| 3378 | } |
| 3379 | } |
| 3380 | else if (strcmp(key, "s") == 0) { |
| 3381 | if (!(px && action)) { |
| 3382 | /* |
| 3383 | * Indicates that we'll need to reprocess the parameters |
| 3384 | * as soon as backend and action are known |
| 3385 | */ |
| 3386 | if (!reprocess) { |
| 3387 | st_cur_param = cur_param; |
| 3388 | st_next_param = next_param; |
| 3389 | } |
| 3390 | reprocess = 1; |
| 3391 | } |
| 3392 | else if ((sv = findserver(px, value)) != NULL) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3393 | HA_SPIN_LOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3394 | switch (action) { |
| 3395 | case ST_ADM_ACTION_DISABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 3396 | if (!(sv->cur_admin & SRV_ADMF_FMAINT)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3397 | altered_servers++; |
| 3398 | total_servers++; |
| 3399 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page"); |
| 3400 | } |
| 3401 | break; |
| 3402 | case ST_ADM_ACTION_ENABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 3403 | if (sv->cur_admin & SRV_ADMF_FMAINT) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3404 | altered_servers++; |
| 3405 | total_servers++; |
| 3406 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
| 3407 | } |
| 3408 | break; |
| 3409 | case ST_ADM_ACTION_STOP: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 3410 | if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3411 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page"); |
| 3412 | altered_servers++; |
| 3413 | total_servers++; |
| 3414 | } |
| 3415 | break; |
| 3416 | case ST_ADM_ACTION_START: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 3417 | if (sv->cur_admin & SRV_ADMF_FDRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3418 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 3419 | altered_servers++; |
| 3420 | total_servers++; |
| 3421 | } |
| 3422 | break; |
| 3423 | case ST_ADM_ACTION_DHLTH: |
| 3424 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 3425 | sv->check.state &= ~CHK_ST_ENABLED; |
| 3426 | altered_servers++; |
| 3427 | total_servers++; |
| 3428 | } |
| 3429 | break; |
| 3430 | case ST_ADM_ACTION_EHLTH: |
| 3431 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 3432 | sv->check.state |= CHK_ST_ENABLED; |
| 3433 | altered_servers++; |
| 3434 | total_servers++; |
| 3435 | } |
| 3436 | break; |
| 3437 | case ST_ADM_ACTION_HRUNN: |
| 3438 | if (!(sv->track)) { |
| 3439 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3440 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3441 | altered_servers++; |
| 3442 | total_servers++; |
| 3443 | } |
| 3444 | break; |
| 3445 | case ST_ADM_ACTION_HNOLB: |
| 3446 | if (!(sv->track)) { |
| 3447 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3448 | srv_set_stopping(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3449 | altered_servers++; |
| 3450 | total_servers++; |
| 3451 | } |
| 3452 | break; |
| 3453 | case ST_ADM_ACTION_HDOWN: |
| 3454 | if (!(sv->track)) { |
| 3455 | sv->check.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3456 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3457 | altered_servers++; |
| 3458 | total_servers++; |
| 3459 | } |
| 3460 | break; |
| 3461 | case ST_ADM_ACTION_DAGENT: |
| 3462 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 3463 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 3464 | altered_servers++; |
| 3465 | total_servers++; |
| 3466 | } |
| 3467 | break; |
| 3468 | case ST_ADM_ACTION_EAGENT: |
| 3469 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 3470 | sv->agent.state |= CHK_ST_ENABLED; |
| 3471 | altered_servers++; |
| 3472 | total_servers++; |
| 3473 | } |
| 3474 | break; |
| 3475 | case ST_ADM_ACTION_ARUNN: |
| 3476 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 3477 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3478 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3479 | altered_servers++; |
| 3480 | total_servers++; |
| 3481 | } |
| 3482 | break; |
| 3483 | case ST_ADM_ACTION_ADOWN: |
| 3484 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 3485 | sv->agent.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3486 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3487 | altered_servers++; |
| 3488 | total_servers++; |
| 3489 | } |
| 3490 | break; |
| 3491 | case ST_ADM_ACTION_READY: |
| 3492 | srv_adm_set_ready(sv); |
| 3493 | altered_servers++; |
| 3494 | total_servers++; |
| 3495 | break; |
| 3496 | case ST_ADM_ACTION_DRAIN: |
| 3497 | srv_adm_set_drain(sv); |
| 3498 | altered_servers++; |
| 3499 | total_servers++; |
| 3500 | break; |
| 3501 | case ST_ADM_ACTION_MAINT: |
| 3502 | srv_adm_set_maint(sv); |
| 3503 | altered_servers++; |
| 3504 | total_servers++; |
| 3505 | break; |
| 3506 | case ST_ADM_ACTION_SHUTDOWN: |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 3507 | if (!px->disabled) { |
Willy Tarreau | af7ea81 | 2019-11-14 16:42:04 +0100 | [diff] [blame] | 3508 | srv_shutdown_streams(sv, SF_ERR_KILLED); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3509 | altered_servers++; |
| 3510 | total_servers++; |
| 3511 | } |
| 3512 | break; |
| 3513 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3514 | HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3515 | } else { |
| 3516 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 3517 | total_servers++; |
| 3518 | } |
| 3519 | } |
| 3520 | if (reprocess && px && action) { |
| 3521 | /* Now, we know the backend and the action chosen by the user. |
| 3522 | * We can safely restart from the first server parameter |
| 3523 | * to reprocess them |
| 3524 | */ |
| 3525 | cur_param = st_cur_param; |
| 3526 | next_param = st_next_param; |
| 3527 | reprocess = 0; |
| 3528 | goto reprocess_servers; |
| 3529 | } |
| 3530 | |
| 3531 | next_param = cur_param; |
| 3532 | } |
| 3533 | } |
| 3534 | |
| 3535 | if (total_servers == 0) { |
| 3536 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
| 3537 | } |
| 3538 | else if (altered_servers == 0) { |
| 3539 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
| 3540 | } |
| 3541 | else if (altered_servers == total_servers) { |
| 3542 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
| 3543 | } |
| 3544 | else { |
| 3545 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
| 3546 | } |
| 3547 | out: |
| 3548 | return 1; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 3549 | wait: |
| 3550 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
| 3551 | return 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3555 | static int stats_send_http_headers(struct stream_interface *si, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3556 | { |
| 3557 | struct stream *s = si_strm(si); |
| 3558 | struct uri_auth *uri = s->be->uri_auth; |
| 3559 | struct appctx *appctx = __objt_appctx(si->end); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3560 | struct htx_sl *sl; |
| 3561 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3562 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3563 | 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); |
| 3564 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 3565 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3566 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3567 | sl->info.res.status = 200; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3568 | |
Christopher Faulet | b829f4c | 2019-03-29 16:13:55 +0100 | [diff] [blame] | 3569 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache"))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3570 | goto full; |
| 3571 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
| 3572 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/html"))) |
| 3573 | goto full; |
| 3574 | } |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3575 | else if (appctx->ctx.stats.flags & (STAT_FMT_JSON|STAT_JSON_SCHM)) { |
| 3576 | if (!htx_add_header(htx, ist("Content-Type"), ist("application/json"))) |
| 3577 | goto full; |
| 3578 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3579 | else { |
| 3580 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain"))) |
| 3581 | goto full; |
| 3582 | } |
| 3583 | |
| 3584 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) { |
| 3585 | const char *refresh = U2A(uri->refresh); |
| 3586 | if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh)))) |
| 3587 | goto full; |
| 3588 | } |
| 3589 | |
| 3590 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 3591 | if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked"))) |
| 3592 | goto full; |
| 3593 | } |
| 3594 | |
| 3595 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 3596 | goto full; |
| 3597 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 3598 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3599 | return 1; |
| 3600 | |
| 3601 | full: |
| 3602 | htx_reset(htx); |
| 3603 | si_rx_room_blk(si); |
| 3604 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3605 | } |
| 3606 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3607 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3608 | static int stats_send_http_redirect(struct stream_interface *si, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3609 | { |
| 3610 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3611 | struct stream *s = si_strm(si); |
| 3612 | struct uri_auth *uri = s->be->uri_auth; |
| 3613 | struct appctx *appctx = __objt_appctx(si->end); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3614 | struct htx_sl *sl; |
| 3615 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3616 | |
| 3617 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3618 | scope_txt[0] = 0; |
| 3619 | if (appctx->ctx.stats.scope_len) { |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3620 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
| 3621 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3622 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3623 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3624 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
| 3625 | } |
| 3626 | |
| 3627 | /* We don't want to land on the posted stats page because a refresh will |
| 3628 | * repost the data. We don't want this to happen on accident so we redirect |
| 3629 | * the browse to the stats page with a GET. |
| 3630 | */ |
| 3631 | chunk_printf(&trash, "%s;st=%s%s%s%s", |
| 3632 | uri->uri_prefix, |
| 3633 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 3634 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 3635 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 3636 | stat_status_codes[appctx->ctx.stats.st_code] : |
| 3637 | stat_status_codes[STAT_STATUS_UNKN], |
| 3638 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3639 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3640 | scope_txt); |
| 3641 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3642 | flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK); |
| 3643 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other")); |
| 3644 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3645 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3646 | sl->info.res.status = 303; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3647 | |
| 3648 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3649 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) || |
| 3650 | !htx_add_header(htx, ist("Content-Length"), ist("0")) || |
| 3651 | !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data))) |
| 3652 | goto full; |
| 3653 | |
| 3654 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 3655 | goto full; |
| 3656 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 3657 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3658 | return 1; |
| 3659 | |
| 3660 | full: |
| 3661 | htx_reset(htx); |
| 3662 | si_rx_room_blk(si); |
| 3663 | return 0; |
| 3664 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3665 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3666 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3667 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3668 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 3669 | * appctx->st0 contains the operation in progress (dump, done). The handler |
| 3670 | * automatically unregisters itself once transfer is complete. |
| 3671 | */ |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3672 | static void http_stats_io_handler(struct appctx *appctx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3673 | { |
| 3674 | struct stream_interface *si = appctx->owner; |
| 3675 | struct stream *s = si_strm(si); |
| 3676 | struct channel *req = si_oc(si); |
| 3677 | struct channel *res = si_ic(si); |
| 3678 | struct htx *req_htx, *res_htx; |
| 3679 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 3680 | /* only proxy stats are available via http */ |
| 3681 | appctx->ctx.stats.domain = STATS_DOMAIN_PROXY; |
| 3682 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3683 | res_htx = htx_from_buf(&res->buf); |
| 3684 | |
| 3685 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3686 | goto out; |
| 3687 | |
Ilya Shipitsin | 856aabc | 2020-04-16 23:51:34 +0500 | [diff] [blame] | 3688 | /* Check if the input buffer is available. */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3689 | if (!b_size(&res->buf)) { |
| 3690 | si_rx_room_blk(si); |
| 3691 | goto out; |
| 3692 | } |
| 3693 | |
| 3694 | /* check that the output is not closed */ |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3695 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_SHUTR)) |
| 3696 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3697 | |
| 3698 | /* all states are processed in sequence */ |
| 3699 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3700 | if (stats_send_http_headers(si, res_htx)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3701 | if (s->txn->meth == HTTP_METH_HEAD) |
| 3702 | appctx->st0 = STAT_HTTP_DONE; |
| 3703 | else |
| 3704 | appctx->st0 = STAT_HTTP_DUMP; |
| 3705 | } |
| 3706 | } |
| 3707 | |
| 3708 | if (appctx->st0 == STAT_HTTP_DUMP) { |
| 3709 | if (stats_dump_stat_to_buffer(si, res_htx, s->be->uri_auth)) |
| 3710 | appctx->st0 = STAT_HTTP_DONE; |
| 3711 | } |
| 3712 | |
| 3713 | if (appctx->st0 == STAT_HTTP_POST) { |
| 3714 | if (stats_process_http_post(si)) |
| 3715 | appctx->st0 = STAT_HTTP_LAST; |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3716 | else if (req->flags & CF_SHUTR) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3717 | appctx->st0 = STAT_HTTP_DONE; |
| 3718 | } |
| 3719 | |
| 3720 | if (appctx->st0 == STAT_HTTP_LAST) { |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3721 | if (stats_send_http_redirect(si, res_htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3722 | appctx->st0 = STAT_HTTP_DONE; |
| 3723 | } |
| 3724 | |
| 3725 | if (appctx->st0 == STAT_HTTP_DONE) { |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 3726 | /* Don't add TLR because mux-h1 will take care of it */ |
Christopher Faulet | 810df06 | 2020-07-22 16:20:34 +0200 | [diff] [blame] | 3727 | res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3728 | if (!htx_add_endof(res_htx, HTX_BLK_EOM)) { |
| 3729 | si_rx_room_blk(si); |
| 3730 | goto out; |
| 3731 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3732 | channel_add_input(&s->res, 1); |
| 3733 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3734 | } |
| 3735 | |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3736 | if (appctx->st0 == STAT_HTTP_END) { |
| 3737 | if (!(res->flags & CF_SHUTR)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3738 | res->flags |= CF_READ_NULL; |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3739 | si_shutr(si); |
| 3740 | } |
| 3741 | |
| 3742 | /* eat the whole request */ |
| 3743 | if (co_data(req)) { |
| 3744 | req_htx = htx_from_buf(&req->buf); |
| 3745 | co_htx_skip(req, req_htx, co_data(req)); |
| 3746 | htx_to_buf(req_htx, &req->buf); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3747 | } |
| 3748 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3749 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3750 | out: |
| 3751 | /* we have left the request in the buffer for the case where we |
| 3752 | * process a POST, and this automatically re-enables activity on |
| 3753 | * read. It's better to indicate that we want to stop reading when |
| 3754 | * we're sending, so that we know there's at most one direction |
| 3755 | * deciding to wake the applet up. It saves it from looping when |
| 3756 | * emitting large blocks into small TCP windows. |
| 3757 | */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 3758 | htx_to_buf(res_htx, &res->buf); |
| 3759 | if (!channel_is_empty(res)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3760 | si_stop_get(si); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3761 | } |
| 3762 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3763 | /* 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] | 3764 | static int stats_dump_info_fields(struct buffer *out, |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 3765 | const struct field *info, unsigned int flags) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3766 | { |
| 3767 | int field; |
| 3768 | |
| 3769 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 3770 | if (!field_format(info, field)) |
| 3771 | continue; |
| 3772 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 3773 | if (!chunk_appendf(out, "%s: ", info_fields[field].name)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3774 | return 0; |
| 3775 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 3776 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 3777 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 3778 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3779 | if (!chunk_strcat(out, "\n")) |
| 3780 | return 0; |
| 3781 | } |
| 3782 | return 1; |
| 3783 | } |
| 3784 | |
| 3785 | /* 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] | 3786 | static int stats_dump_typed_info_fields(struct buffer *out, |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 3787 | const struct field *info, unsigned int flags) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3788 | { |
| 3789 | int field; |
| 3790 | |
| 3791 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 3792 | if (!field_format(info, field)) |
| 3793 | continue; |
| 3794 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 3795 | 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] | 3796 | return 0; |
| 3797 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 3798 | return 0; |
| 3799 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 3800 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 3801 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 3802 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3803 | if (!chunk_strcat(out, "\n")) |
| 3804 | return 0; |
| 3805 | } |
| 3806 | return 1; |
| 3807 | } |
| 3808 | |
| 3809 | /* Fill <info> with HAProxy global info. <info> is preallocated |
Ilya Shipitsin | 856aabc | 2020-04-16 23:51:34 +0500 | [diff] [blame] | 3810 | * array of length <len>. The length of the array must be |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3811 | * INF_TOTAL_FIELDS. If this length is less then this value, the |
| 3812 | * function returns 0, otherwise, it returns 1. |
| 3813 | */ |
| 3814 | int stats_fill_info(struct field *info, int len) |
| 3815 | { |
| 3816 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3817 | struct buffer *out = get_trash_chunk(); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3818 | |
| 3819 | #ifdef USE_OPENSSL |
| 3820 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 3821 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 3822 | int ssl_reuse = 0; |
| 3823 | |
| 3824 | if (ssl_key_rate < ssl_sess_rate) { |
| 3825 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 3826 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 3827 | } |
| 3828 | #endif |
| 3829 | |
| 3830 | if (len < INF_TOTAL_FIELDS) |
| 3831 | return 0; |
| 3832 | |
| 3833 | chunk_reset(out); |
| 3834 | memset(info, 0, sizeof(*info) * len); |
| 3835 | |
| 3836 | 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] | 3837 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version); |
| 3838 | 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] | 3839 | |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 3840 | info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3841 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 3842 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 3843 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 3844 | |
| 3845 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 3846 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 3847 | |
| 3848 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 3849 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 3850 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 3851 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 3852 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 3853 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 3854 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 3855 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 3856 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 3857 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 3858 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 3859 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 3860 | #ifdef USE_OPENSSL |
| 3861 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 3862 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 3863 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 3864 | #endif |
| 3865 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 3866 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 3867 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 3868 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 3869 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 3870 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 3871 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 3872 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 3873 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 3874 | |
| 3875 | #ifdef USE_OPENSSL |
| 3876 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3877 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3878 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3879 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3880 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3881 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3882 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3883 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3884 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3885 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3886 | #endif |
| 3887 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3888 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3889 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3890 | #ifdef USE_ZLIB |
| 3891 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3892 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3893 | #endif |
| 3894 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
Christopher Faulet | 34c5cc9 | 2016-12-06 09:15:30 +0100 | [diff] [blame] | 3895 | info[INF_RUN_QUEUE] = mkf_u32(0, tasks_run_queue_cur); |
Willy Tarreau | 81036f2 | 2019-05-20 19:24:50 +0200 | [diff] [blame] | 3896 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, ti->idle_pct); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3897 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3898 | if (global.desc) |
| 3899 | 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] | 3900 | info[INF_STOPPING] = mkf_u32(0, stopping); |
| 3901 | info[INF_JOBS] = mkf_u32(0, jobs); |
William Lallemand | a719926 | 2018-11-16 16:57:20 +0100 | [diff] [blame] | 3902 | info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs); |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 3903 | info[INF_LISTENERS] = mkf_u32(0, listeners); |
Willy Tarreau | 199ad24 | 2018-11-05 16:31:22 +0100 | [diff] [blame] | 3904 | info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers); |
Willy Tarreau | 2d372c2 | 2018-11-05 17:12:27 +0100 | [diff] [blame] | 3905 | info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers); |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 3906 | info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs); |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 3907 | info[INF_BUSY_POLLING] = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING)); |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 3908 | info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, dns_failed_resolutions); |
Willy Tarreau | 7cf0e45 | 2019-05-23 11:39:14 +0200 | [diff] [blame] | 3909 | info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, global.out_bytes); |
Christopher Faulet | aaa7085 | 2020-07-10 13:56:30 +0200 | [diff] [blame] | 3910 | info[INF_TOTAL_SPLICED_BYTES_OUT] = mkf_u64(0, global.spliced_out_bytes); |
Willy Tarreau | 7cf0e45 | 2019-05-23 11:39:14 +0200 | [diff] [blame] | 3911 | info[INF_BYTES_OUT_RATE] = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32); |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 3912 | info[INF_DEBUG_COMMANDS_ISSUED] = mkf_u32(0, debug_commands_issued); |
Emeric Brun | 45c457a | 2020-07-09 23:23:34 +0200 | [diff] [blame] | 3913 | info[INF_CUM_LOG_MSGS] = mkf_u32(FN_COUNTER, cum_log_messages); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3914 | |
| 3915 | return 1; |
| 3916 | } |
| 3917 | |
| 3918 | /* This function dumps information onto the stream interface's read buffer. |
| 3919 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3920 | * No state is used. |
| 3921 | */ |
| 3922 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
| 3923 | { |
| 3924 | struct appctx *appctx = __objt_appctx(si->end); |
| 3925 | |
| 3926 | if (!stats_fill_info(info, INF_TOTAL_FIELDS)) |
| 3927 | return 0; |
| 3928 | |
| 3929 | chunk_reset(&trash); |
| 3930 | |
| 3931 | if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 3932 | stats_dump_typed_info_fields(&trash, info, appctx->ctx.stats.flags); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3933 | else if (appctx->ctx.stats.flags & STAT_FMT_JSON) |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 3934 | stats_dump_json_info_fields(&trash, info, appctx->ctx.stats.flags); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3935 | else |
Willy Tarreau | 43241ff | 2019-10-09 11:27:51 +0200 | [diff] [blame] | 3936 | stats_dump_info_fields(&trash, info, appctx->ctx.stats.flags); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3937 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3938 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3939 | si_rx_room_blk(si); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3940 | return 0; |
| 3941 | } |
| 3942 | |
| 3943 | return 1; |
| 3944 | } |
| 3945 | |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3946 | /* This function dumps the schema onto the stream interface's read buffer. |
| 3947 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3948 | * No state is used. |
| 3949 | * |
| 3950 | * Integer values bouned to the range [-(2**53)+1, (2**53)-1] as |
| 3951 | * per the recommendation for interoperable integers in section 6 of RFC 7159. |
| 3952 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3953 | static void stats_dump_json_schema(struct buffer *out) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3954 | { |
| 3955 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 3956 | int old_len = out->data; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3957 | |
| 3958 | chunk_strcat(out, |
| 3959 | "{" |
| 3960 | "\"$schema\":\"http://json-schema.org/draft-04/schema#\"," |
| 3961 | "\"oneOf\":[" |
| 3962 | "{" |
| 3963 | "\"title\":\"Info\"," |
| 3964 | "\"type\":\"array\"," |
| 3965 | "\"items\":{" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 3966 | "\"title\":\"InfoItem\"," |
| 3967 | "\"type\":\"object\"," |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3968 | "\"properties\":{" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3969 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 3970 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 3971 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 3972 | "\"value\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 3973 | "}," |
| 3974 | "\"required\":[\"field\",\"processNum\",\"tags\"," |
| 3975 | "\"value\"]" |
| 3976 | "}" |
| 3977 | "}," |
| 3978 | "{" |
| 3979 | "\"title\":\"Stat\"," |
| 3980 | "\"type\":\"array\"," |
| 3981 | "\"items\":{" |
| 3982 | "\"title\":\"InfoItem\"," |
| 3983 | "\"type\":\"object\"," |
| 3984 | "\"properties\":{" |
| 3985 | "\"objType\":{" |
| 3986 | "\"enum\":[\"Frontend\",\"Backend\",\"Listener\"," |
| 3987 | "\"Server\",\"Unknown\"]" |
| 3988 | "}," |
| 3989 | "\"proxyId\":{" |
| 3990 | "\"type\":\"integer\"," |
| 3991 | "\"minimum\":0" |
| 3992 | "}," |
| 3993 | "\"id\":{" |
| 3994 | "\"type\":\"integer\"," |
| 3995 | "\"minimum\":0" |
| 3996 | "}," |
| 3997 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 3998 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 3999 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 4000 | "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 4001 | "}," |
| 4002 | "\"required\":[\"objType\",\"proxyId\",\"id\"," |
| 4003 | "\"field\",\"processNum\",\"tags\"," |
| 4004 | "\"value\"]" |
| 4005 | "}" |
| 4006 | "}," |
| 4007 | "{" |
| 4008 | "\"title\":\"Error\"," |
| 4009 | "\"type\":\"object\"," |
| 4010 | "\"properties\":{" |
| 4011 | "\"errorStr\":{" |
| 4012 | "\"type\":\"string\"" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 4013 | "}" |
| 4014 | "}," |
| 4015 | "\"required\":[\"errorStr\"]" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4016 | "}" |
| 4017 | "]," |
| 4018 | "\"definitions\":{" |
| 4019 | "\"field\":{" |
| 4020 | "\"type\":\"object\"," |
| 4021 | "\"pos\":{" |
| 4022 | "\"type\":\"integer\"," |
| 4023 | "\"minimum\":0" |
| 4024 | "}," |
| 4025 | "\"name\":{" |
| 4026 | "\"type\":\"string\"" |
| 4027 | "}," |
| 4028 | "\"required\":[\"pos\",\"name\"]" |
| 4029 | "}," |
| 4030 | "\"processNum\":{" |
| 4031 | "\"type\":\"integer\"," |
| 4032 | "\"minimum\":1" |
| 4033 | "}," |
| 4034 | "\"tags\":{" |
| 4035 | "\"type\":\"object\"," |
| 4036 | "\"origin\":{" |
| 4037 | "\"type\":\"string\"," |
| 4038 | "\"enum\":[\"Metric\",\"Status\",\"Key\"," |
| 4039 | "\"Config\",\"Product\",\"Unknown\"]" |
| 4040 | "}," |
| 4041 | "\"nature\":{" |
| 4042 | "\"type\":\"string\"," |
| 4043 | "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\"," |
| 4044 | "\"Rate\",\"Counter\",\"Duration\"," |
| 4045 | "\"Age\",\"Time\",\"Name\",\"Output\"," |
| 4046 | "\"Avg\", \"Unknown\"]" |
| 4047 | "}," |
| 4048 | "\"scope\":{" |
| 4049 | "\"type\":\"string\"," |
| 4050 | "\"enum\":[\"Cluster\",\"Process\",\"Service\"," |
| 4051 | "\"System\",\"Unknown\"]" |
| 4052 | "}," |
| 4053 | "\"required\":[\"origin\",\"nature\",\"scope\"]" |
| 4054 | "}," |
| 4055 | "\"typedValue\":{" |
| 4056 | "\"type\":\"object\"," |
| 4057 | "\"oneOf\":[" |
| 4058 | "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"}," |
| 4059 | "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"}," |
| 4060 | "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"}," |
| 4061 | "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"}," |
| 4062 | "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}" |
| 4063 | "]," |
| 4064 | "\"definitions\":{" |
| 4065 | "\"s32Value\":{" |
| 4066 | "\"properties\":{" |
| 4067 | "\"type\":{" |
| 4068 | "\"type\":\"string\"," |
| 4069 | "\"enum\":[\"s32\"]" |
| 4070 | "}," |
| 4071 | "\"value\":{" |
| 4072 | "\"type\":\"integer\"," |
| 4073 | "\"minimum\":-2147483648," |
| 4074 | "\"maximum\":2147483647" |
| 4075 | "}" |
| 4076 | "}," |
| 4077 | "\"required\":[\"type\",\"value\"]" |
| 4078 | "}," |
| 4079 | "\"s64Value\":{" |
| 4080 | "\"properties\":{" |
| 4081 | "\"type\":{" |
| 4082 | "\"type\":\"string\"," |
| 4083 | "\"enum\":[\"s64\"]" |
| 4084 | "}," |
| 4085 | "\"value\":{" |
| 4086 | "\"type\":\"integer\"," |
| 4087 | "\"minimum\":-9007199254740991," |
| 4088 | "\"maximum\":9007199254740991" |
| 4089 | "}" |
| 4090 | "}," |
| 4091 | "\"required\":[\"type\",\"value\"]" |
| 4092 | "}," |
| 4093 | "\"u32Value\":{" |
| 4094 | "\"properties\":{" |
| 4095 | "\"type\":{" |
| 4096 | "\"type\":\"string\"," |
| 4097 | "\"enum\":[\"u32\"]" |
| 4098 | "}," |
| 4099 | "\"value\":{" |
| 4100 | "\"type\":\"integer\"," |
| 4101 | "\"minimum\":0," |
| 4102 | "\"maximum\":4294967295" |
| 4103 | "}" |
| 4104 | "}," |
| 4105 | "\"required\":[\"type\",\"value\"]" |
| 4106 | "}," |
| 4107 | "\"u64Value\":{" |
| 4108 | "\"properties\":{" |
| 4109 | "\"type\":{" |
| 4110 | "\"type\":\"string\"," |
| 4111 | "\"enum\":[\"u64\"]" |
| 4112 | "}," |
| 4113 | "\"value\":{" |
| 4114 | "\"type\":\"integer\"," |
| 4115 | "\"minimum\":0," |
| 4116 | "\"maximum\":9007199254740991" |
| 4117 | "}" |
| 4118 | "}," |
| 4119 | "\"required\":[\"type\",\"value\"]" |
| 4120 | "}," |
| 4121 | "\"strValue\":{" |
| 4122 | "\"properties\":{" |
| 4123 | "\"type\":{" |
| 4124 | "\"type\":\"string\"," |
| 4125 | "\"enum\":[\"str\"]" |
| 4126 | "}," |
| 4127 | "\"value\":{\"type\":\"string\"}" |
| 4128 | "}," |
| 4129 | "\"required\":[\"type\",\"value\"]" |
| 4130 | "}," |
| 4131 | "\"unknownValue\":{" |
| 4132 | "\"properties\":{" |
| 4133 | "\"type\":{" |
| 4134 | "\"type\":\"integer\"," |
| 4135 | "\"minimum\":0" |
| 4136 | "}," |
| 4137 | "\"value\":{" |
| 4138 | "\"type\":\"string\"," |
| 4139 | "\"enum\":[\"unknown\"]" |
| 4140 | "}" |
| 4141 | "}," |
| 4142 | "\"required\":[\"type\",\"value\"]" |
| 4143 | "}" |
| 4144 | "}" |
| 4145 | "}" |
| 4146 | "}" |
| 4147 | "}"); |
| 4148 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4149 | if (old_len == out->data) { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4150 | chunk_reset(out); |
| 4151 | chunk_appendf(out, |
| 4152 | "{\"errorStr\":\"output buffer too short\"}"); |
| 4153 | } |
| 4154 | } |
| 4155 | |
| 4156 | /* This function dumps the schema onto the stream interface's read buffer. |
| 4157 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4158 | * No state is used. |
| 4159 | */ |
| 4160 | static int stats_dump_json_schema_to_buffer(struct stream_interface *si) |
| 4161 | { |
| 4162 | chunk_reset(&trash); |
| 4163 | |
| 4164 | stats_dump_json_schema(&trash); |
| 4165 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 4166 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 4167 | si_rx_room_blk(si); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4168 | return 0; |
| 4169 | } |
| 4170 | |
| 4171 | return 1; |
| 4172 | } |
| 4173 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 4174 | 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] | 4175 | { |
| 4176 | struct proxy *px; |
| 4177 | struct server *sv; |
| 4178 | struct listener *li; |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 4179 | struct stats_module *mod; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4180 | int clrall = 0; |
| 4181 | |
| 4182 | if (strcmp(args[2], "all") == 0) |
| 4183 | clrall = 1; |
| 4184 | |
| 4185 | /* check permissions */ |
| 4186 | if (!cli_has_level(appctx, ACCESS_LVL_OPER) || |
| 4187 | (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN))) |
| 4188 | return 1; |
| 4189 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 4190 | for (px = proxies_list; px; px = px->next) { |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4191 | if (clrall) { |
| 4192 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 4193 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 4194 | } |
| 4195 | else { |
| 4196 | px->be_counters.conn_max = 0; |
| 4197 | px->be_counters.p.http.rps_max = 0; |
| 4198 | px->be_counters.sps_max = 0; |
| 4199 | px->be_counters.cps_max = 0; |
| 4200 | px->be_counters.nbpend_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 4201 | px->be_counters.qtime_max = 0; |
| 4202 | px->be_counters.ctime_max = 0; |
| 4203 | px->be_counters.dtime_max = 0; |
| 4204 | px->be_counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4205 | |
| 4206 | px->fe_counters.conn_max = 0; |
| 4207 | px->fe_counters.p.http.rps_max = 0; |
| 4208 | px->fe_counters.sps_max = 0; |
| 4209 | px->fe_counters.cps_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4210 | } |
| 4211 | |
| 4212 | for (sv = px->srv; sv; sv = sv->next) |
| 4213 | if (clrall) |
| 4214 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 4215 | else { |
| 4216 | sv->counters.cur_sess_max = 0; |
| 4217 | sv->counters.nbpend_max = 0; |
| 4218 | sv->counters.sps_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 4219 | sv->counters.qtime_max = 0; |
| 4220 | sv->counters.ctime_max = 0; |
| 4221 | sv->counters.dtime_max = 0; |
| 4222 | sv->counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
| 4226 | if (li->counters) { |
| 4227 | if (clrall) |
| 4228 | memset(li->counters, 0, sizeof(*li->counters)); |
| 4229 | else |
| 4230 | li->counters->conn_max = 0; |
| 4231 | } |
| 4232 | } |
| 4233 | |
| 4234 | global.cps_max = 0; |
| 4235 | global.sps_max = 0; |
Olivier Houchard | 00bc3cb | 2017-10-17 19:23:25 +0200 | [diff] [blame] | 4236 | global.ssl_max = 0; |
| 4237 | global.ssl_fe_keys_max = 0; |
| 4238 | global.ssl_be_keys_max = 0; |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 4239 | |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 4240 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 4241 | if (!mod->clearable && !clrall) |
| 4242 | continue; |
| 4243 | |
| 4244 | for (px = proxies_list; px; px = px->next) { |
| 4245 | enum stats_domain_px_cap mod_cap = stats_px_get_cap(mod->domain_flags); |
| 4246 | |
| 4247 | if (px->cap & PR_CAP_FE && mod_cap & STATS_PX_CAP_FE) { |
| 4248 | EXTRA_COUNTERS_INIT(px->extra_counters_fe, |
| 4249 | mod, |
| 4250 | mod->counters, |
| 4251 | mod->counters_size); |
| 4252 | } |
| 4253 | |
| 4254 | if (px->cap & PR_CAP_BE && mod_cap & STATS_PX_CAP_BE) { |
| 4255 | EXTRA_COUNTERS_INIT(px->extra_counters_be, |
| 4256 | mod, |
| 4257 | mod->counters, |
| 4258 | mod->counters_size); |
| 4259 | } |
| 4260 | |
| 4261 | if (mod_cap & STATS_PX_CAP_SRV) { |
| 4262 | for (sv = px->srv; sv; sv = sv->next) { |
| 4263 | EXTRA_COUNTERS_INIT(sv->extra_counters, |
| 4264 | mod, |
| 4265 | mod->counters, |
| 4266 | mod->counters_size); |
| 4267 | } |
| 4268 | } |
| 4269 | |
| 4270 | if (mod_cap & STATS_PX_CAP_LI) { |
| 4271 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 4272 | EXTRA_COUNTERS_INIT(li->extra_counters, |
| 4273 | mod, |
| 4274 | mod->counters, |
| 4275 | mod->counters_size); |
| 4276 | } |
| 4277 | } |
| 4278 | } |
| 4279 | } |
| 4280 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 4281 | dns_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_DNS]); |
| 4282 | |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 4283 | memset(activity, 0, sizeof(activity)); |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4284 | return 1; |
| 4285 | } |
| 4286 | |
| 4287 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 4288 | 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] | 4289 | { |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 4290 | int arg = 2; |
| 4291 | |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 4292 | appctx->ctx.stats.scope_str = 0; |
| 4293 | appctx->ctx.stats.scope_len = 0; |
| 4294 | appctx->ctx.stats.flags = 0; |
| 4295 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 4296 | while (*args[arg]) { |
| 4297 | if (strcmp(args[arg], "typed") == 0) |
| 4298 | appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
| 4299 | else if (strcmp(args[arg], "json") == 0) |
| 4300 | appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
| 4301 | else if (strcmp(args[arg], "desc") == 0) |
| 4302 | appctx->ctx.stats.flags |= STAT_SHOW_FDESC; |
| 4303 | arg++; |
| 4304 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4305 | return 0; |
| 4306 | } |
| 4307 | |
| 4308 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 4309 | 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] | 4310 | { |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 4311 | int arg = 2; |
| 4312 | |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 4313 | appctx->ctx.stats.scope_str = 0; |
| 4314 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 578d6e4 | 2019-10-09 11:00:22 +0200 | [diff] [blame] | 4315 | appctx->ctx.stats.flags = STAT_SHNODE | STAT_SHDESC; |
| 4316 | |
| 4317 | if ((strm_li(si_strm(appctx->owner))->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) |
| 4318 | appctx->ctx.stats.flags |= STAT_SHLGNDS; |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 4319 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4320 | /* proxy is the default domain */ |
| 4321 | appctx->ctx.stats.domain = STATS_DOMAIN_PROXY; |
| 4322 | if (!strcmp(args[arg], "domain")) { |
| 4323 | ++args; |
| 4324 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 4325 | if (!strcmp(args[arg], "proxy")) { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4326 | ++args; |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 4327 | } else if (!strcmp(args[arg], "dns")) { |
| 4328 | appctx->ctx.stats.domain = STATS_DOMAIN_DNS; |
| 4329 | ++args; |
| 4330 | } else { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4331 | return cli_err(appctx, "Invalid statistics domain.\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 4332 | } |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | if (appctx->ctx.stats.domain == STATS_DOMAIN_PROXY |
| 4336 | && *args[arg] && *args[arg+1] && *args[arg+2]) { |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 4337 | struct proxy *px; |
| 4338 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 4339 | px = proxy_find_by_name(args[arg], 0, 0); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 4340 | if (px) |
| 4341 | appctx->ctx.stats.iid = px->uuid; |
| 4342 | else |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 4343 | appctx->ctx.stats.iid = atoi(args[arg]); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 4344 | |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 4345 | if (!appctx->ctx.stats.iid) |
| 4346 | return cli_err(appctx, "No such proxy.\n"); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 4347 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4348 | appctx->ctx.stats.flags |= STAT_BOUND; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 4349 | appctx->ctx.stats.type = atoi(args[arg+1]); |
| 4350 | appctx->ctx.stats.sid = atoi(args[arg+2]); |
| 4351 | arg += 3; |
| 4352 | } |
| 4353 | |
| 4354 | while (*args[arg]) { |
| 4355 | if (strcmp(args[arg], "typed") == 0) |
| 4356 | appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
| 4357 | else if (strcmp(args[arg], "json") == 0) |
| 4358 | appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
| 4359 | else if (strcmp(args[arg], "desc") == 0) |
| 4360 | appctx->ctx.stats.flags |= STAT_SHOW_FDESC; |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 4361 | else if (strcmp(args[arg], "no-maint") == 0) |
| 4362 | appctx->ctx.stats.flags |= STAT_HIDE_MAINT; |
Willy Tarreau | 65141ff | 2020-10-23 17:19:48 +0200 | [diff] [blame] | 4363 | else if (strcmp(args[arg], "up") == 0) |
| 4364 | appctx->ctx.stats.flags |= STAT_HIDE_DOWN; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 4365 | arg++; |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4366 | } |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4367 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4368 | return 0; |
| 4369 | } |
| 4370 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4371 | static int cli_io_handler_dump_info(struct appctx *appctx) |
| 4372 | { |
| 4373 | return stats_dump_info_to_buffer(appctx->owner); |
| 4374 | } |
| 4375 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4376 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4377 | * used to send raw stats over a socket. |
| 4378 | */ |
| 4379 | static int cli_io_handler_dump_stat(struct appctx *appctx) |
| 4380 | { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4381 | return stats_dump_stat_to_buffer(appctx->owner, NULL, NULL); |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4382 | } |
| 4383 | |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4384 | static int cli_io_handler_dump_json_schema(struct appctx *appctx) |
| 4385 | { |
| 4386 | return stats_dump_json_schema_to_buffer(appctx->owner); |
| 4387 | } |
| 4388 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 4389 | static int stats_allocate_proxy_counters_internal(struct extra_counters **counters, |
| 4390 | int type, int px_cap) |
| 4391 | { |
| 4392 | struct stats_module *mod; |
| 4393 | |
| 4394 | EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed); |
| 4395 | |
| 4396 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 4397 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 4398 | continue; |
| 4399 | |
| 4400 | EXTRA_COUNTERS_ADD(mod, *counters, mod->counters, mod->counters_size); |
| 4401 | } |
| 4402 | |
| 4403 | EXTRA_COUNTERS_ALLOC(*counters, alloc_failed); |
| 4404 | |
| 4405 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 4406 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 4407 | continue; |
| 4408 | |
| 4409 | EXTRA_COUNTERS_INIT(*counters, mod, mod->counters, mod->counters_size); |
| 4410 | } |
| 4411 | |
| 4412 | return 1; |
| 4413 | |
| 4414 | alloc_failed: |
| 4415 | return 0; |
| 4416 | } |
| 4417 | |
| 4418 | /* Initialize and allocate all extra counters for a proxy and its attached |
| 4419 | * servers/listeners with all already registered stats module |
| 4420 | */ |
| 4421 | int stats_allocate_proxy_counters(struct proxy *px) |
| 4422 | { |
| 4423 | struct server *sv; |
| 4424 | struct listener *li; |
| 4425 | |
| 4426 | if (px->cap & PR_CAP_FE) { |
| 4427 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_fe, |
| 4428 | COUNTERS_FE, |
| 4429 | STATS_PX_CAP_FE)) { |
| 4430 | return 0; |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | if (px->cap & PR_CAP_BE) { |
| 4435 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be, |
| 4436 | COUNTERS_BE, |
| 4437 | STATS_PX_CAP_BE)) { |
| 4438 | return 0; |
| 4439 | } |
| 4440 | } |
| 4441 | |
| 4442 | for (sv = px->srv; sv; sv = sv->next) { |
| 4443 | if (!stats_allocate_proxy_counters_internal(&sv->extra_counters, |
| 4444 | COUNTERS_SV, |
| 4445 | STATS_PX_CAP_SRV)) { |
| 4446 | return 0; |
| 4447 | } |
| 4448 | } |
| 4449 | |
| 4450 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 4451 | if (!stats_allocate_proxy_counters_internal(&li->extra_counters, |
| 4452 | COUNTERS_LI, |
| 4453 | STATS_PX_CAP_LI)) { |
| 4454 | return 0; |
| 4455 | } |
| 4456 | } |
| 4457 | |
| 4458 | return 1; |
| 4459 | } |
| 4460 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 4461 | void stats_register_module(struct stats_module *m) |
| 4462 | { |
| 4463 | const uint8_t domain = stats_get_domain(m->domain_flags); |
| 4464 | |
| 4465 | LIST_ADDQ(&stats_module_list[domain], &m->list); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 4466 | stat_count[domain] += m->stats_count; |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 4467 | } |
| 4468 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 4469 | static int allocate_stats_px_postcheck(void) |
| 4470 | { |
| 4471 | struct stats_module *mod; |
| 4472 | size_t i = ST_F_TOTAL_FIELDS; |
| 4473 | int err_code = 0; |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 4474 | struct proxy *px; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 4475 | |
| 4476 | stat_count[STATS_DOMAIN_PROXY] += ST_F_TOTAL_FIELDS; |
| 4477 | |
| 4478 | stat_f[STATS_DOMAIN_PROXY] = malloc(stat_count[STATS_DOMAIN_PROXY] * sizeof(struct name_desc)); |
| 4479 | if (!stat_f[STATS_DOMAIN_PROXY]) { |
| 4480 | ha_alert("stats: cannot allocate all fields for proxy statistics\n"); |
| 4481 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4482 | return err_code; |
| 4483 | } |
| 4484 | |
| 4485 | memcpy(stat_f[STATS_DOMAIN_PROXY], stat_fields, |
| 4486 | ST_F_TOTAL_FIELDS * sizeof(struct name_desc)); |
| 4487 | |
| 4488 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 4489 | memcpy(stat_f[STATS_DOMAIN_PROXY] + i, |
| 4490 | mod->stats, |
| 4491 | mod->stats_count * sizeof(struct name_desc)); |
| 4492 | i += mod->stats_count; |
| 4493 | } |
| 4494 | |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 4495 | for (px = proxies_list; px; px = px->next) { |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 4496 | if (!stats_allocate_proxy_counters(px)) { |
| 4497 | ha_alert("stats: cannot allocate all counters for proxy statistics\n"); |
| 4498 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4499 | return err_code; |
| 4500 | } |
| 4501 | } |
| 4502 | |
| 4503 | stat_l[STATS_DOMAIN_PROXY] = malloc(stat_count[STATS_DOMAIN_PROXY] * sizeof(struct field)); |
| 4504 | if (!stat_l[STATS_DOMAIN_PROXY]) { |
| 4505 | ha_alert("stats: cannot allocate a line for proxy statistics\n"); |
| 4506 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4507 | return err_code; |
| 4508 | } |
| 4509 | |
| 4510 | return err_code; |
| 4511 | } |
| 4512 | |
| 4513 | REGISTER_CONFIG_POSTPARSER("allocate-stats-px", allocate_stats_px_postcheck); |
| 4514 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 4515 | static int allocate_stats_dns_postcheck(void) |
| 4516 | { |
| 4517 | struct stats_module *mod; |
| 4518 | size_t i = 0; |
| 4519 | int err_code = 0; |
| 4520 | |
| 4521 | stat_f[STATS_DOMAIN_DNS] = malloc(stat_count[STATS_DOMAIN_DNS] * sizeof(struct name_desc)); |
| 4522 | if (!stat_f[STATS_DOMAIN_DNS]) { |
| 4523 | ha_alert("stats: cannot allocate all fields for dns statistics\n"); |
| 4524 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4525 | return err_code; |
| 4526 | } |
| 4527 | |
| 4528 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_DNS], list) { |
| 4529 | memcpy(stat_f[STATS_DOMAIN_DNS] + i, |
| 4530 | mod->stats, |
| 4531 | mod->stats_count * sizeof(struct name_desc)); |
| 4532 | i += mod->stats_count; |
| 4533 | } |
| 4534 | |
| 4535 | if (!dns_allocate_counters(&stats_module_list[STATS_DOMAIN_DNS])) { |
| 4536 | ha_alert("stats: cannot allocate all counters for dns statistics\n"); |
| 4537 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4538 | return err_code; |
| 4539 | } |
| 4540 | |
| 4541 | stat_l[STATS_DOMAIN_DNS] = malloc(stat_count[STATS_DOMAIN_DNS] * sizeof(struct field)); |
| 4542 | if (!stat_l[STATS_DOMAIN_DNS]) { |
| 4543 | ha_alert("stats: cannot allocate a line for dns statistics\n"); |
| 4544 | err_code |= ERR_ALERT | ERR_FATAL; |
| 4545 | return err_code; |
| 4546 | } |
| 4547 | |
| 4548 | return err_code; |
| 4549 | } |
| 4550 | |
| 4551 | REGISTER_CONFIG_POSTPARSER("allocate-stats-dns", allocate_stats_dns_postcheck); |
| 4552 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 4553 | static int allocate_trash_counters(void) |
| 4554 | { |
| 4555 | struct stats_module *mod; |
| 4556 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_DNS }, i; |
| 4557 | size_t max_counters_size = 0; |
| 4558 | |
| 4559 | /* calculate the greatest counters used by any stats modules */ |
| 4560 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 4561 | list_for_each_entry(mod, &stats_module_list[domains[i]], list) { |
| 4562 | max_counters_size = mod->counters_size > max_counters_size ? |
| 4563 | mod->counters_size : max_counters_size; |
| 4564 | } |
| 4565 | } |
| 4566 | |
| 4567 | /* allocate the trash with the size of the greatest counters */ |
| 4568 | if (max_counters_size) { |
| 4569 | trash_counters = malloc(max_counters_size); |
| 4570 | if (!trash_counters) { |
| 4571 | ha_alert("stats: cannot allocate trash counters for statistics\n"); |
| 4572 | return 0; |
| 4573 | } |
| 4574 | } |
| 4575 | |
| 4576 | return 1; |
| 4577 | } |
| 4578 | |
| 4579 | REGISTER_PER_THREAD_ALLOC(allocate_trash_counters); |
| 4580 | |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 4581 | static void deinit_stats(void) |
| 4582 | { |
| 4583 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_DNS }, i; |
| 4584 | |
| 4585 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 4586 | const int domain = domains[i]; |
| 4587 | |
| 4588 | if (stat_l[domain]) |
| 4589 | free(stat_l[domain]); |
| 4590 | |
| 4591 | if (stat_f[domain]) |
| 4592 | free(stat_f[domain]); |
| 4593 | } |
| 4594 | } |
| 4595 | |
| 4596 | REGISTER_POST_DEINIT(deinit_stats); |
| 4597 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 4598 | static void free_trash_counters(void) |
| 4599 | { |
| 4600 | if (trash_counters) |
| 4601 | free(trash_counters); |
| 4602 | } |
| 4603 | |
| 4604 | REGISTER_PER_THREAD_FREE(free_trash_counters); |
| 4605 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4606 | /* register cli keywords */ |
| 4607 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4608 | { { "clear", "counters", NULL }, "clear counters : clear max statistics counters (add 'all' for all counters)", cli_parse_clear_counters, NULL, NULL }, |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 4609 | { { "show", "info", NULL }, "show info : report information about the running process [desc|json|typed]*", cli_parse_show_info, cli_io_handler_dump_info, NULL }, |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 4610 | { { "show", "stat", NULL }, "show stat : report counters for each proxy and server [desc|json|no-maint|typed|up]*", cli_parse_show_stat, cli_io_handler_dump_stat, NULL }, |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4611 | { { "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] | 4612 | {{},} |
| 4613 | }}; |
| 4614 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 4615 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 4616 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4617 | struct applet http_stats_applet = { |
| 4618 | .obj_type = OBJ_TYPE_APPLET, |
| 4619 | .name = "<STATS>", /* used for logging */ |
| 4620 | .fct = http_stats_io_handler, |
| 4621 | .release = NULL, |
| 4622 | }; |
| 4623 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4624 | /* |
| 4625 | * Local variables: |
| 4626 | * c-indent-level: 8 |
| 4627 | * c-basic-offset: 8 |
| 4628 | * End: |
| 4629 | */ |