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