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> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <pwd.h> |
| 20 | #include <grp.h> |
| 21 | |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 26 | #include <haproxy/api.h> |
Willy Tarreau | 5d9ddc5 | 2021-10-06 19:54:09 +0200 | [diff] [blame] | 27 | #include <haproxy/activity.h> |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 28 | #include <haproxy/applet.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 | 5554264 | 2021-10-08 09:33:24 +0200 | [diff] [blame] | 35 | #include <haproxy/clock.h> |
Willy Tarreau | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 36 | #include <haproxy/compression.h> |
Willy Tarreau | 2a83d60 | 2020-05-27 16:58:08 +0200 | [diff] [blame] | 37 | #include <haproxy/debug.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 38 | #include <haproxy/errors.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 39 | #include <haproxy/fd.h> |
| 40 | #include <haproxy/freq_ctr.h> |
Willy Tarreau | 762d7a5 | 2020-06-04 11:23:07 +0200 | [diff] [blame] | 41 | #include <haproxy/frontend.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 42 | #include <haproxy/global.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 43 | #include <haproxy/http.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 44 | #include <haproxy/http_ana.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 45 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 46 | #include <haproxy/htx.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 47 | #include <haproxy/list.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 48 | #include <haproxy/listener.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 49 | #include <haproxy/log.h> |
Willy Tarreau | 2cd5809 | 2020-06-04 15:10:43 +0200 | [diff] [blame] | 50 | #include <haproxy/map-t.h> |
Willy Tarreau | 225a90a | 2020-06-04 15:06:28 +0200 | [diff] [blame] | 51 | #include <haproxy/pattern-t.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 52 | #include <haproxy/pipe.h> |
| 53 | #include <haproxy/pool.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 54 | #include <haproxy/proxy.h> |
Emeric Brun | c943799 | 2021-02-12 19:42:55 +0100 | [diff] [blame] | 55 | #include <haproxy/resolvers.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 56 | #include <haproxy/sc_strm.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 57 | #include <haproxy/server.h> |
Willy Tarreau | 48d25b3 | 2020-06-04 18:58:52 +0200 | [diff] [blame] | 58 | #include <haproxy/session.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 59 | #include <haproxy/stats.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 60 | #include <haproxy/stconn.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 61 | #include <haproxy/stream.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 62 | #include <haproxy/task.h> |
Willy Tarreau | c2f7c58 | 2020-06-02 18:15:32 +0200 | [diff] [blame] | 63 | #include <haproxy/ticks.h> |
Willy Tarreau | 92b4f13 | 2020-06-01 11:05:15 +0200 | [diff] [blame] | 64 | #include <haproxy/time.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 65 | #include <haproxy/tools.h> |
Willy Tarreau | 8c42b8a | 2020-06-04 19:27:34 +0200 | [diff] [blame] | 66 | #include <haproxy/uri_auth-t.h> |
Willy Tarreau | d678805 | 2020-05-27 15:59:00 +0200 | [diff] [blame] | 67 | #include <haproxy/version.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 68 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 69 | |
Christopher Faulet | 2b9b678 | 2019-02-27 16:42:58 +0100 | [diff] [blame] | 70 | /* status codes available for the stats admin page (strictly 4 chars length) */ |
| 71 | const char *stat_status_codes[STAT_STATUS_SIZE] = { |
| 72 | [STAT_STATUS_DENY] = "DENY", |
| 73 | [STAT_STATUS_DONE] = "DONE", |
| 74 | [STAT_STATUS_ERRP] = "ERRP", |
| 75 | [STAT_STATUS_EXCD] = "EXCD", |
| 76 | [STAT_STATUS_NONE] = "NONE", |
| 77 | [STAT_STATUS_PART] = "PART", |
| 78 | [STAT_STATUS_UNKN] = "UNKN", |
| 79 | [STAT_STATUS_IVAL] = "IVAL", |
| 80 | }; |
| 81 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 82 | /* These are the field names for each INF_* field position. Please pay attention |
| 83 | * to always use the exact same name except that the strings for new names must |
| 84 | * be lower case or CamelCase while the enum entries must be upper case. |
| 85 | */ |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 86 | const struct name_desc info_fields[INF_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 87 | [INF_NAME] = { .name = "Name", .desc = "Product name" }, |
| 88 | [INF_VERSION] = { .name = "Version", .desc = "Product version" }, |
| 89 | [INF_RELEASE_DATE] = { .name = "Release_date", .desc = "Date of latest source code update" }, |
| 90 | [INF_NBTHREAD] = { .name = "Nbthread", .desc = "Number of started threads (global.nbthread)" }, |
Willy Tarreau | 9135859 | 2021-06-15 08:08:04 +0200 | [diff] [blame] | 91 | [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] | 92 | [INF_PROCESS_NUM] = { .name = "Process_num", .desc = "Relative worker process number (1)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 93 | [INF_PID] = { .name = "Pid", .desc = "This worker process identifier for the system" }, |
| 94 | [INF_UPTIME] = { .name = "Uptime", .desc = "How long ago this worker process was started (days+hours+minutes+seconds)" }, |
| 95 | [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] | 96 | [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] | 97 | [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] | 98 | [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] | 99 | [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] | 100 | [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] | 101 | [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] | 102 | [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] | 103 | [INF_POOL_FAILED] = { .name = "PoolFailed", .desc = "Number of failed pool allocations since this worker was started" }, |
| 104 | [INF_ULIMIT_N] = { .name = "Ulimit-n", .desc = "Hard limit on the number of per-process file descriptors" }, |
| 105 | [INF_MAXSOCK] = { .name = "Maxsock", .desc = "Hard limit on the number of per-process sockets" }, |
| 106 | [INF_MAXCONN] = { .name = "Maxconn", .desc = "Hard limit on the number of per-process connections (configured or imposed by Ulimit-n)" }, |
| 107 | [INF_HARD_MAXCONN] = { .name = "Hard_maxconn", .desc = "Hard limit on the number of per-process connections (imposed by Memmax_MB or Ulimit-n)" }, |
| 108 | [INF_CURR_CONN] = { .name = "CurrConns", .desc = "Current number of connections on this worker process" }, |
| 109 | [INF_CUM_CONN] = { .name = "CumConns", .desc = "Total number of connections on this worker process since started" }, |
| 110 | [INF_CUM_REQ] = { .name = "CumReq", .desc = "Total number of requests on this worker process since started" }, |
| 111 | [INF_MAX_SSL_CONNS] = { .name = "MaxSslConns", .desc = "Hard limit on the number of per-process SSL endpoints (front+back), 0=unlimited" }, |
| 112 | [INF_CURR_SSL_CONNS] = { .name = "CurrSslConns", .desc = "Current number of SSL endpoints on this worker process (front+back)" }, |
| 113 | [INF_CUM_SSL_CONNS] = { .name = "CumSslConns", .desc = "Total number of SSL endpoints on this worker process since started (front+back)" }, |
| 114 | [INF_MAXPIPES] = { .name = "Maxpipes", .desc = "Hard limit on the number of pipes for splicing, 0=unlimited" }, |
| 115 | [INF_PIPES_USED] = { .name = "PipesUsed", .desc = "Current number of pipes in use in this worker process" }, |
| 116 | [INF_PIPES_FREE] = { .name = "PipesFree", .desc = "Current number of allocated and available pipes in this worker process" }, |
| 117 | [INF_CONN_RATE] = { .name = "ConnRate", .desc = "Number of front connections created on this worker process over the last second" }, |
| 118 | [INF_CONN_RATE_LIMIT] = { .name = "ConnRateLimit", .desc = "Hard limit for ConnRate (global.maxconnrate)" }, |
| 119 | [INF_MAX_CONN_RATE] = { .name = "MaxConnRate", .desc = "Highest ConnRate reached on this worker process since started (in connections per second)" }, |
| 120 | [INF_SESS_RATE] = { .name = "SessRate", .desc = "Number of sessions created on this worker process over the last second" }, |
| 121 | [INF_SESS_RATE_LIMIT] = { .name = "SessRateLimit", .desc = "Hard limit for SessRate (global.maxsessrate)" }, |
| 122 | [INF_MAX_SESS_RATE] = { .name = "MaxSessRate", .desc = "Highest SessRate reached on this worker process since started (in sessions per second)" }, |
| 123 | [INF_SSL_RATE] = { .name = "SslRate", .desc = "Number of SSL connections created on this worker process over the last second" }, |
| 124 | [INF_SSL_RATE_LIMIT] = { .name = "SslRateLimit", .desc = "Hard limit for SslRate (global.maxsslrate)" }, |
| 125 | [INF_MAX_SSL_RATE] = { .name = "MaxSslRate", .desc = "Highest SslRate reached on this worker process since started (in connections per second)" }, |
| 126 | [INF_SSL_FRONTEND_KEY_RATE] = { .name = "SslFrontendKeyRate", .desc = "Number of SSL keys created on frontends in this worker process over the last second" }, |
| 127 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = { .name = "SslFrontendMaxKeyRate", .desc = "Highest SslFrontendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 128 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = { .name = "SslFrontendSessionReuse_pct", .desc = "Percent of frontend SSL connections which did not require a new key" }, |
| 129 | [INF_SSL_BACKEND_KEY_RATE] = { .name = "SslBackendKeyRate", .desc = "Number of SSL keys created on backends in this worker process over the last second" }, |
| 130 | [INF_SSL_BACKEND_MAX_KEY_RATE] = { .name = "SslBackendMaxKeyRate", .desc = "Highest SslBackendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 131 | [INF_SSL_CACHE_LOOKUPS] = { .name = "SslCacheLookups", .desc = "Total number of SSL session ID lookups in the SSL session cache on this worker since started" }, |
| 132 | [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" }, |
| 133 | [INF_COMPRESS_BPS_IN] = { .name = "CompressBpsIn", .desc = "Number of bytes submitted to the HTTP compressor in this worker process over the last second" }, |
| 134 | [INF_COMPRESS_BPS_OUT] = { .name = "CompressBpsOut", .desc = "Number of bytes emitted by the HTTP compressor in this worker process over the last second" }, |
| 135 | [INF_COMPRESS_BPS_RATE_LIM] = { .name = "CompressBpsRateLim", .desc = "Limit of CompressBpsOut beyond which HTTP compression is automatically disabled" }, |
| 136 | [INF_ZLIB_MEM_USAGE] = { .name = "ZlibMemUsage", .desc = "Amount of memory currently used by HTTP compression on the current worker process (in bytes)" }, |
| 137 | [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)" }, |
| 138 | [INF_TASKS] = { .name = "Tasks", .desc = "Total number of tasks in the current worker process (active + sleeping)" }, |
| 139 | [INF_RUN_QUEUE] = { .name = "Run_queue", .desc = "Total number of active tasks+tasklets in the current worker process" }, |
| 140 | [INF_IDLE_PCT] = { .name = "Idle_pct", .desc = "Percentage of last second spent waiting in the current worker thread" }, |
| 141 | [INF_NODE] = { .name = "node", .desc = "Node name (global.node)" }, |
| 142 | [INF_DESCRIPTION] = { .name = "description", .desc = "Node description (global.description)" }, |
| 143 | [INF_STOPPING] = { .name = "Stopping", .desc = "1 if the worker process is currently stopping, otherwise zero" }, |
| 144 | [INF_JOBS] = { .name = "Jobs", .desc = "Current number of active jobs on the current worker process (frontend connections, master connections, listeners)" }, |
| 145 | [INF_UNSTOPPABLE_JOBS] = { .name = "Unstoppable Jobs", .desc = "Current number of unstoppable jobs on the current worker process (master connections)" }, |
| 146 | [INF_LISTENERS] = { .name = "Listeners", .desc = "Current number of active listeners on the current worker process" }, |
| 147 | [INF_ACTIVE_PEERS] = { .name = "ActivePeers", .desc = "Current number of verified active peers connections on the current worker process" }, |
| 148 | [INF_CONNECTED_PEERS] = { .name = "ConnectedPeers", .desc = "Current number of peers having passed the connection step on the current worker process" }, |
| 149 | [INF_DROPPED_LOGS] = { .name = "DroppedLogs", .desc = "Total number of dropped logs for current worker process since started" }, |
| 150 | [INF_BUSY_POLLING] = { .name = "BusyPolling", .desc = "1 if busy-polling is currently in use on the worker process, otherwise zero (config.busy-polling)" }, |
| 151 | [INF_FAILED_RESOLUTIONS] = { .name = "FailedResolutions", .desc = "Total number of failed DNS resolutions in current worker process since started" }, |
| 152 | [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] | 153 | [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] | 154 | [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] | 155 | [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] | 156 | [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] | 157 | [INF_BUILD_INFO] = { .name = "Build info", .desc = "Build info" }, |
Amaury Denoyelle | 5dfdf3e | 2021-05-05 17:09:12 +0200 | [diff] [blame] | 158 | [INF_TAINTED] = { .name = "Tainted", .desc = "Experimental features used" }, |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 161 | const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 162 | [ST_F_PXNAME] = { .name = "pxname", .desc = "Proxy name" }, |
| 163 | [ST_F_SVNAME] = { .name = "svname", .desc = "Server name" }, |
William Dauchy | eedb9b1 | 2021-02-01 13:11:53 +0100 | [diff] [blame] | 164 | [ST_F_QCUR] = { .name = "qcur", .desc = "Number of current queued connections" }, |
| 165 | [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] | 166 | [ST_F_SCUR] = { .name = "scur", .desc = "Number of current sessions on the frontend, backend or server" }, |
| 167 | [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] | 168 | [ST_F_SLIM] = { .name = "slim", .desc = "Frontend/listener/server's maxconn, backend's fullconn" }, |
| 169 | [ST_F_STOT] = { .name = "stot", .desc = "Total number of sessions since process started" }, |
| 170 | [ST_F_BIN] = { .name = "bin", .desc = "Total number of request bytes since process started" }, |
| 171 | [ST_F_BOUT] = { .name = "bout", .desc = "Total number of response bytes since process started" }, |
| 172 | [ST_F_DREQ] = { .name = "dreq", .desc = "Total number of denied requests since process started" }, |
| 173 | [ST_F_DRESP] = { .name = "dresp", .desc = "Total number of denied responses since process started" }, |
| 174 | [ST_F_EREQ] = { .name = "ereq", .desc = "Total number of invalid requests since process started" }, |
| 175 | [ST_F_ECON] = { .name = "econ", .desc = "Total number of failed connections to server since the worker process started" }, |
| 176 | [ST_F_ERESP] = { .name = "eresp", .desc = "Total number of invalid responses since the worker process started" }, |
| 177 | [ST_F_WRETR] = { .name = "wretr", .desc = "Total number of server connection retries since the worker process started" }, |
| 178 | [ST_F_WREDIS] = { .name = "wredis", .desc = "Total number of server redispatches due to connection failures since the worker process started" }, |
| 179 | [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] | 180 | [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] | 181 | [ST_F_ACT] = { .name = "act", .desc = "Total number of active UP servers with a non-zero weight" }, |
| 182 | [ST_F_BCK] = { .name = "bck", .desc = "Total number of backup UP servers with a non-zero weight" }, |
| 183 | [ST_F_CHKFAIL] = { .name = "chkfail", .desc = "Total number of failed individual health checks per server/backend, since the worker process started" }, |
| 184 | [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" }, |
| 185 | [ST_F_LASTCHG] = { .name = "lastchg", .desc = "How long ago the last server state changed, in seconds" }, |
| 186 | [ST_F_DOWNTIME] = { .name = "downtime", .desc = "Total time spent in DOWN state, for server or backend" }, |
| 187 | [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] | 188 | [ST_F_PID] = { .name = "pid", .desc = "Relative worker process number (1)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 189 | [ST_F_IID] = { .name = "iid", .desc = "Frontend or Backend numeric identifier ('id' setting)" }, |
| 190 | [ST_F_SID] = { .name = "sid", .desc = "Server numeric identifier ('id' setting)" }, |
| 191 | [ST_F_THROTTLE] = { .name = "throttle", .desc = "Throttling ratio applied to a server's maxconn and weight during the slowstart period (0 to 100%)" }, |
| 192 | [ST_F_LBTOT] = { .name = "lbtot", .desc = "Total number of requests routed by load balancing since the worker process started (ignores queue pop and stickiness)" }, |
| 193 | [ST_F_TRACKED] = { .name = "tracked", .desc = "Name of the other server this server tracks for its state" }, |
| 194 | [ST_F_TYPE] = { .name = "type", .desc = "Type of the object (Listener, Frontend, Backend, Server)" }, |
| 195 | [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)" }, |
| 196 | [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] | 197 | [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] | 198 | [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" }, |
| 199 | [ST_F_CHECK_CODE] = { .name = "check_code", .desc = "HTTP/SMTP/LDAP status code reported by the latest server health check" }, |
| 200 | [ST_F_CHECK_DURATION] = { .name = "check_duration", .desc = "Total duration of the latest server health check, in milliseconds" }, |
| 201 | [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" }, |
| 202 | [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" }, |
| 203 | [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" }, |
| 204 | [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" }, |
| 205 | [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" }, |
| 206 | [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)" }, |
| 207 | [ST_F_HANAFAIL] = { .name = "hanafail", .desc = "Total number of failed checks caused by an 'on-error' directive after an 'observe' condition matched" }, |
| 208 | [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] | 209 | [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] | 210 | [ST_F_REQ_TOT] = { .name = "req_tot", .desc = "Total number of HTTP requests processed by this object since the worker process started" }, |
| 211 | [ST_F_CLI_ABRT] = { .name = "cli_abrt", .desc = "Total number of requests or connections aborted by the client since the worker process started" }, |
| 212 | [ST_F_SRV_ABRT] = { .name = "srv_abrt", .desc = "Total number of requests or connections aborted by the server since the worker process started" }, |
| 213 | [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" }, |
| 214 | [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" }, |
| 215 | [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)" }, |
| 216 | [ST_F_COMP_RSP] = { .name = "comp_rsp", .desc = "Total number of HTTP responses that were compressed for this object since the worker process started" }, |
| 217 | [ST_F_LASTSESS] = { .name = "lastsess", .desc = "How long ago some traffic was seen on this object on this worker process, in seconds" }, |
| 218 | [ST_F_LAST_CHK] = { .name = "last_chk", .desc = "Short description of the latest health check report for this server (see also check_desc)" }, |
| 219 | [ST_F_LAST_AGT] = { .name = "last_agt", .desc = "Short description of the latest agent check report for this server (see also agent_desc)" }, |
| 220 | [ST_F_QTIME] = { .name = "qtime", .desc = "Time spent in the queue, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 221 | [ST_F_CTIME] = { .name = "ctime", .desc = "Time spent waiting for a connection to complete, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 222 | [ST_F_RTIME] = { .name = "rtime", .desc = "Time spent waiting for a server response, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 223 | [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)" }, |
| 224 | [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" }, |
| 225 | [ST_F_AGENT_CODE] = { .name = "agent_code", .desc = "Status code reported by the latest server agent check" }, |
| 226 | [ST_F_AGENT_DURATION] = { .name = "agent_duration", .desc = "Total duration of the latest server agent check, in milliseconds" }, |
| 227 | [ST_F_CHECK_DESC] = { .name = "check_desc", .desc = "Textual description of the latest health check report for this server" }, |
| 228 | [ST_F_AGENT_DESC] = { .name = "agent_desc", .desc = "Textual description of the latest agent check report for this server" }, |
| 229 | [ST_F_CHECK_RISE] = { .name = "check_rise", .desc = "Number of successful health checks before declaring a server UP (server 'rise' setting)" }, |
| 230 | [ST_F_CHECK_FALL] = { .name = "check_fall", .desc = "Number of failed health checks before declaring a server DOWN (server 'fall' setting)" }, |
| 231 | [ST_F_CHECK_HEALTH] = { .name = "check_health", .desc = "Current server health check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 232 | [ST_F_AGENT_RISE] = { .name = "agent_rise", .desc = "Number of successful agent checks before declaring a server UP (server 'rise' setting)" }, |
| 233 | [ST_F_AGENT_FALL] = { .name = "agent_fall", .desc = "Number of failed agent checks before declaring a server DOWN (server 'fall' setting)" }, |
| 234 | [ST_F_AGENT_HEALTH] = { .name = "agent_health", .desc = "Current server agent check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 235 | [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" }, |
| 236 | [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" }, |
| 237 | [ST_F_MODE] = { .name = "mode", .desc = "'mode' setting (tcp/http/health/cli)" }, |
| 238 | [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" }, |
| 239 | [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] | 240 | [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] | 241 | [ST_F_CONN_TOT] = { .name = "conn_tot", .desc = "Total number of new connections accepted on this frontend since the worker process started" }, |
| 242 | [ST_F_INTERCEPTED] = { .name = "intercepted", .desc = "Total number of HTTP requests intercepted on the frontend (redirects/stats/services) since the worker process started" }, |
| 243 | [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" }, |
| 244 | [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" }, |
| 245 | [ST_F_WREW] = { .name = "wrew", .desc = "Total number of failed HTTP header rewrites since the worker process started" }, |
| 246 | [ST_F_CONNECT] = { .name = "connect", .desc = "Total number of outgoing connection attempts on this backend/server since the worker process started" }, |
| 247 | [ST_F_REUSE] = { .name = "reuse", .desc = "Total number of reused connection on this backend/server since the worker process started" }, |
| 248 | [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" }, |
| 249 | [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" }, |
| 250 | [ST_F_SRV_ICUR] = { .name = "srv_icur", .desc = "Current number of idle connections available for reuse on this server" }, |
| 251 | [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] | 252 | [ST_F_QT_MAX] = { .name = "qtime_max", .desc = "Maximum observed time spent in the queue, in milliseconds (backend/server)" }, |
| 253 | [ST_F_CT_MAX] = { .name = "ctime_max", .desc = "Maximum observed time spent waiting for a connection to complete, in milliseconds (backend/server)" }, |
| 254 | [ST_F_RT_MAX] = { .name = "rtime_max", .desc = "Maximum observed time spent waiting for a server response, in milliseconds (backend/server)" }, |
| 255 | [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] | 256 | [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] | 257 | [ST_F_IDLE_CONN_CUR] = { .name = "idle_conn_cur", .desc = "Current number of unsafe idle connections"}, |
| 258 | [ST_F_SAFE_CONN_CUR] = { .name = "safe_conn_cur", .desc = "Current number of safe idle connections"}, |
| 259 | [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] | 260 | [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] | 261 | [ST_F_UWEIGHT] = { .name = "uweight", .desc = "Server's user weight, or sum of active servers' user weights for a backend" }, |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 262 | [ST_F_AGG_SRV_CHECK_STATUS] = { .name = "agg_server_check_status", .desc = "[DEPRECATED] Backend's aggregated gauge of servers' status" }, |
| 263 | [ST_F_AGG_SRV_STATUS ] = { .name = "agg_server_status", .desc = "Backend's aggregated gauge of servers' status" }, |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame] | 264 | [ST_F_AGG_CHECK_STATUS] = { .name = "agg_check_status", .desc = "Backend's aggregated gauge of servers' state check status" }, |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 265 | [ST_F_SRID] = { .name = "srid", .desc = "Server id revision, to prevent server id reuse mixups" }, |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 266 | [ST_F_SESS_OTHER] = { .name = "sess_other", .desc = "Total number of sessions other than HTTP since process started" }, |
| 267 | [ST_F_H1SESS] = { .name = "h1sess", .desc = "Total number of HTTP/1 sessions since process started" }, |
| 268 | [ST_F_H2SESS] = { .name = "h2sess", .desc = "Total number of HTTP/2 sessions since process started" }, |
| 269 | [ST_F_H3SESS] = { .name = "h3sess", .desc = "Total number of HTTP/3 sessions since process started" }, |
| 270 | [ST_F_REQ_OTHER] = { .name = "req_other", .desc = "Total number of sessions other than HTTP processed by this object since the worker process started" }, |
| 271 | [ST_F_H1REQ] = { .name = "h1req", .desc = "Total number of HTTP/1 sessions processed by this object since the worker process started" }, |
| 272 | [ST_F_H2REQ] = { .name = "h2req", .desc = "Total number of hTTP/2 sessions processed by this object since the worker process started" }, |
| 273 | [ST_F_H3REQ] = { .name = "h3req", .desc = "Total number of HTTP/3 sessions processed by this object since the worker process started" }, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 274 | }; |
| 275 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 276 | /* one line of info */ |
William Dauchy | 5d9b8f3 | 2021-01-11 20:07:49 +0100 | [diff] [blame] | 277 | THREAD_LOCAL struct field info[INF_TOTAL_FIELDS]; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 278 | |
| 279 | /* description of statistics (static and dynamic) */ |
| 280 | static struct name_desc *stat_f[STATS_DOMAIN_COUNT]; |
| 281 | static size_t stat_count[STATS_DOMAIN_COUNT]; |
| 282 | |
| 283 | /* one line for stats */ |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 284 | THREAD_LOCAL struct field *stat_l[STATS_DOMAIN_COUNT]; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 285 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 286 | /* list of all registered stats module */ |
| 287 | static struct list stats_module_list[STATS_DOMAIN_COUNT] = { |
| 288 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_PROXY]), |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 289 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_RESOLVERS]), |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 290 | }; |
| 291 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 292 | THREAD_LOCAL void *trash_counters; |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 293 | static THREAD_LOCAL struct buffer trash_chunk = BUF_NULL; |
| 294 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 295 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 296 | static inline uint8_t stats_get_domain(uint32_t domain) |
| 297 | { |
| 298 | return domain >> STATS_DOMAIN & STATS_DOMAIN_MASK; |
| 299 | } |
| 300 | |
Amaury Denoyelle | 72b16e5 | 2020-10-05 11:49:38 +0200 | [diff] [blame] | 301 | static inline enum stats_domain_px_cap stats_px_get_cap(uint32_t domain) |
| 302 | { |
| 303 | return domain >> STATS_PX_CAP & STATS_PX_CAP_MASK; |
| 304 | } |
| 305 | |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 306 | static void stats_dump_json_schema(struct buffer *out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 307 | |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 308 | int stats_putchk(struct channel *chn, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 309 | { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 310 | struct buffer *chk = &trash_chunk; |
| 311 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 312 | if (htx) { |
Christopher Faulet | 69fc88c | 2019-01-07 14:27:53 +0100 | [diff] [blame] | 313 | if (chk->data >= channel_htx_recv_max(chn, htx)) |
| 314 | return 0; |
Willy Tarreau | 0a7ef02 | 2019-05-28 10:30:11 +0200 | [diff] [blame] | 315 | if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 316 | return 0; |
Christopher Faulet | 5adbeeb | 2019-01-02 14:34:39 +0100 | [diff] [blame] | 317 | channel_add_input(chn, chk->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 318 | chk->data = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 319 | } |
| 320 | else { |
| 321 | if (ci_putchk(chn, chk) == -1) |
| 322 | return 0; |
| 323 | } |
| 324 | return 1; |
| 325 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 326 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 327 | static const char *stats_scope_ptr(struct appctx *appctx, struct stconn *sc) |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 328 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 329 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 330 | struct channel *req = sc_oc(sc); |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 331 | struct htx *htx = htxbuf(&req->buf); |
| 332 | struct htx_blk *blk; |
| 333 | struct ist uri; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 334 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 335 | blk = htx_get_head_blk(htx); |
Christopher Faulet | ea00973 | 2019-11-18 15:50:25 +0100 | [diff] [blame] | 336 | BUG_ON(!blk || htx_get_blk_type(blk) != HTX_BLK_REQ_SL); |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 337 | ALREADY_CHECKED(blk); |
| 338 | uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 339 | return uri.ptr + ctx->scope_str; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 340 | } |
| 341 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 342 | /* |
| 343 | * http_stats_io_handler() |
| 344 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 345 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 346 | * -> stats_dump_json_header() // emits the JSON headers (same as above) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 347 | * -> stats_dump_html_head() // emits the HTML headers |
| 348 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 349 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 350 | * -> stats_dump_html_px_hdr() |
| 351 | * -> stats_dump_fe_stats() |
| 352 | * -> stats_dump_li_stats() |
| 353 | * -> stats_dump_sv_stats() |
| 354 | * -> stats_dump_be_stats() |
| 355 | * -> stats_dump_html_px_end() |
| 356 | * -> stats_dump_html_end() // emits HTML trailer |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 357 | * -> stats_dump_json_end() // emits JSON trailer |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 358 | */ |
| 359 | |
| 360 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 361 | /* Dumps the stats CSV header to the local trash buffer. The caller is |
| 362 | * responsible for clearing it if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 363 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 364 | * so please only append new fields at the end, never in the middle. |
| 365 | */ |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 366 | static void stats_dump_csv_header(enum stats_domain domain) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 367 | { |
| 368 | int field; |
| 369 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 370 | chunk_appendf(&trash_chunk, "# "); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 371 | if (stat_f[domain]) { |
| 372 | for (field = 0; field < stat_count[domain]; ++field) { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 373 | chunk_appendf(&trash_chunk, "%s,", stat_f[domain][field].name); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 374 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 375 | /* print special delimiter on proxy stats to mark end of |
| 376 | static fields */ |
| 377 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 378 | chunk_appendf(&trash_chunk, "-,"); |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 382 | chunk_appendf(&trash_chunk, "\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 383 | } |
| 384 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 385 | /* Emits a stats field without any surrounding element and properly encoded to |
| 386 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 387 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 388 | 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] | 389 | { |
| 390 | switch (field_format(f, 0)) { |
| 391 | case FF_EMPTY: return 1; |
| 392 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 393 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 394 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 395 | 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] | 396 | case FF_FLT: { |
| 397 | size_t prev_data = out->data; |
| 398 | out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "%f", f->u.flt)); |
| 399 | return out->data; |
| 400 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 401 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 402 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 403 | } |
| 404 | } |
| 405 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 406 | const char *field_to_html_str(const struct field *f) |
| 407 | { |
| 408 | switch (field_format(f, 0)) { |
| 409 | case FF_S32: return U2H(f->u.s32); |
| 410 | case FF_S64: return U2H(f->u.s64); |
| 411 | case FF_U64: return U2H(f->u.u64); |
| 412 | case FF_U32: return U2H(f->u.u32); |
Willy Tarreau | 6004fb7 | 2021-05-08 07:37:38 +0200 | [diff] [blame] | 413 | case FF_FLT: return F2H(f->u.flt); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 414 | case FF_STR: return field_str(f, 0); |
| 415 | case FF_EMPTY: |
| 416 | default: |
| 417 | return ""; |
| 418 | } |
| 419 | } |
| 420 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 421 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 422 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 423 | * if the buffer is full. |
| 424 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 425 | 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] | 426 | { |
| 427 | switch (field_format(f, 0)) { |
| 428 | case FF_EMPTY: return 1; |
| 429 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 430 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 431 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 432 | 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] | 433 | case FF_FLT: { |
| 434 | size_t prev_data = out->data; |
| 435 | out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "flt:%f", f->u.flt)); |
| 436 | return out->data; |
| 437 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 438 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 439 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 440 | } |
| 441 | } |
| 442 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 443 | /* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per |
| 444 | * the recommendation for interoperable integers in section 6 of RFC 7159. |
| 445 | */ |
| 446 | #define JSON_INT_MAX ((1ULL << 53) - 1) |
| 447 | #define JSON_INT_MIN (0 - JSON_INT_MAX) |
| 448 | |
| 449 | /* Emits a stats field value and its type in JSON. |
| 450 | * Returns non-zero on success, 0 on error. |
| 451 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 452 | 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] | 453 | { |
| 454 | int old_len; |
| 455 | char buf[20]; |
| 456 | const char *type, *value = buf, *quote = ""; |
| 457 | |
| 458 | switch (field_format(f, 0)) { |
| 459 | case FF_EMPTY: return 1; |
| 460 | case FF_S32: type = "\"s32\""; |
| 461 | snprintf(buf, sizeof(buf), "%d", f->u.s32); |
| 462 | break; |
| 463 | case FF_U32: type = "\"u32\""; |
| 464 | snprintf(buf, sizeof(buf), "%u", f->u.u32); |
| 465 | break; |
| 466 | case FF_S64: type = "\"s64\""; |
| 467 | if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX) |
| 468 | return 0; |
| 469 | type = "\"s64\""; |
| 470 | snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64); |
| 471 | break; |
| 472 | case FF_U64: if (f->u.u64 > JSON_INT_MAX) |
| 473 | return 0; |
| 474 | type = "\"u64\""; |
| 475 | snprintf(buf, sizeof(buf), "%llu", |
| 476 | (unsigned long long) f->u.u64); |
Christopher Faulet | 52c91bb | 2019-09-28 10:37:31 +0200 | [diff] [blame] | 477 | break; |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 478 | case FF_FLT: type = "\"flt\""; |
Willy Tarreau | 065ba31 | 2021-05-08 10:38:20 +0200 | [diff] [blame] | 479 | flt_trim(buf, 0, snprintf(buf, sizeof(buf), "%f", f->u.flt)); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 480 | break; |
| 481 | case FF_STR: type = "\"str\""; |
| 482 | value = field_str(f, 0); |
| 483 | quote = "\""; |
| 484 | break; |
| 485 | default: snprintf(buf, sizeof(buf), "%u", f->type); |
| 486 | type = buf; |
| 487 | value = "unknown"; |
| 488 | quote = "\""; |
| 489 | break; |
| 490 | } |
| 491 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 492 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 493 | chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}", |
| 494 | type, quote, value, quote); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 495 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 496 | } |
| 497 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 498 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 499 | * Returns non-zero on success, 0 if the buffer is full. |
| 500 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 501 | int stats_emit_field_tags(struct buffer *out, const struct field *f, |
| 502 | char delim) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 503 | { |
| 504 | char origin, nature, scope; |
| 505 | |
| 506 | switch (field_origin(f, 0)) { |
| 507 | case FO_METRIC: origin = 'M'; break; |
| 508 | case FO_STATUS: origin = 'S'; break; |
| 509 | case FO_KEY: origin = 'K'; break; |
| 510 | case FO_CONFIG: origin = 'C'; break; |
| 511 | case FO_PRODUCT: origin = 'P'; break; |
| 512 | default: origin = '?'; break; |
| 513 | } |
| 514 | |
| 515 | switch (field_nature(f, 0)) { |
| 516 | case FN_GAUGE: nature = 'G'; break; |
| 517 | case FN_LIMIT: nature = 'L'; break; |
| 518 | case FN_MIN: nature = 'm'; break; |
| 519 | case FN_MAX: nature = 'M'; break; |
| 520 | case FN_RATE: nature = 'R'; break; |
| 521 | case FN_COUNTER: nature = 'C'; break; |
| 522 | case FN_DURATION: nature = 'D'; break; |
| 523 | case FN_AGE: nature = 'A'; break; |
| 524 | case FN_TIME: nature = 'T'; break; |
| 525 | case FN_NAME: nature = 'N'; break; |
| 526 | case FN_OUTPUT: nature = 'O'; break; |
| 527 | case FN_AVG: nature = 'a'; break; |
| 528 | default: nature = '?'; break; |
| 529 | } |
| 530 | |
| 531 | switch (field_scope(f, 0)) { |
| 532 | case FS_PROCESS: scope = 'P'; break; |
| 533 | case FS_SERVICE: scope = 'S'; break; |
| 534 | case FS_SYSTEM: scope = 's'; break; |
| 535 | case FS_CLUSTER: scope = 'C'; break; |
| 536 | default: scope = '?'; break; |
| 537 | } |
| 538 | |
| 539 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 540 | } |
| 541 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 542 | /* Emits an encoding of the field type as JSON. |
| 543 | * Returns non-zero on success, 0 if the buffer is full. |
| 544 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 545 | 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] | 546 | { |
| 547 | const char *origin, *nature, *scope; |
| 548 | int old_len; |
| 549 | |
| 550 | switch (field_origin(f, 0)) { |
| 551 | case FO_METRIC: origin = "Metric"; break; |
| 552 | case FO_STATUS: origin = "Status"; break; |
| 553 | case FO_KEY: origin = "Key"; break; |
| 554 | case FO_CONFIG: origin = "Config"; break; |
| 555 | case FO_PRODUCT: origin = "Product"; break; |
| 556 | default: origin = "Unknown"; break; |
| 557 | } |
| 558 | |
| 559 | switch (field_nature(f, 0)) { |
| 560 | case FN_GAUGE: nature = "Gauge"; break; |
| 561 | case FN_LIMIT: nature = "Limit"; break; |
| 562 | case FN_MIN: nature = "Min"; break; |
| 563 | case FN_MAX: nature = "Max"; break; |
| 564 | case FN_RATE: nature = "Rate"; break; |
| 565 | case FN_COUNTER: nature = "Counter"; break; |
| 566 | case FN_DURATION: nature = "Duration"; break; |
| 567 | case FN_AGE: nature = "Age"; break; |
| 568 | case FN_TIME: nature = "Time"; break; |
| 569 | case FN_NAME: nature = "Name"; break; |
| 570 | case FN_OUTPUT: nature = "Output"; break; |
| 571 | case FN_AVG: nature = "Avg"; break; |
| 572 | default: nature = "Unknown"; break; |
| 573 | } |
| 574 | |
| 575 | switch (field_scope(f, 0)) { |
| 576 | case FS_PROCESS: scope = "Process"; break; |
| 577 | case FS_SERVICE: scope = "Service"; break; |
| 578 | case FS_SYSTEM: scope = "System"; break; |
| 579 | case FS_CLUSTER: scope = "Cluster"; break; |
| 580 | default: scope = "Unknown"; break; |
| 581 | } |
| 582 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 583 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 584 | chunk_appendf(out, "\"tags\":{" |
| 585 | "\"origin\":\"%s\"," |
| 586 | "\"nature\":\"%s\"," |
| 587 | "\"scope\":\"%s\"" |
| 588 | "}", origin, nature, scope); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 589 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 590 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 591 | |
| 592 | /* Dump all fields from <stats> into <out> using CSV format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 593 | static int stats_dump_fields_csv(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 594 | const struct field *stats, size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 595 | struct show_stat_ctx *ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 596 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 597 | int domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 598 | int field; |
| 599 | |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 600 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 601 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 602 | return 0; |
| 603 | if (!chunk_strcat(out, ",")) |
| 604 | return 0; |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 605 | |
| 606 | /* print special delimiter on proxy stats to mark end of |
| 607 | static fields */ |
| 608 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) { |
| 609 | if (!chunk_strcat(out, "-,")) |
| 610 | return 0; |
| 611 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 612 | } |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 613 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 614 | chunk_strcat(out, "\n"); |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | /* 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] | 619 | static int stats_dump_fields_typed(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 620 | const struct field *stats, |
| 621 | size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 622 | struct show_stat_ctx * ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 623 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 624 | int flags = ctx->flags; |
| 625 | int domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 626 | int field; |
| 627 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 628 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 629 | if (!stats[field].type) |
| 630 | continue; |
| 631 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 632 | switch (domain) { |
| 633 | case STATS_DOMAIN_PROXY: |
| 634 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 635 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 636 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 637 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 638 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 639 | '?', |
| 640 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 641 | field, |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 642 | stat_f[domain][field].name, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 643 | stats[ST_F_PID].u.u32); |
| 644 | break; |
| 645 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 646 | case STATS_DOMAIN_RESOLVERS: |
| 647 | chunk_appendf(out, "N.%d.%s:", field, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 648 | stat_f[domain][field].name); |
| 649 | break; |
| 650 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 651 | default: |
| 652 | break; |
| 653 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 654 | |
| 655 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 656 | return 0; |
| 657 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 658 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 659 | |
Willy Tarreau | fc8e438 | 2021-06-17 07:22:27 +0200 | [diff] [blame] | 660 | if (flags & STAT_SHOW_FDESC && |
| 661 | !chunk_appendf(out, ":\"%s\"", stat_f[domain][field].desc)) { |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 662 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 663 | } |
| 664 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 665 | if (!chunk_strcat(out, "\n")) |
| 666 | return 0; |
| 667 | } |
| 668 | return 1; |
| 669 | } |
| 670 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 671 | /* 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] | 672 | static int stats_dump_json_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 673 | const struct field *info, |
| 674 | struct show_stat_ctx *ctx) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 675 | { |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 676 | int started = (ctx->field) ? 1 : 0; |
| 677 | int ready_data = 0; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 678 | |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 679 | if (!started && !chunk_strcat(out, "[")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 680 | return 0; |
| 681 | |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 682 | for (; ctx->field < INF_TOTAL_FIELDS; ctx->field++) { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 683 | int old_len; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 684 | int field = ctx->field; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 685 | |
| 686 | if (!field_format(info, field)) |
| 687 | continue; |
| 688 | |
| 689 | if (started && !chunk_strcat(out, ",")) |
| 690 | goto err; |
| 691 | started = 1; |
| 692 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 693 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 694 | chunk_appendf(out, |
| 695 | "{\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 696 | "\"processNum\":%u,", |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 697 | field, info_fields[field].name, |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 698 | info[INF_PROCESS_NUM].u.u32); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 699 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 700 | goto err; |
| 701 | |
| 702 | if (!stats_emit_json_field_tags(out, &info[field])) |
| 703 | goto err; |
| 704 | |
| 705 | if (!stats_emit_json_data_field(out, &info[field])) |
| 706 | goto err; |
| 707 | |
| 708 | if (!chunk_strcat(out, "}")) |
| 709 | goto err; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 710 | ready_data = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Willy Tarreau | c6b7a97 | 2022-06-10 15:12:21 +0200 | [diff] [blame] | 713 | if (!chunk_strcat(out, "]\n")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 714 | goto err; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 715 | ctx->field = 0; /* we're done */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 716 | return 1; |
| 717 | |
| 718 | err: |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 719 | if (!ready_data) { |
| 720 | /* not enough buffer space for a single entry.. */ |
| 721 | chunk_reset(out); |
| 722 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}\n"); |
| 723 | return 0; /* hard error */ |
| 724 | } |
| 725 | /* push ready data and wait for a new buffer to complete the dump */ |
| 726 | out->data = ready_data; |
| 727 | return 1; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 730 | static void stats_print_proxy_field_json(struct buffer *out, |
| 731 | const struct field *stat, |
| 732 | const char *name, |
| 733 | int pos, |
| 734 | uint32_t field_type, |
| 735 | uint32_t iid, |
| 736 | uint32_t sid, |
| 737 | uint32_t pid) |
| 738 | { |
| 739 | const char *obj_type; |
| 740 | switch (field_type) { |
| 741 | case STATS_TYPE_FE: obj_type = "Frontend"; break; |
| 742 | case STATS_TYPE_BE: obj_type = "Backend"; break; |
| 743 | case STATS_TYPE_SO: obj_type = "Listener"; break; |
| 744 | case STATS_TYPE_SV: obj_type = "Server"; break; |
| 745 | default: obj_type = "Unknown"; break; |
| 746 | } |
| 747 | |
| 748 | chunk_appendf(out, |
| 749 | "{" |
| 750 | "\"objType\":\"%s\"," |
| 751 | "\"proxyId\":%u," |
| 752 | "\"id\":%u," |
| 753 | "\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 754 | "\"processNum\":%u,", |
| 755 | obj_type, iid, sid, pos, name, pid); |
| 756 | } |
| 757 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 758 | static void stats_print_rslv_field_json(struct buffer *out, |
| 759 | const struct field *stat, |
| 760 | const char *name, |
| 761 | int pos) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 762 | { |
| 763 | chunk_appendf(out, |
| 764 | "{" |
| 765 | "\"field\":{\"pos\":%d,\"name\":\"%s\"},", |
| 766 | pos, name); |
| 767 | } |
| 768 | |
| 769 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 770 | /* 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] | 771 | static int stats_dump_fields_json(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 772 | const struct field *stats, size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 773 | struct show_stat_ctx *ctx) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 774 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 775 | int flags = ctx->flags; |
| 776 | int domain = ctx->domain; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 777 | int started = (ctx->field) ? 1 : 0; |
| 778 | int ready_data = 0; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 779 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 780 | if (!started && (flags & STAT_STARTED) && !chunk_strcat(out, ",")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 781 | return 0; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 782 | if (!started && !chunk_strcat(out, "[")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 783 | return 0; |
| 784 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 785 | for (; ctx->field < stats_count; ctx->field++) { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 786 | int old_len; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 787 | int field = ctx->field; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 788 | |
| 789 | if (!stats[field].type) |
| 790 | continue; |
| 791 | |
| 792 | if (started && !chunk_strcat(out, ",")) |
| 793 | goto err; |
| 794 | started = 1; |
| 795 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 796 | old_len = out->data; |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 797 | if (domain == STATS_DOMAIN_PROXY) { |
| 798 | stats_print_proxy_field_json(out, &stats[field], |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 799 | stat_f[domain][field].name, |
| 800 | field, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 801 | stats[ST_F_TYPE].u.u32, |
| 802 | stats[ST_F_IID].u.u32, |
| 803 | stats[ST_F_SID].u.u32, |
| 804 | stats[ST_F_PID].u.u32); |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 805 | } else if (domain == STATS_DOMAIN_RESOLVERS) { |
| 806 | stats_print_rslv_field_json(out, &stats[field], |
| 807 | stat_f[domain][field].name, |
| 808 | field); |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 809 | } |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 810 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 811 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 812 | goto err; |
| 813 | |
| 814 | if (!stats_emit_json_field_tags(out, &stats[field])) |
| 815 | goto err; |
| 816 | |
| 817 | if (!stats_emit_json_data_field(out, &stats[field])) |
| 818 | goto err; |
| 819 | |
| 820 | if (!chunk_strcat(out, "}")) |
| 821 | goto err; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 822 | ready_data = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | if (!chunk_strcat(out, "]")) |
| 826 | goto err; |
| 827 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 828 | ctx->field = 0; /* we're done */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 829 | return 1; |
| 830 | |
| 831 | err: |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 832 | if (!ready_data) { |
| 833 | /* not enough buffer space for a single entry.. */ |
| 834 | chunk_reset(out); |
| 835 | if (ctx->flags & STAT_STARTED) |
| 836 | chunk_strcat(out, ","); |
| 837 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}"); |
| 838 | return 0; /* hard error */ |
| 839 | } |
| 840 | /* push ready data and wait for a new buffer to complete the dump */ |
| 841 | out->data = ready_data; |
| 842 | return 1; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 843 | } |
| 844 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 845 | /* 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] | 846 | * 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] | 847 | * are provided if STAT_SHLGNDS is present in <flags>. The statistics from |
| 848 | * extra modules are displayed at the end of the lines if STAT_SHMODULES is |
| 849 | * present in <flags>. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 850 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 851 | static int stats_dump_fields_html(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 852 | const struct field *stats, |
| 853 | struct show_stat_ctx *ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 854 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 855 | struct buffer src; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 856 | struct stats_module *mod; |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 857 | int flags = ctx->flags; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 858 | int i = 0, j = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 859 | |
| 860 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
| 861 | chunk_appendf(out, |
| 862 | /* name, queue */ |
| 863 | "<tr class=\"frontend\">"); |
| 864 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 865 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 866 | /* Column sub-heading for Enable or Disable server */ |
| 867 | chunk_appendf(out, "<td></td>"); |
| 868 | } |
| 869 | |
| 870 | chunk_appendf(out, |
| 871 | "<td class=ac>" |
| 872 | "<a name=\"%s/Frontend\"></a>" |
| 873 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 874 | "<td colspan=3></td>" |
| 875 | "", |
| 876 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 877 | |
| 878 | chunk_appendf(out, |
| 879 | /* sessions rate : current */ |
| 880 | "<td><u>%s<div class=tips><table class=det>" |
| 881 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 882 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 883 | "", |
| 884 | U2H(stats[ST_F_RATE].u.u32), |
| 885 | U2H(stats[ST_F_CONN_RATE].u.u32), |
| 886 | U2H(stats[ST_F_RATE].u.u32)); |
| 887 | |
| 888 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 889 | chunk_appendf(out, |
| 890 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
| 891 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
| 892 | |
| 893 | chunk_appendf(out, |
| 894 | "</table></div></u></td>" |
| 895 | /* sessions rate : max */ |
| 896 | "<td><u>%s<div class=tips><table class=det>" |
| 897 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 898 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 899 | "", |
| 900 | U2H(stats[ST_F_RATE_MAX].u.u32), |
| 901 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
| 902 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 903 | |
| 904 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 905 | chunk_appendf(out, |
| 906 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
| 907 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
| 908 | |
| 909 | chunk_appendf(out, |
| 910 | "</table></div></u></td>" |
| 911 | /* sessions rate : limit */ |
| 912 | "<td>%s</td>", |
| 913 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
| 914 | |
| 915 | chunk_appendf(out, |
| 916 | /* sessions: current, max, limit, total */ |
| 917 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 918 | "<td><u>%s<div class=tips><table class=det>" |
| 919 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 920 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 921 | "", |
| 922 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 923 | U2H(stats[ST_F_STOT].u.u64), |
| 924 | U2H(stats[ST_F_CONN_TOT].u.u64), |
| 925 | U2H(stats[ST_F_STOT].u.u64)); |
| 926 | |
| 927 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 928 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 929 | chunk_appendf(out, |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 930 | "<tr><th>- HTTP/1 sessions:</th><td>%s</td></tr>" |
| 931 | "<tr><th>- HTTP/2 sessions:</th><td>%s</td></tr>" |
| 932 | "<tr><th>- HTTP/3 sessions:</th><td>%s</td></tr>" |
| 933 | "<tr><th>- other sessions:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 934 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 935 | "<tr><th>- HTTP/1 requests:</th><td>%s</td></tr>" |
| 936 | "<tr><th>- HTTP/2 requests:</th><td>%s</td></tr>" |
| 937 | "<tr><th>- HTTP/3 requests:</th><td>%s</td></tr>" |
| 938 | "<tr><th>- other requests:</th><td>%s</td></tr>" |
| 939 | "", |
| 940 | U2H(stats[ST_F_H1SESS].u.u64), |
| 941 | U2H(stats[ST_F_H2SESS].u.u64), |
| 942 | U2H(stats[ST_F_H3SESS].u.u64), |
| 943 | U2H(stats[ST_F_SESS_OTHER].u.u64), |
| 944 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 945 | U2H(stats[ST_F_H1REQ].u.u64), |
| 946 | U2H(stats[ST_F_H2REQ].u.u64), |
| 947 | U2H(stats[ST_F_H3REQ].u.u64), |
| 948 | U2H(stats[ST_F_REQ_OTHER].u.u64)); |
| 949 | |
| 950 | chunk_appendf(out, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 951 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 952 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 953 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 954 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 955 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 956 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 957 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 958 | "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 959 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 960 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 961 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 962 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 963 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 964 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 965 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 966 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 967 | U2H(stats[ST_F_HRSP_OTHER].u.u64)); |
| 968 | |
| 969 | chunk_appendf(out, |
| 970 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 971 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 972 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 973 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
| 974 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
| 975 | "", |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 976 | U2H(stats[ST_F_INTERCEPTED].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 977 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 978 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 979 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 980 | (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] | 981 | U2H(stats[ST_F_WREW].u.u64), |
| 982 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | chunk_appendf(out, |
| 986 | "</table></div></u></td>" |
| 987 | /* sessions: lbtot, lastsess */ |
| 988 | "<td></td><td></td>" |
| 989 | /* bytes : in */ |
| 990 | "<td>%s</td>" |
| 991 | "", |
| 992 | U2H(stats[ST_F_BIN].u.u64)); |
| 993 | |
| 994 | chunk_appendf(out, |
| 995 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 996 | "<td>%s%s<div class=tips><table class=det>" |
| 997 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 998 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 999 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1000 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1001 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1002 | "</table></div>%s</td>", |
| 1003 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1004 | U2H(stats[ST_F_BOUT].u.u64), |
| 1005 | U2H(stats[ST_F_BOUT].u.u64), |
| 1006 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1007 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1008 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1009 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1010 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1011 | 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, |
| 1012 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1013 | |
| 1014 | chunk_appendf(out, |
| 1015 | /* denied: req, resp */ |
| 1016 | "<td>%s</td><td>%s</td>" |
| 1017 | /* errors : request, connect, response */ |
| 1018 | "<td>%s</td><td></td><td></td>" |
| 1019 | /* warnings: retries, redispatches */ |
| 1020 | "<td></td><td></td>" |
| 1021 | /* server status : reflect frontend status */ |
| 1022 | "<td class=ac>%s</td>" |
| 1023 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1024 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1025 | "", |
| 1026 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1027 | U2H(stats[ST_F_EREQ].u.u64), |
| 1028 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1029 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1030 | if (flags & STAT_SHMODULES) { |
| 1031 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1032 | chunk_appendf(out, "<td>"); |
| 1033 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1034 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1035 | chunk_appendf(out, |
| 1036 | "<u>%s<div class=tips><table class=det>", |
| 1037 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1038 | for (j = 0; j < mod->stats_count; ++j) { |
| 1039 | chunk_appendf(out, |
| 1040 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1041 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1042 | ++i; |
| 1043 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1044 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1045 | } else { |
| 1046 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1047 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1048 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1049 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1050 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1054 | } |
| 1055 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
| 1056 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1057 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1058 | /* Column sub-heading for Enable or Disable server */ |
| 1059 | chunk_appendf(out, "<td></td>"); |
| 1060 | } |
| 1061 | |
| 1062 | chunk_appendf(out, |
| 1063 | /* frontend name, listener name */ |
| 1064 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 1065 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 1066 | "", |
| 1067 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1068 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1069 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 1070 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1071 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1072 | chunk_appendf(out, "<div class=tips>"); |
| 1073 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 1074 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1075 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 1076 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 1077 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1078 | else if (*field_str(stats, ST_F_ADDR)) |
| 1079 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1080 | |
| 1081 | /* id */ |
| 1082 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
| 1083 | } |
| 1084 | |
| 1085 | chunk_appendf(out, |
| 1086 | /* queue */ |
| 1087 | "%s</td><td colspan=3></td>" |
| 1088 | /* sessions rate: current, max, limit */ |
| 1089 | "<td colspan=3> </td>" |
| 1090 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 1091 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1092 | "<td>%s</td><td> </td><td> </td>" |
| 1093 | /* bytes: in, out */ |
| 1094 | "<td>%s</td><td>%s</td>" |
| 1095 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1096 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1097 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 1098 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 1099 | |
| 1100 | chunk_appendf(out, |
| 1101 | /* denied: req, resp */ |
| 1102 | "<td>%s</td><td>%s</td>" |
| 1103 | /* errors: request, connect, response */ |
| 1104 | "<td>%s</td><td></td><td></td>" |
| 1105 | /* warnings: retries, redispatches */ |
| 1106 | "<td></td><td></td>" |
| 1107 | /* server status: reflect listener status */ |
| 1108 | "<td class=ac>%s</td>" |
| 1109 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1110 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1111 | "", |
| 1112 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1113 | U2H(stats[ST_F_EREQ].u.u64), |
| 1114 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1115 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1116 | if (flags & STAT_SHMODULES) { |
| 1117 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1118 | chunk_appendf(out, "<td>"); |
| 1119 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1120 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1121 | chunk_appendf(out, |
| 1122 | "<u>%s<div class=tips><table class=det>", |
| 1123 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1124 | for (j = 0; j < mod->stats_count; ++j) { |
| 1125 | chunk_appendf(out, |
| 1126 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1127 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1128 | ++i; |
| 1129 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1130 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1131 | } else { |
| 1132 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1133 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1134 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1135 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1136 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1140 | } |
| 1141 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 1142 | const char *style; |
| 1143 | |
| 1144 | /* determine the style to use depending on the server's state, |
| 1145 | * its health and weight. There isn't a 1-to-1 mapping between |
| 1146 | * state and styles for the cases where the server is (still) |
| 1147 | * up. The reason is that we don't want to report nolb and |
| 1148 | * drain with the same color. |
| 1149 | */ |
| 1150 | |
| 1151 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 1152 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 1153 | style = "down"; |
| 1154 | } |
Florian Apolloner | 39272c2 | 2021-03-30 13:28:35 +0200 | [diff] [blame] | 1155 | 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] | 1156 | style = "going_up"; |
| 1157 | } |
Daniel Corbett | b428517 | 2020-03-28 12:35:50 -0400 | [diff] [blame] | 1158 | else if (strcmp(field_str(stats, ST_F_STATUS), "DRAIN") == 0) { |
| 1159 | style = "draining"; |
| 1160 | } |
Florian Apolloner | 39272c2 | 2021-03-30 13:28:35 +0200 | [diff] [blame] | 1161 | 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] | 1162 | style = "going_down"; |
| 1163 | } |
| 1164 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 1165 | style = "nolb"; |
| 1166 | } |
| 1167 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 1168 | style = "no_check"; |
| 1169 | } |
| 1170 | else if (!stats[ST_F_CHKFAIL].type || |
| 1171 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 1172 | /* no check or max health = UP */ |
| 1173 | if (stats[ST_F_WEIGHT].u.u32) |
| 1174 | style = "up"; |
| 1175 | else |
| 1176 | style = "draining"; |
| 1177 | } |
| 1178 | else { |
| 1179 | style = "going_down"; |
| 1180 | } |
| 1181 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1182 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1183 | chunk_appendf(out, "<tr class=\"maintain\">"); |
| 1184 | else |
| 1185 | chunk_appendf(out, |
| 1186 | "<tr class=\"%s_%s\">", |
| 1187 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
| 1188 | |
| 1189 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1190 | if (flags & STAT_ADMIN) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1191 | chunk_appendf(out, |
David Harrigan | d3db35a | 2016-12-30 12:12:49 +0000 | [diff] [blame] | 1192 | "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 1193 | field_str(stats, ST_F_PXNAME), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1194 | field_str(stats, ST_F_SVNAME)); |
| 1195 | |
| 1196 | chunk_appendf(out, |
| 1197 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 1198 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 1199 | "", |
| 1200 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1201 | (flags & STAT_SHLGNDS) ? "<u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1202 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 1203 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1204 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1205 | chunk_appendf(out, "<div class=tips>"); |
| 1206 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 1207 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1208 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 1209 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 1210 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1211 | else if (*field_str(stats, ST_F_ADDR)) |
| 1212 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1213 | |
| 1214 | /* id */ |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 1215 | chunk_appendf(out, "id: %d, rid: %d", stats[ST_F_SID].u.u32, stats[ST_F_SRID].u.u32); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1216 | |
| 1217 | /* cookie */ |
| 1218 | if (stats[ST_F_COOKIE].type) { |
| 1219 | chunk_appendf(out, ", cookie: '"); |
| 1220 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1221 | chunk_htmlencode(out, &src); |
| 1222 | chunk_appendf(out, "'"); |
| 1223 | } |
| 1224 | |
| 1225 | chunk_appendf(out, "</div>"); |
| 1226 | } |
| 1227 | |
| 1228 | chunk_appendf(out, |
| 1229 | /* queue : current, max, limit */ |
| 1230 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 1231 | /* sessions rate : current, max, limit */ |
| 1232 | "<td>%s</td><td>%s</td><td></td>" |
| 1233 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1234 | (flags & STAT_SHLGNDS) ? "</u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1235 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 1236 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1237 | |
| 1238 | chunk_appendf(out, |
| 1239 | /* sessions: current, max, limit, total */ |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1240 | "<td><u>%s<div class=tips>" |
| 1241 | "<table class=det>" |
| 1242 | "<tr><th>Current active connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1243 | "<tr><th>Current used connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1244 | "<tr><th>Current idle connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1245 | "<tr><th>- unsafe:</th><td>%s</td></tr>" |
| 1246 | "<tr><th>- safe:</th><td>%s</td></tr>" |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1247 | "<tr><th>Estimated need of connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1248 | "<tr><th>Active connections limit:</th><td>%s</td></tr>" |
| 1249 | "<tr><th>Idle connections limit:</th><td>%s</td></tr>" |
| 1250 | "</table></div></u>" |
| 1251 | "</td><td>%s</td><td>%s</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1252 | "<td><u>%s<div class=tips><table class=det>" |
| 1253 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1254 | "", |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1255 | U2H(stats[ST_F_SCUR].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1256 | U2H(stats[ST_F_SCUR].u.u32), |
| 1257 | U2H(stats[ST_F_USED_CONN_CUR].u.u32), |
| 1258 | U2H(stats[ST_F_SRV_ICUR].u.u32), |
| 1259 | U2H(stats[ST_F_IDLE_CONN_CUR].u.u32), |
| 1260 | U2H(stats[ST_F_SAFE_CONN_CUR].u.u32), |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1261 | U2H(stats[ST_F_NEED_CONN_EST].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1262 | |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1263 | LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 1264 | stats[ST_F_SRV_ILIM].type ? U2H(stats[ST_F_SRV_ILIM].u.u32) : "-", |
| 1265 | 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] | 1266 | U2H(stats[ST_F_STOT].u.u64), |
| 1267 | U2H(stats[ST_F_STOT].u.u64)); |
| 1268 | |
| 1269 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1270 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1271 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1272 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1273 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1274 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1275 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1276 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1277 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1278 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1279 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1280 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1281 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1282 | "<tr><th>Internal error:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1283 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1284 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1285 | U2H(stats[ST_F_REUSE].u.u64), |
| 1286 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1287 | (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] | 1288 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1289 | U2H(stats[ST_F_HRSP_1XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1290 | (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1291 | U2H(stats[ST_F_HRSP_2XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1292 | (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1293 | U2H(stats[ST_F_HRSP_3XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1294 | (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1295 | U2H(stats[ST_F_HRSP_4XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1296 | (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1297 | U2H(stats[ST_F_HRSP_5XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1298 | (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1299 | U2H(stats[ST_F_HRSP_OTHER].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1300 | (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] | 1301 | U2H(stats[ST_F_WREW].u.u64), |
| 1302 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1305 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1306 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1307 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1308 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1309 | 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] | 1310 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1311 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1312 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1313 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1314 | 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] | 1315 | |
| 1316 | chunk_appendf(out, |
| 1317 | "</table></div></u></td>" |
| 1318 | /* sessions: lbtot, last */ |
| 1319 | "<td>%s</td><td>%s</td>", |
| 1320 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1321 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
| 1322 | |
| 1323 | chunk_appendf(out, |
| 1324 | /* bytes : in, out */ |
| 1325 | "<td>%s</td><td>%s</td>" |
| 1326 | /* denied: req, resp */ |
| 1327 | "<td></td><td>%s</td>" |
| 1328 | /* errors : request, connect */ |
| 1329 | "<td></td><td>%s</td>" |
| 1330 | /* errors : response */ |
| 1331 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1332 | /* warnings: retries, redispatches */ |
| 1333 | "<td>%lld</td><td>%lld</td>" |
| 1334 | "", |
| 1335 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 1336 | U2H(stats[ST_F_DRESP].u.u64), |
| 1337 | U2H(stats[ST_F_ECON].u.u64), |
| 1338 | U2H(stats[ST_F_ERESP].u.u64), |
| 1339 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1340 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1341 | (long long)stats[ST_F_WRETR].u.u64, |
| 1342 | (long long)stats[ST_F_WREDIS].u.u64); |
| 1343 | |
| 1344 | /* status, last change */ |
| 1345 | chunk_appendf(out, "<td class=ac>"); |
| 1346 | |
| 1347 | /* FIXME!!!! |
| 1348 | * LASTCHG should contain the last change for *this* server and must be computed |
| 1349 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 1350 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 1351 | */ |
| 1352 | |
| 1353 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1354 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1355 | chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); |
| 1356 | } |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1357 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1358 | chunk_strcat(out, "<i>no check</i>"); |
| 1359 | } |
| 1360 | else { |
| 1361 | 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] | 1362 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1363 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
| 1364 | chunk_strcat(out, " ↑"); |
| 1365 | } |
| 1366 | else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) |
| 1367 | chunk_strcat(out, " ↓"); |
| 1368 | } |
| 1369 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1370 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1371 | stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { |
| 1372 | chunk_appendf(out, |
| 1373 | "</td><td class=ac><u> %s", |
| 1374 | field_str(stats, ST_F_AGENT_STATUS)); |
| 1375 | |
| 1376 | if (stats[ST_F_AGENT_CODE].type) |
| 1377 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
| 1378 | |
| 1379 | if (stats[ST_F_AGENT_DURATION].type) |
| 1380 | chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); |
| 1381 | |
| 1382 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC)); |
| 1383 | |
| 1384 | if (*field_str(stats, ST_F_LAST_AGT)) { |
| 1385 | chunk_appendf(out, ": "); |
| 1386 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
| 1387 | chunk_htmlencode(out, &src); |
| 1388 | } |
| 1389 | chunk_appendf(out, "</div></u>"); |
| 1390 | } |
| 1391 | else if (stats[ST_F_CHECK_STATUS].type) { |
| 1392 | chunk_appendf(out, |
| 1393 | "</td><td class=ac><u> %s", |
| 1394 | field_str(stats, ST_F_CHECK_STATUS)); |
| 1395 | |
| 1396 | if (stats[ST_F_CHECK_CODE].type) |
| 1397 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
| 1398 | |
| 1399 | if (stats[ST_F_CHECK_DURATION].type) |
| 1400 | chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); |
| 1401 | |
| 1402 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC)); |
| 1403 | |
| 1404 | if (*field_str(stats, ST_F_LAST_CHK)) { |
| 1405 | chunk_appendf(out, ": "); |
| 1406 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
| 1407 | chunk_htmlencode(out, &src); |
| 1408 | } |
| 1409 | chunk_appendf(out, "</div></u>"); |
| 1410 | } |
| 1411 | else |
| 1412 | chunk_appendf(out, "</td><td>"); |
| 1413 | |
| 1414 | chunk_appendf(out, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1415 | /* weight / uweight */ |
| 1416 | "</td><td class=ac>%d/%d</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1417 | /* act, bck */ |
| 1418 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 1419 | "", |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1420 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1421 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 1422 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 1423 | |
| 1424 | /* check failures: unique, fatal, down time */ |
| 1425 | if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) { |
| 1426 | chunk_appendf(out, "<td class=ac colspan=3>resolution</td>"); |
| 1427 | } |
| 1428 | else if (stats[ST_F_CHKFAIL].type) { |
| 1429 | chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64); |
| 1430 | |
| 1431 | if (stats[ST_F_HANAFAIL].type) |
| 1432 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
| 1433 | |
| 1434 | chunk_appendf(out, |
| 1435 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 1436 | "<td>%lld</td><td>%s</td>" |
| 1437 | "", |
| 1438 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 1439 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 1440 | } |
| 1441 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 1442 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
| 1443 | chunk_appendf(out, |
| 1444 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 1445 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 1446 | } |
| 1447 | else |
| 1448 | chunk_appendf(out, "<td colspan=3></td>"); |
| 1449 | |
| 1450 | /* throttle */ |
| 1451 | if (stats[ST_F_THROTTLE].type) |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1452 | 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] | 1453 | else |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1454 | chunk_appendf(out, "<td class=ac>-</td>"); |
| 1455 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1456 | if (flags & STAT_SHMODULES) { |
| 1457 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1458 | chunk_appendf(out, "<td>"); |
| 1459 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1460 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1461 | chunk_appendf(out, |
| 1462 | "<u>%s<div class=tips><table class=det>", |
| 1463 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1464 | for (j = 0; j < mod->stats_count; ++j) { |
| 1465 | chunk_appendf(out, |
| 1466 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1467 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1468 | ++i; |
| 1469 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1470 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1471 | } else { |
| 1472 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1473 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1474 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1475 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1476 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | chunk_appendf(out, "</tr>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1480 | } |
| 1481 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
| 1482 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1483 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1484 | /* Column sub-heading for Enable or Disable server */ |
| 1485 | chunk_appendf(out, "<td></td>"); |
| 1486 | } |
| 1487 | chunk_appendf(out, |
| 1488 | "<td class=ac>" |
| 1489 | /* name */ |
| 1490 | "%s<a name=\"%s/Backend\"></a>" |
| 1491 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 1492 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1493 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1494 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 1495 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1496 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1497 | /* balancing */ |
| 1498 | chunk_appendf(out, "<div class=tips>balancing: %s", |
| 1499 | field_str(stats, ST_F_ALGO)); |
| 1500 | |
| 1501 | /* cookie */ |
| 1502 | if (stats[ST_F_COOKIE].type) { |
| 1503 | chunk_appendf(out, ", cookie: '"); |
| 1504 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1505 | chunk_htmlencode(out, &src); |
| 1506 | chunk_appendf(out, "'"); |
| 1507 | } |
| 1508 | chunk_appendf(out, "</div>"); |
| 1509 | } |
| 1510 | |
| 1511 | chunk_appendf(out, |
| 1512 | "%s</td>" |
| 1513 | /* queue : current, max */ |
| 1514 | "<td>%s</td><td>%s</td><td></td>" |
| 1515 | /* sessions rate : current, max, limit */ |
| 1516 | "<td>%s</td><td>%s</td><td></td>" |
| 1517 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1518 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1519 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 1520 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1521 | |
| 1522 | chunk_appendf(out, |
| 1523 | /* sessions: current, max, limit, total */ |
| 1524 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1525 | "<td><u>%s<div class=tips><table class=det>" |
| 1526 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1527 | "", |
Willy Tarreau | 8e0f175 | 2016-12-12 15:07:29 +0100 | [diff] [blame] | 1528 | 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] | 1529 | U2H(stats[ST_F_STOT].u.u64), |
| 1530 | U2H(stats[ST_F_STOT].u.u64)); |
| 1531 | |
| 1532 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1533 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 1534 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1535 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1536 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1537 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1538 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1539 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1540 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1541 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1542 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1543 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1544 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1545 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 1546 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1547 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1548 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1549 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1550 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1551 | U2H(stats[ST_F_REUSE].u.u64), |
| 1552 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1553 | (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] | 1554 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1555 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 1556 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 1557 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 1558 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 1559 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 1560 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 1561 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 1562 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Willy Tarreau | feead3a | 2018-12-14 13:48:44 +0100 | [diff] [blame] | 1563 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1564 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 1565 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 1566 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 1567 | (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] | 1568 | U2H(stats[ST_F_WREW].u.u64), |
| 1569 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1570 | } |
| 1571 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1572 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1573 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1574 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1575 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1576 | 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] | 1577 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1578 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1579 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1580 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1581 | 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] | 1582 | |
| 1583 | chunk_appendf(out, |
| 1584 | "</table></div></u></td>" |
| 1585 | /* sessions: lbtot, last */ |
| 1586 | "<td>%s</td><td>%s</td>" |
| 1587 | /* bytes: in */ |
| 1588 | "<td>%s</td>" |
| 1589 | "", |
| 1590 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1591 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 1592 | U2H(stats[ST_F_BIN].u.u64)); |
| 1593 | |
| 1594 | chunk_appendf(out, |
| 1595 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 1596 | "<td>%s%s<div class=tips><table class=det>" |
| 1597 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 1598 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 1599 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1600 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1601 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1602 | "</table></div>%s</td>", |
| 1603 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1604 | U2H(stats[ST_F_BOUT].u.u64), |
| 1605 | U2H(stats[ST_F_BOUT].u.u64), |
| 1606 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1607 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1608 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1609 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1610 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1611 | 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, |
| 1612 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1613 | |
| 1614 | chunk_appendf(out, |
| 1615 | /* denied: req, resp */ |
| 1616 | "<td>%s</td><td>%s</td>" |
| 1617 | /* errors : request, connect */ |
| 1618 | "<td></td><td>%s</td>" |
| 1619 | /* errors : response */ |
| 1620 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1621 | /* warnings: retries, redispatches */ |
| 1622 | "<td>%lld</td><td>%lld</td>" |
| 1623 | /* backend status: reflect backend status (up/down): we display UP |
| 1624 | * if the backend has known working servers or if it has no server at |
| 1625 | * all (eg: for stats). Then we display the total weight, number of |
| 1626 | * active and backups. */ |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1627 | "<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] | 1628 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 1629 | "", |
| 1630 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1631 | U2H(stats[ST_F_ECON].u.u64), |
| 1632 | U2H(stats[ST_F_ERESP].u.u64), |
| 1633 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1634 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1635 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 1636 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 1637 | 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] | 1638 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1639 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 1640 | |
| 1641 | chunk_appendf(out, |
| 1642 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 1643 | "<td class=ac> </td><td>%d</td>" |
| 1644 | "<td>%s</td>" |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1645 | "<td></td>", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1646 | stats[ST_F_CHKDOWN].u.u32, |
| 1647 | 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] | 1648 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1649 | if (flags & STAT_SHMODULES) { |
| 1650 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1651 | chunk_appendf(out, "<td>"); |
| 1652 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1653 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1654 | chunk_appendf(out, |
| 1655 | "<u>%s<div class=tips><table class=det>", |
| 1656 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1657 | for (j = 0; j < mod->stats_count; ++j) { |
| 1658 | chunk_appendf(out, |
| 1659 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1660 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1661 | ++i; |
| 1662 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1663 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1664 | } else { |
| 1665 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1666 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1667 | |
| 1668 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1669 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1670 | } |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1671 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1672 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1673 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1674 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1675 | return 1; |
| 1676 | } |
| 1677 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 1678 | int stats_dump_one_line(const struct field *stats, size_t stats_count, |
| 1679 | struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1680 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1681 | struct show_stat_ctx *ctx = appctx->svcctx; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1682 | int ret; |
| 1683 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1684 | if (ctx->flags & STAT_FMT_HTML) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1685 | ret = stats_dump_fields_html(&trash_chunk, stats, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1686 | else if (ctx->flags & STAT_FMT_TYPED) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1687 | ret = stats_dump_fields_typed(&trash_chunk, stats, stats_count, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1688 | else if (ctx->flags & STAT_FMT_JSON) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1689 | ret = stats_dump_fields_json(&trash_chunk, stats, stats_count, ctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1690 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1691 | ret = stats_dump_fields_csv(&trash_chunk, stats, stats_count, ctx); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1692 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1693 | return ret; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1696 | /* Fill <stats> with the frontend statistics. <stats> is preallocated array of |
Christopher Faulet | d808f17 | 2021-01-22 17:33:22 +0100 | [diff] [blame] | 1697 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 1698 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 1699 | * this value, or if the selected field is not implemented for frontends, the |
| 1700 | * function returns 0, otherwise, it returns 1. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1701 | */ |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1702 | int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len, |
| 1703 | enum stat_field *selected_field) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1704 | { |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1705 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1706 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1707 | if (len < ST_F_TOTAL_FIELDS) |
| 1708 | return 0; |
| 1709 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1710 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
Christopher Faulet | 8596bfb | 2021-01-25 15:16:41 +0100 | [diff] [blame] | 1711 | struct field metric = { 0 }; |
| 1712 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1713 | switch (current_field) { |
| 1714 | case ST_F_PXNAME: |
| 1715 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1716 | break; |
| 1717 | case ST_F_SVNAME: |
| 1718 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
| 1719 | break; |
| 1720 | case ST_F_MODE: |
| 1721 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1722 | break; |
| 1723 | case ST_F_SCUR: |
| 1724 | metric = mkf_u32(0, px->feconn); |
| 1725 | break; |
| 1726 | case ST_F_SMAX: |
| 1727 | metric = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 1728 | break; |
| 1729 | case ST_F_SLIM: |
| 1730 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 1731 | break; |
| 1732 | case ST_F_STOT: |
| 1733 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 1734 | break; |
| 1735 | case ST_F_BIN: |
| 1736 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 1737 | break; |
| 1738 | case ST_F_BOUT: |
| 1739 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 1740 | break; |
| 1741 | case ST_F_DREQ: |
| 1742 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 1743 | break; |
| 1744 | case ST_F_DRESP: |
| 1745 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 1746 | break; |
| 1747 | case ST_F_EREQ: |
| 1748 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 1749 | break; |
| 1750 | case ST_F_DCON: |
| 1751 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); |
| 1752 | break; |
| 1753 | case ST_F_DSES: |
| 1754 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); |
| 1755 | break; |
Aurelien DARRAGON | cddec0a | 2022-09-09 15:58:57 +0200 | [diff] [blame] | 1756 | case ST_F_STATUS: { |
| 1757 | const char *state; |
| 1758 | |
| 1759 | if (px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) |
| 1760 | state = "STOP"; |
| 1761 | else if (px->flags & PR_FL_PAUSED) |
| 1762 | state = "PAUSED"; |
| 1763 | else |
| 1764 | state = "OPEN"; |
| 1765 | metric = mkf_str(FO_STATUS, state); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1766 | break; |
Aurelien DARRAGON | cddec0a | 2022-09-09 15:58:57 +0200 | [diff] [blame] | 1767 | } |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1768 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 1769 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1770 | break; |
| 1771 | case ST_F_IID: |
| 1772 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1773 | break; |
| 1774 | case ST_F_SID: |
| 1775 | metric = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 1776 | break; |
| 1777 | case ST_F_TYPE: |
| 1778 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 1779 | break; |
| 1780 | case ST_F_RATE: |
| 1781 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 1782 | break; |
| 1783 | case ST_F_RATE_LIM: |
| 1784 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 1785 | break; |
| 1786 | case ST_F_RATE_MAX: |
| 1787 | metric = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 1788 | break; |
| 1789 | case ST_F_WREW: |
| 1790 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites); |
| 1791 | break; |
| 1792 | case ST_F_EINT: |
| 1793 | metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors); |
| 1794 | break; |
| 1795 | case ST_F_HRSP_1XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1796 | if (px->mode == PR_MODE_HTTP) |
| 1797 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1798 | break; |
| 1799 | case ST_F_HRSP_2XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1800 | if (px->mode == PR_MODE_HTTP) |
| 1801 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1802 | break; |
| 1803 | case ST_F_HRSP_3XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1804 | if (px->mode == PR_MODE_HTTP) |
| 1805 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1806 | break; |
| 1807 | case ST_F_HRSP_4XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1808 | if (px->mode == PR_MODE_HTTP) |
| 1809 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1810 | break; |
| 1811 | case ST_F_HRSP_5XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1812 | if (px->mode == PR_MODE_HTTP) |
| 1813 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1814 | break; |
| 1815 | case ST_F_HRSP_OTHER: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1816 | if (px->mode == PR_MODE_HTTP) |
| 1817 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1818 | break; |
| 1819 | case ST_F_INTERCEPTED: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1820 | if (px->mode == PR_MODE_HTTP) |
| 1821 | metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1822 | break; |
| 1823 | case ST_F_CACHE_LOOKUPS: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1824 | if (px->mode == PR_MODE_HTTP) |
| 1825 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1826 | break; |
| 1827 | case ST_F_CACHE_HITS: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1828 | if (px->mode == PR_MODE_HTTP) |
| 1829 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1830 | break; |
| 1831 | case ST_F_REQ_RATE: |
| 1832 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 1833 | break; |
| 1834 | case ST_F_REQ_RATE_MAX: |
| 1835 | metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 1836 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1837 | case ST_F_REQ_TOT: { |
| 1838 | int i; |
| 1839 | uint64_t total_req; |
| 1840 | size_t nb_reqs = |
| 1841 | sizeof(px->fe_counters.p.http.cum_req) / sizeof(*px->fe_counters.p.http.cum_req); |
| 1842 | |
| 1843 | total_req = 0; |
| 1844 | for (i = 0; i < nb_reqs; i++) |
| 1845 | total_req += px->fe_counters.p.http.cum_req[i]; |
| 1846 | metric = mkf_u64(FN_COUNTER, total_req); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1847 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1848 | } |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1849 | case ST_F_COMP_IN: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 1850 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in[COMP_DIR_RES]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1851 | break; |
| 1852 | case ST_F_COMP_OUT: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 1853 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out[COMP_DIR_RES]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1854 | break; |
| 1855 | case ST_F_COMP_BYP: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 1856 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp[COMP_DIR_RES]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1857 | break; |
| 1858 | case ST_F_COMP_RSP: |
| 1859 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 1860 | break; |
| 1861 | case ST_F_CONN_RATE: |
| 1862 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 1863 | break; |
| 1864 | case ST_F_CONN_RATE_MAX: |
| 1865 | metric = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 1866 | break; |
| 1867 | case ST_F_CONN_TOT: |
| 1868 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 1869 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1870 | case ST_F_SESS_OTHER: { |
| 1871 | int i; |
| 1872 | uint64_t total_sess; |
| 1873 | size_t nb_sess = |
| 1874 | sizeof(px->fe_counters.cum_sess_ver) / sizeof(*px->fe_counters.cum_sess_ver); |
| 1875 | |
| 1876 | total_sess = px->fe_counters.cum_sess; |
| 1877 | for (i = 0; i < nb_sess; i++) |
| 1878 | total_sess -= px->fe_counters.cum_sess_ver[i]; |
Frédéric Lécaille | d97d1d7 | 2023-02-06 09:23:56 +0100 | [diff] [blame] | 1879 | total_sess = (int64_t)total_sess < 0 ? 0 : total_sess; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1880 | metric = mkf_u64(FN_COUNTER, total_sess); |
| 1881 | break; |
| 1882 | } |
| 1883 | case ST_F_H1SESS: |
| 1884 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[0]); |
| 1885 | break; |
| 1886 | case ST_F_H2SESS: |
| 1887 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[1]); |
| 1888 | break; |
| 1889 | case ST_F_H3SESS: |
| 1890 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[2]); |
| 1891 | break; |
| 1892 | case ST_F_REQ_OTHER: |
| 1893 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[0]); |
| 1894 | break; |
| 1895 | case ST_F_H1REQ: |
| 1896 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[1]); |
| 1897 | break; |
| 1898 | case ST_F_H2REQ: |
| 1899 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[2]); |
| 1900 | break; |
| 1901 | case ST_F_H3REQ: |
| 1902 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[3]); |
| 1903 | break; |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1904 | default: |
Christopher Faulet | d808f17 | 2021-01-22 17:33:22 +0100 | [diff] [blame] | 1905 | /* not used for frontends. If a specific metric |
| 1906 | * is requested, return an error. Otherwise continue. |
| 1907 | */ |
| 1908 | if (selected_field != NULL) |
| 1909 | return 0; |
| 1910 | continue; |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1911 | } |
| 1912 | stats[current_field] = metric; |
| 1913 | if (selected_field != NULL) |
| 1914 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1915 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1916 | return 1; |
| 1917 | } |
| 1918 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1919 | /* Dumps a frontend's line to the local trash buffer for the current proxy <px> |
| 1920 | * and uses the state from stream connector <sc>. The caller is responsible for |
| 1921 | * clearing the local trash buffer if needed. Returns non-zero if it emits |
| 1922 | * anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1923 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 1924 | static int stats_dump_fe_stats(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1925 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 1926 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1927 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1928 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 1929 | struct stats_module *mod; |
| 1930 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1931 | |
| 1932 | if (!(px->cap & PR_CAP_FE)) |
| 1933 | return 0; |
| 1934 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1935 | if ((ctx->flags & STAT_BOUND) && !(ctx->type & (1 << STATS_TYPE_FE))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1936 | return 0; |
| 1937 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1938 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 1939 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1940 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1941 | return 0; |
| 1942 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1943 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 1944 | void *counters; |
| 1945 | |
| 1946 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE)) { |
| 1947 | stats_count += mod->stats_count; |
| 1948 | continue; |
| 1949 | } |
| 1950 | |
| 1951 | counters = EXTRA_COUNTERS_GET(px->extra_counters_fe, mod); |
| 1952 | mod->fill_stats(counters, stats + stats_count); |
| 1953 | stats_count += mod->stats_count; |
| 1954 | } |
| 1955 | |
| 1956 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1959 | /* Fill <stats> with the listener statistics. <stats> is preallocated array of |
| 1960 | * length <len>. The length of the array must be at least ST_F_TOTAL_FIELDS. If |
| 1961 | * this length is less then this value, the function returns 0, otherwise, it |
| 1962 | * returns 1. If selected_field is != NULL, only fill this one. <flags> can |
| 1963 | * take the value STAT_SHLGNDS. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1964 | */ |
| 1965 | 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] | 1966 | struct field *stats, int len, enum stat_field *selected_field) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1967 | { |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1968 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 1969 | struct buffer *out = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1970 | |
| 1971 | if (len < ST_F_TOTAL_FIELDS) |
| 1972 | return 0; |
| 1973 | |
| 1974 | if (!l->counters) |
| 1975 | return 0; |
| 1976 | |
| 1977 | chunk_reset(out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1978 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1979 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 1980 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1981 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1982 | switch (current_field) { |
| 1983 | case ST_F_PXNAME: |
| 1984 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1985 | break; |
| 1986 | case ST_F_SVNAME: |
| 1987 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name); |
| 1988 | break; |
| 1989 | case ST_F_MODE: |
| 1990 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1991 | break; |
| 1992 | case ST_F_SCUR: |
| 1993 | metric = mkf_u32(0, l->nbconn); |
| 1994 | break; |
| 1995 | case ST_F_SMAX: |
| 1996 | metric = mkf_u32(FN_MAX, l->counters->conn_max); |
| 1997 | break; |
| 1998 | case ST_F_SLIM: |
Willy Tarreau | 758c69d | 2023-01-12 18:59:37 +0100 | [diff] [blame] | 1999 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, l->bind_conf->maxconn); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2000 | break; |
| 2001 | case ST_F_STOT: |
| 2002 | metric = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 2003 | break; |
| 2004 | case ST_F_BIN: |
| 2005 | metric = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 2006 | break; |
| 2007 | case ST_F_BOUT: |
| 2008 | metric = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 2009 | break; |
| 2010 | case ST_F_DREQ: |
| 2011 | metric = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 2012 | break; |
| 2013 | case ST_F_DRESP: |
| 2014 | metric = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 2015 | break; |
| 2016 | case ST_F_EREQ: |
| 2017 | metric = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 2018 | break; |
| 2019 | case ST_F_DCON: |
| 2020 | metric = mkf_u64(FN_COUNTER, l->counters->denied_conn); |
| 2021 | break; |
| 2022 | case ST_F_DSES: |
| 2023 | metric = mkf_u64(FN_COUNTER, l->counters->denied_sess); |
| 2024 | break; |
| 2025 | case ST_F_STATUS: |
William Dauchy | 3679d0c | 2021-02-14 23:22:55 +0100 | [diff] [blame] | 2026 | metric = mkf_str(FO_STATUS, li_status_st[get_li_status(l)]); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2027 | break; |
| 2028 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2029 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2030 | break; |
| 2031 | case ST_F_IID: |
| 2032 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2033 | break; |
| 2034 | case ST_F_SID: |
| 2035 | metric = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 2036 | break; |
| 2037 | case ST_F_TYPE: |
| 2038 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 2039 | break; |
| 2040 | case ST_F_WREW: |
| 2041 | metric = mkf_u64(FN_COUNTER, l->counters->failed_rewrites); |
| 2042 | break; |
| 2043 | case ST_F_EINT: |
| 2044 | metric = mkf_u64(FN_COUNTER, l->counters->internal_errors); |
| 2045 | break; |
| 2046 | case ST_F_ADDR: |
| 2047 | if (flags & STAT_SHLGNDS) { |
| 2048 | char str[INET6_ADDRSTRLEN]; |
| 2049 | int port; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2050 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2051 | port = get_host_port(&l->rx.addr); |
| 2052 | switch (addr_to_str(&l->rx.addr, str, sizeof(str))) { |
| 2053 | case AF_INET: |
| 2054 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2055 | chunk_appendf(out, "%s:%d", str, port); |
| 2056 | break; |
| 2057 | case AF_INET6: |
| 2058 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2059 | chunk_appendf(out, "[%s]:%d", str, port); |
| 2060 | break; |
| 2061 | case AF_UNIX: |
| 2062 | metric = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 2063 | break; |
| 2064 | case -1: |
| 2065 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2066 | chunk_strcat(out, strerror(errno)); |
| 2067 | break; |
| 2068 | default: /* address family not supported */ |
| 2069 | break; |
| 2070 | } |
| 2071 | } |
| 2072 | break; |
| 2073 | default: |
| 2074 | /* not used for listen. If a specific metric |
| 2075 | * is requested, return an error. Otherwise continue. |
| 2076 | */ |
| 2077 | if (selected_field != NULL) |
| 2078 | return 0; |
| 2079 | continue; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2080 | } |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2081 | stats[current_field] = metric; |
| 2082 | if (selected_field != NULL) |
| 2083 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2084 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2085 | return 1; |
| 2086 | } |
| 2087 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2088 | /* Dumps a line for listener <l> and proxy <px> to the local trash buffer and |
| 2089 | * uses the state from stream connector <sc>. The caller is responsible for |
| 2090 | * clearing the local trash buffer if needed. Returns non-zero if it emits |
| 2091 | * anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2092 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2093 | static int stats_dump_li_stats(struct stconn *sc, struct proxy *px, struct listener *l) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2094 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2095 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2096 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2097 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2098 | struct stats_module *mod; |
| 2099 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 2100 | |
| 2101 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2102 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2103 | if (!stats_fill_li_stats(px, l, ctx->flags, stats, |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2104 | ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2105 | return 0; |
| 2106 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2107 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2108 | void *counters; |
| 2109 | |
| 2110 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI)) { |
| 2111 | stats_count += mod->stats_count; |
| 2112 | continue; |
| 2113 | } |
| 2114 | |
| 2115 | counters = EXTRA_COUNTERS_GET(l->extra_counters, mod); |
| 2116 | mod->fill_stats(counters, stats + stats_count); |
| 2117 | stats_count += mod->stats_count; |
| 2118 | } |
| 2119 | |
| 2120 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | enum srv_stats_state { |
| 2124 | SRV_STATS_STATE_DOWN = 0, |
| 2125 | SRV_STATS_STATE_DOWN_AGENT, |
| 2126 | SRV_STATS_STATE_GOING_UP, |
| 2127 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 2128 | SRV_STATS_STATE_UP, |
| 2129 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 2130 | SRV_STATS_STATE_NOLB, |
| 2131 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 2132 | SRV_STATS_STATE_DRAIN, |
| 2133 | SRV_STATS_STATE_DRAIN_AGENT, |
| 2134 | SRV_STATS_STATE_NO_CHECK, |
| 2135 | |
| 2136 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 2137 | }; |
| 2138 | |
| 2139 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 2140 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 2141 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 2142 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 2143 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 2144 | [SRV_STATS_STATE_UP] = "UP", |
| 2145 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 2146 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 2147 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 2148 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 2149 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 2150 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 2151 | }; |
| 2152 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2153 | /* Compute server state helper |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2154 | */ |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2155 | static void stats_fill_sv_stats_computestate(struct server *sv, struct server *ref, |
| 2156 | enum srv_stats_state *state) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2157 | { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2158 | 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] | 2159 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 2160 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2161 | *state = SRV_STATS_STATE_UP_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2162 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2163 | *state = SRV_STATS_STATE_UP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2164 | } |
| 2165 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2166 | if (sv->cur_admin & SRV_ADMF_DRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2167 | if (ref->agent.state & CHK_ST_ENABLED) |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2168 | *state = SRV_STATS_STATE_DRAIN_AGENT; |
| 2169 | else if (*state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 2170 | *state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2171 | else |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2172 | *state = SRV_STATS_STATE_DRAIN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2173 | } |
| 2174 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2175 | if (*state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 2176 | *state = SRV_STATS_STATE_NO_CHECK; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2177 | } |
| 2178 | } |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2179 | else if (sv->cur_state == SRV_ST_STOPPING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2180 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 2181 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2182 | *state = SRV_STATS_STATE_NOLB; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2183 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2184 | *state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | else { /* stopped */ |
| 2188 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2189 | *state = SRV_STATS_STATE_DOWN_AGENT; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2190 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2191 | *state = SRV_STATS_STATE_DOWN; /* DOWN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2192 | } 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] | 2193 | *state = SRV_STATS_STATE_GOING_UP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2194 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2195 | *state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2196 | } |
| 2197 | } |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2198 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2199 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2200 | /* Fill <stats> with the backend statistics. <stats> is preallocated array of |
| 2201 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 2202 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 2203 | * this value, or if the selected field is not implemented for servers, the |
| 2204 | * function returns 0, otherwise, it returns 1. <flags> can take the value |
| 2205 | * STAT_SHLGNDS. |
| 2206 | */ |
| 2207 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 2208 | struct field *stats, int len, |
| 2209 | enum stat_field *selected_field) |
| 2210 | { |
| 2211 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
| 2212 | struct server *via = sv->track ? sv->track : sv; |
| 2213 | struct server *ref = via; |
| 2214 | enum srv_stats_state state = 0; |
| 2215 | char str[INET6_ADDRSTRLEN]; |
| 2216 | struct buffer *out = get_trash_chunk(); |
| 2217 | char *fld_status; |
| 2218 | long long srv_samples_counter; |
| 2219 | unsigned int srv_samples_window = TIME_STATS_SAMPLES; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2220 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2221 | if (len < ST_F_TOTAL_FIELDS) |
| 2222 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2223 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2224 | chunk_reset(out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2225 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2226 | /* compute state for later use */ |
| 2227 | if (selected_field == NULL || *selected_field == ST_F_STATUS || |
| 2228 | *selected_field == ST_F_CHECK_RISE || *selected_field == ST_F_CHECK_FALL || |
| 2229 | *selected_field == ST_F_CHECK_HEALTH || *selected_field == ST_F_HANAFAIL) { |
| 2230 | /* we have "via" which is the tracked server as described in the configuration, |
| 2231 | * and "ref" which is the checked server and the end of the chain. |
| 2232 | */ |
| 2233 | while (ref->track) |
| 2234 | ref = ref->track; |
| 2235 | stats_fill_sv_stats_computestate(sv, ref, &state); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2236 | } |
| 2237 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2238 | /* compue time values for later use */ |
| 2239 | if (selected_field == NULL || *selected_field == ST_F_QTIME || |
| 2240 | *selected_field == ST_F_CTIME || *selected_field == ST_F_RTIME || |
| 2241 | *selected_field == ST_F_TTIME) { |
| 2242 | srv_samples_counter = (px->mode == PR_MODE_HTTP) ? sv->counters.p.http.cum_req : sv->counters.cum_lbconn; |
| 2243 | if (srv_samples_counter < TIME_STATS_SAMPLES && srv_samples_counter > 0) |
| 2244 | srv_samples_window = srv_samples_counter; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2245 | } |
| 2246 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2247 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 2248 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2249 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2250 | switch (current_field) { |
| 2251 | case ST_F_PXNAME: |
| 2252 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 2253 | break; |
| 2254 | case ST_F_SVNAME: |
| 2255 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id); |
| 2256 | break; |
| 2257 | case ST_F_MODE: |
| 2258 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Christopher Faulet | 3888b8c | 2021-01-27 13:32:25 +0100 | [diff] [blame] | 2259 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2260 | case ST_F_QCUR: |
Willy Tarreau | a057045 | 2021-06-18 09:30:30 +0200 | [diff] [blame] | 2261 | metric = mkf_u32(0, sv->queue.length); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2262 | break; |
| 2263 | case ST_F_QMAX: |
| 2264 | metric = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 2265 | break; |
| 2266 | case ST_F_SCUR: |
| 2267 | metric = mkf_u32(0, sv->cur_sess); |
| 2268 | break; |
| 2269 | case ST_F_SMAX: |
| 2270 | metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 2271 | break; |
| 2272 | case ST_F_SLIM: |
| 2273 | if (sv->maxconn) |
| 2274 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 2275 | break; |
| 2276 | case ST_F_SRV_ICUR: |
| 2277 | metric = mkf_u32(0, sv->curr_idle_conns); |
| 2278 | break; |
| 2279 | case ST_F_SRV_ILIM: |
| 2280 | if (sv->max_idle_conns != -1) |
| 2281 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->max_idle_conns); |
| 2282 | break; |
| 2283 | case ST_F_STOT: |
| 2284 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 2285 | break; |
| 2286 | case ST_F_BIN: |
| 2287 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 2288 | break; |
| 2289 | case ST_F_BOUT: |
| 2290 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 2291 | break; |
| 2292 | case ST_F_DRESP: |
| 2293 | metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp); |
| 2294 | break; |
| 2295 | case ST_F_ECON: |
| 2296 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 2297 | break; |
| 2298 | case ST_F_ERESP: |
| 2299 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 2300 | break; |
| 2301 | case ST_F_WRETR: |
| 2302 | metric = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 2303 | break; |
| 2304 | case ST_F_WREDIS: |
| 2305 | metric = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 2306 | break; |
| 2307 | case ST_F_WREW: |
| 2308 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites); |
| 2309 | break; |
| 2310 | case ST_F_EINT: |
| 2311 | metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors); |
| 2312 | break; |
| 2313 | case ST_F_CONNECT: |
| 2314 | metric = mkf_u64(FN_COUNTER, sv->counters.connect); |
| 2315 | break; |
| 2316 | case ST_F_REUSE: |
| 2317 | metric = mkf_u64(FN_COUNTER, sv->counters.reuse); |
| 2318 | break; |
| 2319 | case ST_F_IDLE_CONN_CUR: |
| 2320 | metric = mkf_u32(0, sv->curr_idle_nb); |
| 2321 | break; |
| 2322 | case ST_F_SAFE_CONN_CUR: |
| 2323 | metric = mkf_u32(0, sv->curr_safe_nb); |
| 2324 | break; |
| 2325 | case ST_F_USED_CONN_CUR: |
| 2326 | metric = mkf_u32(0, sv->curr_used_conns); |
| 2327 | break; |
| 2328 | case ST_F_NEED_CONN_EST: |
| 2329 | metric = mkf_u32(0, sv->est_need_conns); |
| 2330 | break; |
| 2331 | case ST_F_STATUS: |
| 2332 | fld_status = chunk_newstr(out); |
| 2333 | if (sv->cur_admin & SRV_ADMF_RMAINT) |
| 2334 | chunk_appendf(out, "MAINT (resolution)"); |
| 2335 | else if (sv->cur_admin & SRV_ADMF_IMAINT) |
| 2336 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 2337 | else if (sv->cur_admin & SRV_ADMF_MAINT) |
| 2338 | chunk_appendf(out, "MAINT"); |
| 2339 | else |
| 2340 | chunk_appendf(out, |
| 2341 | srv_hlt_st[state], |
| 2342 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2343 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2344 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2345 | metric = mkf_str(FO_STATUS, fld_status); |
| 2346 | break; |
| 2347 | case ST_F_LASTCHG: |
| 2348 | metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 2349 | break; |
| 2350 | case ST_F_WEIGHT: |
| 2351 | metric = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 2352 | break; |
| 2353 | case ST_F_UWEIGHT: |
| 2354 | metric = mkf_u32(FN_AVG, sv->uweight); |
| 2355 | break; |
| 2356 | case ST_F_ACT: |
| 2357 | metric = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 2358 | break; |
| 2359 | case ST_F_BCK: |
| 2360 | metric = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
| 2361 | break; |
| 2362 | case ST_F_CHKFAIL: |
| 2363 | if (sv->check.state & CHK_ST_ENABLED) |
| 2364 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 2365 | break; |
| 2366 | case ST_F_CHKDOWN: |
| 2367 | if (sv->check.state & CHK_ST_ENABLED) |
| 2368 | metric = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 2369 | break; |
| 2370 | case ST_F_DOWNTIME: |
| 2371 | if (sv->check.state & CHK_ST_ENABLED) |
| 2372 | metric = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 2373 | break; |
| 2374 | case ST_F_QLIMIT: |
| 2375 | if (sv->maxqueue) |
| 2376 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
| 2377 | break; |
| 2378 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2379 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2380 | break; |
| 2381 | case ST_F_IID: |
| 2382 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2383 | break; |
| 2384 | case ST_F_SID: |
| 2385 | metric = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
| 2386 | break; |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 2387 | case ST_F_SRID: |
| 2388 | metric = mkf_u32(FN_COUNTER, sv->rid); |
| 2389 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2390 | case ST_F_THROTTLE: |
| 2391 | if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 2392 | metric = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
| 2393 | break; |
| 2394 | case ST_F_LBTOT: |
| 2395 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
| 2396 | break; |
| 2397 | case ST_F_TRACKED: |
| 2398 | if (sv->track) { |
| 2399 | char *fld_track = chunk_newstr(out); |
| 2400 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 2401 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 2402 | } |
| 2403 | break; |
| 2404 | case ST_F_TYPE: |
| 2405 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 2406 | break; |
| 2407 | case ST_F_RATE: |
| 2408 | metric = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 2409 | break; |
| 2410 | case ST_F_RATE_MAX: |
| 2411 | metric = mkf_u32(FN_MAX, sv->counters.sps_max); |
| 2412 | break; |
| 2413 | case ST_F_CHECK_STATUS: |
| 2414 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2415 | const char *fld_chksts; |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 2416 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2417 | fld_chksts = chunk_newstr(out); |
| 2418 | chunk_strcat(out, "* "); // for check in progress |
| 2419 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 2420 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 2421 | fld_chksts += 2; // skip "* " |
Willy Tarreau | 973a937 | 2021-05-12 17:29:14 +0200 | [diff] [blame] | 2422 | metric = mkf_str(FN_OUTPUT, fld_chksts); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2423 | } |
| 2424 | break; |
| 2425 | case ST_F_CHECK_CODE: |
| 2426 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2427 | sv->check.status >= HCHK_STATUS_L57DATA) |
| 2428 | metric = mkf_u32(FN_OUTPUT, sv->check.code); |
| 2429 | break; |
| 2430 | case ST_F_CHECK_DURATION: |
| 2431 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2432 | sv->check.status >= HCHK_STATUS_CHECKED) |
Aurelien DARRAGON | b118f2f | 2022-12-07 14:52:10 +0100 | [diff] [blame] | 2433 | metric = mkf_u64(FN_DURATION, MAX(sv->check.duration, 0)); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2434 | break; |
| 2435 | case ST_F_CHECK_DESC: |
| 2436 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2437 | metric = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 2438 | break; |
| 2439 | case ST_F_LAST_CHK: |
| 2440 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2441 | metric = mkf_str(FN_OUTPUT, sv->check.desc); |
| 2442 | break; |
| 2443 | case ST_F_CHECK_RISE: |
| 2444 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2445 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 2446 | break; |
| 2447 | case ST_F_CHECK_FALL: |
| 2448 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2449 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 2450 | break; |
| 2451 | case ST_F_CHECK_HEALTH: |
| 2452 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2453 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 2454 | break; |
Christopher Faulet | 59bab61 | 2021-07-22 08:04:38 +0200 | [diff] [blame] | 2455 | case ST_F_AGENT_STATUS: |
| 2456 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2457 | const char *fld_chksts; |
| 2458 | |
| 2459 | fld_chksts = chunk_newstr(out); |
| 2460 | chunk_strcat(out, "* "); // for check in progress |
| 2461 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 2462 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 2463 | fld_chksts += 2; // skip "* " |
| 2464 | metric = mkf_str(FN_OUTPUT, fld_chksts); |
| 2465 | } |
| 2466 | break; |
| 2467 | case ST_F_AGENT_CODE: |
| 2468 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2469 | (sv->agent.status >= HCHK_STATUS_L57DATA)) |
| 2470 | metric = mkf_u32(FN_OUTPUT, sv->agent.code); |
| 2471 | break; |
| 2472 | case ST_F_AGENT_DURATION: |
| 2473 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2474 | metric = mkf_u64(FN_DURATION, sv->agent.duration); |
| 2475 | break; |
| 2476 | case ST_F_AGENT_DESC: |
| 2477 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2478 | metric = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 2479 | break; |
| 2480 | case ST_F_LAST_AGT: |
| 2481 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2482 | metric = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 2483 | break; |
| 2484 | case ST_F_AGENT_RISE: |
| 2485 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2486 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 2487 | break; |
| 2488 | case ST_F_AGENT_FALL: |
| 2489 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2490 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 2491 | break; |
| 2492 | case ST_F_AGENT_HEALTH: |
| 2493 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2494 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 2495 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2496 | case ST_F_REQ_TOT: |
| 2497 | if (px->mode == PR_MODE_HTTP) |
| 2498 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req); |
| 2499 | break; |
| 2500 | case ST_F_HRSP_1XX: |
| 2501 | if (px->mode == PR_MODE_HTTP) |
| 2502 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 2503 | break; |
| 2504 | case ST_F_HRSP_2XX: |
| 2505 | if (px->mode == PR_MODE_HTTP) |
| 2506 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 2507 | break; |
| 2508 | case ST_F_HRSP_3XX: |
| 2509 | if (px->mode == PR_MODE_HTTP) |
| 2510 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 2511 | break; |
| 2512 | case ST_F_HRSP_4XX: |
| 2513 | if (px->mode == PR_MODE_HTTP) |
| 2514 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 2515 | break; |
| 2516 | case ST_F_HRSP_5XX: |
| 2517 | if (px->mode == PR_MODE_HTTP) |
| 2518 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 2519 | break; |
| 2520 | case ST_F_HRSP_OTHER: |
| 2521 | if (px->mode == PR_MODE_HTTP) |
| 2522 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 2523 | break; |
| 2524 | case ST_F_HANAFAIL: |
| 2525 | if (ref->observe) |
| 2526 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
| 2527 | break; |
| 2528 | case ST_F_CLI_ABRT: |
| 2529 | metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 2530 | break; |
| 2531 | case ST_F_SRV_ABRT: |
| 2532 | metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 2533 | break; |
| 2534 | case ST_F_LASTSESS: |
| 2535 | metric = mkf_s32(FN_AGE, srv_lastsession(sv)); |
| 2536 | break; |
| 2537 | case ST_F_QTIME: |
| 2538 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, srv_samples_window)); |
| 2539 | break; |
| 2540 | case ST_F_CTIME: |
| 2541 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, srv_samples_window)); |
| 2542 | break; |
| 2543 | case ST_F_RTIME: |
| 2544 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, srv_samples_window)); |
| 2545 | break; |
| 2546 | case ST_F_TTIME: |
| 2547 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, srv_samples_window)); |
| 2548 | break; |
| 2549 | case ST_F_QT_MAX: |
| 2550 | metric = mkf_u32(FN_MAX, sv->counters.qtime_max); |
| 2551 | break; |
| 2552 | case ST_F_CT_MAX: |
| 2553 | metric = mkf_u32(FN_MAX, sv->counters.ctime_max); |
| 2554 | break; |
| 2555 | case ST_F_RT_MAX: |
| 2556 | metric = mkf_u32(FN_MAX, sv->counters.dtime_max); |
| 2557 | break; |
| 2558 | case ST_F_TT_MAX: |
| 2559 | metric = mkf_u32(FN_MAX, sv->counters.ttime_max); |
| 2560 | break; |
| 2561 | case ST_F_ADDR: |
| 2562 | if (flags & STAT_SHLGNDS) { |
| 2563 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2564 | case AF_INET: |
| 2565 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2566 | chunk_appendf(out, "%s:%d", str, sv->svc_port); |
| 2567 | break; |
| 2568 | case AF_INET6: |
| 2569 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2570 | chunk_appendf(out, "[%s]:%d", str, sv->svc_port); |
| 2571 | break; |
| 2572 | case AF_UNIX: |
| 2573 | metric = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 2574 | break; |
| 2575 | case -1: |
| 2576 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2577 | chunk_strcat(out, strerror(errno)); |
| 2578 | break; |
| 2579 | default: /* address family not supported */ |
| 2580 | break; |
| 2581 | } |
| 2582 | } |
| 2583 | break; |
| 2584 | case ST_F_COOKIE: |
| 2585 | if (flags & STAT_SHLGNDS && sv->cookie) |
| 2586 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 2587 | break; |
| 2588 | default: |
| 2589 | /* not used for servers. If a specific metric |
| 2590 | * is requested, return an error. Otherwise continue. |
| 2591 | */ |
| 2592 | if (selected_field != NULL) |
| 2593 | return 0; |
| 2594 | continue; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2595 | } |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2596 | stats[current_field] = metric; |
| 2597 | if (selected_field != NULL) |
| 2598 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2599 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2600 | return 1; |
| 2601 | } |
| 2602 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2603 | /* Dumps a line for server <sv> and proxy <px> to the local trash vbuffer and |
| 2604 | * uses the state from stream connector <sc>, and server state <state>. The |
| 2605 | * caller is responsible for clearing the local trash buffer if needed. Returns |
| 2606 | * non-zero if it emits anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2607 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2608 | static int stats_dump_sv_stats(struct stconn *sc, struct proxy *px, struct server *sv) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2609 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2610 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2611 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2612 | struct stats_module *mod; |
| 2613 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2614 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 2615 | |
| 2616 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2617 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2618 | if (!stats_fill_sv_stats(px, sv, ctx->flags, stats, |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2619 | ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2620 | return 0; |
| 2621 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2622 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2623 | void *counters; |
| 2624 | |
| 2625 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2626 | continue; |
| 2627 | |
| 2628 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV)) { |
| 2629 | stats_count += mod->stats_count; |
| 2630 | continue; |
| 2631 | } |
| 2632 | |
| 2633 | counters = EXTRA_COUNTERS_GET(sv->extra_counters, mod); |
| 2634 | mod->fill_stats(counters, stats + stats_count); |
| 2635 | stats_count += mod->stats_count; |
| 2636 | } |
| 2637 | |
| 2638 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2639 | } |
| 2640 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2641 | /* Helper to compute srv values for a given backend |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2642 | */ |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2643 | 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] | 2644 | { |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2645 | int nbup_tmp, nbsrv_tmp, totuw_tmp; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2646 | const struct server *srv; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2647 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2648 | nbup_tmp = nbsrv_tmp = totuw_tmp = 0; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2649 | for (srv = px->srv; srv; srv = srv->next) { |
| 2650 | if (srv->cur_state != SRV_ST_STOPPED) { |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2651 | nbup_tmp++; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2652 | if (srv_currently_usable(srv) && |
| 2653 | (!px->srv_act ^ !(srv->flags & SRV_F_BACKUP))) |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2654 | totuw_tmp += srv->uweight; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2655 | } |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2656 | nbsrv_tmp++; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2657 | } |
| 2658 | |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2659 | HA_RWLOCK_RDLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2660 | if (!px->srv_act && px->lbprm.fbck) |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2661 | totuw_tmp = px->lbprm.fbck->uweight; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2662 | HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2663 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2664 | /* use tmp variable then assign result to make gcc happy */ |
| 2665 | *nbup = nbup_tmp; |
| 2666 | *nbsrv = nbsrv_tmp; |
| 2667 | *totuw = totuw_tmp; |
| 2668 | } |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2669 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2670 | /* Fill <stats> with the backend statistics. <stats> is preallocated array of |
| 2671 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 2672 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 2673 | * this value, or if the selected field is not implemented for backends, the |
| 2674 | * function returns 0, otherwise, it returns 1. <flags> can take the value |
| 2675 | * STAT_SHLGNDS. |
| 2676 | */ |
| 2677 | int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len, |
| 2678 | enum stat_field *selected_field) |
| 2679 | { |
| 2680 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
| 2681 | long long be_samples_counter; |
| 2682 | unsigned int be_samples_window = TIME_STATS_SAMPLES; |
| 2683 | struct buffer *out = get_trash_chunk(); |
| 2684 | int nbup, nbsrv, totuw; |
| 2685 | char *fld; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2686 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2687 | if (len < ST_F_TOTAL_FIELDS) |
| 2688 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2689 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2690 | nbup = nbsrv = totuw = 0; |
| 2691 | /* some srv values compute for later if we either select all fields or |
| 2692 | * need them for one of the mentioned ones */ |
| 2693 | if (selected_field == NULL || *selected_field == ST_F_STATUS || |
| 2694 | *selected_field == ST_F_UWEIGHT) |
| 2695 | stats_fill_be_stats_computesrv(px, &nbup, &nbsrv, &totuw); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2696 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2697 | /* same here but specific to time fields */ |
| 2698 | if (selected_field == NULL || *selected_field == ST_F_QTIME || |
| 2699 | *selected_field == ST_F_CTIME || *selected_field == ST_F_RTIME || |
| 2700 | *selected_field == ST_F_TTIME) { |
| 2701 | be_samples_counter = (px->mode == PR_MODE_HTTP) ? px->be_counters.p.http.cum_req : px->be_counters.cum_lbconn; |
| 2702 | if (be_samples_counter < TIME_STATS_SAMPLES && be_samples_counter > 0) |
| 2703 | be_samples_window = be_samples_counter; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2704 | } |
| 2705 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2706 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 2707 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2708 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2709 | switch (current_field) { |
| 2710 | case ST_F_PXNAME: |
| 2711 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 2712 | break; |
| 2713 | case ST_F_SVNAME: |
| 2714 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND"); |
| 2715 | break; |
| 2716 | case ST_F_MODE: |
| 2717 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 2718 | break; |
| 2719 | case ST_F_QCUR: |
Willy Tarreau | 7f3c1df | 2021-06-18 09:22:21 +0200 | [diff] [blame] | 2720 | metric = mkf_u32(0, px->queue.length); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2721 | break; |
| 2722 | case ST_F_QMAX: |
| 2723 | metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 2724 | break; |
| 2725 | case ST_F_SCUR: |
| 2726 | metric = mkf_u32(0, px->beconn); |
| 2727 | break; |
| 2728 | case ST_F_SMAX: |
| 2729 | metric = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 2730 | break; |
| 2731 | case ST_F_SLIM: |
| 2732 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 2733 | break; |
| 2734 | case ST_F_STOT: |
| 2735 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 2736 | break; |
| 2737 | case ST_F_BIN: |
| 2738 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 2739 | break; |
| 2740 | case ST_F_BOUT: |
| 2741 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 2742 | break; |
| 2743 | case ST_F_DREQ: |
| 2744 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 2745 | break; |
| 2746 | case ST_F_DRESP: |
| 2747 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 2748 | break; |
| 2749 | case ST_F_ECON: |
| 2750 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 2751 | break; |
| 2752 | case ST_F_ERESP: |
| 2753 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 2754 | break; |
| 2755 | case ST_F_WRETR: |
| 2756 | metric = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 2757 | break; |
| 2758 | case ST_F_WREDIS: |
| 2759 | metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 2760 | break; |
| 2761 | case ST_F_WREW: |
| 2762 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites); |
| 2763 | break; |
| 2764 | case ST_F_EINT: |
| 2765 | metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors); |
| 2766 | break; |
| 2767 | case ST_F_CONNECT: |
| 2768 | metric = mkf_u64(FN_COUNTER, px->be_counters.connect); |
| 2769 | break; |
| 2770 | case ST_F_REUSE: |
| 2771 | metric = mkf_u64(FN_COUNTER, px->be_counters.reuse); |
| 2772 | break; |
| 2773 | case ST_F_STATUS: |
| 2774 | fld = chunk_newstr(out); |
| 2775 | chunk_appendf(out, "%s", (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 2776 | if (flags & (STAT_HIDE_MAINT|STAT_HIDE_DOWN)) |
| 2777 | chunk_appendf(out, " (%d/%d)", nbup, nbsrv); |
| 2778 | metric = mkf_str(FO_STATUS, fld); |
| 2779 | break; |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 2780 | case ST_F_AGG_SRV_CHECK_STATUS: // DEPRECATED |
| 2781 | case ST_F_AGG_SRV_STATUS: |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 2782 | metric = mkf_u32(FN_GAUGE, 0); |
| 2783 | break; |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame] | 2784 | case ST_F_AGG_CHECK_STATUS: |
| 2785 | metric = mkf_u32(FN_GAUGE, 0); |
| 2786 | break; |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2787 | case ST_F_WEIGHT: |
| 2788 | metric = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 2789 | break; |
| 2790 | case ST_F_UWEIGHT: |
| 2791 | metric = mkf_u32(FN_AVG, totuw); |
| 2792 | break; |
| 2793 | case ST_F_ACT: |
| 2794 | metric = mkf_u32(0, px->srv_act); |
| 2795 | break; |
| 2796 | case ST_F_BCK: |
| 2797 | metric = mkf_u32(0, px->srv_bck); |
| 2798 | break; |
| 2799 | case ST_F_CHKDOWN: |
| 2800 | metric = mkf_u64(FN_COUNTER, px->down_trans); |
| 2801 | break; |
| 2802 | case ST_F_LASTCHG: |
| 2803 | metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change); |
| 2804 | break; |
| 2805 | case ST_F_DOWNTIME: |
| 2806 | if (px->srv) |
| 2807 | metric = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 2808 | break; |
| 2809 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2810 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2811 | break; |
| 2812 | case ST_F_IID: |
| 2813 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2814 | break; |
| 2815 | case ST_F_SID: |
| 2816 | metric = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 2817 | break; |
| 2818 | case ST_F_LBTOT: |
| 2819 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 2820 | break; |
| 2821 | case ST_F_TYPE: |
| 2822 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 2823 | break; |
| 2824 | case ST_F_RATE: |
| 2825 | metric = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 2826 | break; |
| 2827 | case ST_F_RATE_MAX: |
| 2828 | metric = mkf_u32(0, px->be_counters.sps_max); |
| 2829 | break; |
| 2830 | case ST_F_COOKIE: |
| 2831 | if (flags & STAT_SHLGNDS && px->cookie_name) |
| 2832 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name); |
| 2833 | break; |
| 2834 | case ST_F_ALGO: |
| 2835 | if (flags & STAT_SHLGNDS) |
| 2836 | metric = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2837 | break; |
| 2838 | case ST_F_REQ_TOT: |
| 2839 | if (px->mode == PR_MODE_HTTP) |
| 2840 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 2841 | break; |
| 2842 | case ST_F_HRSP_1XX: |
| 2843 | if (px->mode == PR_MODE_HTTP) |
| 2844 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 2845 | break; |
| 2846 | case ST_F_HRSP_2XX: |
| 2847 | if (px->mode == PR_MODE_HTTP) |
| 2848 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 2849 | break; |
| 2850 | case ST_F_HRSP_3XX: |
| 2851 | if (px->mode == PR_MODE_HTTP) |
| 2852 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 2853 | break; |
| 2854 | case ST_F_HRSP_4XX: |
| 2855 | if (px->mode == PR_MODE_HTTP) |
| 2856 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 2857 | break; |
| 2858 | case ST_F_HRSP_5XX: |
| 2859 | if (px->mode == PR_MODE_HTTP) |
| 2860 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 2861 | break; |
| 2862 | case ST_F_HRSP_OTHER: |
| 2863 | if (px->mode == PR_MODE_HTTP) |
| 2864 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
| 2865 | break; |
| 2866 | case ST_F_CACHE_LOOKUPS: |
| 2867 | if (px->mode == PR_MODE_HTTP) |
| 2868 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups); |
| 2869 | break; |
| 2870 | case ST_F_CACHE_HITS: |
| 2871 | if (px->mode == PR_MODE_HTTP) |
| 2872 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits); |
| 2873 | break; |
| 2874 | case ST_F_CLI_ABRT: |
| 2875 | metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 2876 | break; |
| 2877 | case ST_F_SRV_ABRT: |
| 2878 | metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 2879 | break; |
| 2880 | case ST_F_COMP_IN: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 2881 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in[COMP_DIR_RES]); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2882 | break; |
| 2883 | case ST_F_COMP_OUT: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 2884 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out[COMP_DIR_RES]); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2885 | break; |
| 2886 | case ST_F_COMP_BYP: |
Olivier Houchard | dea25f5 | 2023-04-06 00:33:01 +0200 | [diff] [blame] | 2887 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp[COMP_DIR_RES]); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2888 | break; |
| 2889 | case ST_F_COMP_RSP: |
| 2890 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 2891 | break; |
| 2892 | case ST_F_LASTSESS: |
| 2893 | metric = mkf_s32(FN_AGE, be_lastsession(px)); |
| 2894 | break; |
| 2895 | case ST_F_QTIME: |
| 2896 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, be_samples_window)); |
| 2897 | break; |
| 2898 | case ST_F_CTIME: |
| 2899 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, be_samples_window)); |
| 2900 | break; |
| 2901 | case ST_F_RTIME: |
| 2902 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, be_samples_window)); |
| 2903 | break; |
| 2904 | case ST_F_TTIME: |
| 2905 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, be_samples_window)); |
| 2906 | break; |
| 2907 | case ST_F_QT_MAX: |
| 2908 | metric = mkf_u32(FN_MAX, px->be_counters.qtime_max); |
| 2909 | break; |
| 2910 | case ST_F_CT_MAX: |
| 2911 | metric = mkf_u32(FN_MAX, px->be_counters.ctime_max); |
| 2912 | break; |
| 2913 | case ST_F_RT_MAX: |
| 2914 | metric = mkf_u32(FN_MAX, px->be_counters.dtime_max); |
| 2915 | break; |
| 2916 | case ST_F_TT_MAX: |
| 2917 | metric = mkf_u32(FN_MAX, px->be_counters.ttime_max); |
| 2918 | break; |
| 2919 | default: |
| 2920 | /* not used for backends. If a specific metric |
| 2921 | * is requested, return an error. Otherwise continue. |
| 2922 | */ |
| 2923 | if (selected_field != NULL) |
| 2924 | return 0; |
| 2925 | continue; |
| 2926 | } |
| 2927 | stats[current_field] = metric; |
| 2928 | if (selected_field != NULL) |
| 2929 | break; |
| 2930 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2931 | return 1; |
| 2932 | } |
| 2933 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2934 | /* Dumps a line for backend <px> to the local trash buffer for and uses the |
| 2935 | * state from stream interface <si>. The caller is responsible for clearing the |
| 2936 | * local trash buffer if needed. Returns non-zero if it emits anything, zero |
| 2937 | * otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2938 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2939 | static int stats_dump_be_stats(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2940 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2941 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2942 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2943 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2944 | struct stats_module *mod; |
| 2945 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2946 | |
| 2947 | if (!(px->cap & PR_CAP_BE)) |
| 2948 | return 0; |
| 2949 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2950 | if ((ctx->flags & STAT_BOUND) && !(ctx->type & (1 << STATS_TYPE_BE))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2951 | return 0; |
| 2952 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2953 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 2954 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2955 | if (!stats_fill_be_stats(px, ctx->flags, stats, ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2956 | return 0; |
| 2957 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2958 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2959 | struct extra_counters *counters; |
| 2960 | |
| 2961 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2962 | continue; |
| 2963 | |
| 2964 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE)) { |
| 2965 | stats_count += mod->stats_count; |
| 2966 | continue; |
| 2967 | } |
| 2968 | |
| 2969 | counters = EXTRA_COUNTERS_GET(px->extra_counters_be, mod); |
| 2970 | mod->fill_stats(counters, stats + stats_count); |
| 2971 | stats_count += mod->stats_count; |
| 2972 | } |
| 2973 | |
| 2974 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2975 | } |
| 2976 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2977 | /* Dumps the HTML table header for proxy <px> to the local trash buffer for and |
| 2978 | * uses the state from stream connector <sc> and per-uri parameters <uri>. The |
| 2979 | * caller is responsible for clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2980 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2981 | static void stats_dump_html_px_hdr(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2982 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2983 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2984 | struct show_stat_ctx *ctx = appctx->svcctx; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2985 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 2986 | struct stats_module *mod; |
| 2987 | int stats_module_len = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2988 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2989 | if (px->cap & PR_CAP_BE && px->srv && (ctx->flags & STAT_ADMIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2990 | /* A form to enable/disable this proxy servers */ |
| 2991 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2992 | /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2993 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2994 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2995 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2996 | |
Willy Tarreau | fc458ec | 2023-04-07 18:11:39 +0200 | [diff] [blame] | 2997 | strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2998 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 2999 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3000 | } |
| 3001 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3002 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3003 | "<form method=\"post\">"); |
| 3004 | } |
| 3005 | |
| 3006 | /* print a new table */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3007 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3008 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3009 | "<tr class=\"titre\">" |
| 3010 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3011 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3012 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3013 | "<a name=\"%s\"></a>%s" |
| 3014 | "<a class=px href=\"#%s\">%s</a>", |
| 3015 | px->id, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3016 | (ctx->flags & STAT_SHLGNDS) ? "<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3017 | px->id, px->id); |
| 3018 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3019 | if (ctx->flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3020 | /* cap, mode, id */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3021 | chunk_appendf(&trash_chunk, "<div class=tips>cap: %s, mode: %s, id: %d", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3022 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3023 | px->uuid); |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3024 | chunk_appendf(&trash_chunk, "</div>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3025 | } |
| 3026 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3027 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3028 | "%s</th>" |
| 3029 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3030 | "</tr>\n" |
| 3031 | "</table>\n" |
| 3032 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3033 | "<tr class=\"titre\">", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3034 | (ctx->flags & STAT_SHLGNDS) ? "</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3035 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3036 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3037 | if (ctx->flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3038 | /* Column heading for Enable or Disable server */ |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 3039 | if ((px->cap & PR_CAP_BE) && px->srv) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3040 | chunk_appendf(&trash_chunk, |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 3041 | "<th rowspan=2 width=1><input type=\"checkbox\" " |
| 3042 | "onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) " |
| 3043 | "document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>", |
| 3044 | px->id, |
| 3045 | px->id); |
| 3046 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3047 | chunk_appendf(&trash_chunk, "<th rowspan=2></th>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3050 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3051 | "<th rowspan=2></th>" |
| 3052 | "<th colspan=3>Queue</th>" |
| 3053 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
| 3054 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3055 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3056 | "<th colspan=9>Server</th>"); |
| 3057 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3058 | if (ctx->flags & STAT_SHMODULES) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3059 | // calculate the count of module for colspan attribute |
| 3060 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 3061 | ++stats_module_len; |
| 3062 | } |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3063 | chunk_appendf(&trash_chunk, "<th colspan=%d>Extra modules</th>", |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3064 | stats_module_len); |
| 3065 | } |
| 3066 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3067 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3068 | "</tr>\n" |
| 3069 | "<tr class=\"titre\">" |
| 3070 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3071 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 3072 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>" |
| 3073 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3074 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3075 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3076 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3077 | "<th>Thrtle</th>\n"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 3078 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3079 | if (ctx->flags & STAT_SHMODULES) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3080 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3081 | chunk_appendf(&trash_chunk, "<th>%s</th>", mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3082 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 3083 | } |
| 3084 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3085 | chunk_appendf(&trash_chunk, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3088 | /* Dumps the HTML table trailer for proxy <px> to the local trash buffer for and |
| 3089 | * uses the state from stream connector <sc>. The caller is responsible for |
| 3090 | * clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3091 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3092 | static void stats_dump_html_px_end(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3093 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3094 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3095 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | 693b23b | 2022-02-28 09:09:05 +0100 | [diff] [blame] | 3096 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3097 | chunk_appendf(&trash_chunk, "</table>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3098 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3099 | if ((px->cap & PR_CAP_BE) && px->srv && (ctx->flags & STAT_ADMIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3100 | /* close the form used to enable/disable this proxy servers */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3101 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3102 | "Choose the action to perform on the checked servers : " |
| 3103 | "<select name=action>" |
| 3104 | "<option value=\"\"></option>" |
| 3105 | "<option value=\"ready\">Set state to READY</option>" |
| 3106 | "<option value=\"drain\">Set state to DRAIN</option>" |
| 3107 | "<option value=\"maint\">Set state to MAINT</option>" |
| 3108 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3109 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3110 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3111 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3112 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3113 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3114 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3115 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3116 | "<option value=\"adown\">Agent: force DOWN</option>" |
| 3117 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3118 | "</select>" |
| 3119 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3120 | " <input type=\"submit\" value=\"Apply\">" |
| 3121 | "</form>", |
| 3122 | px->uuid); |
| 3123 | } |
| 3124 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3125 | chunk_appendf(&trash_chunk, "<p>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | /* |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 3129 | * Dumps statistics for a proxy. The output is sent to the stream connector's |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3130 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3131 | * buffer space, or non-zero if everything completed. This function is used |
| 3132 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3133 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
| 3134 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3135 | int stats_dump_proxy_to_buffer(struct stconn *sc, struct htx *htx, |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3136 | struct proxy *px, struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3137 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3138 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3139 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3140 | struct stream *s = __sc_strm(sc); |
| 3141 | struct channel *rep = sc_ic(sc); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3142 | struct server *sv, *svs; /* server and server-state, server-state=server or server->track */ |
| 3143 | struct listener *l; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3144 | int current_field; |
Aurelien DARRAGON | 99a8d0f | 2023-01-31 09:51:32 +0100 | [diff] [blame] | 3145 | int px_st = ctx->px_st; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3146 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3147 | chunk_reset(&trash_chunk); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3148 | more: |
| 3149 | current_field = ctx->field; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3150 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3151 | switch (ctx->px_st) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3152 | case STAT_PX_ST_INIT: |
| 3153 | /* we are on a new proxy */ |
| 3154 | if (uri && uri->scope) { |
| 3155 | /* we have a limited scope, we have to check the proxy name */ |
| 3156 | struct stat_scope *scope; |
| 3157 | int len; |
| 3158 | |
| 3159 | len = strlen(px->id); |
| 3160 | scope = uri->scope; |
| 3161 | |
| 3162 | while (scope) { |
| 3163 | /* match exact proxy name */ |
| 3164 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3165 | break; |
| 3166 | |
| 3167 | /* match '.' which means 'self' proxy */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 3168 | if (strcmp(scope->px_id, ".") == 0 && px == s->be) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3169 | break; |
| 3170 | scope = scope->next; |
| 3171 | } |
| 3172 | |
| 3173 | /* proxy name not found : don't dump anything */ |
| 3174 | if (scope == NULL) |
| 3175 | return 1; |
| 3176 | } |
| 3177 | |
| 3178 | /* if the user has requested a limited output and the proxy |
| 3179 | * name does not match, skip it. |
| 3180 | */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3181 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3182 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3183 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3184 | if (strnistr(px->id, strlen(px->id), scope_ptr, ctx->scope_len) == NULL) |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3185 | return 1; |
| 3186 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3187 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3188 | if ((ctx->flags & STAT_BOUND) && |
| 3189 | (ctx->iid != -1) && |
| 3190 | (px->uuid != ctx->iid)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3191 | return 1; |
| 3192 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3193 | ctx->px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3194 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3195 | |
| 3196 | case STAT_PX_ST_TH: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3197 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3198 | stats_dump_html_px_hdr(sc, px); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3199 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3200 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3201 | } |
| 3202 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3203 | ctx->px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3204 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3205 | |
| 3206 | case STAT_PX_ST_FE: |
| 3207 | /* print the frontend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3208 | if (stats_dump_fe_stats(sc, px)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3209 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3210 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3211 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3212 | if (ctx->field) |
| 3213 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3214 | } |
| 3215 | |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3216 | current_field = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3217 | ctx->obj2 = px->conf.listeners.n; |
| 3218 | ctx->px_st = STAT_PX_ST_LI; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3219 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3220 | |
| 3221 | case STAT_PX_ST_LI: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 3222 | /* obj2 points to listeners list as initialized above */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3223 | for (; ctx->obj2 != &px->conf.listeners; ctx->obj2 = l->by_fe.n) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3224 | if (htx) { |
| 3225 | if (htx_almost_full(htx)) |
| 3226 | goto full; |
| 3227 | } |
| 3228 | else { |
| 3229 | if (buffer_almost_full(&rep->buf)) |
| 3230 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3231 | } |
| 3232 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3233 | l = LIST_ELEM(ctx->obj2, struct listener *, by_fe); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3234 | if (!l->counters) |
| 3235 | continue; |
| 3236 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3237 | if (ctx->flags & STAT_BOUND) { |
| 3238 | if (!(ctx->type & (1 << STATS_TYPE_SO))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3239 | break; |
| 3240 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3241 | if (ctx->sid != -1 && l->luid != ctx->sid) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3242 | continue; |
| 3243 | } |
| 3244 | |
| 3245 | /* print the frontend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3246 | if (stats_dump_li_stats(sc, px, l)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3247 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3248 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3249 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3250 | if (ctx->field) |
| 3251 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3252 | } |
Aurelien DARRAGON | 9b07d4f | 2023-02-03 11:43:05 +0100 | [diff] [blame] | 3253 | current_field = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3254 | } |
| 3255 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3256 | ctx->obj2 = px->srv; /* may be NULL */ |
| 3257 | ctx->px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3258 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3259 | |
| 3260 | case STAT_PX_ST_SV: |
Aurelien DARRAGON | 99a8d0f | 2023-01-31 09:51:32 +0100 | [diff] [blame] | 3261 | /* check for dump resumption */ |
| 3262 | if (px_st == STAT_PX_ST_SV) { |
| 3263 | struct server *cur = ctx->obj2; |
| 3264 | |
| 3265 | /* re-entrant dump */ |
| 3266 | BUG_ON(!cur); |
| 3267 | if (cur->flags & SRV_F_DELETED) { |
| 3268 | /* the server could have been marked as deleted |
| 3269 | * between two dumping attempts, skip it. |
| 3270 | */ |
| 3271 | cur = cur->next; |
| 3272 | } |
| 3273 | srv_drop(ctx->obj2); /* drop old srv taken on last dumping attempt */ |
| 3274 | ctx->obj2 = cur; /* could be NULL */ |
| 3275 | /* back to normal */ |
| 3276 | } |
| 3277 | |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3278 | /* obj2 points to servers list as initialized above. |
| 3279 | * |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3280 | * A server may be removed during the stats dumping. |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3281 | * Temporarily increment its refcount to prevent its |
Aurelien DARRAGON | 99a8d0f | 2023-01-31 09:51:32 +0100 | [diff] [blame] | 3282 | * anticipated cleaning. Call srv_drop() to release it. |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3283 | */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3284 | for (; ctx->obj2 != NULL; |
| 3285 | ctx->obj2 = srv_drop(sv)) { |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3286 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3287 | sv = ctx->obj2; |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3288 | srv_take(sv); |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3289 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3290 | if (htx) { |
| 3291 | if (htx_almost_full(htx)) |
| 3292 | goto full; |
| 3293 | } |
| 3294 | else { |
| 3295 | if (buffer_almost_full(&rep->buf)) |
| 3296 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3297 | } |
| 3298 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3299 | if (ctx->flags & STAT_BOUND) { |
| 3300 | if (!(ctx->type & (1 << STATS_TYPE_SV))) { |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3301 | srv_drop(sv); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3302 | break; |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3303 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3304 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3305 | if (ctx->sid != -1 && sv->puid != ctx->sid) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3306 | continue; |
| 3307 | } |
| 3308 | |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 3309 | /* do not report disabled servers */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3310 | if (ctx->flags & STAT_HIDE_MAINT && |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 3311 | sv->cur_admin & SRV_ADMF_MAINT) { |
| 3312 | continue; |
| 3313 | } |
| 3314 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3315 | svs = sv; |
| 3316 | while (svs->track) |
| 3317 | svs = svs->track; |
| 3318 | |
| 3319 | /* do not report servers which are DOWN and not changing state */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3320 | if ((ctx->flags & STAT_HIDE_DOWN) && |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 3321 | ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 3322 | (sv->cur_state == SRV_ST_STOPPED && /* server is down */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3323 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 3324 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 3325 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
| 3326 | continue; |
| 3327 | } |
| 3328 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3329 | if (stats_dump_sv_stats(sc, px, sv)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3330 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3331 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3332 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 28a2361 | 2023-02-02 18:13:30 +0100 | [diff] [blame] | 3333 | if (ctx->field) |
| 3334 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3335 | } |
Aurelien DARRAGON | 28a2361 | 2023-02-02 18:13:30 +0100 | [diff] [blame] | 3336 | current_field = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3337 | } /* for sv */ |
| 3338 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3339 | ctx->px_st = STAT_PX_ST_BE; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3340 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3341 | |
| 3342 | case STAT_PX_ST_BE: |
| 3343 | /* print the backend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3344 | if (stats_dump_be_stats(sc, px)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3345 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3346 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3347 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3348 | if (ctx->field) |
| 3349 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3350 | } |
| 3351 | |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3352 | current_field = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3353 | ctx->px_st = STAT_PX_ST_END; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3354 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3355 | |
| 3356 | case STAT_PX_ST_END: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3357 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3358 | stats_dump_html_px_end(sc, px); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3359 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3360 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3361 | } |
| 3362 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3363 | ctx->px_st = STAT_PX_ST_FIN; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3364 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3365 | |
| 3366 | case STAT_PX_ST_FIN: |
| 3367 | return 1; |
| 3368 | |
| 3369 | default: |
| 3370 | /* unknown state, we should put an abort() here ! */ |
| 3371 | return 1; |
| 3372 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3373 | |
| 3374 | full: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3375 | sc_need_room(sc); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3376 | /* restore previous field */ |
| 3377 | ctx->field = current_field; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3378 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3379 | } |
| 3380 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3381 | /* Dumps the HTTP stats head block to the local trash buffer for and uses the |
| 3382 | * per-uri parameters <uri>. The caller is responsible for clearing the local |
| 3383 | * trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3384 | */ |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 3385 | 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] | 3386 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3387 | struct show_stat_ctx *ctx = appctx->svcctx; |
| 3388 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3389 | /* WARNING! This must fit in the first buffer !!! */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3390 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3391 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3392 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3393 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
Thierry Fournier | b6b1cde | 2021-09-24 00:03:07 +0200 | [diff] [blame] | 3394 | "<link rel=\"icon\" href=\"data:,\">\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3395 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3396 | "<style type=\"text/css\"><!--\n" |
| 3397 | "body {" |
| 3398 | " font-family: arial, helvetica, sans-serif;" |
| 3399 | " font-size: 12px;" |
| 3400 | " font-weight: normal;" |
| 3401 | " color: black;" |
| 3402 | " background: white;" |
| 3403 | "}\n" |
| 3404 | "th,td {" |
| 3405 | " font-size: 10px;" |
| 3406 | "}\n" |
| 3407 | "h1 {" |
| 3408 | " font-size: x-large;" |
| 3409 | " margin-bottom: 0.5em;" |
| 3410 | "}\n" |
| 3411 | "h2 {" |
| 3412 | " font-family: helvetica, arial;" |
| 3413 | " font-size: x-large;" |
| 3414 | " font-weight: bold;" |
| 3415 | " font-style: italic;" |
| 3416 | " color: #6020a0;" |
| 3417 | " margin-top: 0em;" |
| 3418 | " margin-bottom: 0em;" |
| 3419 | "}\n" |
| 3420 | "h3 {" |
| 3421 | " font-family: helvetica, arial;" |
| 3422 | " font-size: 16px;" |
| 3423 | " font-weight: bold;" |
| 3424 | " color: #b00040;" |
| 3425 | " background: #e8e8d0;" |
| 3426 | " margin-top: 0em;" |
| 3427 | " margin-bottom: 0em;" |
| 3428 | "}\n" |
| 3429 | "li {" |
| 3430 | " margin-top: 0.25em;" |
| 3431 | " margin-right: 2em;" |
| 3432 | "}\n" |
| 3433 | ".hr {margin-top: 0.25em;" |
| 3434 | " border-color: black;" |
| 3435 | " border-bottom-style: solid;" |
| 3436 | "}\n" |
| 3437 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3438 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3439 | ".frontend {background: #e8e8d0;}\n" |
| 3440 | ".socket {background: #d0d0d0;}\n" |
| 3441 | ".backend {background: #e8e8d0;}\n" |
| 3442 | ".active_down {background: #ff9090;}\n" |
| 3443 | ".active_going_up {background: #ffd020;}\n" |
| 3444 | ".active_going_down {background: #ffffa0;}\n" |
| 3445 | ".active_up {background: #c0ffc0;}\n" |
| 3446 | ".active_nolb {background: #20a0ff;}\n" |
| 3447 | ".active_draining {background: #20a0FF;}\n" |
| 3448 | ".active_no_check {background: #e0e0e0;}\n" |
| 3449 | ".backup_down {background: #ff9090;}\n" |
| 3450 | ".backup_going_up {background: #ff80ff;}\n" |
| 3451 | ".backup_going_down {background: #c060ff;}\n" |
| 3452 | ".backup_up {background: #b0d0ff;}\n" |
| 3453 | ".backup_nolb {background: #90b0e0;}\n" |
| 3454 | ".backup_draining {background: #cc9900;}\n" |
| 3455 | ".backup_no_check {background: #e0e0e0;}\n" |
| 3456 | ".maintain {background: #c07820;}\n" |
| 3457 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3458 | "\n" |
| 3459 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3460 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3461 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3462 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3463 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3464 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3465 | "\n" |
| 3466 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3467 | "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" |
| 3468 | "table.tbl td.ac { text-align: center;}\n" |
| 3469 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3470 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3471 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3472 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3473 | "\n" |
| 3474 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3475 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3476 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 3477 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3478 | "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" |
| 3479 | "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" |
| 3480 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Thierry Fournier | b6b1cde | 2021-09-24 00:03:07 +0200 | [diff] [blame] | 3481 | "div.tips {\n" |
| 3482 | " display:block;\n" |
| 3483 | " visibility:hidden;\n" |
| 3484 | " z-index:2147483647;\n" |
| 3485 | " position:absolute;\n" |
| 3486 | " padding:2px 4px 3px;\n" |
| 3487 | " background:#f0f060; color:#000000;\n" |
| 3488 | " border:1px solid #7040c0;\n" |
| 3489 | " white-space:nowrap;\n" |
| 3490 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3491 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3492 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3493 | "}\n" |
| 3494 | "u:hover div.tips {visibility:visible;}\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3495 | "@media (prefers-color-scheme: dark) {\n" |
| 3496 | " body { font-family: arial, helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #e8e6e3; background: #131516;}\n" |
| 3497 | " h1 { color: #a265e0!important; }\n" |
| 3498 | " h2 { color: #a265e0; }\n" |
| 3499 | " h3 { color: #ff5190; background-color: #3e3e1f; }\n" |
| 3500 | " a { color: #3391ff; }\n" |
| 3501 | " input { background-color: #2f3437; }\n" |
| 3502 | " .hr { border-color: #8c8273; }\n" |
| 3503 | " .titre { background-color: #1aa6a6; color: #e8e6e3; }\n" |
| 3504 | " .frontend {background: #2f3437;}\n" |
Marno Krahmer | a690b73 | 2022-03-08 13:45:09 +0100 | [diff] [blame] | 3505 | " .socket {background: #2a2d2f;}\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3506 | " .backend {background: #2f3437;}\n" |
| 3507 | " .active_down {background: #760000;}\n" |
| 3508 | " .active_going_up {background: #b99200;}\n" |
| 3509 | " .active_going_down {background: #6c6c00;}\n" |
| 3510 | " .active_up {background: #165900;}\n" |
| 3511 | " .active_nolb {background: #006ab9;}\n" |
| 3512 | " .active_draining {background: #006ab9;}\n" |
| 3513 | " .active_no_check {background: #2a2d2f;}\n" |
| 3514 | " .backup_down {background: #760000;}\n" |
| 3515 | " .backup_going_up {background: #7f007f;}\n" |
| 3516 | " .backup_going_down {background: #580092;}\n" |
| 3517 | " .backup_up {background: #2e3234;}\n" |
| 3518 | " .backup_nolb {background: #1e3c6a;}\n" |
| 3519 | " .backup_draining {background: #a37a00;}\n" |
| 3520 | " .backup_no_check {background: #2a2d2f;}\n" |
| 3521 | " .maintain {background: #9a601a;}\n" |
| 3522 | " a.px:link {color: #d8d83b; text-decoration: none;}\n" |
| 3523 | " a.px:visited {color: #d8d83b; text-decoration: none;}\n" |
| 3524 | " a.px:hover {color: #ffffff; text-decoration: none;}\n" |
| 3525 | " a.lfsb:link {color: #e8e6e3; text-decoration: none;}\n" |
| 3526 | " a.lfsb:visited {color: #e8e6e3; text-decoration: none;}\n" |
| 3527 | " a.lfsb:hover {color: #b5afa6; text-decoration: none;}\n" |
| 3528 | " table.tbl th.empty { background-color: #181a1b; }\n" |
Willy Tarreau | 00147f7 | 2022-04-11 07:59:27 +0200 | [diff] [blame] | 3529 | " table.tbl th.desc { background: #181a1b; }\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3530 | " table.tbl th.pxname { background-color: #8d0033; color: #ffff46; }\n" |
| 3531 | " table.tbl th { border-color: #808080; }\n" |
| 3532 | " table.tbl td { border-color: #808080; }\n" |
| 3533 | " u {text-decoration:none; border-bottom: 1px dotted #e8e6e3;}\n" |
| 3534 | " div.tips {\n" |
| 3535 | " background:#8e8e0d;\n" |
| 3536 | " color:#e8e6e3;\n" |
| 3537 | " border-color: #4e2c86;\n" |
| 3538 | " -moz-box-shadow: #60686c 2px 2px 3px;\n" |
| 3539 | " -webkit-box-shadow: #60686c 2px 2px 3px;\n" |
| 3540 | " box-shadow: #60686c 2px 2px 3px;\n" |
| 3541 | " }\n" |
| 3542 | "}\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3543 | "-->\n" |
| 3544 | "</style></head>\n", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3545 | (ctx->flags & STAT_SHNODE) ? " on " : "", |
| 3546 | (ctx->flags & STAT_SHNODE) ? (uri && uri->node ? uri->node : global.node) : "" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3547 | ); |
| 3548 | } |
| 3549 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3550 | /* Dumps the HTML stats information block to the local trash buffer for and uses |
| 3551 | * the state from stream connector <sc> and per-uri parameters <uri>. The caller |
| 3552 | * is responsible for clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3553 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3554 | static void stats_dump_html_info(struct stconn *sc, struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3555 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3556 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3557 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | b685ad0 | 2023-02-10 16:53:35 +0100 | [diff] [blame] | 3558 | unsigned int up = (now.tv_sec - start_time.tv_sec); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3559 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3560 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 3561 | unsigned long long bps; |
| 3562 | int thr; |
| 3563 | |
| 3564 | for (bps = thr = 0; thr < global.nbthread; thr++) |
| 3565 | bps += 32ULL * read_freq_ctr(&ha_thread_ctx[thr].out_32bps); |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 3566 | |
| 3567 | /* Turn the bytes per second to bits per second and take care of the |
| 3568 | * usual ethernet overhead in order to help figure how far we are from |
| 3569 | * interface saturation since it's the only case which usually matters. |
| 3570 | * For this we count the total size of an Ethernet frame on the wire |
| 3571 | * including preamble and IFG (1538) for the largest TCP segment it |
| 3572 | * transports (1448 with TCP timestamps). This is not valid for smaller |
| 3573 | * packets (under-estimated), but it gives a reasonably accurate |
| 3574 | * estimation of how far we are from uplink saturation. |
| 3575 | */ |
| 3576 | bps = bps * 8 * 1538 / 1448; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3577 | |
| 3578 | /* WARNING! this has to fit the first packet too. |
| 3579 | * We are around 3.5 kB, add adding entries will |
| 3580 | * become tricky if we want to support 4kB buffers ! |
| 3581 | */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3582 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3583 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3584 | PRODUCT_NAME "%s</a></h1>\n" |
| 3585 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3586 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3587 | "<h3>> General process information</h3>\n" |
| 3588 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 3589 | "<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] | 3590 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3591 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3592 | "<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] | 3593 | "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] | 3594 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3595 | "</td><td align=\"center\" nowrap>\n" |
| 3596 | "<table class=\"lgd\"><tr>\n" |
| 3597 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 3598 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
| 3599 | "</tr><tr>\n" |
| 3600 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3601 | "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3602 | "</tr><tr>\n" |
| 3603 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3604 | "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3605 | "</tr><tr>\n" |
| 3606 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 3607 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
| 3608 | "</tr><tr>\n" |
| 3609 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
| 3610 | "</tr><tr>\n" |
| 3611 | "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance </td>" |
| 3612 | "</tr></table>\n" |
| 3613 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
| 3614 | "</td>" |
| 3615 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3616 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3617 | "", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3618 | (ctx->flags & STAT_HIDEVER) ? "" : (stats_version_string), |
| 3619 | pid, (ctx->flags & STAT_SHNODE) ? " on " : "", |
| 3620 | (ctx->flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3621 | (ctx->flags & STAT_SHDESC) ? ": " : "", |
| 3622 | (ctx->flags & STAT_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 3623 | pid, 1, 1, global.nbthread, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3624 | up / 86400, (up % 86400) / 3600, |
| 3625 | (up % 3600) / 60, (up % 60), |
| 3626 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3627 | global.rlimit_memmax ? " MB" : "", |
| 3628 | global.rlimit_nofile, |
| 3629 | global.maxsock, global.maxconn, global.maxpipes, |
| 3630 | 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] | 3631 | bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0), |
| 3632 | bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k', |
Willy Tarreau | f9d5e10 | 2021-10-08 10:43:59 +0200 | [diff] [blame] | 3633 | total_run_queues(), total_allocated_tasks(), clock_report_idle() |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3634 | ); |
| 3635 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3636 | /* scope_txt = search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3637 | memcpy(scope_txt, scope_ptr, ctx->scope_len); |
| 3638 | scope_txt[ctx->scope_len] = '\0'; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3639 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3640 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3641 | "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3642 | (ctx->scope_len > 0) ? scope_txt : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3643 | STAT_SCOPE_TXT_MAXLEN); |
| 3644 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3645 | /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3646 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3647 | if (ctx->scope_len) { |
Willy Tarreau | fc458ec | 2023-04-07 18:11:39 +0200 | [diff] [blame] | 3648 | strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3649 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 3650 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3651 | } |
| 3652 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3653 | if (ctx->flags & STAT_HIDE_DOWN) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3654 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3655 | "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n", |
| 3656 | uri->uri_prefix, |
| 3657 | "", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3658 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3659 | scope_txt); |
| 3660 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3661 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3662 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 3663 | uri->uri_prefix, |
| 3664 | ";up", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3665 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3666 | scope_txt); |
| 3667 | |
| 3668 | if (uri->refresh > 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3669 | if (ctx->flags & STAT_NO_REFRESH) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3670 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3671 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
| 3672 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3673 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3674 | "", |
| 3675 | scope_txt); |
| 3676 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3677 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3678 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
| 3679 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3680 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3681 | ";norefresh", |
| 3682 | scope_txt); |
| 3683 | } |
| 3684 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3685 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3686 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
| 3687 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3688 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3689 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3690 | scope_txt); |
| 3691 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3692 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3693 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
| 3694 | uri->uri_prefix, |
| 3695 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3696 | scope_txt); |
| 3697 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3698 | chunk_appendf(&trash_chunk, |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3699 | "<li><a href=\"%s;json%s%s\">JSON export</a> (<a href=\"%s;json-schema\">schema</a>)<br>\n", |
| 3700 | uri->uri_prefix, |
| 3701 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3702 | scope_txt, uri->uri_prefix); |
| 3703 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3704 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3705 | "</ul></td>" |
| 3706 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3707 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3708 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3709 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3710 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3711 | "</ul>" |
| 3712 | "</td>" |
| 3713 | "</tr></table>\n" |
| 3714 | "" |
| 3715 | ); |
| 3716 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3717 | if (ctx->st_code) { |
| 3718 | switch (ctx->st_code) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3719 | case STAT_STATUS_DONE: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3720 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3721 | "<p><div class=active_up>" |
| 3722 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3723 | "Action processed successfully." |
| 3724 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3725 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3726 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3727 | scope_txt); |
| 3728 | break; |
| 3729 | case STAT_STATUS_NONE: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3730 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3731 | "<p><div class=active_going_down>" |
| 3732 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3733 | "Nothing has changed." |
| 3734 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3735 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3736 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3737 | scope_txt); |
| 3738 | break; |
| 3739 | case STAT_STATUS_PART: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3740 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3741 | "<p><div class=active_going_down>" |
| 3742 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3743 | "Action partially processed.<br>" |
| 3744 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
| 3745 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3746 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3747 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3748 | scope_txt); |
| 3749 | break; |
| 3750 | case STAT_STATUS_ERRP: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3751 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3752 | "<p><div class=active_down>" |
| 3753 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3754 | "Action not processed because of invalid parameters." |
| 3755 | "<ul>" |
| 3756 | "<li>The action is maybe unknown.</li>" |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 3757 | "<li>Invalid key parameter (empty or too long).</li>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3758 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3759 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3760 | "</ul>" |
| 3761 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3762 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3763 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3764 | scope_txt); |
| 3765 | break; |
| 3766 | case STAT_STATUS_EXCD: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3767 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3768 | "<p><div class=active_down>" |
| 3769 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3770 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3771 | "You should retry with less servers at a time.</b>" |
| 3772 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3773 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3774 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3775 | scope_txt); |
| 3776 | break; |
| 3777 | case STAT_STATUS_DENY: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3778 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3779 | "<p><div class=active_down>" |
| 3780 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3781 | "<b>Action denied.</b>" |
| 3782 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3783 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3784 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3785 | scope_txt); |
| 3786 | break; |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3787 | case STAT_STATUS_IVAL: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3788 | chunk_appendf(&trash_chunk, |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3789 | "<p><div class=active_down>" |
| 3790 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3791 | "<b>Invalid requests (unsupported method or chunked encoded request).</b>" |
| 3792 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3793 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3794 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3795 | scope_txt); |
| 3796 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3797 | default: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3798 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3799 | "<p><div class=active_no_check>" |
| 3800 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3801 | "Unexpected result." |
| 3802 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3803 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3804 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3805 | scope_txt); |
| 3806 | } |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3807 | chunk_appendf(&trash_chunk, "<p>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3808 | } |
| 3809 | } |
| 3810 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3811 | /* Dumps the HTML stats trailer block to the local trash buffer. The caller is |
| 3812 | * responsible for clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3813 | */ |
| 3814 | static void stats_dump_html_end() |
| 3815 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3816 | chunk_appendf(&trash_chunk, "</body></html>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3817 | } |
| 3818 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3819 | /* Dumps the stats JSON header to the local trash buffer buffer which. The |
| 3820 | * caller is responsible for clearing it if needed. |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3821 | */ |
| 3822 | static void stats_dump_json_header() |
| 3823 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3824 | chunk_strcat(&trash_chunk, "["); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3828 | /* Dumps the JSON stats trailer block to the local trash buffer. The caller is |
| 3829 | * responsible for clearing the local trash buffer if needed. |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3830 | */ |
| 3831 | static void stats_dump_json_end() |
| 3832 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3833 | chunk_strcat(&trash_chunk, "]\n"); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3834 | } |
| 3835 | |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3836 | /* Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as |
| 3837 | * a pointer to the current server/listener. |
| 3838 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3839 | static int stats_dump_proxies(struct stconn *sc, |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3840 | struct htx *htx, |
| 3841 | struct uri_auth *uri) |
| 3842 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3843 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3844 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3845 | struct channel *rep = sc_ic(sc); |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3846 | struct proxy *px; |
| 3847 | |
| 3848 | /* dump proxies */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3849 | while (ctx->obj1) { |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3850 | if (htx) { |
| 3851 | if (htx_almost_full(htx)) |
| 3852 | goto full; |
| 3853 | } |
| 3854 | else { |
| 3855 | if (buffer_almost_full(&rep->buf)) |
| 3856 | goto full; |
| 3857 | } |
| 3858 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3859 | px = ctx->obj1; |
Marno Krahmer | 07954fb | 2021-06-24 16:51:08 +0200 | [diff] [blame] | 3860 | /* Skip the global frontend proxies and non-networked ones. |
William Lallemand | 85a16b2 | 2021-08-03 13:18:11 +0200 | [diff] [blame] | 3861 | * Also skip proxies that were disabled in the configuration |
Marno Krahmer | 07954fb | 2021-06-24 16:51:08 +0200 | [diff] [blame] | 3862 | * This change allows retrieving stats from "old" proxies after a reload. |
| 3863 | */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 3864 | if (!(px->flags & PR_FL_DISABLED) && px->uuid > 0 && |
William Lallemand | e7f7462 | 2021-07-28 17:45:18 +0200 | [diff] [blame] | 3865 | (px->cap & (PR_CAP_FE | PR_CAP_BE)) && !(px->cap & PR_CAP_INT)) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3866 | if (stats_dump_proxy_to_buffer(sc, htx, px, uri) == 0) |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3867 | return 0; |
| 3868 | } |
| 3869 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3870 | ctx->obj1 = px->next; |
| 3871 | ctx->px_st = STAT_PX_ST_INIT; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3872 | ctx->field = 0; |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | return 1; |
| 3876 | |
| 3877 | full: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3878 | sc_need_room(sc); |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3879 | return 0; |
| 3880 | } |
| 3881 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 3882 | /* This function dumps statistics onto the stream connector's read buffer in |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3883 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
| 3884 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3885 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3886 | * and the stream must be closed, or -1 in case of any error. This function is |
| 3887 | * used by both the CLI and the HTTP handlers. |
| 3888 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3889 | static int stats_dump_stat_to_buffer(struct stconn *sc, struct htx *htx, |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3890 | struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3891 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3892 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3893 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3894 | struct channel *rep = sc_ic(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3895 | enum stats_domain domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3896 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3897 | chunk_reset(&trash_chunk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3898 | |
Willy Tarreau | 41f8852 | 2022-05-03 18:39:27 +0200 | [diff] [blame] | 3899 | switch (ctx->state) { |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3900 | case STAT_STATE_INIT: |
| 3901 | ctx->state = STAT_STATE_HEAD; /* let's start producing data */ |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3902 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3903 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3904 | case STAT_STATE_HEAD: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3905 | if (ctx->flags & STAT_FMT_HTML) |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 3906 | stats_dump_html_head(appctx, uri); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3907 | else if (ctx->flags & STAT_JSON_SCHM) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3908 | stats_dump_json_schema(&trash_chunk); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3909 | else if (ctx->flags & STAT_FMT_JSON) |
Willy Tarreau | 9d7fb63 | 2017-04-11 07:53:04 +0200 | [diff] [blame] | 3910 | stats_dump_json_header(); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3911 | else if (!(ctx->flags & STAT_FMT_TYPED)) |
| 3912 | stats_dump_csv_header(ctx->domain); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3913 | |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3914 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3915 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3916 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3917 | if (ctx->flags & STAT_JSON_SCHM) { |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3918 | ctx->state = STAT_STATE_FIN; |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3919 | return 1; |
| 3920 | } |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3921 | ctx->state = STAT_STATE_INFO; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3922 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3923 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3924 | case STAT_STATE_INFO: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3925 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3926 | stats_dump_html_info(sc, uri); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3927 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3928 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3929 | } |
| 3930 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3931 | if (domain == STATS_DOMAIN_PROXY) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3932 | ctx->obj1 = proxies_list; |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3933 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3934 | ctx->px_st = STAT_PX_ST_INIT; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3935 | ctx->field = 0; |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3936 | ctx->state = STAT_STATE_LIST; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3937 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3938 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3939 | case STAT_STATE_LIST: |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3940 | switch (domain) { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 3941 | case STATS_DOMAIN_RESOLVERS: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3942 | if (!stats_dump_resolvers(sc, stat_l[domain], |
Emeric Brun | d3b4495 | 2021-01-06 16:01:02 +0100 | [diff] [blame] | 3943 | stat_count[domain], |
| 3944 | &stats_module_list[domain])) { |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3945 | return 0; |
| 3946 | } |
| 3947 | break; |
| 3948 | |
| 3949 | case STATS_DOMAIN_PROXY: |
| 3950 | default: |
| 3951 | /* dump proxies */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3952 | if (!stats_dump_proxies(sc, htx, uri)) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3953 | return 0; |
| 3954 | break; |
| 3955 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3956 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3957 | ctx->state = STAT_STATE_END; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3958 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3959 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3960 | case STAT_STATE_END: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3961 | if (ctx->flags & (STAT_FMT_HTML|STAT_FMT_JSON)) { |
| 3962 | if (ctx->flags & STAT_FMT_HTML) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3963 | stats_dump_html_end(); |
| 3964 | else |
| 3965 | stats_dump_json_end(); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3966 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3967 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3968 | } |
| 3969 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3970 | ctx->state = STAT_STATE_FIN; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3971 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3972 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3973 | case STAT_STATE_FIN: |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3974 | return 1; |
| 3975 | |
| 3976 | default: |
| 3977 | /* unknown state ! */ |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3978 | ctx->state = STAT_STATE_FIN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3979 | return -1; |
| 3980 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3981 | |
| 3982 | full: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3983 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3984 | return 0; |
| 3985 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3986 | } |
| 3987 | |
| 3988 | /* We reached the stats page through a POST request. The appctx is |
| 3989 | * expected to have already been allocated by the caller. |
| 3990 | * Parse the posted data and enable/disable servers if necessary. |
| 3991 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3992 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3993 | static int stats_process_http_post(struct stconn *sc) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3994 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3995 | struct stream *s = __sc_strm(sc); |
| 3996 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3997 | struct show_stat_ctx *ctx = appctx->svcctx; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3998 | |
| 3999 | struct proxy *px = NULL; |
| 4000 | struct server *sv = NULL; |
| 4001 | |
| 4002 | char key[LINESIZE]; |
| 4003 | int action = ST_ADM_ACTION_NONE; |
| 4004 | int reprocess = 0; |
| 4005 | |
| 4006 | int total_servers = 0; |
| 4007 | int altered_servers = 0; |
| 4008 | |
| 4009 | char *first_param, *cur_param, *next_param, *end_params; |
| 4010 | char *st_cur_param = NULL; |
| 4011 | char *st_next_param = NULL; |
| 4012 | |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4013 | struct buffer *temp = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4014 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4015 | struct htx *htx = htxbuf(&s->req.buf); |
| 4016 | struct htx_blk *blk; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4017 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4018 | /* we need more data */ |
| 4019 | if (s->txn->req.msg_state < HTTP_MSG_DONE) { |
| 4020 | /* check if we can receive more */ |
| 4021 | if (htx_free_data_space(htx) <= global.tune.maxrewrite) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4022 | ctx->st_code = STAT_STATUS_EXCD; |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4023 | goto out; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4024 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4025 | goto wait; |
| 4026 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4027 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4028 | /* The request was fully received. Copy data */ |
| 4029 | blk = htx_get_head_blk(htx); |
| 4030 | while (blk) { |
| 4031 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4032 | |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 4033 | if (type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4034 | break; |
| 4035 | if (type == HTX_BLK_DATA) { |
| 4036 | struct ist v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4037 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4038 | if (!chunk_memcat(temp, v.ptr, v.len)) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4039 | ctx->st_code = STAT_STATUS_EXCD; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4040 | goto out; |
| 4041 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4042 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4043 | blk = htx_get_next_blk(htx, blk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4044 | } |
| 4045 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4046 | first_param = temp->area; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4047 | end_params = temp->area + temp->data; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4048 | cur_param = next_param = end_params; |
| 4049 | *end_params = '\0'; |
| 4050 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4051 | ctx->st_code = STAT_STATUS_NONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4052 | |
| 4053 | /* |
| 4054 | * Parse the parameters in reverse order to only store the last value. |
| 4055 | * From the html form, the backend and the action are at the end. |
| 4056 | */ |
| 4057 | while (cur_param > first_param) { |
| 4058 | char *value; |
| 4059 | int poffset, plen; |
| 4060 | |
| 4061 | cur_param--; |
| 4062 | |
| 4063 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4064 | reprocess_servers: |
| 4065 | /* Parse the key */ |
| 4066 | poffset = (cur_param != first_param ? 1 : 0); |
| 4067 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4068 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4069 | strncpy(key, cur_param + poffset, plen); |
| 4070 | key[plen - 1] = '\0'; |
| 4071 | } else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4072 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4073 | goto out; |
| 4074 | } |
| 4075 | |
| 4076 | /* Parse the value */ |
| 4077 | value = key; |
| 4078 | while (*value != '\0' && *value != '=') { |
| 4079 | value++; |
| 4080 | } |
| 4081 | if (*value == '=') { |
| 4082 | /* Ok, a value is found, we can mark the end of the key */ |
| 4083 | *value++ = '\0'; |
| 4084 | } |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 4085 | if (url_decode(key, 1) < 0 || url_decode(value, 1) < 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4086 | break; |
| 4087 | |
| 4088 | /* Now we can check the key to see what to do */ |
| 4089 | if (!px && (strcmp(key, "b") == 0)) { |
| 4090 | if ((px = proxy_be_by_name(value)) == NULL) { |
| 4091 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4092 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4093 | goto out; |
| 4094 | } |
| 4095 | } |
| 4096 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4097 | if (strcmp(value, "ready") == 0) { |
| 4098 | action = ST_ADM_ACTION_READY; |
| 4099 | } |
| 4100 | else if (strcmp(value, "drain") == 0) { |
| 4101 | action = ST_ADM_ACTION_DRAIN; |
| 4102 | } |
| 4103 | else if (strcmp(value, "maint") == 0) { |
| 4104 | action = ST_ADM_ACTION_MAINT; |
| 4105 | } |
| 4106 | else if (strcmp(value, "shutdown") == 0) { |
| 4107 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4108 | } |
| 4109 | else if (strcmp(value, "dhlth") == 0) { |
| 4110 | action = ST_ADM_ACTION_DHLTH; |
| 4111 | } |
| 4112 | else if (strcmp(value, "ehlth") == 0) { |
| 4113 | action = ST_ADM_ACTION_EHLTH; |
| 4114 | } |
| 4115 | else if (strcmp(value, "hrunn") == 0) { |
| 4116 | action = ST_ADM_ACTION_HRUNN; |
| 4117 | } |
| 4118 | else if (strcmp(value, "hnolb") == 0) { |
| 4119 | action = ST_ADM_ACTION_HNOLB; |
| 4120 | } |
| 4121 | else if (strcmp(value, "hdown") == 0) { |
| 4122 | action = ST_ADM_ACTION_HDOWN; |
| 4123 | } |
| 4124 | else if (strcmp(value, "dagent") == 0) { |
| 4125 | action = ST_ADM_ACTION_DAGENT; |
| 4126 | } |
| 4127 | else if (strcmp(value, "eagent") == 0) { |
| 4128 | action = ST_ADM_ACTION_EAGENT; |
| 4129 | } |
| 4130 | else if (strcmp(value, "arunn") == 0) { |
| 4131 | action = ST_ADM_ACTION_ARUNN; |
| 4132 | } |
| 4133 | else if (strcmp(value, "adown") == 0) { |
| 4134 | action = ST_ADM_ACTION_ADOWN; |
| 4135 | } |
| 4136 | /* else these are the old supported methods */ |
| 4137 | else if (strcmp(value, "disable") == 0) { |
| 4138 | action = ST_ADM_ACTION_DISABLE; |
| 4139 | } |
| 4140 | else if (strcmp(value, "enable") == 0) { |
| 4141 | action = ST_ADM_ACTION_ENABLE; |
| 4142 | } |
| 4143 | else if (strcmp(value, "stop") == 0) { |
| 4144 | action = ST_ADM_ACTION_STOP; |
| 4145 | } |
| 4146 | else if (strcmp(value, "start") == 0) { |
| 4147 | action = ST_ADM_ACTION_START; |
| 4148 | } |
| 4149 | else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4150 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4151 | goto out; |
| 4152 | } |
| 4153 | } |
| 4154 | else if (strcmp(key, "s") == 0) { |
| 4155 | if (!(px && action)) { |
| 4156 | /* |
| 4157 | * Indicates that we'll need to reprocess the parameters |
| 4158 | * as soon as backend and action are known |
| 4159 | */ |
| 4160 | if (!reprocess) { |
| 4161 | st_cur_param = cur_param; |
| 4162 | st_next_param = next_param; |
| 4163 | } |
| 4164 | reprocess = 1; |
| 4165 | } |
| 4166 | else if ((sv = findserver(px, value)) != NULL) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4167 | HA_SPIN_LOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4168 | switch (action) { |
| 4169 | case ST_ADM_ACTION_DISABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4170 | if (!(sv->cur_admin & SRV_ADMF_FMAINT)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4171 | altered_servers++; |
| 4172 | total_servers++; |
| 4173 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page"); |
| 4174 | } |
| 4175 | break; |
| 4176 | case ST_ADM_ACTION_ENABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4177 | if (sv->cur_admin & SRV_ADMF_FMAINT) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4178 | altered_servers++; |
| 4179 | total_servers++; |
| 4180 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
| 4181 | } |
| 4182 | break; |
| 4183 | case ST_ADM_ACTION_STOP: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4184 | if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4185 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page"); |
| 4186 | altered_servers++; |
| 4187 | total_servers++; |
| 4188 | } |
| 4189 | break; |
| 4190 | case ST_ADM_ACTION_START: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4191 | if (sv->cur_admin & SRV_ADMF_FDRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4192 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4193 | altered_servers++; |
| 4194 | total_servers++; |
| 4195 | } |
| 4196 | break; |
| 4197 | case ST_ADM_ACTION_DHLTH: |
| 4198 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4199 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4200 | altered_servers++; |
| 4201 | total_servers++; |
| 4202 | } |
| 4203 | break; |
| 4204 | case ST_ADM_ACTION_EHLTH: |
| 4205 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4206 | sv->check.state |= CHK_ST_ENABLED; |
| 4207 | altered_servers++; |
| 4208 | total_servers++; |
| 4209 | } |
| 4210 | break; |
| 4211 | case ST_ADM_ACTION_HRUNN: |
| 4212 | if (!(sv->track)) { |
| 4213 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4214 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4215 | altered_servers++; |
| 4216 | total_servers++; |
| 4217 | } |
| 4218 | break; |
| 4219 | case ST_ADM_ACTION_HNOLB: |
| 4220 | if (!(sv->track)) { |
| 4221 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4222 | srv_set_stopping(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4223 | altered_servers++; |
| 4224 | total_servers++; |
| 4225 | } |
| 4226 | break; |
| 4227 | case ST_ADM_ACTION_HDOWN: |
| 4228 | if (!(sv->track)) { |
| 4229 | sv->check.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4230 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4231 | altered_servers++; |
| 4232 | total_servers++; |
| 4233 | } |
| 4234 | break; |
| 4235 | case ST_ADM_ACTION_DAGENT: |
| 4236 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4237 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4238 | altered_servers++; |
| 4239 | total_servers++; |
| 4240 | } |
| 4241 | break; |
| 4242 | case ST_ADM_ACTION_EAGENT: |
| 4243 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4244 | sv->agent.state |= CHK_ST_ENABLED; |
| 4245 | altered_servers++; |
| 4246 | total_servers++; |
| 4247 | } |
| 4248 | break; |
| 4249 | case ST_ADM_ACTION_ARUNN: |
| 4250 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4251 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4252 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4253 | altered_servers++; |
| 4254 | total_servers++; |
| 4255 | } |
| 4256 | break; |
| 4257 | case ST_ADM_ACTION_ADOWN: |
| 4258 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4259 | sv->agent.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4260 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4261 | altered_servers++; |
| 4262 | total_servers++; |
| 4263 | } |
| 4264 | break; |
| 4265 | case ST_ADM_ACTION_READY: |
| 4266 | srv_adm_set_ready(sv); |
| 4267 | altered_servers++; |
| 4268 | total_servers++; |
| 4269 | break; |
| 4270 | case ST_ADM_ACTION_DRAIN: |
| 4271 | srv_adm_set_drain(sv); |
| 4272 | altered_servers++; |
| 4273 | total_servers++; |
| 4274 | break; |
| 4275 | case ST_ADM_ACTION_MAINT: |
| 4276 | srv_adm_set_maint(sv); |
| 4277 | altered_servers++; |
| 4278 | total_servers++; |
| 4279 | break; |
| 4280 | case ST_ADM_ACTION_SHUTDOWN: |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 4281 | if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) { |
Willy Tarreau | af7ea81 | 2019-11-14 16:42:04 +0100 | [diff] [blame] | 4282 | srv_shutdown_streams(sv, SF_ERR_KILLED); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4283 | altered_servers++; |
| 4284 | total_servers++; |
| 4285 | } |
| 4286 | break; |
| 4287 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4288 | HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4289 | } else { |
| 4290 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4291 | total_servers++; |
| 4292 | } |
| 4293 | } |
| 4294 | if (reprocess && px && action) { |
| 4295 | /* Now, we know the backend and the action chosen by the user. |
| 4296 | * We can safely restart from the first server parameter |
| 4297 | * to reprocess them |
| 4298 | */ |
| 4299 | cur_param = st_cur_param; |
| 4300 | next_param = st_next_param; |
| 4301 | reprocess = 0; |
| 4302 | goto reprocess_servers; |
| 4303 | } |
| 4304 | |
| 4305 | next_param = cur_param; |
| 4306 | } |
| 4307 | } |
| 4308 | |
| 4309 | if (total_servers == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4310 | ctx->st_code = STAT_STATUS_NONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4311 | } |
| 4312 | else if (altered_servers == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4313 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4314 | } |
| 4315 | else if (altered_servers == total_servers) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4316 | ctx->st_code = STAT_STATUS_DONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4317 | } |
| 4318 | else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4319 | ctx->st_code = STAT_STATUS_PART; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4320 | } |
| 4321 | out: |
| 4322 | return 1; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4323 | wait: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4324 | ctx->st_code = STAT_STATUS_NONE; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4325 | return 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4326 | } |
| 4327 | |
| 4328 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4329 | static int stats_send_http_headers(struct stconn *sc, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4330 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4331 | struct stream *s = __sc_strm(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4332 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4333 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4334 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4335 | struct htx_sl *sl; |
| 4336 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4337 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4338 | 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); |
| 4339 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 4340 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4341 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4342 | sl->info.res.status = 200; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4343 | |
Christopher Faulet | b829f4c | 2019-03-29 16:13:55 +0100 | [diff] [blame] | 4344 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache"))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4345 | goto full; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4346 | if (ctx->flags & STAT_FMT_HTML) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4347 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/html"))) |
| 4348 | goto full; |
| 4349 | } |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4350 | else if (ctx->flags & (STAT_FMT_JSON|STAT_JSON_SCHM)) { |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 4351 | if (!htx_add_header(htx, ist("Content-Type"), ist("application/json"))) |
| 4352 | goto full; |
| 4353 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4354 | else { |
| 4355 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain"))) |
| 4356 | goto full; |
| 4357 | } |
| 4358 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4359 | if (uri->refresh > 0 && !(ctx->flags & STAT_NO_REFRESH)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4360 | const char *refresh = U2A(uri->refresh); |
Tim Duesterhus | dcf753a | 2021-03-04 17:31:47 +0100 | [diff] [blame] | 4361 | if (!htx_add_header(htx, ist("Refresh"), ist(refresh))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4362 | goto full; |
| 4363 | } |
| 4364 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4365 | if (ctx->flags & STAT_CHUNKED) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4366 | if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked"))) |
| 4367 | goto full; |
| 4368 | } |
| 4369 | |
| 4370 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 4371 | goto full; |
| 4372 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 4373 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4374 | return 1; |
| 4375 | |
| 4376 | full: |
| 4377 | htx_reset(htx); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4378 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4379 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4380 | } |
| 4381 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4382 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4383 | static int stats_send_http_redirect(struct stconn *sc, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4384 | { |
| 4385 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4386 | struct stream *s = __sc_strm(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4387 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4388 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4389 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4390 | struct htx_sl *sl; |
| 4391 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4392 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4393 | /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4394 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4395 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4396 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 4397 | |
Willy Tarreau | fc458ec | 2023-04-07 18:11:39 +0200 | [diff] [blame] | 4398 | strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4399 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 4400 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4401 | } |
| 4402 | |
| 4403 | /* We don't want to land on the posted stats page because a refresh will |
| 4404 | * repost the data. We don't want this to happen on accident so we redirect |
| 4405 | * the browse to the stats page with a GET. |
| 4406 | */ |
| 4407 | chunk_printf(&trash, "%s;st=%s%s%s%s", |
| 4408 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4409 | ((ctx->st_code > STAT_STATUS_INIT) && |
| 4410 | (ctx->st_code < STAT_STATUS_SIZE) && |
| 4411 | stat_status_codes[ctx->st_code]) ? |
| 4412 | stat_status_codes[ctx->st_code] : |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4413 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4414 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4415 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4416 | scope_txt); |
| 4417 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4418 | flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK); |
| 4419 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other")); |
| 4420 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4421 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4422 | sl->info.res.status = 303; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4423 | |
| 4424 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4425 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) || |
| 4426 | !htx_add_header(htx, ist("Content-Length"), ist("0")) || |
| 4427 | !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data))) |
| 4428 | goto full; |
| 4429 | |
| 4430 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 4431 | goto full; |
| 4432 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 4433 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4434 | return 1; |
| 4435 | |
| 4436 | full: |
| 4437 | htx_reset(htx); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4438 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4439 | return 0; |
| 4440 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4441 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 4442 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4443 | /* This I/O handler runs as an applet embedded in a stream connector. It is |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4444 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 4445 | * appctx->st0 contains the operation in progress (dump, done). The handler |
| 4446 | * automatically unregisters itself once transfer is complete. |
| 4447 | */ |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4448 | static void http_stats_io_handler(struct appctx *appctx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4449 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4450 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 4451 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4452 | struct stream *s = __sc_strm(sc); |
| 4453 | struct channel *req = sc_oc(sc); |
| 4454 | struct channel *res = sc_ic(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4455 | struct htx *req_htx, *res_htx; |
| 4456 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4457 | /* only proxy stats are available via http */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4458 | ctx->domain = STATS_DOMAIN_PROXY; |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4459 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4460 | res_htx = htx_from_buf(&res->buf); |
| 4461 | |
Christopher Faulet | 9837bd8 | 2023-04-11 07:41:30 +0200 | [diff] [blame^] | 4462 | if (unlikely(se_fl_test(appctx->sedesc, (SE_FL_EOS|SE_FL_ERROR|SE_FL_SHR|SE_FL_SHW)))) { |
| 4463 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4464 | goto out; |
Christopher Faulet | 9837bd8 | 2023-04-11 07:41:30 +0200 | [diff] [blame^] | 4465 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4466 | |
Ilya Shipitsin | 856aabc | 2020-04-16 23:51:34 +0500 | [diff] [blame] | 4467 | /* Check if the input buffer is available. */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4468 | if (!b_size(&res->buf)) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4469 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4470 | goto out; |
| 4471 | } |
| 4472 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4473 | /* all states are processed in sequence */ |
| 4474 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4475 | if (stats_send_http_headers(sc, res_htx)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4476 | if (s->txn->meth == HTTP_METH_HEAD) |
| 4477 | appctx->st0 = STAT_HTTP_DONE; |
| 4478 | else |
| 4479 | appctx->st0 = STAT_HTTP_DUMP; |
| 4480 | } |
| 4481 | } |
| 4482 | |
| 4483 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Aurelien DARRAGON | 1465684 | 2023-02-03 08:31:42 +0100 | [diff] [blame] | 4484 | trash_chunk = b_make(trash.area, res->buf.size, 0, 0); |
Aurelien DARRAGON | 5e7ecbe | 2023-02-02 15:03:12 +0100 | [diff] [blame] | 4485 | /* adjust buffer size to take htx overhead into account, |
| 4486 | * make sure to perform this call on an empty buffer |
| 4487 | */ |
| 4488 | trash_chunk.size = buf_room_for_htx_data(&trash_chunk); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4489 | if (stats_dump_stat_to_buffer(sc, res_htx, s->be->uri_auth)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4490 | appctx->st0 = STAT_HTTP_DONE; |
| 4491 | } |
| 4492 | |
| 4493 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4494 | if (stats_process_http_post(sc)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4495 | appctx->st0 = STAT_HTTP_LAST; |
Christopher Faulet | 87633c3 | 2023-04-03 18:32:50 +0200 | [diff] [blame] | 4496 | else if (chn_prod(req)->flags & SC_FL_SHUTR) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4497 | appctx->st0 = STAT_HTTP_DONE; |
| 4498 | } |
| 4499 | |
| 4500 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4501 | if (stats_send_http_redirect(sc, res_htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4502 | appctx->st0 = STAT_HTTP_DONE; |
| 4503 | } |
| 4504 | |
| 4505 | if (appctx->st0 == STAT_HTTP_DONE) { |
Christopher Faulet | 08b45cb | 2022-04-07 09:25:13 +0200 | [diff] [blame] | 4506 | /* no more data are expected. If the response buffer is empty, |
| 4507 | * be sure to add something (EOT block in this case) to have |
| 4508 | * something to send. It is important to be sure the EOM flags |
| 4509 | * will be handled by the endpoint. |
| 4510 | */ |
| 4511 | if (htx_is_empty(res_htx)) { |
| 4512 | if (!htx_add_endof(res_htx, HTX_BLK_EOT)) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4513 | sc_need_room(sc); |
Christopher Faulet | 08b45cb | 2022-04-07 09:25:13 +0200 | [diff] [blame] | 4514 | goto out; |
| 4515 | } |
| 4516 | channel_add_input(res, 1); |
| 4517 | } |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 4518 | res_htx->flags |= HTX_FL_EOM; |
Willy Tarreau | d869e13 | 2022-05-17 18:05:31 +0200 | [diff] [blame] | 4519 | se_fl_set(appctx->sedesc, SE_FL_EOI); |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4520 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4523 | if (appctx->st0 == STAT_HTTP_END) { |
Christopher Faulet | df15a5d | 2023-03-31 11:28:22 +0200 | [diff] [blame] | 4524 | se_fl_set(appctx->sedesc, SE_FL_EOS); |
Christopher Faulet | c2c043e | 2023-03-22 09:30:40 +0100 | [diff] [blame] | 4525 | applet_will_consume(appctx); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4526 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4527 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4528 | out: |
| 4529 | /* we have left the request in the buffer for the case where we |
| 4530 | * process a POST, and this automatically re-enables activity on |
| 4531 | * read. It's better to indicate that we want to stop reading when |
| 4532 | * we're sending, so that we know there's at most one direction |
| 4533 | * deciding to wake the applet up. It saves it from looping when |
| 4534 | * emitting large blocks into small TCP windows. |
| 4535 | */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 4536 | htx_to_buf(res_htx, &res->buf); |
Christopher Faulet | c2c043e | 2023-03-22 09:30:40 +0100 | [diff] [blame] | 4537 | if (appctx->st0 == STAT_HTTP_END) { |
| 4538 | /* eat the whole request */ |
| 4539 | if (co_data(req)) { |
| 4540 | req_htx = htx_from_buf(&req->buf); |
| 4541 | co_htx_skip(req, req_htx, co_data(req)); |
| 4542 | htx_to_buf(req_htx, &req->buf); |
| 4543 | } |
| 4544 | } |
| 4545 | else if (!channel_is_empty(res)) |
Willy Tarreau | 75a8f8e | 2022-05-25 18:12:11 +0200 | [diff] [blame] | 4546 | applet_wont_consume(appctx); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4547 | } |
| 4548 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4549 | /* 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] | 4550 | static int stats_dump_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4551 | const struct field *info, |
| 4552 | struct show_stat_ctx *ctx) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4553 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4554 | int flags = ctx->flags; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4555 | int field; |
| 4556 | |
| 4557 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 4558 | if (!field_format(info, field)) |
| 4559 | continue; |
| 4560 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 4561 | if (!chunk_appendf(out, "%s: ", info_fields[field].name)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4562 | return 0; |
| 4563 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 4564 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 4565 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 4566 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4567 | if (!chunk_strcat(out, "\n")) |
| 4568 | return 0; |
| 4569 | } |
| 4570 | return 1; |
| 4571 | } |
| 4572 | |
| 4573 | /* 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] | 4574 | static int stats_dump_typed_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4575 | const struct field *info, |
| 4576 | struct show_stat_ctx *ctx) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4577 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4578 | int flags = ctx->flags; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4579 | int field; |
| 4580 | |
| 4581 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 4582 | if (!field_format(info, field)) |
| 4583 | continue; |
| 4584 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 4585 | 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] | 4586 | return 0; |
| 4587 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 4588 | return 0; |
| 4589 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 4590 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 4591 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 4592 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4593 | if (!chunk_strcat(out, "\n")) |
| 4594 | return 0; |
| 4595 | } |
| 4596 | return 1; |
| 4597 | } |
| 4598 | |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 4599 | /* Fill <info> with HAProxy global info. <info> is preallocated array of length |
| 4600 | * <len>. The length of the array must be INF_TOTAL_FIELDS. If this length is |
| 4601 | * less then this value, the function returns 0, otherwise, it returns 1. Some |
| 4602 | * fields' presence or precision may depend on some of the STAT_* flags present |
| 4603 | * in <flags>. |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4604 | */ |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 4605 | int stats_fill_info(struct field *info, int len, uint flags) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4606 | { |
Willy Tarreau | d37e26e | 2021-05-08 07:40:52 +0200 | [diff] [blame] | 4607 | struct timeval up; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4608 | struct buffer *out = get_trash_chunk(); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4609 | uint64_t glob_out_bytes, glob_spl_bytes, glob_out_b32; |
| 4610 | int thr; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4611 | |
| 4612 | #ifdef USE_OPENSSL |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4613 | double ssl_sess_rate = read_freq_ctr_flt(&global.ssl_per_sec); |
| 4614 | double ssl_key_rate = read_freq_ctr_flt(&global.ssl_fe_keys_per_sec); |
| 4615 | double ssl_reuse = 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4616 | |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4617 | if (ssl_key_rate < ssl_sess_rate) |
| 4618 | ssl_reuse = 100.0 * (1.0 - ssl_key_rate / ssl_sess_rate); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4619 | #endif |
| 4620 | |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4621 | /* sum certain per-thread totals (mostly byte counts) */ |
| 4622 | glob_out_bytes = glob_spl_bytes = glob_out_b32 = 0; |
| 4623 | for (thr = 0; thr < global.nbthread; thr++) { |
| 4624 | glob_out_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].out_bytes); |
| 4625 | glob_spl_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].spliced_out_bytes); |
| 4626 | glob_out_b32 += read_freq_ctr(&ha_thread_ctx[thr].out_32bps); |
| 4627 | } |
| 4628 | glob_out_b32 *= 32; // values are 32-byte units |
| 4629 | |
Willy Tarreau | 6093ba4 | 2023-02-07 15:52:14 +0100 | [diff] [blame] | 4630 | tv_remain(&start_time, &now, &up); |
Willy Tarreau | d37e26e | 2021-05-08 07:40:52 +0200 | [diff] [blame] | 4631 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4632 | if (len < INF_TOTAL_FIELDS) |
| 4633 | return 0; |
| 4634 | |
| 4635 | chunk_reset(out); |
| 4636 | memset(info, 0, sizeof(*info) * len); |
| 4637 | |
| 4638 | 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] | 4639 | 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] | 4640 | 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] | 4641 | 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] | 4642 | |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 4643 | info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread); |
Willy Tarreau | 9135859 | 2021-06-15 08:08:04 +0200 | [diff] [blame] | 4644 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, 1); |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 4645 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, 1); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4646 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 4647 | |
| 4648 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
Willy Tarreau | d37e26e | 2021-05-08 07:40:52 +0200 | [diff] [blame] | 4649 | 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] | 4650 | |
Willy Tarreau | e8abc32 | 2021-05-08 07:56:56 +0200 | [diff] [blame] | 4651 | 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); |
Willy Tarreau | 6093ba4 | 2023-02-07 15:52:14 +0100 | [diff] [blame] | 4652 | info[INF_START_TIME_SEC] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, start_time.tv_sec + start_time.tv_usec / 1000000.0) : mkf_u32(FN_DURATION, start_time.tv_sec); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4653 | 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] | 4654 | 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] | 4655 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
Christopher Faulet | c960a3b | 2022-12-22 11:05:48 +0100 | [diff] [blame] | 4656 | info[INF_POOL_ALLOC_BYTES] = mkf_u64(0, pool_total_allocated()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4657 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
Christopher Faulet | c960a3b | 2022-12-22 11:05:48 +0100 | [diff] [blame] | 4658 | info[INF_POOL_USED_BYTES] = mkf_u64(0, pool_total_used()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4659 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 4660 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 4661 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 4662 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 4663 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 4664 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 4665 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 4666 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 4667 | #ifdef USE_OPENSSL |
| 4668 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
Willy Tarreau | 82531f6 | 2021-10-06 12:15:18 +0200 | [diff] [blame] | 4669 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, global.sslconns); |
| 4670 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, global.totalsslconns); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4671 | #endif |
| 4672 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 4673 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 4674 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4675 | 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] | 4676 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 4677 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4678 | 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] | 4679 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 4680 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 4681 | |
| 4682 | #ifdef USE_OPENSSL |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4683 | 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] | 4684 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 4685 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4686 | 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] | 4687 | 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] | 4688 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, ssl_reuse) : mkf_u32(0, ssl_reuse); |
| 4689 | 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] | 4690 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 4691 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 4692 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 4693 | #endif |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4694 | 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)); |
| 4695 | 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] | 4696 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 4697 | #ifdef USE_ZLIB |
| 4698 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 4699 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 4700 | #endif |
Willy Tarreau | 955a11e | 2021-02-24 17:03:30 +0100 | [diff] [blame] | 4701 | info[INF_TASKS] = mkf_u32(0, total_allocated_tasks()); |
Willy Tarreau | 9c7b808 | 2021-02-24 15:10:07 +0100 | [diff] [blame] | 4702 | info[INF_RUN_QUEUE] = mkf_u32(0, total_run_queues()); |
Willy Tarreau | f9d5e10 | 2021-10-08 10:43:59 +0200 | [diff] [blame] | 4703 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, clock_report_idle()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4704 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 4705 | if (global.desc) |
| 4706 | 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] | 4707 | info[INF_STOPPING] = mkf_u32(0, stopping); |
| 4708 | info[INF_JOBS] = mkf_u32(0, jobs); |
William Lallemand | a719926 | 2018-11-16 16:57:20 +0100 | [diff] [blame] | 4709 | info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs); |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 4710 | info[INF_LISTENERS] = mkf_u32(0, listeners); |
Willy Tarreau | 199ad24 | 2018-11-05 16:31:22 +0100 | [diff] [blame] | 4711 | info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers); |
Willy Tarreau | 2d372c2 | 2018-11-05 17:12:27 +0100 | [diff] [blame] | 4712 | info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers); |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 4713 | info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs); |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 4714 | 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] | 4715 | info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, resolv_failed_resolutions); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4716 | info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, glob_out_bytes); |
| 4717 | info[INF_TOTAL_SPLICED_BYTES_OUT] = mkf_u64(0, glob_spl_bytes); |
| 4718 | info[INF_BYTES_OUT_RATE] = mkf_u64(FN_RATE, glob_out_b32); |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 4719 | info[INF_DEBUG_COMMANDS_ISSUED] = mkf_u32(0, debug_commands_issued); |
Emeric Brun | 45c457a | 2020-07-09 23:23:34 +0200 | [diff] [blame] | 4720 | info[INF_CUM_LOG_MSGS] = mkf_u32(FN_COUNTER, cum_log_messages); |
Amaury Denoyelle | 5dfdf3e | 2021-05-05 17:09:12 +0200 | [diff] [blame] | 4721 | |
| 4722 | info[INF_TAINTED] = mkf_str(FO_STATUS, chunk_newstr(out)); |
| 4723 | chunk_appendf(out, "%#x", get_tainted()); |
| 4724 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4725 | return 1; |
| 4726 | } |
| 4727 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4728 | /* This function dumps information onto the stream connector's read buffer. |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4729 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4730 | * No state is used. |
| 4731 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4732 | static int stats_dump_info_to_buffer(struct stconn *sc) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4733 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4734 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4735 | struct show_stat_ctx *ctx = appctx->svcctx; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4736 | int ret; |
| 4737 | int current_field; |
Christopher Faulet | 2da02ae | 2022-02-24 13:45:27 +0100 | [diff] [blame] | 4738 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4739 | if (!stats_fill_info(info, INF_TOTAL_FIELDS, ctx->flags)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4740 | return 0; |
| 4741 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4742 | chunk_reset(&trash_chunk); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4743 | more: |
| 4744 | current_field = ctx->field; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4745 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4746 | if (ctx->flags & STAT_FMT_TYPED) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4747 | ret = stats_dump_typed_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4748 | else if (ctx->flags & STAT_FMT_JSON) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4749 | ret = stats_dump_json_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4750 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4751 | ret = stats_dump_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4752 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4753 | if (applet_putchk(appctx, &trash_chunk) == -1) { |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4754 | /* restore previous field */ |
| 4755 | ctx->field = current_field; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4756 | return 0; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4757 | } |
| 4758 | if (ret && ctx->field) { |
| 4759 | /* partial dump */ |
| 4760 | goto more; |
| 4761 | } |
| 4762 | ctx->field = 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4763 | return 1; |
| 4764 | } |
| 4765 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4766 | /* This function dumps the schema onto the stream connector's read buffer. |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4767 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4768 | * No state is used. |
| 4769 | * |
Ilya Shipitsin | f38a018 | 2020-12-21 01:16:17 +0500 | [diff] [blame] | 4770 | * 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] | 4771 | * per the recommendation for interoperable integers in section 6 of RFC 7159. |
| 4772 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4773 | static void stats_dump_json_schema(struct buffer *out) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4774 | { |
| 4775 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4776 | int old_len = out->data; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4777 | |
| 4778 | chunk_strcat(out, |
| 4779 | "{" |
| 4780 | "\"$schema\":\"http://json-schema.org/draft-04/schema#\"," |
| 4781 | "\"oneOf\":[" |
| 4782 | "{" |
| 4783 | "\"title\":\"Info\"," |
| 4784 | "\"type\":\"array\"," |
| 4785 | "\"items\":{" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 4786 | "\"title\":\"InfoItem\"," |
| 4787 | "\"type\":\"object\"," |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4788 | "\"properties\":{" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4789 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 4790 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 4791 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 4792 | "\"value\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 4793 | "}," |
| 4794 | "\"required\":[\"field\",\"processNum\",\"tags\"," |
| 4795 | "\"value\"]" |
| 4796 | "}" |
| 4797 | "}," |
| 4798 | "{" |
| 4799 | "\"title\":\"Stat\"," |
| 4800 | "\"type\":\"array\"," |
| 4801 | "\"items\":{" |
| 4802 | "\"title\":\"InfoItem\"," |
| 4803 | "\"type\":\"object\"," |
| 4804 | "\"properties\":{" |
| 4805 | "\"objType\":{" |
| 4806 | "\"enum\":[\"Frontend\",\"Backend\",\"Listener\"," |
| 4807 | "\"Server\",\"Unknown\"]" |
| 4808 | "}," |
| 4809 | "\"proxyId\":{" |
| 4810 | "\"type\":\"integer\"," |
| 4811 | "\"minimum\":0" |
| 4812 | "}," |
| 4813 | "\"id\":{" |
| 4814 | "\"type\":\"integer\"," |
| 4815 | "\"minimum\":0" |
| 4816 | "}," |
| 4817 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 4818 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 4819 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 4820 | "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 4821 | "}," |
| 4822 | "\"required\":[\"objType\",\"proxyId\",\"id\"," |
| 4823 | "\"field\",\"processNum\",\"tags\"," |
| 4824 | "\"value\"]" |
| 4825 | "}" |
| 4826 | "}," |
| 4827 | "{" |
| 4828 | "\"title\":\"Error\"," |
| 4829 | "\"type\":\"object\"," |
| 4830 | "\"properties\":{" |
| 4831 | "\"errorStr\":{" |
| 4832 | "\"type\":\"string\"" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 4833 | "}" |
| 4834 | "}," |
| 4835 | "\"required\":[\"errorStr\"]" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4836 | "}" |
| 4837 | "]," |
| 4838 | "\"definitions\":{" |
| 4839 | "\"field\":{" |
| 4840 | "\"type\":\"object\"," |
| 4841 | "\"pos\":{" |
| 4842 | "\"type\":\"integer\"," |
| 4843 | "\"minimum\":0" |
| 4844 | "}," |
| 4845 | "\"name\":{" |
| 4846 | "\"type\":\"string\"" |
| 4847 | "}," |
| 4848 | "\"required\":[\"pos\",\"name\"]" |
| 4849 | "}," |
| 4850 | "\"processNum\":{" |
| 4851 | "\"type\":\"integer\"," |
| 4852 | "\"minimum\":1" |
| 4853 | "}," |
| 4854 | "\"tags\":{" |
| 4855 | "\"type\":\"object\"," |
| 4856 | "\"origin\":{" |
| 4857 | "\"type\":\"string\"," |
| 4858 | "\"enum\":[\"Metric\",\"Status\",\"Key\"," |
| 4859 | "\"Config\",\"Product\",\"Unknown\"]" |
| 4860 | "}," |
| 4861 | "\"nature\":{" |
| 4862 | "\"type\":\"string\"," |
| 4863 | "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\"," |
| 4864 | "\"Rate\",\"Counter\",\"Duration\"," |
| 4865 | "\"Age\",\"Time\",\"Name\",\"Output\"," |
| 4866 | "\"Avg\", \"Unknown\"]" |
| 4867 | "}," |
| 4868 | "\"scope\":{" |
| 4869 | "\"type\":\"string\"," |
| 4870 | "\"enum\":[\"Cluster\",\"Process\",\"Service\"," |
| 4871 | "\"System\",\"Unknown\"]" |
| 4872 | "}," |
| 4873 | "\"required\":[\"origin\",\"nature\",\"scope\"]" |
| 4874 | "}," |
| 4875 | "\"typedValue\":{" |
| 4876 | "\"type\":\"object\"," |
| 4877 | "\"oneOf\":[" |
| 4878 | "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"}," |
| 4879 | "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"}," |
| 4880 | "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"}," |
| 4881 | "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"}," |
| 4882 | "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}" |
| 4883 | "]," |
| 4884 | "\"definitions\":{" |
| 4885 | "\"s32Value\":{" |
| 4886 | "\"properties\":{" |
| 4887 | "\"type\":{" |
| 4888 | "\"type\":\"string\"," |
| 4889 | "\"enum\":[\"s32\"]" |
| 4890 | "}," |
| 4891 | "\"value\":{" |
| 4892 | "\"type\":\"integer\"," |
| 4893 | "\"minimum\":-2147483648," |
| 4894 | "\"maximum\":2147483647" |
| 4895 | "}" |
| 4896 | "}," |
| 4897 | "\"required\":[\"type\",\"value\"]" |
| 4898 | "}," |
| 4899 | "\"s64Value\":{" |
| 4900 | "\"properties\":{" |
| 4901 | "\"type\":{" |
| 4902 | "\"type\":\"string\"," |
| 4903 | "\"enum\":[\"s64\"]" |
| 4904 | "}," |
| 4905 | "\"value\":{" |
| 4906 | "\"type\":\"integer\"," |
| 4907 | "\"minimum\":-9007199254740991," |
| 4908 | "\"maximum\":9007199254740991" |
| 4909 | "}" |
| 4910 | "}," |
| 4911 | "\"required\":[\"type\",\"value\"]" |
| 4912 | "}," |
| 4913 | "\"u32Value\":{" |
| 4914 | "\"properties\":{" |
| 4915 | "\"type\":{" |
| 4916 | "\"type\":\"string\"," |
| 4917 | "\"enum\":[\"u32\"]" |
| 4918 | "}," |
| 4919 | "\"value\":{" |
| 4920 | "\"type\":\"integer\"," |
| 4921 | "\"minimum\":0," |
| 4922 | "\"maximum\":4294967295" |
| 4923 | "}" |
| 4924 | "}," |
| 4925 | "\"required\":[\"type\",\"value\"]" |
| 4926 | "}," |
| 4927 | "\"u64Value\":{" |
| 4928 | "\"properties\":{" |
| 4929 | "\"type\":{" |
| 4930 | "\"type\":\"string\"," |
| 4931 | "\"enum\":[\"u64\"]" |
| 4932 | "}," |
| 4933 | "\"value\":{" |
| 4934 | "\"type\":\"integer\"," |
| 4935 | "\"minimum\":0," |
| 4936 | "\"maximum\":9007199254740991" |
| 4937 | "}" |
| 4938 | "}," |
| 4939 | "\"required\":[\"type\",\"value\"]" |
| 4940 | "}," |
| 4941 | "\"strValue\":{" |
| 4942 | "\"properties\":{" |
| 4943 | "\"type\":{" |
| 4944 | "\"type\":\"string\"," |
| 4945 | "\"enum\":[\"str\"]" |
| 4946 | "}," |
| 4947 | "\"value\":{\"type\":\"string\"}" |
| 4948 | "}," |
| 4949 | "\"required\":[\"type\",\"value\"]" |
| 4950 | "}," |
| 4951 | "\"unknownValue\":{" |
| 4952 | "\"properties\":{" |
| 4953 | "\"type\":{" |
| 4954 | "\"type\":\"integer\"," |
| 4955 | "\"minimum\":0" |
| 4956 | "}," |
| 4957 | "\"value\":{" |
| 4958 | "\"type\":\"string\"," |
| 4959 | "\"enum\":[\"unknown\"]" |
| 4960 | "}" |
| 4961 | "}," |
| 4962 | "\"required\":[\"type\",\"value\"]" |
| 4963 | "}" |
| 4964 | "}" |
| 4965 | "}" |
| 4966 | "}" |
| 4967 | "}"); |
| 4968 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4969 | if (old_len == out->data) { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4970 | chunk_reset(out); |
| 4971 | chunk_appendf(out, |
| 4972 | "{\"errorStr\":\"output buffer too short\"}"); |
| 4973 | } |
Willy Tarreau | 5a0e7ca | 2022-06-10 09:21:22 +0200 | [diff] [blame] | 4974 | chunk_appendf(out, "\n"); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4975 | } |
| 4976 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4977 | /* This function dumps the schema onto the stream connector's read buffer. |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4978 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4979 | * No state is used. |
| 4980 | */ |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4981 | static int stats_dump_json_schema_to_buffer(struct appctx *appctx) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4982 | { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4983 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4984 | chunk_reset(&trash_chunk); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4985 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4986 | stats_dump_json_schema(&trash_chunk); |
| 4987 | |
| 4988 | if (applet_putchk(appctx, &trash_chunk) == -1) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4989 | return 0; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4990 | |
| 4991 | return 1; |
| 4992 | } |
| 4993 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 4994 | 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] | 4995 | { |
| 4996 | struct proxy *px; |
| 4997 | struct server *sv; |
| 4998 | struct listener *li; |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 4999 | struct stats_module *mod; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5000 | int clrall = 0; |
| 5001 | |
| 5002 | if (strcmp(args[2], "all") == 0) |
| 5003 | clrall = 1; |
| 5004 | |
| 5005 | /* check permissions */ |
| 5006 | if (!cli_has_level(appctx, ACCESS_LVL_OPER) || |
| 5007 | (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN))) |
| 5008 | return 1; |
| 5009 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 5010 | for (px = proxies_list; px; px = px->next) { |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5011 | if (clrall) { |
| 5012 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 5013 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 5014 | } |
| 5015 | else { |
| 5016 | px->be_counters.conn_max = 0; |
| 5017 | px->be_counters.p.http.rps_max = 0; |
| 5018 | px->be_counters.sps_max = 0; |
| 5019 | px->be_counters.cps_max = 0; |
| 5020 | px->be_counters.nbpend_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 5021 | px->be_counters.qtime_max = 0; |
| 5022 | px->be_counters.ctime_max = 0; |
| 5023 | px->be_counters.dtime_max = 0; |
| 5024 | px->be_counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5025 | |
| 5026 | px->fe_counters.conn_max = 0; |
| 5027 | px->fe_counters.p.http.rps_max = 0; |
| 5028 | px->fe_counters.sps_max = 0; |
| 5029 | px->fe_counters.cps_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | for (sv = px->srv; sv; sv = sv->next) |
| 5033 | if (clrall) |
| 5034 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 5035 | else { |
| 5036 | sv->counters.cur_sess_max = 0; |
| 5037 | sv->counters.nbpend_max = 0; |
| 5038 | sv->counters.sps_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 5039 | sv->counters.qtime_max = 0; |
| 5040 | sv->counters.ctime_max = 0; |
| 5041 | sv->counters.dtime_max = 0; |
| 5042 | sv->counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5043 | } |
| 5044 | |
| 5045 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
| 5046 | if (li->counters) { |
| 5047 | if (clrall) |
| 5048 | memset(li->counters, 0, sizeof(*li->counters)); |
| 5049 | else |
| 5050 | li->counters->conn_max = 0; |
| 5051 | } |
| 5052 | } |
| 5053 | |
| 5054 | global.cps_max = 0; |
| 5055 | global.sps_max = 0; |
Olivier Houchard | 00bc3cb | 2017-10-17 19:23:25 +0200 | [diff] [blame] | 5056 | global.ssl_max = 0; |
| 5057 | global.ssl_fe_keys_max = 0; |
| 5058 | global.ssl_be_keys_max = 0; |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 5059 | |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 5060 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5061 | if (!mod->clearable && !clrall) |
| 5062 | continue; |
| 5063 | |
| 5064 | for (px = proxies_list; px; px = px->next) { |
| 5065 | enum stats_domain_px_cap mod_cap = stats_px_get_cap(mod->domain_flags); |
| 5066 | |
| 5067 | if (px->cap & PR_CAP_FE && mod_cap & STATS_PX_CAP_FE) { |
| 5068 | EXTRA_COUNTERS_INIT(px->extra_counters_fe, |
| 5069 | mod, |
| 5070 | mod->counters, |
| 5071 | mod->counters_size); |
| 5072 | } |
| 5073 | |
| 5074 | if (px->cap & PR_CAP_BE && mod_cap & STATS_PX_CAP_BE) { |
| 5075 | EXTRA_COUNTERS_INIT(px->extra_counters_be, |
| 5076 | mod, |
| 5077 | mod->counters, |
| 5078 | mod->counters_size); |
| 5079 | } |
| 5080 | |
| 5081 | if (mod_cap & STATS_PX_CAP_SRV) { |
| 5082 | for (sv = px->srv; sv; sv = sv->next) { |
| 5083 | EXTRA_COUNTERS_INIT(sv->extra_counters, |
| 5084 | mod, |
| 5085 | mod->counters, |
| 5086 | mod->counters_size); |
| 5087 | } |
| 5088 | } |
| 5089 | |
| 5090 | if (mod_cap & STATS_PX_CAP_LI) { |
| 5091 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 5092 | EXTRA_COUNTERS_INIT(li->extra_counters, |
| 5093 | mod, |
| 5094 | mod->counters, |
| 5095 | mod->counters_size); |
| 5096 | } |
| 5097 | } |
| 5098 | } |
| 5099 | } |
| 5100 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5101 | resolv_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_RESOLVERS]); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5102 | |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 5103 | memset(activity, 0, sizeof(activity)); |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5104 | return 1; |
| 5105 | } |
| 5106 | |
| 5107 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 5108 | 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] | 5109 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5110 | struct show_stat_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5111 | int arg = 2; |
| 5112 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5113 | ctx->scope_str = 0; |
| 5114 | ctx->scope_len = 0; |
| 5115 | ctx->flags = 0; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 5116 | ctx->field = 0; /* explicit default value */ |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 5117 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5118 | while (*args[arg]) { |
| 5119 | if (strcmp(args[arg], "typed") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5120 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5121 | else if (strcmp(args[arg], "json") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5122 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5123 | else if (strcmp(args[arg], "desc") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5124 | ctx->flags |= STAT_SHOW_FDESC; |
Willy Tarreau | 2745620 | 2021-05-08 07:54:24 +0200 | [diff] [blame] | 5125 | else if (strcmp(args[arg], "float") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5126 | ctx->flags |= STAT_USE_FLOAT; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5127 | arg++; |
| 5128 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5129 | return 0; |
| 5130 | } |
| 5131 | |
| 5132 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 5133 | 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] | 5134 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5135 | struct show_stat_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5136 | int arg = 2; |
| 5137 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5138 | ctx->scope_str = 0; |
| 5139 | ctx->scope_len = 0; |
| 5140 | ctx->flags = STAT_SHNODE | STAT_SHDESC; |
Willy Tarreau | 578d6e4 | 2019-10-09 11:00:22 +0200 | [diff] [blame] | 5141 | |
Willy Tarreau | 0698c80 | 2022-05-11 14:09:57 +0200 | [diff] [blame] | 5142 | if ((strm_li(appctx_strm(appctx))->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5143 | ctx->flags |= STAT_SHLGNDS; |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 5144 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5145 | /* proxy is the default domain */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5146 | ctx->domain = STATS_DOMAIN_PROXY; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 5147 | if (strcmp(args[arg], "domain") == 0) { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5148 | ++args; |
| 5149 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 5150 | if (strcmp(args[arg], "proxy") == 0) { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5151 | ++args; |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5152 | } else if (strcmp(args[arg], "resolvers") == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5153 | ctx->domain = STATS_DOMAIN_RESOLVERS; |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5154 | ++args; |
| 5155 | } else { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5156 | return cli_err(appctx, "Invalid statistics domain.\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5157 | } |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5158 | } |
| 5159 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5160 | if (ctx->domain == STATS_DOMAIN_PROXY |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5161 | && *args[arg] && *args[arg+1] && *args[arg+2]) { |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5162 | struct proxy *px; |
| 5163 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5164 | px = proxy_find_by_name(args[arg], 0, 0); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5165 | if (px) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5166 | ctx->iid = px->uuid; |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5167 | else |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5168 | ctx->iid = atoi(args[arg]); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5169 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5170 | if (!ctx->iid) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5171 | return cli_err(appctx, "No such proxy.\n"); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5172 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5173 | ctx->flags |= STAT_BOUND; |
| 5174 | ctx->type = atoi(args[arg+1]); |
| 5175 | ctx->sid = atoi(args[arg+2]); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5176 | arg += 3; |
| 5177 | } |
| 5178 | |
| 5179 | while (*args[arg]) { |
| 5180 | if (strcmp(args[arg], "typed") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5181 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5182 | else if (strcmp(args[arg], "json") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5183 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5184 | else if (strcmp(args[arg], "desc") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5185 | ctx->flags |= STAT_SHOW_FDESC; |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 5186 | else if (strcmp(args[arg], "no-maint") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5187 | ctx->flags |= STAT_HIDE_MAINT; |
Willy Tarreau | 65141ff | 2020-10-23 17:19:48 +0200 | [diff] [blame] | 5188 | else if (strcmp(args[arg], "up") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5189 | ctx->flags |= STAT_HIDE_DOWN; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5190 | arg++; |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5191 | } |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5192 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5193 | return 0; |
| 5194 | } |
| 5195 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5196 | static int cli_io_handler_dump_info(struct appctx *appctx) |
| 5197 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5198 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5199 | return stats_dump_info_to_buffer(appctx_sc(appctx)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5200 | } |
| 5201 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 5202 | /* This I/O handler runs as an applet embedded in a stream connector. It is |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5203 | * used to send raw stats over a socket. |
| 5204 | */ |
| 5205 | static int cli_io_handler_dump_stat(struct appctx *appctx) |
| 5206 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5207 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5208 | return stats_dump_stat_to_buffer(appctx_sc(appctx), NULL, NULL); |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5209 | } |
| 5210 | |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5211 | static int cli_io_handler_dump_json_schema(struct appctx *appctx) |
| 5212 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5213 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5214 | return stats_dump_json_schema_to_buffer(appctx); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5215 | } |
| 5216 | |
Amaury Denoyelle | 216a1ce | 2021-03-18 15:48:14 +0100 | [diff] [blame] | 5217 | int stats_allocate_proxy_counters_internal(struct extra_counters **counters, |
| 5218 | int type, int px_cap) |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5219 | { |
| 5220 | struct stats_module *mod; |
| 5221 | |
| 5222 | EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed); |
| 5223 | |
| 5224 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5225 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 5226 | continue; |
| 5227 | |
| 5228 | EXTRA_COUNTERS_ADD(mod, *counters, mod->counters, mod->counters_size); |
| 5229 | } |
| 5230 | |
| 5231 | EXTRA_COUNTERS_ALLOC(*counters, alloc_failed); |
| 5232 | |
| 5233 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5234 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 5235 | continue; |
| 5236 | |
| 5237 | EXTRA_COUNTERS_INIT(*counters, mod, mod->counters, mod->counters_size); |
| 5238 | } |
| 5239 | |
| 5240 | return 1; |
| 5241 | |
| 5242 | alloc_failed: |
| 5243 | return 0; |
| 5244 | } |
| 5245 | |
| 5246 | /* Initialize and allocate all extra counters for a proxy and its attached |
| 5247 | * servers/listeners with all already registered stats module |
| 5248 | */ |
| 5249 | int stats_allocate_proxy_counters(struct proxy *px) |
| 5250 | { |
| 5251 | struct server *sv; |
| 5252 | struct listener *li; |
| 5253 | |
| 5254 | if (px->cap & PR_CAP_FE) { |
| 5255 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_fe, |
| 5256 | COUNTERS_FE, |
| 5257 | STATS_PX_CAP_FE)) { |
| 5258 | return 0; |
| 5259 | } |
| 5260 | } |
| 5261 | |
| 5262 | if (px->cap & PR_CAP_BE) { |
| 5263 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be, |
| 5264 | COUNTERS_BE, |
| 5265 | STATS_PX_CAP_BE)) { |
| 5266 | return 0; |
| 5267 | } |
| 5268 | } |
| 5269 | |
| 5270 | for (sv = px->srv; sv; sv = sv->next) { |
| 5271 | if (!stats_allocate_proxy_counters_internal(&sv->extra_counters, |
| 5272 | COUNTERS_SV, |
| 5273 | STATS_PX_CAP_SRV)) { |
| 5274 | return 0; |
| 5275 | } |
| 5276 | } |
| 5277 | |
| 5278 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 5279 | if (!stats_allocate_proxy_counters_internal(&li->extra_counters, |
| 5280 | COUNTERS_LI, |
| 5281 | STATS_PX_CAP_LI)) { |
| 5282 | return 0; |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | return 1; |
| 5287 | } |
| 5288 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 5289 | void stats_register_module(struct stats_module *m) |
| 5290 | { |
| 5291 | const uint8_t domain = stats_get_domain(m->domain_flags); |
| 5292 | |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 5293 | LIST_APPEND(&stats_module_list[domain], &m->list); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5294 | stat_count[domain] += m->stats_count; |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 5295 | } |
| 5296 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5297 | static int allocate_stats_px_postcheck(void) |
| 5298 | { |
| 5299 | struct stats_module *mod; |
| 5300 | size_t i = ST_F_TOTAL_FIELDS; |
| 5301 | int err_code = 0; |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 5302 | struct proxy *px; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5303 | |
| 5304 | stat_count[STATS_DOMAIN_PROXY] += ST_F_TOTAL_FIELDS; |
| 5305 | |
| 5306 | stat_f[STATS_DOMAIN_PROXY] = malloc(stat_count[STATS_DOMAIN_PROXY] * sizeof(struct name_desc)); |
| 5307 | if (!stat_f[STATS_DOMAIN_PROXY]) { |
| 5308 | ha_alert("stats: cannot allocate all fields for proxy statistics\n"); |
| 5309 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5310 | return err_code; |
| 5311 | } |
| 5312 | |
| 5313 | memcpy(stat_f[STATS_DOMAIN_PROXY], stat_fields, |
| 5314 | ST_F_TOTAL_FIELDS * sizeof(struct name_desc)); |
| 5315 | |
| 5316 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5317 | memcpy(stat_f[STATS_DOMAIN_PROXY] + i, |
| 5318 | mod->stats, |
| 5319 | mod->stats_count * sizeof(struct name_desc)); |
| 5320 | i += mod->stats_count; |
| 5321 | } |
| 5322 | |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 5323 | for (px = proxies_list; px; px = px->next) { |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5324 | if (!stats_allocate_proxy_counters(px)) { |
| 5325 | ha_alert("stats: cannot allocate all counters for proxy statistics\n"); |
| 5326 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5327 | return err_code; |
| 5328 | } |
| 5329 | } |
| 5330 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5331 | /* wait per-thread alloc to perform corresponding stat_l allocation */ |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5332 | |
| 5333 | return err_code; |
| 5334 | } |
| 5335 | |
| 5336 | REGISTER_CONFIG_POSTPARSER("allocate-stats-px", allocate_stats_px_postcheck); |
| 5337 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5338 | static int allocate_stats_rslv_postcheck(void) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5339 | { |
| 5340 | struct stats_module *mod; |
| 5341 | size_t i = 0; |
| 5342 | int err_code = 0; |
| 5343 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5344 | stat_f[STATS_DOMAIN_RESOLVERS] = malloc(stat_count[STATS_DOMAIN_RESOLVERS] * sizeof(struct name_desc)); |
| 5345 | if (!stat_f[STATS_DOMAIN_RESOLVERS]) { |
| 5346 | ha_alert("stats: cannot allocate all fields for resolver statistics\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5347 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5348 | return err_code; |
| 5349 | } |
| 5350 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5351 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_RESOLVERS], list) { |
| 5352 | memcpy(stat_f[STATS_DOMAIN_RESOLVERS] + i, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5353 | mod->stats, |
| 5354 | mod->stats_count * sizeof(struct name_desc)); |
| 5355 | i += mod->stats_count; |
| 5356 | } |
| 5357 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5358 | if (!resolv_allocate_counters(&stats_module_list[STATS_DOMAIN_RESOLVERS])) { |
| 5359 | ha_alert("stats: cannot allocate all counters for resolver statistics\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5360 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5361 | return err_code; |
| 5362 | } |
| 5363 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5364 | /* wait per-thread alloc to perform corresponding stat_l allocation */ |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5365 | |
| 5366 | return err_code; |
| 5367 | } |
| 5368 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5369 | REGISTER_CONFIG_POSTPARSER("allocate-stats-resolver", allocate_stats_rslv_postcheck); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5370 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5371 | static int allocate_stat_lines_per_thread(void) |
| 5372 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5373 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5374 | |
| 5375 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5376 | const int domain = domains[i]; |
| 5377 | |
| 5378 | stat_l[domain] = malloc(stat_count[domain] * sizeof(struct field)); |
| 5379 | if (!stat_l[domain]) |
| 5380 | return 0; |
| 5381 | } |
| 5382 | return 1; |
| 5383 | } |
| 5384 | |
| 5385 | REGISTER_PER_THREAD_ALLOC(allocate_stat_lines_per_thread); |
| 5386 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5387 | static int allocate_trash_counters(void) |
| 5388 | { |
| 5389 | struct stats_module *mod; |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5390 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5391 | size_t max_counters_size = 0; |
| 5392 | |
| 5393 | /* calculate the greatest counters used by any stats modules */ |
| 5394 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5395 | list_for_each_entry(mod, &stats_module_list[domains[i]], list) { |
| 5396 | max_counters_size = mod->counters_size > max_counters_size ? |
| 5397 | mod->counters_size : max_counters_size; |
| 5398 | } |
| 5399 | } |
| 5400 | |
| 5401 | /* allocate the trash with the size of the greatest counters */ |
| 5402 | if (max_counters_size) { |
| 5403 | trash_counters = malloc(max_counters_size); |
| 5404 | if (!trash_counters) { |
| 5405 | ha_alert("stats: cannot allocate trash counters for statistics\n"); |
| 5406 | return 0; |
| 5407 | } |
| 5408 | } |
| 5409 | |
| 5410 | return 1; |
| 5411 | } |
| 5412 | |
| 5413 | REGISTER_PER_THREAD_ALLOC(allocate_trash_counters); |
| 5414 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5415 | static void deinit_stat_lines_per_thread(void) |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5416 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5417 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5418 | |
| 5419 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5420 | const int domain = domains[i]; |
| 5421 | |
Willy Tarreau | 61cfdf4 | 2021-02-20 10:46:51 +0100 | [diff] [blame] | 5422 | ha_free(&stat_l[domain]); |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5423 | } |
| 5424 | } |
| 5425 | |
| 5426 | |
| 5427 | REGISTER_PER_THREAD_FREE(deinit_stat_lines_per_thread); |
| 5428 | |
| 5429 | static void deinit_stats(void) |
| 5430 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5431 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5432 | |
| 5433 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5434 | const int domain = domains[i]; |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5435 | |
| 5436 | if (stat_f[domain]) |
| 5437 | free(stat_f[domain]); |
| 5438 | } |
| 5439 | } |
| 5440 | |
| 5441 | REGISTER_POST_DEINIT(deinit_stats); |
| 5442 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5443 | static void free_trash_counters(void) |
| 5444 | { |
| 5445 | if (trash_counters) |
| 5446 | free(trash_counters); |
| 5447 | } |
| 5448 | |
| 5449 | REGISTER_PER_THREAD_FREE(free_trash_counters); |
| 5450 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5451 | /* register cli keywords */ |
| 5452 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5453 | { { "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] | 5454 | { { "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] | 5455 | { { "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 }, |
| 5456 | { { "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] | 5457 | {{},} |
| 5458 | }}; |
| 5459 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5460 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 5461 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 5462 | struct applet http_stats_applet = { |
| 5463 | .obj_type = OBJ_TYPE_APPLET, |
| 5464 | .name = "<STATS>", /* used for logging */ |
| 5465 | .fct = http_stats_io_handler, |
| 5466 | .release = NULL, |
| 5467 | }; |
| 5468 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 5469 | /* |
| 5470 | * Local variables: |
| 5471 | * c-indent-level: 8 |
| 5472 | * c-basic-offset: 8 |
| 5473 | * End: |
| 5474 | */ |