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