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