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