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