William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions dedicated to statistics output and the stats socket |
| 3 | * |
| 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
| 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | #include <pwd.h> |
| 20 | #include <grp.h> |
| 21 | |
| 22 | #include <sys/socket.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <sys/types.h> |
| 25 | |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 26 | #include <haproxy/api.h> |
Willy Tarreau | 5d9ddc5 | 2021-10-06 19:54:09 +0200 | [diff] [blame] | 27 | #include <haproxy/activity.h> |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 28 | #include <haproxy/applet.h> |
Willy Tarreau | 4980160 | 2020-06-04 22:50:02 +0200 | [diff] [blame] | 29 | #include <haproxy/backend.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 30 | #include <haproxy/base64.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 31 | #include <haproxy/cfgparse.h> |
Willy Tarreau | f1d32c4 | 2020-06-04 21:07:02 +0200 | [diff] [blame] | 32 | #include <haproxy/channel.h> |
Willy Tarreau | 4aa573d | 2020-06-04 18:21:56 +0200 | [diff] [blame] | 33 | #include <haproxy/check.h> |
Willy Tarreau | 83487a8 | 2020-06-04 20:19:54 +0200 | [diff] [blame] | 34 | #include <haproxy/cli.h> |
Willy Tarreau | 5554264 | 2021-10-08 09:33:24 +0200 | [diff] [blame] | 35 | #include <haproxy/clock.h> |
Willy Tarreau | 0a3bd39 | 2020-06-04 08:52:38 +0200 | [diff] [blame] | 36 | #include <haproxy/compression.h> |
Willy Tarreau | 2a83d60 | 2020-05-27 16:58:08 +0200 | [diff] [blame] | 37 | #include <haproxy/debug.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 38 | #include <haproxy/errors.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 39 | #include <haproxy/fd.h> |
| 40 | #include <haproxy/freq_ctr.h> |
Willy Tarreau | 762d7a5 | 2020-06-04 11:23:07 +0200 | [diff] [blame] | 41 | #include <haproxy/frontend.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 42 | #include <haproxy/global.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 43 | #include <haproxy/http.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 44 | #include <haproxy/http_ana.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 45 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 46 | #include <haproxy/htx.h> |
Willy Tarreau | 853b297 | 2020-05-27 18:01:47 +0200 | [diff] [blame] | 47 | #include <haproxy/list.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 48 | #include <haproxy/listener.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 49 | #include <haproxy/log.h> |
Willy Tarreau | 2cd5809 | 2020-06-04 15:10:43 +0200 | [diff] [blame] | 50 | #include <haproxy/map-t.h> |
Willy Tarreau | 225a90a | 2020-06-04 15:06:28 +0200 | [diff] [blame] | 51 | #include <haproxy/pattern-t.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 52 | #include <haproxy/pipe.h> |
| 53 | #include <haproxy/pool.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 54 | #include <haproxy/proxy.h> |
Emeric Brun | c943799 | 2021-02-12 19:42:55 +0100 | [diff] [blame] | 55 | #include <haproxy/resolvers.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 56 | #include <haproxy/sc_strm.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 57 | #include <haproxy/server.h> |
Willy Tarreau | 48d25b3 | 2020-06-04 18:58:52 +0200 | [diff] [blame] | 58 | #include <haproxy/session.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 59 | #include <haproxy/stats.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 60 | #include <haproxy/stconn.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 61 | #include <haproxy/stream.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 62 | #include <haproxy/task.h> |
Willy Tarreau | c2f7c58 | 2020-06-02 18:15:32 +0200 | [diff] [blame] | 63 | #include <haproxy/ticks.h> |
Willy Tarreau | 92b4f13 | 2020-06-01 11:05:15 +0200 | [diff] [blame] | 64 | #include <haproxy/time.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 65 | #include <haproxy/tools.h> |
Willy Tarreau | 8c42b8a | 2020-06-04 19:27:34 +0200 | [diff] [blame] | 66 | #include <haproxy/uri_auth-t.h> |
Willy Tarreau | d678805 | 2020-05-27 15:59:00 +0200 | [diff] [blame] | 67 | #include <haproxy/version.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 68 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 69 | |
Christopher Faulet | 2b9b678 | 2019-02-27 16:42:58 +0100 | [diff] [blame] | 70 | /* status codes available for the stats admin page (strictly 4 chars length) */ |
| 71 | const char *stat_status_codes[STAT_STATUS_SIZE] = { |
| 72 | [STAT_STATUS_DENY] = "DENY", |
| 73 | [STAT_STATUS_DONE] = "DONE", |
| 74 | [STAT_STATUS_ERRP] = "ERRP", |
| 75 | [STAT_STATUS_EXCD] = "EXCD", |
| 76 | [STAT_STATUS_NONE] = "NONE", |
| 77 | [STAT_STATUS_PART] = "PART", |
| 78 | [STAT_STATUS_UNKN] = "UNKN", |
| 79 | [STAT_STATUS_IVAL] = "IVAL", |
| 80 | }; |
| 81 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 82 | /* These are the field names for each INF_* field position. Please pay attention |
| 83 | * to always use the exact same name except that the strings for new names must |
| 84 | * be lower case or CamelCase while the enum entries must be upper case. |
| 85 | */ |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 86 | const struct name_desc info_fields[INF_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 87 | [INF_NAME] = { .name = "Name", .desc = "Product name" }, |
| 88 | [INF_VERSION] = { .name = "Version", .desc = "Product version" }, |
| 89 | [INF_RELEASE_DATE] = { .name = "Release_date", .desc = "Date of latest source code update" }, |
| 90 | [INF_NBTHREAD] = { .name = "Nbthread", .desc = "Number of started threads (global.nbthread)" }, |
Willy Tarreau | 9135859 | 2021-06-15 08:08:04 +0200 | [diff] [blame] | 91 | [INF_NBPROC] = { .name = "Nbproc", .desc = "Number of started worker processes (historical, always 1)" }, |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 92 | [INF_PROCESS_NUM] = { .name = "Process_num", .desc = "Relative worker process number (1)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 93 | [INF_PID] = { .name = "Pid", .desc = "This worker process identifier for the system" }, |
| 94 | [INF_UPTIME] = { .name = "Uptime", .desc = "How long ago this worker process was started (days+hours+minutes+seconds)" }, |
| 95 | [INF_UPTIME_SEC] = { .name = "Uptime_sec", .desc = "How long ago this worker process was started (seconds)" }, |
William Dauchy | defd156 | 2021-01-15 22:41:38 +0100 | [diff] [blame] | 96 | [INF_START_TIME_SEC] = { .name = "Start_time_sec", .desc = "Start time in seconds" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 97 | [INF_MEMMAX_MB] = { .name = "Memmax_MB", .desc = "Worker process's hard limit on memory usage in MB (-m on command line)" }, |
William Dauchy | a8766cf | 2021-01-15 22:41:37 +0100 | [diff] [blame] | 98 | [INF_MEMMAX_BYTES] = { .name = "Memmax_bytes", .desc = "Worker process's hard limit on memory usage in byes (-m on command line)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 99 | [INF_POOL_ALLOC_MB] = { .name = "PoolAlloc_MB", .desc = "Amount of memory allocated in pools (in MB)" }, |
William Dauchy | a8766cf | 2021-01-15 22:41:37 +0100 | [diff] [blame] | 100 | [INF_POOL_ALLOC_BYTES] = { .name = "PoolAlloc_bytes", .desc = "Amount of memory allocated in pools (in bytes)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 101 | [INF_POOL_USED_MB] = { .name = "PoolUsed_MB", .desc = "Amount of pool memory currently used (in MB)" }, |
William Dauchy | a8766cf | 2021-01-15 22:41:37 +0100 | [diff] [blame] | 102 | [INF_POOL_USED_BYTES] = { .name = "PoolUsed_bytes", .desc = "Amount of pool memory currently used (in bytes)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 103 | [INF_POOL_FAILED] = { .name = "PoolFailed", .desc = "Number of failed pool allocations since this worker was started" }, |
| 104 | [INF_ULIMIT_N] = { .name = "Ulimit-n", .desc = "Hard limit on the number of per-process file descriptors" }, |
| 105 | [INF_MAXSOCK] = { .name = "Maxsock", .desc = "Hard limit on the number of per-process sockets" }, |
| 106 | [INF_MAXCONN] = { .name = "Maxconn", .desc = "Hard limit on the number of per-process connections (configured or imposed by Ulimit-n)" }, |
| 107 | [INF_HARD_MAXCONN] = { .name = "Hard_maxconn", .desc = "Hard limit on the number of per-process connections (imposed by Memmax_MB or Ulimit-n)" }, |
| 108 | [INF_CURR_CONN] = { .name = "CurrConns", .desc = "Current number of connections on this worker process" }, |
| 109 | [INF_CUM_CONN] = { .name = "CumConns", .desc = "Total number of connections on this worker process since started" }, |
| 110 | [INF_CUM_REQ] = { .name = "CumReq", .desc = "Total number of requests on this worker process since started" }, |
| 111 | [INF_MAX_SSL_CONNS] = { .name = "MaxSslConns", .desc = "Hard limit on the number of per-process SSL endpoints (front+back), 0=unlimited" }, |
| 112 | [INF_CURR_SSL_CONNS] = { .name = "CurrSslConns", .desc = "Current number of SSL endpoints on this worker process (front+back)" }, |
| 113 | [INF_CUM_SSL_CONNS] = { .name = "CumSslConns", .desc = "Total number of SSL endpoints on this worker process since started (front+back)" }, |
| 114 | [INF_MAXPIPES] = { .name = "Maxpipes", .desc = "Hard limit on the number of pipes for splicing, 0=unlimited" }, |
| 115 | [INF_PIPES_USED] = { .name = "PipesUsed", .desc = "Current number of pipes in use in this worker process" }, |
| 116 | [INF_PIPES_FREE] = { .name = "PipesFree", .desc = "Current number of allocated and available pipes in this worker process" }, |
| 117 | [INF_CONN_RATE] = { .name = "ConnRate", .desc = "Number of front connections created on this worker process over the last second" }, |
| 118 | [INF_CONN_RATE_LIMIT] = { .name = "ConnRateLimit", .desc = "Hard limit for ConnRate (global.maxconnrate)" }, |
| 119 | [INF_MAX_CONN_RATE] = { .name = "MaxConnRate", .desc = "Highest ConnRate reached on this worker process since started (in connections per second)" }, |
| 120 | [INF_SESS_RATE] = { .name = "SessRate", .desc = "Number of sessions created on this worker process over the last second" }, |
| 121 | [INF_SESS_RATE_LIMIT] = { .name = "SessRateLimit", .desc = "Hard limit for SessRate (global.maxsessrate)" }, |
| 122 | [INF_MAX_SESS_RATE] = { .name = "MaxSessRate", .desc = "Highest SessRate reached on this worker process since started (in sessions per second)" }, |
| 123 | [INF_SSL_RATE] = { .name = "SslRate", .desc = "Number of SSL connections created on this worker process over the last second" }, |
| 124 | [INF_SSL_RATE_LIMIT] = { .name = "SslRateLimit", .desc = "Hard limit for SslRate (global.maxsslrate)" }, |
| 125 | [INF_MAX_SSL_RATE] = { .name = "MaxSslRate", .desc = "Highest SslRate reached on this worker process since started (in connections per second)" }, |
| 126 | [INF_SSL_FRONTEND_KEY_RATE] = { .name = "SslFrontendKeyRate", .desc = "Number of SSL keys created on frontends in this worker process over the last second" }, |
| 127 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = { .name = "SslFrontendMaxKeyRate", .desc = "Highest SslFrontendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 128 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = { .name = "SslFrontendSessionReuse_pct", .desc = "Percent of frontend SSL connections which did not require a new key" }, |
| 129 | [INF_SSL_BACKEND_KEY_RATE] = { .name = "SslBackendKeyRate", .desc = "Number of SSL keys created on backends in this worker process over the last second" }, |
| 130 | [INF_SSL_BACKEND_MAX_KEY_RATE] = { .name = "SslBackendMaxKeyRate", .desc = "Highest SslBackendKeyRate reached on this worker process since started (in SSL keys per second)" }, |
| 131 | [INF_SSL_CACHE_LOOKUPS] = { .name = "SslCacheLookups", .desc = "Total number of SSL session ID lookups in the SSL session cache on this worker since started" }, |
| 132 | [INF_SSL_CACHE_MISSES] = { .name = "SslCacheMisses", .desc = "Total number of SSL session ID lookups that didn't find a session in the SSL session cache on this worker since started" }, |
| 133 | [INF_COMPRESS_BPS_IN] = { .name = "CompressBpsIn", .desc = "Number of bytes submitted to the HTTP compressor in this worker process over the last second" }, |
| 134 | [INF_COMPRESS_BPS_OUT] = { .name = "CompressBpsOut", .desc = "Number of bytes emitted by the HTTP compressor in this worker process over the last second" }, |
| 135 | [INF_COMPRESS_BPS_RATE_LIM] = { .name = "CompressBpsRateLim", .desc = "Limit of CompressBpsOut beyond which HTTP compression is automatically disabled" }, |
| 136 | [INF_ZLIB_MEM_USAGE] = { .name = "ZlibMemUsage", .desc = "Amount of memory currently used by HTTP compression on the current worker process (in bytes)" }, |
| 137 | [INF_MAX_ZLIB_MEM_USAGE] = { .name = "MaxZlibMemUsage", .desc = "Limit on the amount of memory used by HTTP compression above which it is automatically disabled (in bytes, see global.maxzlibmem)" }, |
| 138 | [INF_TASKS] = { .name = "Tasks", .desc = "Total number of tasks in the current worker process (active + sleeping)" }, |
| 139 | [INF_RUN_QUEUE] = { .name = "Run_queue", .desc = "Total number of active tasks+tasklets in the current worker process" }, |
| 140 | [INF_IDLE_PCT] = { .name = "Idle_pct", .desc = "Percentage of last second spent waiting in the current worker thread" }, |
| 141 | [INF_NODE] = { .name = "node", .desc = "Node name (global.node)" }, |
| 142 | [INF_DESCRIPTION] = { .name = "description", .desc = "Node description (global.description)" }, |
| 143 | [INF_STOPPING] = { .name = "Stopping", .desc = "1 if the worker process is currently stopping, otherwise zero" }, |
| 144 | [INF_JOBS] = { .name = "Jobs", .desc = "Current number of active jobs on the current worker process (frontend connections, master connections, listeners)" }, |
| 145 | [INF_UNSTOPPABLE_JOBS] = { .name = "Unstoppable Jobs", .desc = "Current number of unstoppable jobs on the current worker process (master connections)" }, |
| 146 | [INF_LISTENERS] = { .name = "Listeners", .desc = "Current number of active listeners on the current worker process" }, |
| 147 | [INF_ACTIVE_PEERS] = { .name = "ActivePeers", .desc = "Current number of verified active peers connections on the current worker process" }, |
| 148 | [INF_CONNECTED_PEERS] = { .name = "ConnectedPeers", .desc = "Current number of peers having passed the connection step on the current worker process" }, |
| 149 | [INF_DROPPED_LOGS] = { .name = "DroppedLogs", .desc = "Total number of dropped logs for current worker process since started" }, |
| 150 | [INF_BUSY_POLLING] = { .name = "BusyPolling", .desc = "1 if busy-polling is currently in use on the worker process, otherwise zero (config.busy-polling)" }, |
| 151 | [INF_FAILED_RESOLUTIONS] = { .name = "FailedResolutions", .desc = "Total number of failed DNS resolutions in current worker process since started" }, |
| 152 | [INF_TOTAL_BYTES_OUT] = { .name = "TotalBytesOut", .desc = "Total number of bytes emitted by current worker process since started" }, |
Christopher Faulet | aaa7085 | 2020-07-10 13:56:30 +0200 | [diff] [blame] | 153 | [INF_TOTAL_SPLICED_BYTES_OUT] = { .name = "TotalSplicdedBytesOut", .desc = "Total number of bytes emitted by current worker process through a kernel pipe since started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 154 | [INF_BYTES_OUT_RATE] = { .name = "BytesOutRate", .desc = "Number of bytes emitted by current worker process over the last second" }, |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 155 | [INF_DEBUG_COMMANDS_ISSUED] = { .name = "DebugCommandsIssued", .desc = "Number of debug commands issued on this process (anything > 0 is unsafe)" }, |
Emeric Brun | 45c457a | 2020-07-09 23:23:34 +0200 | [diff] [blame] | 156 | [INF_CUM_LOG_MSGS] = { .name = "CumRecvLogs", .desc = "Total number of log messages received by log-forwarding listeners on this worker process since started" }, |
Adis Nezirovic | b62b78b | 2021-01-15 13:12:33 +0100 | [diff] [blame] | 157 | [INF_BUILD_INFO] = { .name = "Build info", .desc = "Build info" }, |
Amaury Denoyelle | 5dfdf3e | 2021-05-05 17:09:12 +0200 | [diff] [blame] | 158 | [INF_TAINTED] = { .name = "Tainted", .desc = "Experimental features used" }, |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 161 | const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = { |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 162 | [ST_F_PXNAME] = { .name = "pxname", .desc = "Proxy name" }, |
| 163 | [ST_F_SVNAME] = { .name = "svname", .desc = "Server name" }, |
William Dauchy | eedb9b1 | 2021-02-01 13:11:53 +0100 | [diff] [blame] | 164 | [ST_F_QCUR] = { .name = "qcur", .desc = "Number of current queued connections" }, |
| 165 | [ST_F_QMAX] = { .name = "qmax", .desc = "Highest value of queued connections encountered since process started" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 166 | [ST_F_SCUR] = { .name = "scur", .desc = "Number of current sessions on the frontend, backend or server" }, |
| 167 | [ST_F_SMAX] = { .name = "smax", .desc = "Highest value of current sessions encountered since process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 168 | [ST_F_SLIM] = { .name = "slim", .desc = "Frontend/listener/server's maxconn, backend's fullconn" }, |
| 169 | [ST_F_STOT] = { .name = "stot", .desc = "Total number of sessions since process started" }, |
| 170 | [ST_F_BIN] = { .name = "bin", .desc = "Total number of request bytes since process started" }, |
| 171 | [ST_F_BOUT] = { .name = "bout", .desc = "Total number of response bytes since process started" }, |
| 172 | [ST_F_DREQ] = { .name = "dreq", .desc = "Total number of denied requests since process started" }, |
| 173 | [ST_F_DRESP] = { .name = "dresp", .desc = "Total number of denied responses since process started" }, |
| 174 | [ST_F_EREQ] = { .name = "ereq", .desc = "Total number of invalid requests since process started" }, |
| 175 | [ST_F_ECON] = { .name = "econ", .desc = "Total number of failed connections to server since the worker process started" }, |
| 176 | [ST_F_ERESP] = { .name = "eresp", .desc = "Total number of invalid responses since the worker process started" }, |
| 177 | [ST_F_WRETR] = { .name = "wretr", .desc = "Total number of server connection retries since the worker process started" }, |
| 178 | [ST_F_WREDIS] = { .name = "wredis", .desc = "Total number of server redispatches due to connection failures since the worker process started" }, |
| 179 | [ST_F_STATUS] = { .name = "status", .desc = "Frontend/listen status: OPEN/WAITING/FULL/STOP; backend: UP/DOWN; server: last check status" }, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 180 | [ST_F_WEIGHT] = { .name = "weight", .desc = "Server's effective weight, or sum of active servers' effective weights for a backend" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 181 | [ST_F_ACT] = { .name = "act", .desc = "Total number of active UP servers with a non-zero weight" }, |
| 182 | [ST_F_BCK] = { .name = "bck", .desc = "Total number of backup UP servers with a non-zero weight" }, |
| 183 | [ST_F_CHKFAIL] = { .name = "chkfail", .desc = "Total number of failed individual health checks per server/backend, since the worker process started" }, |
| 184 | [ST_F_CHKDOWN] = { .name = "chkdown", .desc = "Total number of failed checks causing UP to DOWN server transitions, per server/backend, since the worker process started" }, |
| 185 | [ST_F_LASTCHG] = { .name = "lastchg", .desc = "How long ago the last server state changed, in seconds" }, |
| 186 | [ST_F_DOWNTIME] = { .name = "downtime", .desc = "Total time spent in DOWN state, for server or backend" }, |
| 187 | [ST_F_QLIMIT] = { .name = "qlimit", .desc = "Limit on the number of connections in queue, for servers only (maxqueue argument)" }, |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 188 | [ST_F_PID] = { .name = "pid", .desc = "Relative worker process number (1)" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 189 | [ST_F_IID] = { .name = "iid", .desc = "Frontend or Backend numeric identifier ('id' setting)" }, |
| 190 | [ST_F_SID] = { .name = "sid", .desc = "Server numeric identifier ('id' setting)" }, |
| 191 | [ST_F_THROTTLE] = { .name = "throttle", .desc = "Throttling ratio applied to a server's maxconn and weight during the slowstart period (0 to 100%)" }, |
| 192 | [ST_F_LBTOT] = { .name = "lbtot", .desc = "Total number of requests routed by load balancing since the worker process started (ignores queue pop and stickiness)" }, |
| 193 | [ST_F_TRACKED] = { .name = "tracked", .desc = "Name of the other server this server tracks for its state" }, |
| 194 | [ST_F_TYPE] = { .name = "type", .desc = "Type of the object (Listener, Frontend, Backend, Server)" }, |
| 195 | [ST_F_RATE] = { .name = "rate", .desc = "Total number of sessions processed by this object over the last second (sessions for listeners/frontends, requests for backends/servers)" }, |
| 196 | [ST_F_RATE_LIM] = { .name = "rate_lim", .desc = "Limit on the number of sessions accepted in a second (frontend only, 'rate-limit sessions' setting)" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 197 | [ST_F_RATE_MAX] = { .name = "rate_max", .desc = "Highest value of sessions per second observed since the worker process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 198 | [ST_F_CHECK_STATUS] = { .name = "check_status", .desc = "Status report of the server's latest health check, prefixed with '*' if a check is currently in progress" }, |
| 199 | [ST_F_CHECK_CODE] = { .name = "check_code", .desc = "HTTP/SMTP/LDAP status code reported by the latest server health check" }, |
| 200 | [ST_F_CHECK_DURATION] = { .name = "check_duration", .desc = "Total duration of the latest server health check, in milliseconds" }, |
| 201 | [ST_F_HRSP_1XX] = { .name = "hrsp_1xx", .desc = "Total number of HTTP responses with status 100-199 returned by this object since the worker process started" }, |
| 202 | [ST_F_HRSP_2XX] = { .name = "hrsp_2xx", .desc = "Total number of HTTP responses with status 200-299 returned by this object since the worker process started" }, |
| 203 | [ST_F_HRSP_3XX] = { .name = "hrsp_3xx", .desc = "Total number of HTTP responses with status 300-399 returned by this object since the worker process started" }, |
| 204 | [ST_F_HRSP_4XX] = { .name = "hrsp_4xx", .desc = "Total number of HTTP responses with status 400-499 returned by this object since the worker process started" }, |
| 205 | [ST_F_HRSP_5XX] = { .name = "hrsp_5xx", .desc = "Total number of HTTP responses with status 500-599 returned by this object since the worker process started" }, |
| 206 | [ST_F_HRSP_OTHER] = { .name = "hrsp_other", .desc = "Total number of HTTP responses with status <100, >599 returned by this object since the worker process started (error -1 included)" }, |
| 207 | [ST_F_HANAFAIL] = { .name = "hanafail", .desc = "Total number of failed checks caused by an 'on-error' directive after an 'observe' condition matched" }, |
| 208 | [ST_F_REQ_RATE] = { .name = "req_rate", .desc = "Number of HTTP requests processed over the last second on this object" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 209 | [ST_F_REQ_RATE_MAX] = { .name = "req_rate_max", .desc = "Highest value of http requests observed since the worker process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 210 | [ST_F_REQ_TOT] = { .name = "req_tot", .desc = "Total number of HTTP requests processed by this object since the worker process started" }, |
| 211 | [ST_F_CLI_ABRT] = { .name = "cli_abrt", .desc = "Total number of requests or connections aborted by the client since the worker process started" }, |
| 212 | [ST_F_SRV_ABRT] = { .name = "srv_abrt", .desc = "Total number of requests or connections aborted by the server since the worker process started" }, |
| 213 | [ST_F_COMP_IN] = { .name = "comp_in", .desc = "Total number of bytes submitted to the HTTP compressor for this object since the worker process started" }, |
| 214 | [ST_F_COMP_OUT] = { .name = "comp_out", .desc = "Total number of bytes emitted by the HTTP compressor for this object since the worker process started" }, |
| 215 | [ST_F_COMP_BYP] = { .name = "comp_byp", .desc = "Total number of bytes that bypassed HTTP compression for this object since the worker process started (CPU/memory/bandwidth limitation)" }, |
| 216 | [ST_F_COMP_RSP] = { .name = "comp_rsp", .desc = "Total number of HTTP responses that were compressed for this object since the worker process started" }, |
| 217 | [ST_F_LASTSESS] = { .name = "lastsess", .desc = "How long ago some traffic was seen on this object on this worker process, in seconds" }, |
| 218 | [ST_F_LAST_CHK] = { .name = "last_chk", .desc = "Short description of the latest health check report for this server (see also check_desc)" }, |
| 219 | [ST_F_LAST_AGT] = { .name = "last_agt", .desc = "Short description of the latest agent check report for this server (see also agent_desc)" }, |
| 220 | [ST_F_QTIME] = { .name = "qtime", .desc = "Time spent in the queue, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 221 | [ST_F_CTIME] = { .name = "ctime", .desc = "Time spent waiting for a connection to complete, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 222 | [ST_F_RTIME] = { .name = "rtime", .desc = "Time spent waiting for a server response, in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 223 | [ST_F_TTIME] = { .name = "ttime", .desc = "Total request+response time (request+queue+connect+response+processing), in milliseconds, averaged over the 1024 last requests (backend/server)" }, |
| 224 | [ST_F_AGENT_STATUS] = { .name = "agent_status", .desc = "Status report of the server's latest agent check, prefixed with '*' if a check is currently in progress" }, |
| 225 | [ST_F_AGENT_CODE] = { .name = "agent_code", .desc = "Status code reported by the latest server agent check" }, |
| 226 | [ST_F_AGENT_DURATION] = { .name = "agent_duration", .desc = "Total duration of the latest server agent check, in milliseconds" }, |
| 227 | [ST_F_CHECK_DESC] = { .name = "check_desc", .desc = "Textual description of the latest health check report for this server" }, |
| 228 | [ST_F_AGENT_DESC] = { .name = "agent_desc", .desc = "Textual description of the latest agent check report for this server" }, |
| 229 | [ST_F_CHECK_RISE] = { .name = "check_rise", .desc = "Number of successful health checks before declaring a server UP (server 'rise' setting)" }, |
| 230 | [ST_F_CHECK_FALL] = { .name = "check_fall", .desc = "Number of failed health checks before declaring a server DOWN (server 'fall' setting)" }, |
| 231 | [ST_F_CHECK_HEALTH] = { .name = "check_health", .desc = "Current server health check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 232 | [ST_F_AGENT_RISE] = { .name = "agent_rise", .desc = "Number of successful agent checks before declaring a server UP (server 'rise' setting)" }, |
| 233 | [ST_F_AGENT_FALL] = { .name = "agent_fall", .desc = "Number of failed agent checks before declaring a server DOWN (server 'fall' setting)" }, |
| 234 | [ST_F_AGENT_HEALTH] = { .name = "agent_health", .desc = "Current server agent check level (0..fall-1=DOWN, fall..rise-1=UP)" }, |
| 235 | [ST_F_ADDR] = { .name = "addr", .desc = "Server's address:port, shown only if show-legends is set, or at levels oper/admin for the CLI" }, |
| 236 | [ST_F_COOKIE] = { .name = "cookie", .desc = "Backend's cookie name or Server's cookie value, shown only if show-legends is set, or at levels oper/admin for the CLI" }, |
| 237 | [ST_F_MODE] = { .name = "mode", .desc = "'mode' setting (tcp/http/health/cli)" }, |
| 238 | [ST_F_ALGO] = { .name = "algo", .desc = "Backend's load balancing algorithm, shown only if show-legends is set, or at levels oper/admin for the CLI" }, |
| 239 | [ST_F_CONN_RATE] = { .name = "conn_rate", .desc = "Number of new connections accepted over the last second on the frontend for this worker process" }, |
William Dauchy | 19f7cfc | 2021-02-01 13:11:54 +0100 | [diff] [blame] | 240 | [ST_F_CONN_RATE_MAX] = { .name = "conn_rate_max", .desc = "Highest value of connections per second observed since the worker process started" }, |
Willy Tarreau | 6d4897e | 2019-10-11 16:31:46 +0200 | [diff] [blame] | 241 | [ST_F_CONN_TOT] = { .name = "conn_tot", .desc = "Total number of new connections accepted on this frontend since the worker process started" }, |
| 242 | [ST_F_INTERCEPTED] = { .name = "intercepted", .desc = "Total number of HTTP requests intercepted on the frontend (redirects/stats/services) since the worker process started" }, |
| 243 | [ST_F_DCON] = { .name = "dcon", .desc = "Total number of incoming connections blocked on a listener/frontend by a tcp-request connection rule since the worker process started" }, |
| 244 | [ST_F_DSES] = { .name = "dses", .desc = "Total number of incoming sessions blocked on a listener/frontend by a tcp-request connection rule since the worker process started" }, |
| 245 | [ST_F_WREW] = { .name = "wrew", .desc = "Total number of failed HTTP header rewrites since the worker process started" }, |
| 246 | [ST_F_CONNECT] = { .name = "connect", .desc = "Total number of outgoing connection attempts on this backend/server since the worker process started" }, |
| 247 | [ST_F_REUSE] = { .name = "reuse", .desc = "Total number of reused connection on this backend/server since the worker process started" }, |
| 248 | [ST_F_CACHE_LOOKUPS] = { .name = "cache_lookups", .desc = "Total number of HTTP requests looked up in the cache on this frontend/backend since the worker process started" }, |
| 249 | [ST_F_CACHE_HITS] = { .name = "cache_hits", .desc = "Total number of HTTP requests not found in the cache on this frontend/backend since the worker process started" }, |
| 250 | [ST_F_SRV_ICUR] = { .name = "srv_icur", .desc = "Current number of idle connections available for reuse on this server" }, |
| 251 | [ST_F_SRV_ILIM] = { .name = "src_ilim", .desc = "Limit on the number of available idle connections on this server (server 'pool_max_conn' directive)" }, |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 252 | [ST_F_QT_MAX] = { .name = "qtime_max", .desc = "Maximum observed time spent in the queue, in milliseconds (backend/server)" }, |
| 253 | [ST_F_CT_MAX] = { .name = "ctime_max", .desc = "Maximum observed time spent waiting for a connection to complete, in milliseconds (backend/server)" }, |
| 254 | [ST_F_RT_MAX] = { .name = "rtime_max", .desc = "Maximum observed time spent waiting for a server response, in milliseconds (backend/server)" }, |
| 255 | [ST_F_TT_MAX] = { .name = "ttime_max", .desc = "Maximum observed total request+response time (request+queue+connect+response+processing), in milliseconds (backend/server)" }, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 256 | [ST_F_EINT] = { .name = "eint", .desc = "Total number of internal errors since process started"}, |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 257 | [ST_F_IDLE_CONN_CUR] = { .name = "idle_conn_cur", .desc = "Current number of unsafe idle connections"}, |
| 258 | [ST_F_SAFE_CONN_CUR] = { .name = "safe_conn_cur", .desc = "Current number of safe idle connections"}, |
| 259 | [ST_F_USED_CONN_CUR] = { .name = "used_conn_cur", .desc = "Current number of connections in use"}, |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 260 | [ST_F_NEED_CONN_EST] = { .name = "need_conn_est", .desc = "Estimated needed number of connections"}, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 261 | [ST_F_UWEIGHT] = { .name = "uweight", .desc = "Server's user weight, or sum of active servers' user weights for a backend" }, |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 262 | [ST_F_AGG_SRV_CHECK_STATUS] = { .name = "agg_server_check_status", .desc = "[DEPRECATED] Backend's aggregated gauge of servers' status" }, |
| 263 | [ST_F_AGG_SRV_STATUS ] = { .name = "agg_server_status", .desc = "Backend's aggregated gauge of servers' status" }, |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame] | 264 | [ST_F_AGG_CHECK_STATUS] = { .name = "agg_check_status", .desc = "Backend's aggregated gauge of servers' state check status" }, |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 265 | [ST_F_SRID] = { .name = "srid", .desc = "Server id revision, to prevent server id reuse mixups" }, |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 266 | [ST_F_SESS_OTHER] = { .name = "sess_other", .desc = "Total number of sessions other than HTTP since process started" }, |
| 267 | [ST_F_H1SESS] = { .name = "h1sess", .desc = "Total number of HTTP/1 sessions since process started" }, |
| 268 | [ST_F_H2SESS] = { .name = "h2sess", .desc = "Total number of HTTP/2 sessions since process started" }, |
| 269 | [ST_F_H3SESS] = { .name = "h3sess", .desc = "Total number of HTTP/3 sessions since process started" }, |
| 270 | [ST_F_REQ_OTHER] = { .name = "req_other", .desc = "Total number of sessions other than HTTP processed by this object since the worker process started" }, |
| 271 | [ST_F_H1REQ] = { .name = "h1req", .desc = "Total number of HTTP/1 sessions processed by this object since the worker process started" }, |
| 272 | [ST_F_H2REQ] = { .name = "h2req", .desc = "Total number of hTTP/2 sessions processed by this object since the worker process started" }, |
| 273 | [ST_F_H3REQ] = { .name = "h3req", .desc = "Total number of HTTP/3 sessions processed by this object since the worker process started" }, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 274 | }; |
| 275 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 276 | /* one line of info */ |
William Dauchy | 5d9b8f3 | 2021-01-11 20:07:49 +0100 | [diff] [blame] | 277 | THREAD_LOCAL struct field info[INF_TOTAL_FIELDS]; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 278 | |
| 279 | /* description of statistics (static and dynamic) */ |
| 280 | static struct name_desc *stat_f[STATS_DOMAIN_COUNT]; |
| 281 | static size_t stat_count[STATS_DOMAIN_COUNT]; |
| 282 | |
| 283 | /* one line for stats */ |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 284 | THREAD_LOCAL struct field *stat_l[STATS_DOMAIN_COUNT]; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 285 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 286 | /* list of all registered stats module */ |
| 287 | static struct list stats_module_list[STATS_DOMAIN_COUNT] = { |
| 288 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_PROXY]), |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 289 | LIST_HEAD_INIT(stats_module_list[STATS_DOMAIN_RESOLVERS]), |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 290 | }; |
| 291 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 292 | THREAD_LOCAL void *trash_counters; |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 293 | static THREAD_LOCAL struct buffer trash_chunk = BUF_NULL; |
| 294 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 295 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 296 | static inline uint8_t stats_get_domain(uint32_t domain) |
| 297 | { |
| 298 | return domain >> STATS_DOMAIN & STATS_DOMAIN_MASK; |
| 299 | } |
| 300 | |
Amaury Denoyelle | 72b16e5 | 2020-10-05 11:49:38 +0200 | [diff] [blame] | 301 | static inline enum stats_domain_px_cap stats_px_get_cap(uint32_t domain) |
| 302 | { |
| 303 | return domain >> STATS_PX_CAP & STATS_PX_CAP_MASK; |
| 304 | } |
| 305 | |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 306 | static void stats_dump_json_schema(struct buffer *out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 307 | |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 308 | int stats_putchk(struct channel *chn, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 309 | { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 310 | struct buffer *chk = &trash_chunk; |
| 311 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 312 | if (htx) { |
Christopher Faulet | 69fc88c | 2019-01-07 14:27:53 +0100 | [diff] [blame] | 313 | if (chk->data >= channel_htx_recv_max(chn, htx)) |
| 314 | return 0; |
Willy Tarreau | 0a7ef02 | 2019-05-28 10:30:11 +0200 | [diff] [blame] | 315 | if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 316 | return 0; |
Christopher Faulet | 5adbeeb | 2019-01-02 14:34:39 +0100 | [diff] [blame] | 317 | channel_add_input(chn, chk->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 318 | chk->data = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 319 | } |
| 320 | else { |
| 321 | if (ci_putchk(chn, chk) == -1) |
| 322 | return 0; |
| 323 | } |
| 324 | return 1; |
| 325 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 326 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 327 | static const char *stats_scope_ptr(struct appctx *appctx, struct stconn *sc) |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 328 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 329 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 330 | struct channel *req = sc_oc(sc); |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 331 | struct htx *htx = htxbuf(&req->buf); |
| 332 | struct htx_blk *blk; |
| 333 | struct ist uri; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 334 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 335 | blk = htx_get_head_blk(htx); |
Christopher Faulet | ea00973 | 2019-11-18 15:50:25 +0100 | [diff] [blame] | 336 | BUG_ON(!blk || htx_get_blk_type(blk) != HTX_BLK_REQ_SL); |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 337 | ALREADY_CHECKED(blk); |
| 338 | uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk)); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 339 | return uri.ptr + ctx->scope_str; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 340 | } |
| 341 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 342 | /* |
| 343 | * http_stats_io_handler() |
| 344 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 345 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 346 | * -> stats_dump_json_header() // emits the JSON headers (same as above) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 347 | * -> stats_dump_html_head() // emits the HTML headers |
| 348 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 349 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 350 | * -> stats_dump_html_px_hdr() |
| 351 | * -> stats_dump_fe_stats() |
| 352 | * -> stats_dump_li_stats() |
| 353 | * -> stats_dump_sv_stats() |
| 354 | * -> stats_dump_be_stats() |
| 355 | * -> stats_dump_html_px_end() |
| 356 | * -> stats_dump_html_end() // emits HTML trailer |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 357 | * -> stats_dump_json_end() // emits JSON trailer |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 358 | */ |
| 359 | |
| 360 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 361 | /* Dumps the stats CSV header to the local trash buffer. The caller is |
| 362 | * responsible for clearing it if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 363 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 364 | * so please only append new fields at the end, never in the middle. |
| 365 | */ |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 366 | static void stats_dump_csv_header(enum stats_domain domain) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 367 | { |
| 368 | int field; |
| 369 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 370 | chunk_appendf(&trash_chunk, "# "); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 371 | if (stat_f[domain]) { |
| 372 | for (field = 0; field < stat_count[domain]; ++field) { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 373 | chunk_appendf(&trash_chunk, "%s,", stat_f[domain][field].name); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 374 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 375 | /* print special delimiter on proxy stats to mark end of |
| 376 | static fields */ |
| 377 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 378 | chunk_appendf(&trash_chunk, "-,"); |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 382 | chunk_appendf(&trash_chunk, "\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 383 | } |
| 384 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 385 | /* Emits a stats field without any surrounding element and properly encoded to |
| 386 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 387 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 388 | int stats_emit_raw_data_field(struct buffer *out, const struct field *f) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 389 | { |
| 390 | switch (field_format(f, 0)) { |
| 391 | case FF_EMPTY: return 1; |
| 392 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 393 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 394 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 395 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
Willy Tarreau | 065ba31 | 2021-05-08 10:38:20 +0200 | [diff] [blame] | 396 | case FF_FLT: { |
| 397 | size_t prev_data = out->data; |
| 398 | out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "%f", f->u.flt)); |
| 399 | return out->data; |
| 400 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 401 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 402 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 403 | } |
| 404 | } |
| 405 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 406 | const char *field_to_html_str(const struct field *f) |
| 407 | { |
| 408 | switch (field_format(f, 0)) { |
| 409 | case FF_S32: return U2H(f->u.s32); |
| 410 | case FF_S64: return U2H(f->u.s64); |
| 411 | case FF_U64: return U2H(f->u.u64); |
| 412 | case FF_U32: return U2H(f->u.u32); |
Willy Tarreau | 6004fb7 | 2021-05-08 07:37:38 +0200 | [diff] [blame] | 413 | case FF_FLT: return F2H(f->u.flt); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 414 | case FF_STR: return field_str(f, 0); |
| 415 | case FF_EMPTY: |
| 416 | default: |
| 417 | return ""; |
| 418 | } |
| 419 | } |
| 420 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 421 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 422 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 423 | * if the buffer is full. |
| 424 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 425 | int stats_emit_typed_data_field(struct buffer *out, const struct field *f) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 426 | { |
| 427 | switch (field_format(f, 0)) { |
| 428 | case FF_EMPTY: return 1; |
| 429 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 430 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 431 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 432 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
Willy Tarreau | 065ba31 | 2021-05-08 10:38:20 +0200 | [diff] [blame] | 433 | case FF_FLT: { |
| 434 | size_t prev_data = out->data; |
| 435 | out->data = flt_trim(out->area, prev_data, chunk_appendf(out, "flt:%f", f->u.flt)); |
| 436 | return out->data; |
| 437 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 438 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 439 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 440 | } |
| 441 | } |
| 442 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 443 | /* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per |
| 444 | * the recommendation for interoperable integers in section 6 of RFC 7159. |
| 445 | */ |
| 446 | #define JSON_INT_MAX ((1ULL << 53) - 1) |
| 447 | #define JSON_INT_MIN (0 - JSON_INT_MAX) |
| 448 | |
| 449 | /* Emits a stats field value and its type in JSON. |
| 450 | * Returns non-zero on success, 0 on error. |
| 451 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 452 | int stats_emit_json_data_field(struct buffer *out, const struct field *f) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 453 | { |
| 454 | int old_len; |
| 455 | char buf[20]; |
| 456 | const char *type, *value = buf, *quote = ""; |
| 457 | |
| 458 | switch (field_format(f, 0)) { |
| 459 | case FF_EMPTY: return 1; |
| 460 | case FF_S32: type = "\"s32\""; |
| 461 | snprintf(buf, sizeof(buf), "%d", f->u.s32); |
| 462 | break; |
| 463 | case FF_U32: type = "\"u32\""; |
| 464 | snprintf(buf, sizeof(buf), "%u", f->u.u32); |
| 465 | break; |
| 466 | case FF_S64: type = "\"s64\""; |
| 467 | if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX) |
| 468 | return 0; |
| 469 | type = "\"s64\""; |
| 470 | snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64); |
| 471 | break; |
| 472 | case FF_U64: if (f->u.u64 > JSON_INT_MAX) |
| 473 | return 0; |
| 474 | type = "\"u64\""; |
| 475 | snprintf(buf, sizeof(buf), "%llu", |
| 476 | (unsigned long long) f->u.u64); |
Christopher Faulet | 52c91bb | 2019-09-28 10:37:31 +0200 | [diff] [blame] | 477 | break; |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 478 | case FF_FLT: type = "\"flt\""; |
Willy Tarreau | 065ba31 | 2021-05-08 10:38:20 +0200 | [diff] [blame] | 479 | flt_trim(buf, 0, snprintf(buf, sizeof(buf), "%f", f->u.flt)); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 480 | break; |
| 481 | case FF_STR: type = "\"str\""; |
| 482 | value = field_str(f, 0); |
| 483 | quote = "\""; |
| 484 | break; |
| 485 | default: snprintf(buf, sizeof(buf), "%u", f->type); |
| 486 | type = buf; |
| 487 | value = "unknown"; |
| 488 | quote = "\""; |
| 489 | break; |
| 490 | } |
| 491 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 492 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 493 | chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}", |
| 494 | type, quote, value, quote); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 495 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 496 | } |
| 497 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 498 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 499 | * Returns non-zero on success, 0 if the buffer is full. |
| 500 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 501 | int stats_emit_field_tags(struct buffer *out, const struct field *f, |
| 502 | char delim) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 503 | { |
| 504 | char origin, nature, scope; |
| 505 | |
| 506 | switch (field_origin(f, 0)) { |
| 507 | case FO_METRIC: origin = 'M'; break; |
| 508 | case FO_STATUS: origin = 'S'; break; |
| 509 | case FO_KEY: origin = 'K'; break; |
| 510 | case FO_CONFIG: origin = 'C'; break; |
| 511 | case FO_PRODUCT: origin = 'P'; break; |
| 512 | default: origin = '?'; break; |
| 513 | } |
| 514 | |
| 515 | switch (field_nature(f, 0)) { |
| 516 | case FN_GAUGE: nature = 'G'; break; |
| 517 | case FN_LIMIT: nature = 'L'; break; |
| 518 | case FN_MIN: nature = 'm'; break; |
| 519 | case FN_MAX: nature = 'M'; break; |
| 520 | case FN_RATE: nature = 'R'; break; |
| 521 | case FN_COUNTER: nature = 'C'; break; |
| 522 | case FN_DURATION: nature = 'D'; break; |
| 523 | case FN_AGE: nature = 'A'; break; |
| 524 | case FN_TIME: nature = 'T'; break; |
| 525 | case FN_NAME: nature = 'N'; break; |
| 526 | case FN_OUTPUT: nature = 'O'; break; |
| 527 | case FN_AVG: nature = 'a'; break; |
| 528 | default: nature = '?'; break; |
| 529 | } |
| 530 | |
| 531 | switch (field_scope(f, 0)) { |
| 532 | case FS_PROCESS: scope = 'P'; break; |
| 533 | case FS_SERVICE: scope = 'S'; break; |
| 534 | case FS_SYSTEM: scope = 's'; break; |
| 535 | case FS_CLUSTER: scope = 'C'; break; |
| 536 | default: scope = '?'; break; |
| 537 | } |
| 538 | |
| 539 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 540 | } |
| 541 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 542 | /* Emits an encoding of the field type as JSON. |
| 543 | * Returns non-zero on success, 0 if the buffer is full. |
| 544 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 545 | int stats_emit_json_field_tags(struct buffer *out, const struct field *f) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 546 | { |
| 547 | const char *origin, *nature, *scope; |
| 548 | int old_len; |
| 549 | |
| 550 | switch (field_origin(f, 0)) { |
| 551 | case FO_METRIC: origin = "Metric"; break; |
| 552 | case FO_STATUS: origin = "Status"; break; |
| 553 | case FO_KEY: origin = "Key"; break; |
| 554 | case FO_CONFIG: origin = "Config"; break; |
| 555 | case FO_PRODUCT: origin = "Product"; break; |
| 556 | default: origin = "Unknown"; break; |
| 557 | } |
| 558 | |
| 559 | switch (field_nature(f, 0)) { |
| 560 | case FN_GAUGE: nature = "Gauge"; break; |
| 561 | case FN_LIMIT: nature = "Limit"; break; |
| 562 | case FN_MIN: nature = "Min"; break; |
| 563 | case FN_MAX: nature = "Max"; break; |
| 564 | case FN_RATE: nature = "Rate"; break; |
| 565 | case FN_COUNTER: nature = "Counter"; break; |
| 566 | case FN_DURATION: nature = "Duration"; break; |
| 567 | case FN_AGE: nature = "Age"; break; |
| 568 | case FN_TIME: nature = "Time"; break; |
| 569 | case FN_NAME: nature = "Name"; break; |
| 570 | case FN_OUTPUT: nature = "Output"; break; |
| 571 | case FN_AVG: nature = "Avg"; break; |
| 572 | default: nature = "Unknown"; break; |
| 573 | } |
| 574 | |
| 575 | switch (field_scope(f, 0)) { |
| 576 | case FS_PROCESS: scope = "Process"; break; |
| 577 | case FS_SERVICE: scope = "Service"; break; |
| 578 | case FS_SYSTEM: scope = "System"; break; |
| 579 | case FS_CLUSTER: scope = "Cluster"; break; |
| 580 | default: scope = "Unknown"; break; |
| 581 | } |
| 582 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 583 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 584 | chunk_appendf(out, "\"tags\":{" |
| 585 | "\"origin\":\"%s\"," |
| 586 | "\"nature\":\"%s\"," |
| 587 | "\"scope\":\"%s\"" |
| 588 | "}", origin, nature, scope); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 589 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 590 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 591 | |
| 592 | /* Dump all fields from <stats> into <out> using CSV format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 593 | static int stats_dump_fields_csv(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 594 | const struct field *stats, size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 595 | struct show_stat_ctx *ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 596 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 597 | int domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 598 | int field; |
| 599 | |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 600 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 601 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 602 | return 0; |
| 603 | if (!chunk_strcat(out, ",")) |
| 604 | return 0; |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 605 | |
| 606 | /* print special delimiter on proxy stats to mark end of |
| 607 | static fields */ |
| 608 | if (domain == STATS_DOMAIN_PROXY && field + 1 == ST_F_TOTAL_FIELDS) { |
| 609 | if (!chunk_strcat(out, "-,")) |
| 610 | return 0; |
| 611 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 612 | } |
Amaury Denoyelle | 50660a8 | 2020-10-05 11:49:39 +0200 | [diff] [blame] | 613 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 614 | chunk_strcat(out, "\n"); |
| 615 | return 1; |
| 616 | } |
| 617 | |
| 618 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 619 | static int stats_dump_fields_typed(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 620 | const struct field *stats, |
| 621 | size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 622 | struct show_stat_ctx * ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 623 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 624 | int flags = ctx->flags; |
| 625 | int domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 626 | int field; |
| 627 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 628 | for (field = 0; field < stats_count; ++field) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 629 | if (!stats[field].type) |
| 630 | continue; |
| 631 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 632 | switch (domain) { |
| 633 | case STATS_DOMAIN_PROXY: |
| 634 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 635 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 636 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 637 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 638 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 639 | '?', |
| 640 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 641 | field, |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 642 | stat_f[domain][field].name, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 643 | stats[ST_F_PID].u.u32); |
| 644 | break; |
| 645 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 646 | case STATS_DOMAIN_RESOLVERS: |
| 647 | chunk_appendf(out, "N.%d.%s:", field, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 648 | stat_f[domain][field].name); |
| 649 | break; |
| 650 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 651 | default: |
| 652 | break; |
| 653 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 654 | |
| 655 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 656 | return 0; |
| 657 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 658 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 659 | |
Willy Tarreau | fc8e438 | 2021-06-17 07:22:27 +0200 | [diff] [blame] | 660 | if (flags & STAT_SHOW_FDESC && |
| 661 | !chunk_appendf(out, ":\"%s\"", stat_f[domain][field].desc)) { |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 662 | return 0; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 663 | } |
| 664 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 665 | if (!chunk_strcat(out, "\n")) |
| 666 | return 0; |
| 667 | } |
| 668 | return 1; |
| 669 | } |
| 670 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 671 | /* Dump all fields from <stats> into <out> using the "show info json" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 672 | static int stats_dump_json_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 673 | const struct field *info, |
| 674 | struct show_stat_ctx *ctx) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 675 | { |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 676 | int started = (ctx->field) ? 1 : 0; |
| 677 | int ready_data = 0; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 678 | |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 679 | if (!started && !chunk_strcat(out, "[")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 680 | return 0; |
| 681 | |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 682 | for (; ctx->field < INF_TOTAL_FIELDS; ctx->field++) { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 683 | int old_len; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 684 | int field = ctx->field; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 685 | |
| 686 | if (!field_format(info, field)) |
| 687 | continue; |
| 688 | |
| 689 | if (started && !chunk_strcat(out, ",")) |
| 690 | goto err; |
| 691 | started = 1; |
| 692 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 693 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 694 | chunk_appendf(out, |
| 695 | "{\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 696 | "\"processNum\":%u,", |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 697 | field, info_fields[field].name, |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 698 | info[INF_PROCESS_NUM].u.u32); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 699 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 700 | goto err; |
| 701 | |
| 702 | if (!stats_emit_json_field_tags(out, &info[field])) |
| 703 | goto err; |
| 704 | |
| 705 | if (!stats_emit_json_data_field(out, &info[field])) |
| 706 | goto err; |
| 707 | |
| 708 | if (!chunk_strcat(out, "}")) |
| 709 | goto err; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 710 | ready_data = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Willy Tarreau | c6b7a97 | 2022-06-10 15:12:21 +0200 | [diff] [blame] | 713 | if (!chunk_strcat(out, "]\n")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 714 | goto err; |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 715 | ctx->field = 0; /* we're done */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 716 | return 1; |
| 717 | |
| 718 | err: |
Aurelien DARRAGON | 16c9ca9 | 2022-12-15 14:24:30 +0100 | [diff] [blame] | 719 | if (!ready_data) { |
| 720 | /* not enough buffer space for a single entry.. */ |
| 721 | chunk_reset(out); |
| 722 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}\n"); |
| 723 | return 0; /* hard error */ |
| 724 | } |
| 725 | /* push ready data and wait for a new buffer to complete the dump */ |
| 726 | out->data = ready_data; |
| 727 | return 1; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 730 | static void stats_print_proxy_field_json(struct buffer *out, |
| 731 | const struct field *stat, |
| 732 | const char *name, |
| 733 | int pos, |
| 734 | uint32_t field_type, |
| 735 | uint32_t iid, |
| 736 | uint32_t sid, |
| 737 | uint32_t pid) |
| 738 | { |
| 739 | const char *obj_type; |
| 740 | switch (field_type) { |
| 741 | case STATS_TYPE_FE: obj_type = "Frontend"; break; |
| 742 | case STATS_TYPE_BE: obj_type = "Backend"; break; |
| 743 | case STATS_TYPE_SO: obj_type = "Listener"; break; |
| 744 | case STATS_TYPE_SV: obj_type = "Server"; break; |
| 745 | default: obj_type = "Unknown"; break; |
| 746 | } |
| 747 | |
| 748 | chunk_appendf(out, |
| 749 | "{" |
| 750 | "\"objType\":\"%s\"," |
| 751 | "\"proxyId\":%u," |
| 752 | "\"id\":%u," |
| 753 | "\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 754 | "\"processNum\":%u,", |
| 755 | obj_type, iid, sid, pos, name, pid); |
| 756 | } |
| 757 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 758 | static void stats_print_rslv_field_json(struct buffer *out, |
| 759 | const struct field *stat, |
| 760 | const char *name, |
| 761 | int pos) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 762 | { |
| 763 | chunk_appendf(out, |
| 764 | "{" |
| 765 | "\"field\":{\"pos\":%d,\"name\":\"%s\"},", |
| 766 | pos, name); |
| 767 | } |
| 768 | |
| 769 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 770 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 771 | static int stats_dump_fields_json(struct buffer *out, |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 772 | const struct field *stats, size_t stats_count, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 773 | struct show_stat_ctx *ctx) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 774 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 775 | int flags = ctx->flags; |
| 776 | int domain = ctx->domain; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 777 | int started = (ctx->field) ? 1 : 0; |
| 778 | int ready_data = 0; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 779 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 780 | if (!started && (flags & STAT_STARTED) && !chunk_strcat(out, ",")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 781 | return 0; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 782 | if (!started && !chunk_strcat(out, "[")) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 783 | return 0; |
| 784 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 785 | for (; ctx->field < stats_count; ctx->field++) { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 786 | int old_len; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 787 | int field = ctx->field; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 788 | |
| 789 | if (!stats[field].type) |
| 790 | continue; |
| 791 | |
| 792 | if (started && !chunk_strcat(out, ",")) |
| 793 | goto err; |
| 794 | started = 1; |
| 795 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 796 | old_len = out->data; |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 797 | if (domain == STATS_DOMAIN_PROXY) { |
| 798 | stats_print_proxy_field_json(out, &stats[field], |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 799 | stat_f[domain][field].name, |
| 800 | field, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 801 | stats[ST_F_TYPE].u.u32, |
| 802 | stats[ST_F_IID].u.u32, |
| 803 | stats[ST_F_SID].u.u32, |
| 804 | stats[ST_F_PID].u.u32); |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 805 | } else if (domain == STATS_DOMAIN_RESOLVERS) { |
| 806 | stats_print_rslv_field_json(out, &stats[field], |
| 807 | stat_f[domain][field].name, |
| 808 | field); |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 809 | } |
Amaury Denoyelle | f34017b | 2020-10-02 18:32:03 +0200 | [diff] [blame] | 810 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 811 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 812 | goto err; |
| 813 | |
| 814 | if (!stats_emit_json_field_tags(out, &stats[field])) |
| 815 | goto err; |
| 816 | |
| 817 | if (!stats_emit_json_data_field(out, &stats[field])) |
| 818 | goto err; |
| 819 | |
| 820 | if (!chunk_strcat(out, "}")) |
| 821 | goto err; |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 822 | ready_data = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | if (!chunk_strcat(out, "]")) |
| 826 | goto err; |
| 827 | |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 828 | ctx->field = 0; /* we're done */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 829 | return 1; |
| 830 | |
| 831 | err: |
Aurelien DARRAGON | 42b18fb | 2022-12-15 14:17:09 +0100 | [diff] [blame] | 832 | if (!ready_data) { |
| 833 | /* not enough buffer space for a single entry.. */ |
| 834 | chunk_reset(out); |
| 835 | if (ctx->flags & STAT_STARTED) |
| 836 | chunk_strcat(out, ","); |
| 837 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}"); |
| 838 | return 0; /* hard error */ |
| 839 | } |
| 840 | /* push ready data and wait for a new buffer to complete the dump */ |
| 841 | out->data = ready_data; |
| 842 | return 1; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 843 | } |
| 844 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 845 | /* Dump all fields from <stats> into <out> using the HTML format. A column is |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 846 | * reserved for the checkbox is STAT_ADMIN is set in <flags>. Some extra info |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 847 | * are provided if STAT_SHLGNDS is present in <flags>. The statistics from |
| 848 | * extra modules are displayed at the end of the lines if STAT_SHMODULES is |
| 849 | * present in <flags>. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 850 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 851 | static int stats_dump_fields_html(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 852 | const struct field *stats, |
| 853 | struct show_stat_ctx *ctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 854 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 855 | struct buffer src; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 856 | struct stats_module *mod; |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 857 | int flags = ctx->flags; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 858 | int i = 0, j = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 859 | |
| 860 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
| 861 | chunk_appendf(out, |
| 862 | /* name, queue */ |
| 863 | "<tr class=\"frontend\">"); |
| 864 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 865 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 866 | /* Column sub-heading for Enable or Disable server */ |
| 867 | chunk_appendf(out, "<td></td>"); |
| 868 | } |
| 869 | |
| 870 | chunk_appendf(out, |
| 871 | "<td class=ac>" |
| 872 | "<a name=\"%s/Frontend\"></a>" |
| 873 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 874 | "<td colspan=3></td>" |
| 875 | "", |
| 876 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 877 | |
| 878 | chunk_appendf(out, |
| 879 | /* sessions rate : current */ |
| 880 | "<td><u>%s<div class=tips><table class=det>" |
| 881 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 882 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 883 | "", |
| 884 | U2H(stats[ST_F_RATE].u.u32), |
| 885 | U2H(stats[ST_F_CONN_RATE].u.u32), |
| 886 | U2H(stats[ST_F_RATE].u.u32)); |
| 887 | |
| 888 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 889 | chunk_appendf(out, |
| 890 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
| 891 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
| 892 | |
| 893 | chunk_appendf(out, |
| 894 | "</table></div></u></td>" |
| 895 | /* sessions rate : max */ |
| 896 | "<td><u>%s<div class=tips><table class=det>" |
| 897 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 898 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 899 | "", |
| 900 | U2H(stats[ST_F_RATE_MAX].u.u32), |
| 901 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
| 902 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 903 | |
| 904 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 905 | chunk_appendf(out, |
| 906 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
| 907 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
| 908 | |
| 909 | chunk_appendf(out, |
| 910 | "</table></div></u></td>" |
| 911 | /* sessions rate : limit */ |
| 912 | "<td>%s</td>", |
| 913 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
| 914 | |
| 915 | chunk_appendf(out, |
| 916 | /* sessions: current, max, limit, total */ |
| 917 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 918 | "<td><u>%s<div class=tips><table class=det>" |
| 919 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 920 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 921 | "", |
| 922 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 923 | U2H(stats[ST_F_STOT].u.u64), |
| 924 | U2H(stats[ST_F_CONN_TOT].u.u64), |
| 925 | U2H(stats[ST_F_STOT].u.u64)); |
| 926 | |
| 927 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 928 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 929 | chunk_appendf(out, |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 930 | "<tr><th>- HTTP/1 sessions:</th><td>%s</td></tr>" |
| 931 | "<tr><th>- HTTP/2 sessions:</th><td>%s</td></tr>" |
| 932 | "<tr><th>- HTTP/3 sessions:</th><td>%s</td></tr>" |
| 933 | "<tr><th>- other sessions:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 934 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 935 | "<tr><th>- HTTP/1 requests:</th><td>%s</td></tr>" |
| 936 | "<tr><th>- HTTP/2 requests:</th><td>%s</td></tr>" |
| 937 | "<tr><th>- HTTP/3 requests:</th><td>%s</td></tr>" |
| 938 | "<tr><th>- other requests:</th><td>%s</td></tr>" |
| 939 | "", |
| 940 | U2H(stats[ST_F_H1SESS].u.u64), |
| 941 | U2H(stats[ST_F_H2SESS].u.u64), |
| 942 | U2H(stats[ST_F_H3SESS].u.u64), |
| 943 | U2H(stats[ST_F_SESS_OTHER].u.u64), |
| 944 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 945 | U2H(stats[ST_F_H1REQ].u.u64), |
| 946 | U2H(stats[ST_F_H2REQ].u.u64), |
| 947 | U2H(stats[ST_F_H3REQ].u.u64), |
| 948 | U2H(stats[ST_F_REQ_OTHER].u.u64)); |
| 949 | |
| 950 | chunk_appendf(out, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 951 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 952 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 953 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 954 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 955 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 956 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 957 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 958 | "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 959 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 960 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 961 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 962 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 963 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 964 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 965 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 966 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 967 | U2H(stats[ST_F_HRSP_OTHER].u.u64)); |
| 968 | |
| 969 | chunk_appendf(out, |
| 970 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 971 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 972 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 973 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
| 974 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
| 975 | "", |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 976 | U2H(stats[ST_F_INTERCEPTED].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 977 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 978 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 979 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 980 | (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 981 | U2H(stats[ST_F_WREW].u.u64), |
| 982 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | chunk_appendf(out, |
| 986 | "</table></div></u></td>" |
| 987 | /* sessions: lbtot, lastsess */ |
| 988 | "<td></td><td></td>" |
| 989 | /* bytes : in */ |
| 990 | "<td>%s</td>" |
| 991 | "", |
| 992 | U2H(stats[ST_F_BIN].u.u64)); |
| 993 | |
| 994 | chunk_appendf(out, |
| 995 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 996 | "<td>%s%s<div class=tips><table class=det>" |
| 997 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 998 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 999 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1000 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1001 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1002 | "</table></div>%s</td>", |
| 1003 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1004 | U2H(stats[ST_F_BOUT].u.u64), |
| 1005 | U2H(stats[ST_F_BOUT].u.u64), |
| 1006 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1007 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1008 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1009 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1010 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1011 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 1012 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1013 | |
| 1014 | chunk_appendf(out, |
| 1015 | /* denied: req, resp */ |
| 1016 | "<td>%s</td><td>%s</td>" |
| 1017 | /* errors : request, connect, response */ |
| 1018 | "<td>%s</td><td></td><td></td>" |
| 1019 | /* warnings: retries, redispatches */ |
| 1020 | "<td></td><td></td>" |
| 1021 | /* server status : reflect frontend status */ |
| 1022 | "<td class=ac>%s</td>" |
| 1023 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1024 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1025 | "", |
| 1026 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1027 | U2H(stats[ST_F_EREQ].u.u64), |
| 1028 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1029 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1030 | if (flags & STAT_SHMODULES) { |
| 1031 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1032 | chunk_appendf(out, "<td>"); |
| 1033 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1034 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1035 | chunk_appendf(out, |
| 1036 | "<u>%s<div class=tips><table class=det>", |
| 1037 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1038 | for (j = 0; j < mod->stats_count; ++j) { |
| 1039 | chunk_appendf(out, |
| 1040 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1041 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1042 | ++i; |
| 1043 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1044 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1045 | } else { |
| 1046 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1047 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1048 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1049 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1050 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1054 | } |
| 1055 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
| 1056 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1057 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1058 | /* Column sub-heading for Enable or Disable server */ |
| 1059 | chunk_appendf(out, "<td></td>"); |
| 1060 | } |
| 1061 | |
| 1062 | chunk_appendf(out, |
| 1063 | /* frontend name, listener name */ |
| 1064 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 1065 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 1066 | "", |
| 1067 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1068 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1069 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 1070 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1071 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1072 | chunk_appendf(out, "<div class=tips>"); |
| 1073 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 1074 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1075 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 1076 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 1077 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1078 | else if (*field_str(stats, ST_F_ADDR)) |
| 1079 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1080 | |
| 1081 | /* id */ |
| 1082 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
| 1083 | } |
| 1084 | |
| 1085 | chunk_appendf(out, |
| 1086 | /* queue */ |
| 1087 | "%s</td><td colspan=3></td>" |
| 1088 | /* sessions rate: current, max, limit */ |
| 1089 | "<td colspan=3> </td>" |
| 1090 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 1091 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1092 | "<td>%s</td><td> </td><td> </td>" |
| 1093 | /* bytes: in, out */ |
| 1094 | "<td>%s</td><td>%s</td>" |
| 1095 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1096 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1097 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 1098 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 1099 | |
| 1100 | chunk_appendf(out, |
| 1101 | /* denied: req, resp */ |
| 1102 | "<td>%s</td><td>%s</td>" |
| 1103 | /* errors: request, connect, response */ |
| 1104 | "<td>%s</td><td></td><td></td>" |
| 1105 | /* warnings: retries, redispatches */ |
| 1106 | "<td></td><td></td>" |
| 1107 | /* server status: reflect listener status */ |
| 1108 | "<td class=ac>%s</td>" |
| 1109 | /* rest of server: nothing */ |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1110 | "<td class=ac colspan=8></td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1111 | "", |
| 1112 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1113 | U2H(stats[ST_F_EREQ].u.u64), |
| 1114 | field_str(stats, ST_F_STATUS)); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1115 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1116 | if (flags & STAT_SHMODULES) { |
| 1117 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1118 | chunk_appendf(out, "<td>"); |
| 1119 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1120 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1121 | chunk_appendf(out, |
| 1122 | "<u>%s<div class=tips><table class=det>", |
| 1123 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1124 | for (j = 0; j < mod->stats_count; ++j) { |
| 1125 | chunk_appendf(out, |
| 1126 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1127 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1128 | ++i; |
| 1129 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1130 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1131 | } else { |
| 1132 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1133 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1134 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1135 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1136 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1140 | } |
| 1141 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 1142 | const char *style; |
| 1143 | |
| 1144 | /* determine the style to use depending on the server's state, |
| 1145 | * its health and weight. There isn't a 1-to-1 mapping between |
| 1146 | * state and styles for the cases where the server is (still) |
| 1147 | * up. The reason is that we don't want to report nolb and |
| 1148 | * drain with the same color. |
| 1149 | */ |
| 1150 | |
| 1151 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 1152 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 1153 | style = "down"; |
| 1154 | } |
Florian Apolloner | 39272c2 | 2021-03-30 13:28:35 +0200 | [diff] [blame] | 1155 | else if (strncmp(field_str(stats, ST_F_STATUS), "DOWN ", strlen("DOWN ")) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1156 | style = "going_up"; |
| 1157 | } |
Daniel Corbett | b428517 | 2020-03-28 12:35:50 -0400 | [diff] [blame] | 1158 | else if (strcmp(field_str(stats, ST_F_STATUS), "DRAIN") == 0) { |
| 1159 | style = "draining"; |
| 1160 | } |
Florian Apolloner | 39272c2 | 2021-03-30 13:28:35 +0200 | [diff] [blame] | 1161 | else if (strncmp(field_str(stats, ST_F_STATUS), "NOLB ", strlen("NOLB ")) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1162 | style = "going_down"; |
| 1163 | } |
| 1164 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 1165 | style = "nolb"; |
| 1166 | } |
| 1167 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 1168 | style = "no_check"; |
| 1169 | } |
| 1170 | else if (!stats[ST_F_CHKFAIL].type || |
| 1171 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 1172 | /* no check or max health = UP */ |
| 1173 | if (stats[ST_F_WEIGHT].u.u32) |
| 1174 | style = "up"; |
| 1175 | else |
| 1176 | style = "draining"; |
| 1177 | } |
| 1178 | else { |
| 1179 | style = "going_down"; |
| 1180 | } |
| 1181 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1182 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1183 | chunk_appendf(out, "<tr class=\"maintain\">"); |
| 1184 | else |
| 1185 | chunk_appendf(out, |
| 1186 | "<tr class=\"%s_%s\">", |
| 1187 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
| 1188 | |
| 1189 | |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1190 | if (flags & STAT_ADMIN) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1191 | chunk_appendf(out, |
David Harrigan | d3db35a | 2016-12-30 12:12:49 +0000 | [diff] [blame] | 1192 | "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 1193 | field_str(stats, ST_F_PXNAME), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1194 | field_str(stats, ST_F_SVNAME)); |
| 1195 | |
| 1196 | chunk_appendf(out, |
| 1197 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 1198 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 1199 | "", |
| 1200 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1201 | (flags & STAT_SHLGNDS) ? "<u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1202 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 1203 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1204 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1205 | chunk_appendf(out, "<div class=tips>"); |
| 1206 | |
Willy Tarreau | 9080711 | 2020-02-25 08:16:33 +0100 | [diff] [blame] | 1207 | if (isdigit((unsigned char)*field_str(stats, ST_F_ADDR))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1208 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 1209 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 1210 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 1211 | else if (*field_str(stats, ST_F_ADDR)) |
| 1212 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 1213 | |
| 1214 | /* id */ |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 1215 | chunk_appendf(out, "id: %d, rid: %d", stats[ST_F_SID].u.u32, stats[ST_F_SRID].u.u32); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1216 | |
| 1217 | /* cookie */ |
| 1218 | if (stats[ST_F_COOKIE].type) { |
| 1219 | chunk_appendf(out, ", cookie: '"); |
| 1220 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1221 | chunk_htmlencode(out, &src); |
| 1222 | chunk_appendf(out, "'"); |
| 1223 | } |
| 1224 | |
| 1225 | chunk_appendf(out, "</div>"); |
| 1226 | } |
| 1227 | |
| 1228 | chunk_appendf(out, |
| 1229 | /* queue : current, max, limit */ |
| 1230 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 1231 | /* sessions rate : current, max, limit */ |
| 1232 | "<td>%s</td><td>%s</td><td></td>" |
| 1233 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1234 | (flags & STAT_SHLGNDS) ? "</u>" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1235 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 1236 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1237 | |
| 1238 | chunk_appendf(out, |
| 1239 | /* sessions: current, max, limit, total */ |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1240 | "<td><u>%s<div class=tips>" |
| 1241 | "<table class=det>" |
| 1242 | "<tr><th>Current active connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1243 | "<tr><th>Current used connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1244 | "<tr><th>Current idle connections:</th><td>%s</td></tr>" |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1245 | "<tr><th>- unsafe:</th><td>%s</td></tr>" |
| 1246 | "<tr><th>- safe:</th><td>%s</td></tr>" |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1247 | "<tr><th>Estimated need of connections:</th><td>%s</td></tr>" |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1248 | "<tr><th>Active connections limit:</th><td>%s</td></tr>" |
| 1249 | "<tr><th>Idle connections limit:</th><td>%s</td></tr>" |
| 1250 | "</table></div></u>" |
| 1251 | "</td><td>%s</td><td>%s</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1252 | "<td><u>%s<div class=tips><table class=det>" |
| 1253 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1254 | "", |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1255 | U2H(stats[ST_F_SCUR].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1256 | U2H(stats[ST_F_SCUR].u.u32), |
| 1257 | U2H(stats[ST_F_USED_CONN_CUR].u.u32), |
| 1258 | U2H(stats[ST_F_SRV_ICUR].u.u32), |
| 1259 | U2H(stats[ST_F_IDLE_CONN_CUR].u.u32), |
| 1260 | U2H(stats[ST_F_SAFE_CONN_CUR].u.u32), |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 1261 | U2H(stats[ST_F_NEED_CONN_EST].u.u32), |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 1262 | |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 1263 | LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 1264 | stats[ST_F_SRV_ILIM].type ? U2H(stats[ST_F_SRV_ILIM].u.u32) : "-", |
| 1265 | U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1266 | U2H(stats[ST_F_STOT].u.u64), |
| 1267 | U2H(stats[ST_F_STOT].u.u64)); |
| 1268 | |
| 1269 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1270 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1271 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1272 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1273 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1274 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1275 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1276 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1277 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1278 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1279 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1280 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1281 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1282 | "<tr><th>Internal error:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1283 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1284 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1285 | U2H(stats[ST_F_REUSE].u.u64), |
| 1286 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1287 | (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0, |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1288 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1289 | U2H(stats[ST_F_HRSP_1XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1290 | (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1291 | U2H(stats[ST_F_HRSP_2XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1292 | (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1293 | U2H(stats[ST_F_HRSP_3XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1294 | (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1295 | U2H(stats[ST_F_HRSP_4XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1296 | (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1297 | U2H(stats[ST_F_HRSP_5XX].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1298 | (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
| 1299 | U2H(stats[ST_F_HRSP_OTHER].u.u64), stats[ST_F_REQ_TOT].u.u64 ? |
| 1300 | (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / stats[ST_F_REQ_TOT].u.u64) : 0, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1301 | U2H(stats[ST_F_WREW].u.u64), |
| 1302 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1305 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1306 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1307 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1308 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1309 | U2H(stats[ST_F_CT_MAX].u.u32), U2H(stats[ST_F_CTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1310 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1311 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1312 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1313 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1314 | U2H(stats[ST_F_TT_MAX].u.u32), U2H(stats[ST_F_TTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1315 | |
| 1316 | chunk_appendf(out, |
| 1317 | "</table></div></u></td>" |
| 1318 | /* sessions: lbtot, last */ |
| 1319 | "<td>%s</td><td>%s</td>", |
| 1320 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1321 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
| 1322 | |
| 1323 | chunk_appendf(out, |
| 1324 | /* bytes : in, out */ |
| 1325 | "<td>%s</td><td>%s</td>" |
| 1326 | /* denied: req, resp */ |
| 1327 | "<td></td><td>%s</td>" |
| 1328 | /* errors : request, connect */ |
| 1329 | "<td></td><td>%s</td>" |
| 1330 | /* errors : response */ |
| 1331 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1332 | /* warnings: retries, redispatches */ |
| 1333 | "<td>%lld</td><td>%lld</td>" |
| 1334 | "", |
| 1335 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 1336 | U2H(stats[ST_F_DRESP].u.u64), |
| 1337 | U2H(stats[ST_F_ECON].u.u64), |
| 1338 | U2H(stats[ST_F_ERESP].u.u64), |
| 1339 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1340 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1341 | (long long)stats[ST_F_WRETR].u.u64, |
| 1342 | (long long)stats[ST_F_WREDIS].u.u64); |
| 1343 | |
| 1344 | /* status, last change */ |
| 1345 | chunk_appendf(out, "<td class=ac>"); |
| 1346 | |
| 1347 | /* FIXME!!!! |
| 1348 | * LASTCHG should contain the last change for *this* server and must be computed |
| 1349 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 1350 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 1351 | */ |
| 1352 | |
| 1353 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1354 | if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1355 | chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); |
| 1356 | } |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1357 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1358 | chunk_strcat(out, "<i>no check</i>"); |
| 1359 | } |
| 1360 | else { |
| 1361 | chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1362 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1363 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
| 1364 | chunk_strcat(out, " ↑"); |
| 1365 | } |
| 1366 | else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) |
| 1367 | chunk_strcat(out, " ↓"); |
| 1368 | } |
| 1369 | |
Willy Tarreau | 7b52485 | 2020-08-11 10:26:36 +0200 | [diff] [blame] | 1370 | if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1371 | stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { |
| 1372 | chunk_appendf(out, |
| 1373 | "</td><td class=ac><u> %s", |
| 1374 | field_str(stats, ST_F_AGENT_STATUS)); |
| 1375 | |
| 1376 | if (stats[ST_F_AGENT_CODE].type) |
| 1377 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
| 1378 | |
| 1379 | if (stats[ST_F_AGENT_DURATION].type) |
| 1380 | chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); |
| 1381 | |
| 1382 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC)); |
| 1383 | |
| 1384 | if (*field_str(stats, ST_F_LAST_AGT)) { |
| 1385 | chunk_appendf(out, ": "); |
| 1386 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
| 1387 | chunk_htmlencode(out, &src); |
| 1388 | } |
| 1389 | chunk_appendf(out, "</div></u>"); |
| 1390 | } |
| 1391 | else if (stats[ST_F_CHECK_STATUS].type) { |
| 1392 | chunk_appendf(out, |
| 1393 | "</td><td class=ac><u> %s", |
| 1394 | field_str(stats, ST_F_CHECK_STATUS)); |
| 1395 | |
| 1396 | if (stats[ST_F_CHECK_CODE].type) |
| 1397 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
| 1398 | |
| 1399 | if (stats[ST_F_CHECK_DURATION].type) |
| 1400 | chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); |
| 1401 | |
| 1402 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC)); |
| 1403 | |
| 1404 | if (*field_str(stats, ST_F_LAST_CHK)) { |
| 1405 | chunk_appendf(out, ": "); |
| 1406 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
| 1407 | chunk_htmlencode(out, &src); |
| 1408 | } |
| 1409 | chunk_appendf(out, "</div></u>"); |
| 1410 | } |
| 1411 | else |
| 1412 | chunk_appendf(out, "</td><td>"); |
| 1413 | |
| 1414 | chunk_appendf(out, |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1415 | /* weight / uweight */ |
| 1416 | "</td><td class=ac>%d/%d</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1417 | /* act, bck */ |
| 1418 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 1419 | "", |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1420 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1421 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 1422 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 1423 | |
| 1424 | /* check failures: unique, fatal, down time */ |
| 1425 | if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) { |
| 1426 | chunk_appendf(out, "<td class=ac colspan=3>resolution</td>"); |
| 1427 | } |
| 1428 | else if (stats[ST_F_CHKFAIL].type) { |
| 1429 | chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64); |
| 1430 | |
| 1431 | if (stats[ST_F_HANAFAIL].type) |
| 1432 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
| 1433 | |
| 1434 | chunk_appendf(out, |
| 1435 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 1436 | "<td>%lld</td><td>%s</td>" |
| 1437 | "", |
| 1438 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 1439 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 1440 | } |
| 1441 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 1442 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
| 1443 | chunk_appendf(out, |
| 1444 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 1445 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 1446 | } |
| 1447 | else |
| 1448 | chunk_appendf(out, "<td colspan=3></td>"); |
| 1449 | |
| 1450 | /* throttle */ |
| 1451 | if (stats[ST_F_THROTTLE].type) |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1452 | chunk_appendf(out, "<td class=ac>%d %%</td>\n", stats[ST_F_THROTTLE].u.u32); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1453 | else |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1454 | chunk_appendf(out, "<td class=ac>-</td>"); |
| 1455 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1456 | if (flags & STAT_SHMODULES) { |
| 1457 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1458 | chunk_appendf(out, "<td>"); |
| 1459 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1460 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1461 | chunk_appendf(out, |
| 1462 | "<u>%s<div class=tips><table class=det>", |
| 1463 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1464 | for (j = 0; j < mod->stats_count; ++j) { |
| 1465 | chunk_appendf(out, |
| 1466 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1467 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1468 | ++i; |
| 1469 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1470 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1471 | } else { |
| 1472 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1473 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1474 | |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1475 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1476 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | chunk_appendf(out, "</tr>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1480 | } |
| 1481 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
| 1482 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | ab02b3f | 2019-10-09 11:11:46 +0200 | [diff] [blame] | 1483 | if (flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1484 | /* Column sub-heading for Enable or Disable server */ |
| 1485 | chunk_appendf(out, "<td></td>"); |
| 1486 | } |
| 1487 | chunk_appendf(out, |
| 1488 | "<td class=ac>" |
| 1489 | /* name */ |
| 1490 | "%s<a name=\"%s/Backend\"></a>" |
| 1491 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 1492 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1493 | (flags & STAT_SHLGNDS)?"<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1494 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 1495 | |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1496 | if (flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1497 | /* balancing */ |
| 1498 | chunk_appendf(out, "<div class=tips>balancing: %s", |
| 1499 | field_str(stats, ST_F_ALGO)); |
| 1500 | |
| 1501 | /* cookie */ |
| 1502 | if (stats[ST_F_COOKIE].type) { |
| 1503 | chunk_appendf(out, ", cookie: '"); |
| 1504 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1505 | chunk_htmlencode(out, &src); |
| 1506 | chunk_appendf(out, "'"); |
| 1507 | } |
| 1508 | chunk_appendf(out, "</div>"); |
| 1509 | } |
| 1510 | |
| 1511 | chunk_appendf(out, |
| 1512 | "%s</td>" |
| 1513 | /* queue : current, max */ |
| 1514 | "<td>%s</td><td>%s</td><td></td>" |
| 1515 | /* sessions rate : current, max, limit */ |
| 1516 | "<td>%s</td><td>%s</td><td></td>" |
| 1517 | "", |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 1518 | (flags & STAT_SHLGNDS)?"</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1519 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 1520 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1521 | |
| 1522 | chunk_appendf(out, |
| 1523 | /* sessions: current, max, limit, total */ |
| 1524 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1525 | "<td><u>%s<div class=tips><table class=det>" |
| 1526 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1527 | "", |
Willy Tarreau | 8e0f175 | 2016-12-12 15:07:29 +0100 | [diff] [blame] | 1528 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1529 | U2H(stats[ST_F_STOT].u.u64), |
| 1530 | U2H(stats[ST_F_STOT].u.u64)); |
| 1531 | |
| 1532 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1533 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 1534 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1535 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1536 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1537 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1538 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1539 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1540 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1541 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1542 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1543 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1544 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1545 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 1546 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1547 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1548 | "<tr><th>Internal errors:</th><td>%s</td></tr>" |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1549 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1550 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1551 | U2H(stats[ST_F_REUSE].u.u64), |
| 1552 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1553 | (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1554 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1555 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 1556 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 1557 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 1558 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 1559 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 1560 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 1561 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 1562 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Willy Tarreau | feead3a | 2018-12-14 13:48:44 +0100 | [diff] [blame] | 1563 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1564 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 1565 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 1566 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 1567 | (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 1568 | U2H(stats[ST_F_WREW].u.u64), |
| 1569 | U2H(stats[ST_F_EINT].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1570 | } |
| 1571 | |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1572 | chunk_appendf(out, "<tr><th colspan=3>Max / Avg over last 1024 success. conn.</th></tr>"); |
| 1573 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1574 | U2H(stats[ST_F_QT_MAX].u.u32), U2H(stats[ST_F_QTIME].u.u32)); |
| 1575 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1576 | U2H(stats[ST_F_CT_MAX].u.u32), U2H(stats[ST_F_CTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1577 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 1578 | chunk_appendf(out, "<tr><th>- Responses time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1579 | U2H(stats[ST_F_RT_MAX].u.u32), U2H(stats[ST_F_RTIME].u.u32)); |
| 1580 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s / %s</td><td>ms</td></tr>", |
| 1581 | U2H(stats[ST_F_TT_MAX].u.u32), U2H(stats[ST_F_TTIME].u.u32)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1582 | |
| 1583 | chunk_appendf(out, |
| 1584 | "</table></div></u></td>" |
| 1585 | /* sessions: lbtot, last */ |
| 1586 | "<td>%s</td><td>%s</td>" |
| 1587 | /* bytes: in */ |
| 1588 | "<td>%s</td>" |
| 1589 | "", |
| 1590 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1591 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 1592 | U2H(stats[ST_F_BIN].u.u64)); |
| 1593 | |
| 1594 | chunk_appendf(out, |
| 1595 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 1596 | "<td>%s%s<div class=tips><table class=det>" |
| 1597 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 1598 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 1599 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1600 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1601 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1602 | "</table></div>%s</td>", |
| 1603 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1604 | U2H(stats[ST_F_BOUT].u.u64), |
| 1605 | U2H(stats[ST_F_BOUT].u.u64), |
| 1606 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1607 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1608 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1609 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1610 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1611 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 1612 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1613 | |
| 1614 | chunk_appendf(out, |
| 1615 | /* denied: req, resp */ |
| 1616 | "<td>%s</td><td>%s</td>" |
| 1617 | /* errors : request, connect */ |
| 1618 | "<td></td><td>%s</td>" |
| 1619 | /* errors : response */ |
| 1620 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1621 | /* warnings: retries, redispatches */ |
| 1622 | "<td>%lld</td><td>%lld</td>" |
| 1623 | /* backend status: reflect backend status (up/down): we display UP |
| 1624 | * if the backend has known working servers or if it has no server at |
| 1625 | * all (eg: for stats). Then we display the total weight, number of |
| 1626 | * active and backups. */ |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1627 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d/%d</td>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1628 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 1629 | "", |
| 1630 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1631 | U2H(stats[ST_F_ECON].u.u64), |
| 1632 | U2H(stats[ST_F_ERESP].u.u64), |
| 1633 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1634 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1635 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 1636 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 1637 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 1638 | stats[ST_F_WEIGHT].u.u32, stats[ST_F_UWEIGHT].u.u32, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1639 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 1640 | |
| 1641 | chunk_appendf(out, |
| 1642 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 1643 | "<td class=ac> </td><td>%d</td>" |
| 1644 | "<td>%s</td>" |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1645 | "<td></td>", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1646 | stats[ST_F_CHKDOWN].u.u32, |
| 1647 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1648 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1649 | if (flags & STAT_SHMODULES) { |
| 1650 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1651 | chunk_appendf(out, "<td>"); |
| 1652 | |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1653 | if (stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE) { |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1654 | chunk_appendf(out, |
| 1655 | "<u>%s<div class=tips><table class=det>", |
| 1656 | mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1657 | for (j = 0; j < mod->stats_count; ++j) { |
| 1658 | chunk_appendf(out, |
| 1659 | "<tr><th>%s</th><td>%s</td></tr>", |
| 1660 | mod->stats[j].desc, field_to_html_str(&stats[ST_F_TOTAL_FIELDS + i])); |
| 1661 | ++i; |
| 1662 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1663 | chunk_appendf(out, "</table></div></u>"); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1664 | } else { |
| 1665 | i += mod->stats_count; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1666 | } |
Amaury Denoyelle | e6ee820 | 2020-11-03 15:04:46 +0100 | [diff] [blame] | 1667 | |
| 1668 | chunk_appendf(out, "</td>"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1669 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1670 | } |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 1671 | |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1672 | chunk_appendf(out, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1673 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 1674 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1675 | return 1; |
| 1676 | } |
| 1677 | |
Amaury Denoyelle | 97323c9 | 2020-10-02 18:32:01 +0200 | [diff] [blame] | 1678 | int stats_dump_one_line(const struct field *stats, size_t stats_count, |
| 1679 | struct appctx *appctx) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1680 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1681 | struct show_stat_ctx *ctx = appctx->svcctx; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1682 | int ret; |
| 1683 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1684 | if (ctx->flags & STAT_FMT_HTML) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1685 | ret = stats_dump_fields_html(&trash_chunk, stats, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1686 | else if (ctx->flags & STAT_FMT_TYPED) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1687 | ret = stats_dump_fields_typed(&trash_chunk, stats, stats_count, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1688 | else if (ctx->flags & STAT_FMT_JSON) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1689 | ret = stats_dump_fields_json(&trash_chunk, stats, stats_count, ctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1690 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1691 | ret = stats_dump_fields_csv(&trash_chunk, stats, stats_count, ctx); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1692 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1693 | return ret; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1694 | } |
| 1695 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1696 | /* Fill <stats> with the frontend statistics. <stats> is preallocated array of |
Christopher Faulet | d808f17 | 2021-01-22 17:33:22 +0100 | [diff] [blame] | 1697 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 1698 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 1699 | * this value, or if the selected field is not implemented for frontends, the |
| 1700 | * function returns 0, otherwise, it returns 1. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1701 | */ |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1702 | int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len, |
| 1703 | enum stat_field *selected_field) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1704 | { |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1705 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1706 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1707 | if (len < ST_F_TOTAL_FIELDS) |
| 1708 | return 0; |
| 1709 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1710 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
Christopher Faulet | 8596bfb | 2021-01-25 15:16:41 +0100 | [diff] [blame] | 1711 | struct field metric = { 0 }; |
| 1712 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1713 | switch (current_field) { |
| 1714 | case ST_F_PXNAME: |
| 1715 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1716 | break; |
| 1717 | case ST_F_SVNAME: |
| 1718 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
| 1719 | break; |
| 1720 | case ST_F_MODE: |
| 1721 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1722 | break; |
| 1723 | case ST_F_SCUR: |
| 1724 | metric = mkf_u32(0, px->feconn); |
| 1725 | break; |
| 1726 | case ST_F_SMAX: |
| 1727 | metric = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 1728 | break; |
| 1729 | case ST_F_SLIM: |
| 1730 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 1731 | break; |
| 1732 | case ST_F_STOT: |
| 1733 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 1734 | break; |
| 1735 | case ST_F_BIN: |
| 1736 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 1737 | break; |
| 1738 | case ST_F_BOUT: |
| 1739 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 1740 | break; |
| 1741 | case ST_F_DREQ: |
| 1742 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 1743 | break; |
| 1744 | case ST_F_DRESP: |
| 1745 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 1746 | break; |
| 1747 | case ST_F_EREQ: |
| 1748 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 1749 | break; |
| 1750 | case ST_F_DCON: |
| 1751 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); |
| 1752 | break; |
| 1753 | case ST_F_DSES: |
| 1754 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); |
| 1755 | break; |
Aurelien DARRAGON | cddec0a | 2022-09-09 15:58:57 +0200 | [diff] [blame] | 1756 | case ST_F_STATUS: { |
| 1757 | const char *state; |
| 1758 | |
| 1759 | if (px->flags & (PR_FL_DISABLED|PR_FL_STOPPED)) |
| 1760 | state = "STOP"; |
| 1761 | else if (px->flags & PR_FL_PAUSED) |
| 1762 | state = "PAUSED"; |
| 1763 | else |
| 1764 | state = "OPEN"; |
| 1765 | metric = mkf_str(FO_STATUS, state); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1766 | break; |
Aurelien DARRAGON | cddec0a | 2022-09-09 15:58:57 +0200 | [diff] [blame] | 1767 | } |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1768 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 1769 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1770 | break; |
| 1771 | case ST_F_IID: |
| 1772 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1773 | break; |
| 1774 | case ST_F_SID: |
| 1775 | metric = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 1776 | break; |
| 1777 | case ST_F_TYPE: |
| 1778 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 1779 | break; |
| 1780 | case ST_F_RATE: |
| 1781 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 1782 | break; |
| 1783 | case ST_F_RATE_LIM: |
| 1784 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 1785 | break; |
| 1786 | case ST_F_RATE_MAX: |
| 1787 | metric = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 1788 | break; |
| 1789 | case ST_F_WREW: |
| 1790 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites); |
| 1791 | break; |
| 1792 | case ST_F_EINT: |
| 1793 | metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors); |
| 1794 | break; |
| 1795 | case ST_F_HRSP_1XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1796 | if (px->mode == PR_MODE_HTTP) |
| 1797 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1798 | break; |
| 1799 | case ST_F_HRSP_2XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1800 | if (px->mode == PR_MODE_HTTP) |
| 1801 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1802 | break; |
| 1803 | case ST_F_HRSP_3XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1804 | if (px->mode == PR_MODE_HTTP) |
| 1805 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1806 | break; |
| 1807 | case ST_F_HRSP_4XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1808 | if (px->mode == PR_MODE_HTTP) |
| 1809 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1810 | break; |
| 1811 | case ST_F_HRSP_5XX: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1812 | if (px->mode == PR_MODE_HTTP) |
| 1813 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1814 | break; |
| 1815 | case ST_F_HRSP_OTHER: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1816 | if (px->mode == PR_MODE_HTTP) |
| 1817 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1818 | break; |
| 1819 | case ST_F_INTERCEPTED: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1820 | if (px->mode == PR_MODE_HTTP) |
| 1821 | metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1822 | break; |
| 1823 | case ST_F_CACHE_LOOKUPS: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1824 | if (px->mode == PR_MODE_HTTP) |
| 1825 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1826 | break; |
| 1827 | case ST_F_CACHE_HITS: |
William Dauchy | 2107a0f | 2021-01-22 21:09:48 +0100 | [diff] [blame] | 1828 | if (px->mode == PR_MODE_HTTP) |
| 1829 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1830 | break; |
| 1831 | case ST_F_REQ_RATE: |
| 1832 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 1833 | break; |
| 1834 | case ST_F_REQ_RATE_MAX: |
| 1835 | metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 1836 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1837 | case ST_F_REQ_TOT: { |
| 1838 | int i; |
| 1839 | uint64_t total_req; |
| 1840 | size_t nb_reqs = |
| 1841 | sizeof(px->fe_counters.p.http.cum_req) / sizeof(*px->fe_counters.p.http.cum_req); |
| 1842 | |
| 1843 | total_req = 0; |
| 1844 | for (i = 0; i < nb_reqs; i++) |
| 1845 | total_req += px->fe_counters.p.http.cum_req[i]; |
| 1846 | metric = mkf_u64(FN_COUNTER, total_req); |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1847 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1848 | } |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1849 | case ST_F_COMP_IN: |
| 1850 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 1851 | break; |
| 1852 | case ST_F_COMP_OUT: |
| 1853 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 1854 | break; |
| 1855 | case ST_F_COMP_BYP: |
| 1856 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 1857 | break; |
| 1858 | case ST_F_COMP_RSP: |
| 1859 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 1860 | break; |
| 1861 | case ST_F_CONN_RATE: |
| 1862 | metric = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 1863 | break; |
| 1864 | case ST_F_CONN_RATE_MAX: |
| 1865 | metric = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 1866 | break; |
| 1867 | case ST_F_CONN_TOT: |
| 1868 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 1869 | break; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1870 | case ST_F_SESS_OTHER: { |
| 1871 | int i; |
| 1872 | uint64_t total_sess; |
| 1873 | size_t nb_sess = |
| 1874 | sizeof(px->fe_counters.cum_sess_ver) / sizeof(*px->fe_counters.cum_sess_ver); |
| 1875 | |
| 1876 | total_sess = px->fe_counters.cum_sess; |
| 1877 | for (i = 0; i < nb_sess; i++) |
| 1878 | total_sess -= px->fe_counters.cum_sess_ver[i]; |
Frédéric Lécaille | d97d1d7 | 2023-02-06 09:23:56 +0100 | [diff] [blame] | 1879 | total_sess = (int64_t)total_sess < 0 ? 0 : total_sess; |
Frédéric Lécaille | 9969adb | 2023-01-18 11:52:21 +0100 | [diff] [blame] | 1880 | metric = mkf_u64(FN_COUNTER, total_sess); |
| 1881 | break; |
| 1882 | } |
| 1883 | case ST_F_H1SESS: |
| 1884 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[0]); |
| 1885 | break; |
| 1886 | case ST_F_H2SESS: |
| 1887 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[1]); |
| 1888 | break; |
| 1889 | case ST_F_H3SESS: |
| 1890 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess_ver[2]); |
| 1891 | break; |
| 1892 | case ST_F_REQ_OTHER: |
| 1893 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[0]); |
| 1894 | break; |
| 1895 | case ST_F_H1REQ: |
| 1896 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[1]); |
| 1897 | break; |
| 1898 | case ST_F_H2REQ: |
| 1899 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[2]); |
| 1900 | break; |
| 1901 | case ST_F_H3REQ: |
| 1902 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req[3]); |
| 1903 | break; |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1904 | default: |
Christopher Faulet | d808f17 | 2021-01-22 17:33:22 +0100 | [diff] [blame] | 1905 | /* not used for frontends. If a specific metric |
| 1906 | * is requested, return an error. Otherwise continue. |
| 1907 | */ |
| 1908 | if (selected_field != NULL) |
| 1909 | return 0; |
| 1910 | continue; |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1911 | } |
| 1912 | stats[current_field] = metric; |
| 1913 | if (selected_field != NULL) |
| 1914 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1915 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1916 | return 1; |
| 1917 | } |
| 1918 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 1919 | /* Dumps a frontend's line to the local trash buffer for the current proxy <px> |
| 1920 | * and uses the state from stream connector <sc>. The caller is responsible for |
| 1921 | * clearing the local trash buffer if needed. Returns non-zero if it emits |
| 1922 | * anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1923 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 1924 | static int stats_dump_fe_stats(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1925 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 1926 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1927 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1928 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 1929 | struct stats_module *mod; |
| 1930 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1931 | |
| 1932 | if (!(px->cap & PR_CAP_FE)) |
| 1933 | return 0; |
| 1934 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 1935 | if ((ctx->flags & STAT_BOUND) && !(ctx->type & (1 << STATS_TYPE_FE))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1936 | return 0; |
| 1937 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1938 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 1939 | |
William Dauchy | 0ef5439 | 2021-01-17 18:27:45 +0100 | [diff] [blame] | 1940 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1941 | return 0; |
| 1942 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 1943 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 1944 | void *counters; |
| 1945 | |
| 1946 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_FE)) { |
| 1947 | stats_count += mod->stats_count; |
| 1948 | continue; |
| 1949 | } |
| 1950 | |
| 1951 | counters = EXTRA_COUNTERS_GET(px->extra_counters_fe, mod); |
| 1952 | mod->fill_stats(counters, stats + stats_count); |
| 1953 | stats_count += mod->stats_count; |
| 1954 | } |
| 1955 | |
| 1956 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1957 | } |
| 1958 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1959 | /* Fill <stats> with the listener statistics. <stats> is preallocated array of |
| 1960 | * length <len>. The length of the array must be at least ST_F_TOTAL_FIELDS. If |
| 1961 | * this length is less then this value, the function returns 0, otherwise, it |
| 1962 | * returns 1. If selected_field is != NULL, only fill this one. <flags> can |
| 1963 | * take the value STAT_SHLGNDS. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1964 | */ |
| 1965 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1966 | struct field *stats, int len, enum stat_field *selected_field) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1967 | { |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1968 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 1969 | struct buffer *out = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1970 | |
| 1971 | if (len < ST_F_TOTAL_FIELDS) |
| 1972 | return 0; |
| 1973 | |
| 1974 | if (!l->counters) |
| 1975 | return 0; |
| 1976 | |
| 1977 | chunk_reset(out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1978 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1979 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 1980 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1981 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 1982 | switch (current_field) { |
| 1983 | case ST_F_PXNAME: |
| 1984 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1985 | break; |
| 1986 | case ST_F_SVNAME: |
| 1987 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name); |
| 1988 | break; |
| 1989 | case ST_F_MODE: |
| 1990 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1991 | break; |
| 1992 | case ST_F_SCUR: |
| 1993 | metric = mkf_u32(0, l->nbconn); |
| 1994 | break; |
| 1995 | case ST_F_SMAX: |
| 1996 | metric = mkf_u32(FN_MAX, l->counters->conn_max); |
| 1997 | break; |
| 1998 | case ST_F_SLIM: |
Willy Tarreau | 758c69d | 2023-01-12 18:59:37 +0100 | [diff] [blame] | 1999 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, l->bind_conf->maxconn); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2000 | break; |
| 2001 | case ST_F_STOT: |
| 2002 | metric = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 2003 | break; |
| 2004 | case ST_F_BIN: |
| 2005 | metric = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 2006 | break; |
| 2007 | case ST_F_BOUT: |
| 2008 | metric = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 2009 | break; |
| 2010 | case ST_F_DREQ: |
| 2011 | metric = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 2012 | break; |
| 2013 | case ST_F_DRESP: |
| 2014 | metric = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 2015 | break; |
| 2016 | case ST_F_EREQ: |
| 2017 | metric = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 2018 | break; |
| 2019 | case ST_F_DCON: |
| 2020 | metric = mkf_u64(FN_COUNTER, l->counters->denied_conn); |
| 2021 | break; |
| 2022 | case ST_F_DSES: |
| 2023 | metric = mkf_u64(FN_COUNTER, l->counters->denied_sess); |
| 2024 | break; |
| 2025 | case ST_F_STATUS: |
William Dauchy | 3679d0c | 2021-02-14 23:22:55 +0100 | [diff] [blame] | 2026 | metric = mkf_str(FO_STATUS, li_status_st[get_li_status(l)]); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2027 | break; |
| 2028 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2029 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2030 | break; |
| 2031 | case ST_F_IID: |
| 2032 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2033 | break; |
| 2034 | case ST_F_SID: |
| 2035 | metric = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 2036 | break; |
| 2037 | case ST_F_TYPE: |
| 2038 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 2039 | break; |
| 2040 | case ST_F_WREW: |
| 2041 | metric = mkf_u64(FN_COUNTER, l->counters->failed_rewrites); |
| 2042 | break; |
| 2043 | case ST_F_EINT: |
| 2044 | metric = mkf_u64(FN_COUNTER, l->counters->internal_errors); |
| 2045 | break; |
| 2046 | case ST_F_ADDR: |
| 2047 | if (flags & STAT_SHLGNDS) { |
| 2048 | char str[INET6_ADDRSTRLEN]; |
| 2049 | int port; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2050 | |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2051 | port = get_host_port(&l->rx.addr); |
| 2052 | switch (addr_to_str(&l->rx.addr, str, sizeof(str))) { |
| 2053 | case AF_INET: |
| 2054 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2055 | chunk_appendf(out, "%s:%d", str, port); |
| 2056 | break; |
| 2057 | case AF_INET6: |
| 2058 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2059 | chunk_appendf(out, "[%s]:%d", str, port); |
| 2060 | break; |
| 2061 | case AF_UNIX: |
| 2062 | metric = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 2063 | break; |
| 2064 | case -1: |
| 2065 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2066 | chunk_strcat(out, strerror(errno)); |
| 2067 | break; |
| 2068 | default: /* address family not supported */ |
| 2069 | break; |
| 2070 | } |
| 2071 | } |
| 2072 | break; |
| 2073 | default: |
| 2074 | /* not used for listen. If a specific metric |
| 2075 | * is requested, return an error. Otherwise continue. |
| 2076 | */ |
| 2077 | if (selected_field != NULL) |
| 2078 | return 0; |
| 2079 | continue; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2080 | } |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2081 | stats[current_field] = metric; |
| 2082 | if (selected_field != NULL) |
| 2083 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2084 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2085 | return 1; |
| 2086 | } |
| 2087 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2088 | /* Dumps a line for listener <l> and proxy <px> to the local trash buffer and |
| 2089 | * uses the state from stream connector <sc>. The caller is responsible for |
| 2090 | * clearing the local trash buffer if needed. Returns non-zero if it emits |
| 2091 | * anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2092 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2093 | static int stats_dump_li_stats(struct stconn *sc, struct proxy *px, struct listener *l) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2094 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2095 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2096 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2097 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2098 | struct stats_module *mod; |
| 2099 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 2100 | |
| 2101 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2102 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2103 | if (!stats_fill_li_stats(px, l, ctx->flags, stats, |
William Dauchy | 655e14e | 2021-02-14 23:22:54 +0100 | [diff] [blame] | 2104 | ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2105 | return 0; |
| 2106 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2107 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2108 | void *counters; |
| 2109 | |
| 2110 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_LI)) { |
| 2111 | stats_count += mod->stats_count; |
| 2112 | continue; |
| 2113 | } |
| 2114 | |
| 2115 | counters = EXTRA_COUNTERS_GET(l->extra_counters, mod); |
| 2116 | mod->fill_stats(counters, stats + stats_count); |
| 2117 | stats_count += mod->stats_count; |
| 2118 | } |
| 2119 | |
| 2120 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | enum srv_stats_state { |
| 2124 | SRV_STATS_STATE_DOWN = 0, |
| 2125 | SRV_STATS_STATE_DOWN_AGENT, |
| 2126 | SRV_STATS_STATE_GOING_UP, |
| 2127 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 2128 | SRV_STATS_STATE_UP, |
| 2129 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 2130 | SRV_STATS_STATE_NOLB, |
| 2131 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 2132 | SRV_STATS_STATE_DRAIN, |
| 2133 | SRV_STATS_STATE_DRAIN_AGENT, |
| 2134 | SRV_STATS_STATE_NO_CHECK, |
| 2135 | |
| 2136 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 2137 | }; |
| 2138 | |
| 2139 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 2140 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 2141 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 2142 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 2143 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 2144 | [SRV_STATS_STATE_UP] = "UP", |
| 2145 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 2146 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 2147 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 2148 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 2149 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 2150 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 2151 | }; |
| 2152 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2153 | /* Compute server state helper |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2154 | */ |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2155 | static void stats_fill_sv_stats_computestate(struct server *sv, struct server *ref, |
| 2156 | enum srv_stats_state *state) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2157 | { |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2158 | if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2159 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 2160 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2161 | *state = SRV_STATS_STATE_UP_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2162 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2163 | *state = SRV_STATS_STATE_UP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2164 | } |
| 2165 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2166 | if (sv->cur_admin & SRV_ADMF_DRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2167 | if (ref->agent.state & CHK_ST_ENABLED) |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2168 | *state = SRV_STATS_STATE_DRAIN_AGENT; |
| 2169 | else if (*state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 2170 | *state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2171 | else |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2172 | *state = SRV_STATS_STATE_DRAIN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2173 | } |
| 2174 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2175 | if (*state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 2176 | *state = SRV_STATS_STATE_NO_CHECK; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2177 | } |
| 2178 | } |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2179 | else if (sv->cur_state == SRV_ST_STOPPING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2180 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 2181 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2182 | *state = SRV_STATS_STATE_NOLB; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2183 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2184 | *state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | else { /* stopped */ |
| 2188 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2189 | *state = SRV_STATS_STATE_DOWN_AGENT; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2190 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2191 | *state = SRV_STATS_STATE_DOWN; /* DOWN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2192 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2193 | *state = SRV_STATS_STATE_GOING_UP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2194 | } else { |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2195 | *state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2196 | } |
| 2197 | } |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2198 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2199 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2200 | /* Fill <stats> with the backend statistics. <stats> is preallocated array of |
| 2201 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 2202 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 2203 | * this value, or if the selected field is not implemented for servers, the |
| 2204 | * function returns 0, otherwise, it returns 1. <flags> can take the value |
| 2205 | * STAT_SHLGNDS. |
| 2206 | */ |
| 2207 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 2208 | struct field *stats, int len, |
| 2209 | enum stat_field *selected_field) |
| 2210 | { |
| 2211 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
| 2212 | struct server *via = sv->track ? sv->track : sv; |
| 2213 | struct server *ref = via; |
| 2214 | enum srv_stats_state state = 0; |
| 2215 | char str[INET6_ADDRSTRLEN]; |
| 2216 | struct buffer *out = get_trash_chunk(); |
| 2217 | char *fld_status; |
| 2218 | long long srv_samples_counter; |
| 2219 | unsigned int srv_samples_window = TIME_STATS_SAMPLES; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2220 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2221 | if (len < ST_F_TOTAL_FIELDS) |
| 2222 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2223 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2224 | chunk_reset(out); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2225 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2226 | /* compute state for later use */ |
| 2227 | if (selected_field == NULL || *selected_field == ST_F_STATUS || |
| 2228 | *selected_field == ST_F_CHECK_RISE || *selected_field == ST_F_CHECK_FALL || |
| 2229 | *selected_field == ST_F_CHECK_HEALTH || *selected_field == ST_F_HANAFAIL) { |
| 2230 | /* we have "via" which is the tracked server as described in the configuration, |
| 2231 | * and "ref" which is the checked server and the end of the chain. |
| 2232 | */ |
| 2233 | while (ref->track) |
| 2234 | ref = ref->track; |
| 2235 | stats_fill_sv_stats_computestate(sv, ref, &state); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2236 | } |
| 2237 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2238 | /* compue time values for later use */ |
| 2239 | if (selected_field == NULL || *selected_field == ST_F_QTIME || |
| 2240 | *selected_field == ST_F_CTIME || *selected_field == ST_F_RTIME || |
| 2241 | *selected_field == ST_F_TTIME) { |
| 2242 | srv_samples_counter = (px->mode == PR_MODE_HTTP) ? sv->counters.p.http.cum_req : sv->counters.cum_lbconn; |
| 2243 | if (srv_samples_counter < TIME_STATS_SAMPLES && srv_samples_counter > 0) |
| 2244 | srv_samples_window = srv_samples_counter; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2245 | } |
| 2246 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2247 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 2248 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2249 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2250 | switch (current_field) { |
| 2251 | case ST_F_PXNAME: |
| 2252 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 2253 | break; |
| 2254 | case ST_F_SVNAME: |
| 2255 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id); |
| 2256 | break; |
| 2257 | case ST_F_MODE: |
| 2258 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Christopher Faulet | 3888b8c | 2021-01-27 13:32:25 +0100 | [diff] [blame] | 2259 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2260 | case ST_F_QCUR: |
Willy Tarreau | a057045 | 2021-06-18 09:30:30 +0200 | [diff] [blame] | 2261 | metric = mkf_u32(0, sv->queue.length); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2262 | break; |
| 2263 | case ST_F_QMAX: |
| 2264 | metric = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 2265 | break; |
| 2266 | case ST_F_SCUR: |
| 2267 | metric = mkf_u32(0, sv->cur_sess); |
| 2268 | break; |
| 2269 | case ST_F_SMAX: |
| 2270 | metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 2271 | break; |
| 2272 | case ST_F_SLIM: |
| 2273 | if (sv->maxconn) |
| 2274 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 2275 | break; |
| 2276 | case ST_F_SRV_ICUR: |
| 2277 | metric = mkf_u32(0, sv->curr_idle_conns); |
| 2278 | break; |
| 2279 | case ST_F_SRV_ILIM: |
| 2280 | if (sv->max_idle_conns != -1) |
| 2281 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->max_idle_conns); |
| 2282 | break; |
| 2283 | case ST_F_STOT: |
| 2284 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 2285 | break; |
| 2286 | case ST_F_BIN: |
| 2287 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 2288 | break; |
| 2289 | case ST_F_BOUT: |
| 2290 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 2291 | break; |
| 2292 | case ST_F_DRESP: |
| 2293 | metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp); |
| 2294 | break; |
| 2295 | case ST_F_ECON: |
| 2296 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 2297 | break; |
| 2298 | case ST_F_ERESP: |
| 2299 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 2300 | break; |
| 2301 | case ST_F_WRETR: |
| 2302 | metric = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 2303 | break; |
| 2304 | case ST_F_WREDIS: |
| 2305 | metric = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 2306 | break; |
| 2307 | case ST_F_WREW: |
| 2308 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites); |
| 2309 | break; |
| 2310 | case ST_F_EINT: |
| 2311 | metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors); |
| 2312 | break; |
| 2313 | case ST_F_CONNECT: |
| 2314 | metric = mkf_u64(FN_COUNTER, sv->counters.connect); |
| 2315 | break; |
| 2316 | case ST_F_REUSE: |
| 2317 | metric = mkf_u64(FN_COUNTER, sv->counters.reuse); |
| 2318 | break; |
| 2319 | case ST_F_IDLE_CONN_CUR: |
| 2320 | metric = mkf_u32(0, sv->curr_idle_nb); |
| 2321 | break; |
| 2322 | case ST_F_SAFE_CONN_CUR: |
| 2323 | metric = mkf_u32(0, sv->curr_safe_nb); |
| 2324 | break; |
| 2325 | case ST_F_USED_CONN_CUR: |
| 2326 | metric = mkf_u32(0, sv->curr_used_conns); |
| 2327 | break; |
| 2328 | case ST_F_NEED_CONN_EST: |
| 2329 | metric = mkf_u32(0, sv->est_need_conns); |
| 2330 | break; |
| 2331 | case ST_F_STATUS: |
| 2332 | fld_status = chunk_newstr(out); |
| 2333 | if (sv->cur_admin & SRV_ADMF_RMAINT) |
| 2334 | chunk_appendf(out, "MAINT (resolution)"); |
| 2335 | else if (sv->cur_admin & SRV_ADMF_IMAINT) |
| 2336 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 2337 | else if (sv->cur_admin & SRV_ADMF_MAINT) |
| 2338 | chunk_appendf(out, "MAINT"); |
| 2339 | else |
| 2340 | chunk_appendf(out, |
| 2341 | srv_hlt_st[state], |
| 2342 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 2343 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2344 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2345 | metric = mkf_str(FO_STATUS, fld_status); |
| 2346 | break; |
| 2347 | case ST_F_LASTCHG: |
| 2348 | metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 2349 | break; |
| 2350 | case ST_F_WEIGHT: |
| 2351 | metric = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 2352 | break; |
| 2353 | case ST_F_UWEIGHT: |
| 2354 | metric = mkf_u32(FN_AVG, sv->uweight); |
| 2355 | break; |
| 2356 | case ST_F_ACT: |
| 2357 | metric = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 2358 | break; |
| 2359 | case ST_F_BCK: |
| 2360 | metric = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
| 2361 | break; |
| 2362 | case ST_F_CHKFAIL: |
| 2363 | if (sv->check.state & CHK_ST_ENABLED) |
| 2364 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 2365 | break; |
| 2366 | case ST_F_CHKDOWN: |
| 2367 | if (sv->check.state & CHK_ST_ENABLED) |
| 2368 | metric = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 2369 | break; |
| 2370 | case ST_F_DOWNTIME: |
| 2371 | if (sv->check.state & CHK_ST_ENABLED) |
| 2372 | metric = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 2373 | break; |
| 2374 | case ST_F_QLIMIT: |
| 2375 | if (sv->maxqueue) |
| 2376 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
| 2377 | break; |
| 2378 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2379 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2380 | break; |
| 2381 | case ST_F_IID: |
| 2382 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2383 | break; |
| 2384 | case ST_F_SID: |
| 2385 | metric = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
| 2386 | break; |
Aurelien DARRAGON | 745ce8e | 2022-11-17 16:34:07 +0100 | [diff] [blame] | 2387 | case ST_F_SRID: |
| 2388 | metric = mkf_u32(FN_COUNTER, sv->rid); |
| 2389 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2390 | case ST_F_THROTTLE: |
| 2391 | if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 2392 | metric = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
| 2393 | break; |
| 2394 | case ST_F_LBTOT: |
| 2395 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
| 2396 | break; |
| 2397 | case ST_F_TRACKED: |
| 2398 | if (sv->track) { |
| 2399 | char *fld_track = chunk_newstr(out); |
| 2400 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 2401 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 2402 | } |
| 2403 | break; |
| 2404 | case ST_F_TYPE: |
| 2405 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 2406 | break; |
| 2407 | case ST_F_RATE: |
| 2408 | metric = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 2409 | break; |
| 2410 | case ST_F_RATE_MAX: |
| 2411 | metric = mkf_u32(FN_MAX, sv->counters.sps_max); |
| 2412 | break; |
| 2413 | case ST_F_CHECK_STATUS: |
| 2414 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2415 | const char *fld_chksts; |
Marcin Deranek | a8dbdf3 | 2020-05-15 20:02:40 +0200 | [diff] [blame] | 2416 | |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2417 | fld_chksts = chunk_newstr(out); |
| 2418 | chunk_strcat(out, "* "); // for check in progress |
| 2419 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 2420 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 2421 | fld_chksts += 2; // skip "* " |
Willy Tarreau | 973a937 | 2021-05-12 17:29:14 +0200 | [diff] [blame] | 2422 | metric = mkf_str(FN_OUTPUT, fld_chksts); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2423 | } |
| 2424 | break; |
| 2425 | case ST_F_CHECK_CODE: |
| 2426 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2427 | sv->check.status >= HCHK_STATUS_L57DATA) |
| 2428 | metric = mkf_u32(FN_OUTPUT, sv->check.code); |
| 2429 | break; |
| 2430 | case ST_F_CHECK_DURATION: |
| 2431 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2432 | sv->check.status >= HCHK_STATUS_CHECKED) |
Aurelien DARRAGON | b118f2f | 2022-12-07 14:52:10 +0100 | [diff] [blame] | 2433 | metric = mkf_u64(FN_DURATION, MAX(sv->check.duration, 0)); |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2434 | break; |
| 2435 | case ST_F_CHECK_DESC: |
| 2436 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2437 | metric = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 2438 | break; |
| 2439 | case ST_F_LAST_CHK: |
| 2440 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2441 | metric = mkf_str(FN_OUTPUT, sv->check.desc); |
| 2442 | break; |
| 2443 | case ST_F_CHECK_RISE: |
| 2444 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2445 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 2446 | break; |
| 2447 | case ST_F_CHECK_FALL: |
| 2448 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2449 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 2450 | break; |
| 2451 | case ST_F_CHECK_HEALTH: |
| 2452 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2453 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 2454 | break; |
Christopher Faulet | 59bab61 | 2021-07-22 08:04:38 +0200 | [diff] [blame] | 2455 | case ST_F_AGENT_STATUS: |
| 2456 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 2457 | const char *fld_chksts; |
| 2458 | |
| 2459 | fld_chksts = chunk_newstr(out); |
| 2460 | chunk_strcat(out, "* "); // for check in progress |
| 2461 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 2462 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 2463 | fld_chksts += 2; // skip "* " |
| 2464 | metric = mkf_str(FN_OUTPUT, fld_chksts); |
| 2465 | } |
| 2466 | break; |
| 2467 | case ST_F_AGENT_CODE: |
| 2468 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED && |
| 2469 | (sv->agent.status >= HCHK_STATUS_L57DATA)) |
| 2470 | metric = mkf_u32(FN_OUTPUT, sv->agent.code); |
| 2471 | break; |
| 2472 | case ST_F_AGENT_DURATION: |
| 2473 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2474 | metric = mkf_u64(FN_DURATION, sv->agent.duration); |
| 2475 | break; |
| 2476 | case ST_F_AGENT_DESC: |
| 2477 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2478 | metric = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 2479 | break; |
| 2480 | case ST_F_LAST_AGT: |
| 2481 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2482 | metric = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 2483 | break; |
| 2484 | case ST_F_AGENT_RISE: |
| 2485 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2486 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 2487 | break; |
| 2488 | case ST_F_AGENT_FALL: |
| 2489 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2490 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 2491 | break; |
| 2492 | case ST_F_AGENT_HEALTH: |
| 2493 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) |
| 2494 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 2495 | break; |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2496 | case ST_F_REQ_TOT: |
| 2497 | if (px->mode == PR_MODE_HTTP) |
| 2498 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req); |
| 2499 | break; |
| 2500 | case ST_F_HRSP_1XX: |
| 2501 | if (px->mode == PR_MODE_HTTP) |
| 2502 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 2503 | break; |
| 2504 | case ST_F_HRSP_2XX: |
| 2505 | if (px->mode == PR_MODE_HTTP) |
| 2506 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 2507 | break; |
| 2508 | case ST_F_HRSP_3XX: |
| 2509 | if (px->mode == PR_MODE_HTTP) |
| 2510 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 2511 | break; |
| 2512 | case ST_F_HRSP_4XX: |
| 2513 | if (px->mode == PR_MODE_HTTP) |
| 2514 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 2515 | break; |
| 2516 | case ST_F_HRSP_5XX: |
| 2517 | if (px->mode == PR_MODE_HTTP) |
| 2518 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 2519 | break; |
| 2520 | case ST_F_HRSP_OTHER: |
| 2521 | if (px->mode == PR_MODE_HTTP) |
| 2522 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 2523 | break; |
| 2524 | case ST_F_HANAFAIL: |
| 2525 | if (ref->observe) |
| 2526 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
| 2527 | break; |
| 2528 | case ST_F_CLI_ABRT: |
| 2529 | metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 2530 | break; |
| 2531 | case ST_F_SRV_ABRT: |
| 2532 | metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 2533 | break; |
| 2534 | case ST_F_LASTSESS: |
| 2535 | metric = mkf_s32(FN_AGE, srv_lastsession(sv)); |
| 2536 | break; |
| 2537 | case ST_F_QTIME: |
| 2538 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, srv_samples_window)); |
| 2539 | break; |
| 2540 | case ST_F_CTIME: |
| 2541 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, srv_samples_window)); |
| 2542 | break; |
| 2543 | case ST_F_RTIME: |
| 2544 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, srv_samples_window)); |
| 2545 | break; |
| 2546 | case ST_F_TTIME: |
| 2547 | metric = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, srv_samples_window)); |
| 2548 | break; |
| 2549 | case ST_F_QT_MAX: |
| 2550 | metric = mkf_u32(FN_MAX, sv->counters.qtime_max); |
| 2551 | break; |
| 2552 | case ST_F_CT_MAX: |
| 2553 | metric = mkf_u32(FN_MAX, sv->counters.ctime_max); |
| 2554 | break; |
| 2555 | case ST_F_RT_MAX: |
| 2556 | metric = mkf_u32(FN_MAX, sv->counters.dtime_max); |
| 2557 | break; |
| 2558 | case ST_F_TT_MAX: |
| 2559 | metric = mkf_u32(FN_MAX, sv->counters.ttime_max); |
| 2560 | break; |
| 2561 | case ST_F_ADDR: |
| 2562 | if (flags & STAT_SHLGNDS) { |
| 2563 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 2564 | case AF_INET: |
| 2565 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2566 | chunk_appendf(out, "%s:%d", str, sv->svc_port); |
| 2567 | break; |
| 2568 | case AF_INET6: |
| 2569 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2570 | chunk_appendf(out, "[%s]:%d", str, sv->svc_port); |
| 2571 | break; |
| 2572 | case AF_UNIX: |
| 2573 | metric = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 2574 | break; |
| 2575 | case -1: |
| 2576 | metric = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 2577 | chunk_strcat(out, strerror(errno)); |
| 2578 | break; |
| 2579 | default: /* address family not supported */ |
| 2580 | break; |
| 2581 | } |
| 2582 | } |
| 2583 | break; |
| 2584 | case ST_F_COOKIE: |
| 2585 | if (flags & STAT_SHLGNDS && sv->cookie) |
| 2586 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 2587 | break; |
| 2588 | default: |
| 2589 | /* not used for servers. If a specific metric |
| 2590 | * is requested, return an error. Otherwise continue. |
| 2591 | */ |
| 2592 | if (selected_field != NULL) |
| 2593 | return 0; |
| 2594 | continue; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2595 | } |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2596 | stats[current_field] = metric; |
| 2597 | if (selected_field != NULL) |
| 2598 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2599 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2600 | return 1; |
| 2601 | } |
| 2602 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2603 | /* Dumps a line for server <sv> and proxy <px> to the local trash vbuffer and |
| 2604 | * uses the state from stream connector <sc>, and server state <state>. The |
| 2605 | * caller is responsible for clearing the local trash buffer if needed. Returns |
| 2606 | * non-zero if it emits anything, zero otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2607 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2608 | static int stats_dump_sv_stats(struct stconn *sc, struct proxy *px, struct server *sv) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2609 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2610 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2611 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2612 | struct stats_module *mod; |
| 2613 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2614 | size_t stats_count = ST_F_TOTAL_FIELDS; |
| 2615 | |
| 2616 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2617 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2618 | if (!stats_fill_sv_stats(px, sv, ctx->flags, stats, |
William Dauchy | d3a9a49 | 2021-01-25 17:29:03 +0100 | [diff] [blame] | 2619 | ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2620 | return 0; |
| 2621 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2622 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2623 | void *counters; |
| 2624 | |
| 2625 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2626 | continue; |
| 2627 | |
| 2628 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_SRV)) { |
| 2629 | stats_count += mod->stats_count; |
| 2630 | continue; |
| 2631 | } |
| 2632 | |
| 2633 | counters = EXTRA_COUNTERS_GET(sv->extra_counters, mod); |
| 2634 | mod->fill_stats(counters, stats + stats_count); |
| 2635 | stats_count += mod->stats_count; |
| 2636 | } |
| 2637 | |
| 2638 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2639 | } |
| 2640 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2641 | /* Helper to compute srv values for a given backend |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2642 | */ |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2643 | static void stats_fill_be_stats_computesrv(struct proxy *px, int *nbup, int *nbsrv, int *totuw) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2644 | { |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2645 | int nbup_tmp, nbsrv_tmp, totuw_tmp; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2646 | const struct server *srv; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2647 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2648 | nbup_tmp = nbsrv_tmp = totuw_tmp = 0; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2649 | for (srv = px->srv; srv; srv = srv->next) { |
| 2650 | if (srv->cur_state != SRV_ST_STOPPED) { |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2651 | nbup_tmp++; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2652 | if (srv_currently_usable(srv) && |
| 2653 | (!px->srv_act ^ !(srv->flags & SRV_F_BACKUP))) |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2654 | totuw_tmp += srv->uweight; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2655 | } |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2656 | nbsrv_tmp++; |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2657 | } |
| 2658 | |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2659 | HA_RWLOCK_RDLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2660 | if (!px->srv_act && px->lbprm.fbck) |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2661 | totuw_tmp = px->lbprm.fbck->uweight; |
Willy Tarreau | bd71510 | 2020-10-23 22:44:30 +0200 | [diff] [blame] | 2662 | HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &px->lbprm.lock); |
| 2663 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2664 | /* use tmp variable then assign result to make gcc happy */ |
| 2665 | *nbup = nbup_tmp; |
| 2666 | *nbsrv = nbsrv_tmp; |
| 2667 | *totuw = totuw_tmp; |
| 2668 | } |
Willy Tarreau | 2fbe694 | 2020-10-23 18:02:54 +0200 | [diff] [blame] | 2669 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2670 | /* Fill <stats> with the backend statistics. <stats> is preallocated array of |
| 2671 | * length <len>. If <selected_field> is != NULL, only fill this one. The length |
| 2672 | * of the array must be at least ST_F_TOTAL_FIELDS. If this length is less than |
| 2673 | * this value, or if the selected field is not implemented for backends, the |
| 2674 | * function returns 0, otherwise, it returns 1. <flags> can take the value |
| 2675 | * STAT_SHLGNDS. |
| 2676 | */ |
| 2677 | int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len, |
| 2678 | enum stat_field *selected_field) |
| 2679 | { |
| 2680 | enum stat_field current_field = (selected_field != NULL ? *selected_field : 0); |
| 2681 | long long be_samples_counter; |
| 2682 | unsigned int be_samples_window = TIME_STATS_SAMPLES; |
| 2683 | struct buffer *out = get_trash_chunk(); |
| 2684 | int nbup, nbsrv, totuw; |
| 2685 | char *fld; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2686 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2687 | if (len < ST_F_TOTAL_FIELDS) |
| 2688 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2689 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2690 | nbup = nbsrv = totuw = 0; |
| 2691 | /* some srv values compute for later if we either select all fields or |
| 2692 | * need them for one of the mentioned ones */ |
| 2693 | if (selected_field == NULL || *selected_field == ST_F_STATUS || |
| 2694 | *selected_field == ST_F_UWEIGHT) |
| 2695 | stats_fill_be_stats_computesrv(px, &nbup, &nbsrv, &totuw); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2696 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2697 | /* same here but specific to time fields */ |
| 2698 | if (selected_field == NULL || *selected_field == ST_F_QTIME || |
| 2699 | *selected_field == ST_F_CTIME || *selected_field == ST_F_RTIME || |
| 2700 | *selected_field == ST_F_TTIME) { |
| 2701 | be_samples_counter = (px->mode == PR_MODE_HTTP) ? px->be_counters.p.http.cum_req : px->be_counters.cum_lbconn; |
| 2702 | if (be_samples_counter < TIME_STATS_SAMPLES && be_samples_counter > 0) |
| 2703 | be_samples_window = be_samples_counter; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2704 | } |
| 2705 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2706 | for (; current_field < ST_F_TOTAL_FIELDS; current_field++) { |
| 2707 | struct field metric = { 0 }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2708 | |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2709 | switch (current_field) { |
| 2710 | case ST_F_PXNAME: |
| 2711 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 2712 | break; |
| 2713 | case ST_F_SVNAME: |
| 2714 | metric = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND"); |
| 2715 | break; |
| 2716 | case ST_F_MODE: |
| 2717 | metric = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 2718 | break; |
| 2719 | case ST_F_QCUR: |
Willy Tarreau | 7f3c1df | 2021-06-18 09:22:21 +0200 | [diff] [blame] | 2720 | metric = mkf_u32(0, px->queue.length); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2721 | break; |
| 2722 | case ST_F_QMAX: |
| 2723 | metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 2724 | break; |
| 2725 | case ST_F_SCUR: |
| 2726 | metric = mkf_u32(0, px->beconn); |
| 2727 | break; |
| 2728 | case ST_F_SMAX: |
| 2729 | metric = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 2730 | break; |
| 2731 | case ST_F_SLIM: |
| 2732 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 2733 | break; |
| 2734 | case ST_F_STOT: |
| 2735 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 2736 | break; |
| 2737 | case ST_F_BIN: |
| 2738 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 2739 | break; |
| 2740 | case ST_F_BOUT: |
| 2741 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 2742 | break; |
| 2743 | case ST_F_DREQ: |
| 2744 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 2745 | break; |
| 2746 | case ST_F_DRESP: |
| 2747 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 2748 | break; |
| 2749 | case ST_F_ECON: |
| 2750 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 2751 | break; |
| 2752 | case ST_F_ERESP: |
| 2753 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 2754 | break; |
| 2755 | case ST_F_WRETR: |
| 2756 | metric = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 2757 | break; |
| 2758 | case ST_F_WREDIS: |
| 2759 | metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 2760 | break; |
| 2761 | case ST_F_WREW: |
| 2762 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites); |
| 2763 | break; |
| 2764 | case ST_F_EINT: |
| 2765 | metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors); |
| 2766 | break; |
| 2767 | case ST_F_CONNECT: |
| 2768 | metric = mkf_u64(FN_COUNTER, px->be_counters.connect); |
| 2769 | break; |
| 2770 | case ST_F_REUSE: |
| 2771 | metric = mkf_u64(FN_COUNTER, px->be_counters.reuse); |
| 2772 | break; |
| 2773 | case ST_F_STATUS: |
| 2774 | fld = chunk_newstr(out); |
| 2775 | chunk_appendf(out, "%s", (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 2776 | if (flags & (STAT_HIDE_MAINT|STAT_HIDE_DOWN)) |
| 2777 | chunk_appendf(out, " (%d/%d)", nbup, nbsrv); |
| 2778 | metric = mkf_str(FO_STATUS, fld); |
| 2779 | break; |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 2780 | case ST_F_AGG_SRV_CHECK_STATUS: // DEPRECATED |
| 2781 | case ST_F_AGG_SRV_STATUS: |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 2782 | metric = mkf_u32(FN_GAUGE, 0); |
| 2783 | break; |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame] | 2784 | case ST_F_AGG_CHECK_STATUS: |
| 2785 | metric = mkf_u32(FN_GAUGE, 0); |
| 2786 | break; |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2787 | case ST_F_WEIGHT: |
| 2788 | metric = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 2789 | break; |
| 2790 | case ST_F_UWEIGHT: |
| 2791 | metric = mkf_u32(FN_AVG, totuw); |
| 2792 | break; |
| 2793 | case ST_F_ACT: |
| 2794 | metric = mkf_u32(0, px->srv_act); |
| 2795 | break; |
| 2796 | case ST_F_BCK: |
| 2797 | metric = mkf_u32(0, px->srv_bck); |
| 2798 | break; |
| 2799 | case ST_F_CHKDOWN: |
| 2800 | metric = mkf_u64(FN_COUNTER, px->down_trans); |
| 2801 | break; |
| 2802 | case ST_F_LASTCHG: |
| 2803 | metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change); |
| 2804 | break; |
| 2805 | case ST_F_DOWNTIME: |
| 2806 | if (px->srv) |
| 2807 | metric = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 2808 | break; |
| 2809 | case ST_F_PID: |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 2810 | metric = mkf_u32(FO_KEY, 1); |
William Dauchy | da3b466 | 2021-01-25 17:29:01 +0100 | [diff] [blame] | 2811 | break; |
| 2812 | case ST_F_IID: |
| 2813 | metric = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 2814 | break; |
| 2815 | case ST_F_SID: |
| 2816 | metric = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 2817 | break; |
| 2818 | case ST_F_LBTOT: |
| 2819 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 2820 | break; |
| 2821 | case ST_F_TYPE: |
| 2822 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 2823 | break; |
| 2824 | case ST_F_RATE: |
| 2825 | metric = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 2826 | break; |
| 2827 | case ST_F_RATE_MAX: |
| 2828 | metric = mkf_u32(0, px->be_counters.sps_max); |
| 2829 | break; |
| 2830 | case ST_F_COOKIE: |
| 2831 | if (flags & STAT_SHLGNDS && px->cookie_name) |
| 2832 | metric = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name); |
| 2833 | break; |
| 2834 | case ST_F_ALGO: |
| 2835 | if (flags & STAT_SHLGNDS) |
| 2836 | metric = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 2837 | break; |
| 2838 | case ST_F_REQ_TOT: |
| 2839 | if (px->mode == PR_MODE_HTTP) |
| 2840 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 2841 | break; |
| 2842 | case ST_F_HRSP_1XX: |
| 2843 | if (px->mode == PR_MODE_HTTP) |
| 2844 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 2845 | break; |
| 2846 | case ST_F_HRSP_2XX: |
| 2847 | if (px->mode == PR_MODE_HTTP) |
| 2848 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 2849 | break; |
| 2850 | case ST_F_HRSP_3XX: |
| 2851 | if (px->mode == PR_MODE_HTTP) |
| 2852 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 2853 | break; |
| 2854 | case ST_F_HRSP_4XX: |
| 2855 | if (px->mode == PR_MODE_HTTP) |
| 2856 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 2857 | break; |
| 2858 | case ST_F_HRSP_5XX: |
| 2859 | if (px->mode == PR_MODE_HTTP) |
| 2860 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 2861 | break; |
| 2862 | case ST_F_HRSP_OTHER: |
| 2863 | if (px->mode == PR_MODE_HTTP) |
| 2864 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
| 2865 | break; |
| 2866 | case ST_F_CACHE_LOOKUPS: |
| 2867 | if (px->mode == PR_MODE_HTTP) |
| 2868 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups); |
| 2869 | break; |
| 2870 | case ST_F_CACHE_HITS: |
| 2871 | if (px->mode == PR_MODE_HTTP) |
| 2872 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits); |
| 2873 | break; |
| 2874 | case ST_F_CLI_ABRT: |
| 2875 | metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 2876 | break; |
| 2877 | case ST_F_SRV_ABRT: |
| 2878 | metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 2879 | break; |
| 2880 | case ST_F_COMP_IN: |
| 2881 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 2882 | break; |
| 2883 | case ST_F_COMP_OUT: |
| 2884 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 2885 | break; |
| 2886 | case ST_F_COMP_BYP: |
| 2887 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 2888 | break; |
| 2889 | case ST_F_COMP_RSP: |
| 2890 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 2891 | break; |
| 2892 | case ST_F_LASTSESS: |
| 2893 | metric = mkf_s32(FN_AGE, be_lastsession(px)); |
| 2894 | break; |
| 2895 | case ST_F_QTIME: |
| 2896 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, be_samples_window)); |
| 2897 | break; |
| 2898 | case ST_F_CTIME: |
| 2899 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, be_samples_window)); |
| 2900 | break; |
| 2901 | case ST_F_RTIME: |
| 2902 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, be_samples_window)); |
| 2903 | break; |
| 2904 | case ST_F_TTIME: |
| 2905 | metric = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, be_samples_window)); |
| 2906 | break; |
| 2907 | case ST_F_QT_MAX: |
| 2908 | metric = mkf_u32(FN_MAX, px->be_counters.qtime_max); |
| 2909 | break; |
| 2910 | case ST_F_CT_MAX: |
| 2911 | metric = mkf_u32(FN_MAX, px->be_counters.ctime_max); |
| 2912 | break; |
| 2913 | case ST_F_RT_MAX: |
| 2914 | metric = mkf_u32(FN_MAX, px->be_counters.dtime_max); |
| 2915 | break; |
| 2916 | case ST_F_TT_MAX: |
| 2917 | metric = mkf_u32(FN_MAX, px->be_counters.ttime_max); |
| 2918 | break; |
| 2919 | default: |
| 2920 | /* not used for backends. If a specific metric |
| 2921 | * is requested, return an error. Otherwise continue. |
| 2922 | */ |
| 2923 | if (selected_field != NULL) |
| 2924 | return 0; |
| 2925 | continue; |
| 2926 | } |
| 2927 | stats[current_field] = metric; |
| 2928 | if (selected_field != NULL) |
| 2929 | break; |
| 2930 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2931 | return 1; |
| 2932 | } |
| 2933 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2934 | /* Dumps a line for backend <px> to the local trash buffer for and uses the |
| 2935 | * state from stream interface <si>. The caller is responsible for clearing the |
| 2936 | * local trash buffer if needed. Returns non-zero if it emits anything, zero |
| 2937 | * otherwise. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2938 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2939 | static int stats_dump_be_stats(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2940 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2941 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2942 | struct show_stat_ctx *ctx = appctx->svcctx; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2943 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 2944 | struct stats_module *mod; |
| 2945 | size_t stats_count = ST_F_TOTAL_FIELDS; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2946 | |
| 2947 | if (!(px->cap & PR_CAP_BE)) |
| 2948 | return 0; |
| 2949 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2950 | if ((ctx->flags & STAT_BOUND) && !(ctx->type & (1 << STATS_TYPE_BE))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2951 | return 0; |
| 2952 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2953 | memset(stats, 0, sizeof(struct field) * stat_count[STATS_DOMAIN_PROXY]); |
| 2954 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2955 | if (!stats_fill_be_stats(px, ctx->flags, stats, ST_F_TOTAL_FIELDS, NULL)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2956 | return 0; |
| 2957 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 2958 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 2959 | struct extra_counters *counters; |
| 2960 | |
| 2961 | if (stats_get_domain(mod->domain_flags) != STATS_DOMAIN_PROXY) |
| 2962 | continue; |
| 2963 | |
| 2964 | if (!(stats_px_get_cap(mod->domain_flags) & STATS_PX_CAP_BE)) { |
| 2965 | stats_count += mod->stats_count; |
| 2966 | continue; |
| 2967 | } |
| 2968 | |
| 2969 | counters = EXTRA_COUNTERS_GET(px->extra_counters_be, mod); |
| 2970 | mod->fill_stats(counters, stats + stats_count); |
| 2971 | stats_count += mod->stats_count; |
| 2972 | } |
| 2973 | |
| 2974 | return stats_dump_one_line(stats, stats_count, appctx); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2975 | } |
| 2976 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 2977 | /* Dumps the HTML table header for proxy <px> to the local trash buffer for and |
| 2978 | * uses the state from stream connector <sc> and per-uri parameters <uri>. The |
| 2979 | * caller is responsible for clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2980 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2981 | static void stats_dump_html_px_hdr(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2982 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2983 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2984 | struct show_stat_ctx *ctx = appctx->svcctx; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2985 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 2986 | struct stats_module *mod; |
| 2987 | int stats_module_len = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2988 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2989 | if (px->cap & PR_CAP_BE && px->srv && (ctx->flags & STAT_ADMIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2990 | /* A form to enable/disable this proxy servers */ |
| 2991 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2992 | /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2993 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2994 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 2995 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2996 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2997 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 2998 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 2999 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3000 | } |
| 3001 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3002 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3003 | "<form method=\"post\">"); |
| 3004 | } |
| 3005 | |
| 3006 | /* print a new table */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3007 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3008 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3009 | "<tr class=\"titre\">" |
| 3010 | "<th class=\"pxname\" width=\"10%%\">"); |
| 3011 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3012 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3013 | "<a name=\"%s\"></a>%s" |
| 3014 | "<a class=px href=\"#%s\">%s</a>", |
| 3015 | px->id, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3016 | (ctx->flags & STAT_SHLGNDS) ? "<u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3017 | px->id, px->id); |
| 3018 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3019 | if (ctx->flags & STAT_SHLGNDS) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3020 | /* cap, mode, id */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3021 | chunk_appendf(&trash_chunk, "<div class=tips>cap: %s, mode: %s, id: %d", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3022 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 3023 | px->uuid); |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3024 | chunk_appendf(&trash_chunk, "</div>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3025 | } |
| 3026 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3027 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3028 | "%s</th>" |
| 3029 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 3030 | "</tr>\n" |
| 3031 | "</table>\n" |
| 3032 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 3033 | "<tr class=\"titre\">", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3034 | (ctx->flags & STAT_SHLGNDS) ? "</u>":"", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3035 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 3036 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3037 | if (ctx->flags & STAT_ADMIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3038 | /* Column heading for Enable or Disable server */ |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 3039 | if ((px->cap & PR_CAP_BE) && px->srv) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3040 | chunk_appendf(&trash_chunk, |
Christopher Faulet | bc271ec | 2019-12-02 11:29:04 +0100 | [diff] [blame] | 3041 | "<th rowspan=2 width=1><input type=\"checkbox\" " |
| 3042 | "onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) " |
| 3043 | "document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>", |
| 3044 | px->id, |
| 3045 | px->id); |
| 3046 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3047 | chunk_appendf(&trash_chunk, "<th rowspan=2></th>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3048 | } |
| 3049 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3050 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3051 | "<th rowspan=2></th>" |
| 3052 | "<th colspan=3>Queue</th>" |
| 3053 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
| 3054 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 3055 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3056 | "<th colspan=9>Server</th>"); |
| 3057 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3058 | if (ctx->flags & STAT_SHMODULES) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3059 | // calculate the count of module for colspan attribute |
| 3060 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 3061 | ++stats_module_len; |
| 3062 | } |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3063 | chunk_appendf(&trash_chunk, "<th colspan=%d>Extra modules</th>", |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3064 | stats_module_len); |
| 3065 | } |
| 3066 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3067 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3068 | "</tr>\n" |
| 3069 | "<tr class=\"titre\">" |
| 3070 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 3071 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 3072 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>" |
| 3073 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 3074 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 3075 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 3076 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3077 | "<th>Thrtle</th>\n"); |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 3078 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3079 | if (ctx->flags & STAT_SHMODULES) { |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3080 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3081 | chunk_appendf(&trash_chunk, "<th>%s</th>", mod->name); |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 3082 | } |
Amaury Denoyelle | e3f576c | 2020-10-05 11:49:44 +0200 | [diff] [blame] | 3083 | } |
| 3084 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3085 | chunk_appendf(&trash_chunk, "</tr>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3088 | /* Dumps the HTML table trailer for proxy <px> to the local trash buffer for and |
| 3089 | * uses the state from stream connector <sc>. The caller is responsible for |
| 3090 | * clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3091 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3092 | static void stats_dump_html_px_end(struct stconn *sc, struct proxy *px) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3093 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3094 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3095 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | 693b23b | 2022-02-28 09:09:05 +0100 | [diff] [blame] | 3096 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3097 | chunk_appendf(&trash_chunk, "</table>"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3098 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3099 | if ((px->cap & PR_CAP_BE) && px->srv && (ctx->flags & STAT_ADMIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3100 | /* close the form used to enable/disable this proxy servers */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3101 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3102 | "Choose the action to perform on the checked servers : " |
| 3103 | "<select name=action>" |
| 3104 | "<option value=\"\"></option>" |
| 3105 | "<option value=\"ready\">Set state to READY</option>" |
| 3106 | "<option value=\"drain\">Set state to DRAIN</option>" |
| 3107 | "<option value=\"maint\">Set state to MAINT</option>" |
| 3108 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 3109 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 3110 | "<option value=\"hrunn\">Health: force UP</option>" |
| 3111 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 3112 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 3113 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 3114 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 3115 | "<option value=\"arunn\">Agent: force UP</option>" |
| 3116 | "<option value=\"adown\">Agent: force DOWN</option>" |
| 3117 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 3118 | "</select>" |
| 3119 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 3120 | " <input type=\"submit\" value=\"Apply\">" |
| 3121 | "</form>", |
| 3122 | px->uuid); |
| 3123 | } |
| 3124 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3125 | chunk_appendf(&trash_chunk, "<p>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | /* |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 3129 | * Dumps statistics for a proxy. The output is sent to the stream connector's |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3130 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 3131 | * buffer space, or non-zero if everything completed. This function is used |
| 3132 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 3133 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
| 3134 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3135 | int stats_dump_proxy_to_buffer(struct stconn *sc, struct htx *htx, |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3136 | struct proxy *px, struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3137 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3138 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3139 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3140 | struct stream *s = __sc_strm(sc); |
| 3141 | struct channel *rep = sc_ic(sc); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3142 | struct server *sv, *svs; /* server and server-state, server-state=server or server->track */ |
| 3143 | struct listener *l; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3144 | int current_field; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3145 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3146 | chunk_reset(&trash_chunk); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3147 | more: |
| 3148 | current_field = ctx->field; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3149 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3150 | switch (ctx->px_st) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3151 | case STAT_PX_ST_INIT: |
| 3152 | /* we are on a new proxy */ |
| 3153 | if (uri && uri->scope) { |
| 3154 | /* we have a limited scope, we have to check the proxy name */ |
| 3155 | struct stat_scope *scope; |
| 3156 | int len; |
| 3157 | |
| 3158 | len = strlen(px->id); |
| 3159 | scope = uri->scope; |
| 3160 | |
| 3161 | while (scope) { |
| 3162 | /* match exact proxy name */ |
| 3163 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 3164 | break; |
| 3165 | |
| 3166 | /* match '.' which means 'self' proxy */ |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 3167 | if (strcmp(scope->px_id, ".") == 0 && px == s->be) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3168 | break; |
| 3169 | scope = scope->next; |
| 3170 | } |
| 3171 | |
| 3172 | /* proxy name not found : don't dump anything */ |
| 3173 | if (scope == NULL) |
| 3174 | return 1; |
| 3175 | } |
| 3176 | |
| 3177 | /* if the user has requested a limited output and the proxy |
| 3178 | * name does not match, skip it. |
| 3179 | */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3180 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3181 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3182 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3183 | 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] | 3184 | return 1; |
| 3185 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3186 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3187 | if ((ctx->flags & STAT_BOUND) && |
| 3188 | (ctx->iid != -1) && |
| 3189 | (px->uuid != ctx->iid)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3190 | return 1; |
| 3191 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3192 | ctx->px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3193 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3194 | |
| 3195 | case STAT_PX_ST_TH: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3196 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3197 | stats_dump_html_px_hdr(sc, px); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3198 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3199 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3200 | } |
| 3201 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3202 | ctx->px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3203 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3204 | |
| 3205 | case STAT_PX_ST_FE: |
| 3206 | /* print the frontend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3207 | if (stats_dump_fe_stats(sc, px)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3208 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3209 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3210 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3211 | if (ctx->field) |
| 3212 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3213 | } |
| 3214 | |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3215 | current_field = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3216 | ctx->obj2 = px->conf.listeners.n; |
| 3217 | ctx->px_st = STAT_PX_ST_LI; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3218 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3219 | |
| 3220 | case STAT_PX_ST_LI: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 3221 | /* obj2 points to listeners list as initialized above */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3222 | for (; ctx->obj2 != &px->conf.listeners; ctx->obj2 = l->by_fe.n) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3223 | if (htx) { |
| 3224 | if (htx_almost_full(htx)) |
| 3225 | goto full; |
| 3226 | } |
| 3227 | else { |
| 3228 | if (buffer_almost_full(&rep->buf)) |
| 3229 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3230 | } |
| 3231 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3232 | l = LIST_ELEM(ctx->obj2, struct listener *, by_fe); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3233 | if (!l->counters) |
| 3234 | continue; |
| 3235 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3236 | if (ctx->flags & STAT_BOUND) { |
| 3237 | if (!(ctx->type & (1 << STATS_TYPE_SO))) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3238 | break; |
| 3239 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3240 | if (ctx->sid != -1 && l->luid != ctx->sid) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3241 | continue; |
| 3242 | } |
| 3243 | |
| 3244 | /* print the frontend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3245 | if (stats_dump_li_stats(sc, px, l)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3246 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3247 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3248 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3249 | if (ctx->field) |
| 3250 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3251 | } |
Aurelien DARRAGON | 9b07d4f | 2023-02-03 11:43:05 +0100 | [diff] [blame] | 3252 | current_field = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3253 | } |
| 3254 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3255 | ctx->obj2 = px->srv; /* may be NULL */ |
| 3256 | ctx->px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3257 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3258 | |
| 3259 | case STAT_PX_ST_SV: |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3260 | /* obj2 points to servers list as initialized above. |
| 3261 | * |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3262 | * A server may be removed during the stats dumping. |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3263 | * Temporarily increment its refcount to prevent its |
| 3264 | * anticipated cleaning. Call free_server to release it. |
| 3265 | */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3266 | for (; ctx->obj2 != NULL; |
| 3267 | ctx->obj2 = srv_drop(sv)) { |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3268 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3269 | sv = ctx->obj2; |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3270 | srv_take(sv); |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3271 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3272 | if (htx) { |
| 3273 | if (htx_almost_full(htx)) |
| 3274 | goto full; |
| 3275 | } |
| 3276 | else { |
| 3277 | if (buffer_almost_full(&rep->buf)) |
| 3278 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3279 | } |
| 3280 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3281 | if (ctx->flags & STAT_BOUND) { |
| 3282 | if (!(ctx->type & (1 << STATS_TYPE_SV))) { |
Amaury Denoyelle | bc2ebfa | 2021-08-25 15:34:53 +0200 | [diff] [blame] | 3283 | srv_drop(sv); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3284 | break; |
Amaury Denoyelle | 0a8d05d | 2021-08-25 14:39:53 +0200 | [diff] [blame] | 3285 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3286 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3287 | if (ctx->sid != -1 && sv->puid != ctx->sid) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3288 | continue; |
| 3289 | } |
| 3290 | |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 3291 | /* do not report disabled servers */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3292 | if (ctx->flags & STAT_HIDE_MAINT && |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 3293 | sv->cur_admin & SRV_ADMF_MAINT) { |
| 3294 | continue; |
| 3295 | } |
| 3296 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3297 | svs = sv; |
| 3298 | while (svs->track) |
| 3299 | svs = svs->track; |
| 3300 | |
| 3301 | /* do not report servers which are DOWN and not changing state */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3302 | if ((ctx->flags & STAT_HIDE_DOWN) && |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 3303 | ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 3304 | (sv->cur_state == SRV_ST_STOPPED && /* server is down */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3305 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 3306 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 3307 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
| 3308 | continue; |
| 3309 | } |
| 3310 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3311 | if (stats_dump_sv_stats(sc, px, sv)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3312 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3313 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3314 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 28a2361 | 2023-02-02 18:13:30 +0100 | [diff] [blame] | 3315 | if (ctx->field) |
| 3316 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3317 | } |
Aurelien DARRAGON | 28a2361 | 2023-02-02 18:13:30 +0100 | [diff] [blame] | 3318 | current_field = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3319 | } /* for sv */ |
| 3320 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3321 | ctx->px_st = STAT_PX_ST_BE; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3322 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3323 | |
| 3324 | case STAT_PX_ST_BE: |
| 3325 | /* print the backend */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3326 | if (stats_dump_be_stats(sc, px)) { |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3327 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3328 | goto full; |
Aurelien DARRAGON | 90304dc | 2023-02-02 19:01:02 +0100 | [diff] [blame] | 3329 | ctx->flags |= STAT_STARTED; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3330 | if (ctx->field) |
| 3331 | goto more; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3332 | } |
| 3333 | |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3334 | current_field = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3335 | ctx->px_st = STAT_PX_ST_END; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3336 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3337 | |
| 3338 | case STAT_PX_ST_END: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3339 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3340 | stats_dump_html_px_end(sc, px); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3341 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3342 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3343 | } |
| 3344 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3345 | ctx->px_st = STAT_PX_ST_FIN; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3346 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3347 | |
| 3348 | case STAT_PX_ST_FIN: |
| 3349 | return 1; |
| 3350 | |
| 3351 | default: |
| 3352 | /* unknown state, we should put an abort() here ! */ |
| 3353 | return 1; |
| 3354 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3355 | |
| 3356 | full: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3357 | sc_need_room(sc); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3358 | /* restore previous field */ |
| 3359 | ctx->field = current_field; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3360 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3361 | } |
| 3362 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3363 | /* Dumps the HTTP stats head block to the local trash buffer for and uses the |
| 3364 | * per-uri parameters <uri>. The caller is responsible for clearing the local |
| 3365 | * trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3366 | */ |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 3367 | 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] | 3368 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3369 | struct show_stat_ctx *ctx = appctx->svcctx; |
| 3370 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3371 | /* WARNING! This must fit in the first buffer !!! */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3372 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3373 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 3374 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 3375 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
Thierry Fournier | b6b1cde | 2021-09-24 00:03:07 +0200 | [diff] [blame] | 3376 | "<link rel=\"icon\" href=\"data:,\">\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3377 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 3378 | "<style type=\"text/css\"><!--\n" |
| 3379 | "body {" |
| 3380 | " font-family: arial, helvetica, sans-serif;" |
| 3381 | " font-size: 12px;" |
| 3382 | " font-weight: normal;" |
| 3383 | " color: black;" |
| 3384 | " background: white;" |
| 3385 | "}\n" |
| 3386 | "th,td {" |
| 3387 | " font-size: 10px;" |
| 3388 | "}\n" |
| 3389 | "h1 {" |
| 3390 | " font-size: x-large;" |
| 3391 | " margin-bottom: 0.5em;" |
| 3392 | "}\n" |
| 3393 | "h2 {" |
| 3394 | " font-family: helvetica, arial;" |
| 3395 | " font-size: x-large;" |
| 3396 | " font-weight: bold;" |
| 3397 | " font-style: italic;" |
| 3398 | " color: #6020a0;" |
| 3399 | " margin-top: 0em;" |
| 3400 | " margin-bottom: 0em;" |
| 3401 | "}\n" |
| 3402 | "h3 {" |
| 3403 | " font-family: helvetica, arial;" |
| 3404 | " font-size: 16px;" |
| 3405 | " font-weight: bold;" |
| 3406 | " color: #b00040;" |
| 3407 | " background: #e8e8d0;" |
| 3408 | " margin-top: 0em;" |
| 3409 | " margin-bottom: 0em;" |
| 3410 | "}\n" |
| 3411 | "li {" |
| 3412 | " margin-top: 0.25em;" |
| 3413 | " margin-right: 2em;" |
| 3414 | "}\n" |
| 3415 | ".hr {margin-top: 0.25em;" |
| 3416 | " border-color: black;" |
| 3417 | " border-bottom-style: solid;" |
| 3418 | "}\n" |
| 3419 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 3420 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 3421 | ".frontend {background: #e8e8d0;}\n" |
| 3422 | ".socket {background: #d0d0d0;}\n" |
| 3423 | ".backend {background: #e8e8d0;}\n" |
| 3424 | ".active_down {background: #ff9090;}\n" |
| 3425 | ".active_going_up {background: #ffd020;}\n" |
| 3426 | ".active_going_down {background: #ffffa0;}\n" |
| 3427 | ".active_up {background: #c0ffc0;}\n" |
| 3428 | ".active_nolb {background: #20a0ff;}\n" |
| 3429 | ".active_draining {background: #20a0FF;}\n" |
| 3430 | ".active_no_check {background: #e0e0e0;}\n" |
| 3431 | ".backup_down {background: #ff9090;}\n" |
| 3432 | ".backup_going_up {background: #ff80ff;}\n" |
| 3433 | ".backup_going_down {background: #c060ff;}\n" |
| 3434 | ".backup_up {background: #b0d0ff;}\n" |
| 3435 | ".backup_nolb {background: #90b0e0;}\n" |
| 3436 | ".backup_draining {background: #cc9900;}\n" |
| 3437 | ".backup_no_check {background: #e0e0e0;}\n" |
| 3438 | ".maintain {background: #c07820;}\n" |
| 3439 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 3440 | "\n" |
| 3441 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 3442 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 3443 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 3444 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 3445 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 3446 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 3447 | "\n" |
| 3448 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 3449 | "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" |
| 3450 | "table.tbl td.ac { text-align: center;}\n" |
| 3451 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 3452 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 3453 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 3454 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 3455 | "\n" |
| 3456 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 3457 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 3458 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 3459 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 3460 | "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" |
| 3461 | "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" |
| 3462 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Thierry Fournier | b6b1cde | 2021-09-24 00:03:07 +0200 | [diff] [blame] | 3463 | "div.tips {\n" |
| 3464 | " display:block;\n" |
| 3465 | " visibility:hidden;\n" |
| 3466 | " z-index:2147483647;\n" |
| 3467 | " position:absolute;\n" |
| 3468 | " padding:2px 4px 3px;\n" |
| 3469 | " background:#f0f060; color:#000000;\n" |
| 3470 | " border:1px solid #7040c0;\n" |
| 3471 | " white-space:nowrap;\n" |
| 3472 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 3473 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 3474 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 3475 | "}\n" |
| 3476 | "u:hover div.tips {visibility:visible;}\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3477 | "@media (prefers-color-scheme: dark) {\n" |
| 3478 | " body { font-family: arial, helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #e8e6e3; background: #131516;}\n" |
| 3479 | " h1 { color: #a265e0!important; }\n" |
| 3480 | " h2 { color: #a265e0; }\n" |
| 3481 | " h3 { color: #ff5190; background-color: #3e3e1f; }\n" |
| 3482 | " a { color: #3391ff; }\n" |
| 3483 | " input { background-color: #2f3437; }\n" |
| 3484 | " .hr { border-color: #8c8273; }\n" |
| 3485 | " .titre { background-color: #1aa6a6; color: #e8e6e3; }\n" |
| 3486 | " .frontend {background: #2f3437;}\n" |
Marno Krahmer | a690b73 | 2022-03-08 13:45:09 +0100 | [diff] [blame] | 3487 | " .socket {background: #2a2d2f;}\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3488 | " .backend {background: #2f3437;}\n" |
| 3489 | " .active_down {background: #760000;}\n" |
| 3490 | " .active_going_up {background: #b99200;}\n" |
| 3491 | " .active_going_down {background: #6c6c00;}\n" |
| 3492 | " .active_up {background: #165900;}\n" |
| 3493 | " .active_nolb {background: #006ab9;}\n" |
| 3494 | " .active_draining {background: #006ab9;}\n" |
| 3495 | " .active_no_check {background: #2a2d2f;}\n" |
| 3496 | " .backup_down {background: #760000;}\n" |
| 3497 | " .backup_going_up {background: #7f007f;}\n" |
| 3498 | " .backup_going_down {background: #580092;}\n" |
| 3499 | " .backup_up {background: #2e3234;}\n" |
| 3500 | " .backup_nolb {background: #1e3c6a;}\n" |
| 3501 | " .backup_draining {background: #a37a00;}\n" |
| 3502 | " .backup_no_check {background: #2a2d2f;}\n" |
| 3503 | " .maintain {background: #9a601a;}\n" |
| 3504 | " a.px:link {color: #d8d83b; text-decoration: none;}\n" |
| 3505 | " a.px:visited {color: #d8d83b; text-decoration: none;}\n" |
| 3506 | " a.px:hover {color: #ffffff; text-decoration: none;}\n" |
| 3507 | " a.lfsb:link {color: #e8e6e3; text-decoration: none;}\n" |
| 3508 | " a.lfsb:visited {color: #e8e6e3; text-decoration: none;}\n" |
| 3509 | " a.lfsb:hover {color: #b5afa6; text-decoration: none;}\n" |
| 3510 | " table.tbl th.empty { background-color: #181a1b; }\n" |
Willy Tarreau | 00147f7 | 2022-04-11 07:59:27 +0200 | [diff] [blame] | 3511 | " table.tbl th.desc { background: #181a1b; }\n" |
Thierry Fournier | e9ed63e | 2021-09-23 23:59:49 +0200 | [diff] [blame] | 3512 | " table.tbl th.pxname { background-color: #8d0033; color: #ffff46; }\n" |
| 3513 | " table.tbl th { border-color: #808080; }\n" |
| 3514 | " table.tbl td { border-color: #808080; }\n" |
| 3515 | " u {text-decoration:none; border-bottom: 1px dotted #e8e6e3;}\n" |
| 3516 | " div.tips {\n" |
| 3517 | " background:#8e8e0d;\n" |
| 3518 | " color:#e8e6e3;\n" |
| 3519 | " border-color: #4e2c86;\n" |
| 3520 | " -moz-box-shadow: #60686c 2px 2px 3px;\n" |
| 3521 | " -webkit-box-shadow: #60686c 2px 2px 3px;\n" |
| 3522 | " box-shadow: #60686c 2px 2px 3px;\n" |
| 3523 | " }\n" |
| 3524 | "}\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3525 | "-->\n" |
| 3526 | "</style></head>\n", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3527 | (ctx->flags & STAT_SHNODE) ? " on " : "", |
| 3528 | (ctx->flags & STAT_SHNODE) ? (uri && uri->node ? uri->node : global.node) : "" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3529 | ); |
| 3530 | } |
| 3531 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3532 | /* Dumps the HTML stats information block to the local trash buffer for and uses |
| 3533 | * the state from stream connector <sc> and per-uri parameters <uri>. The caller |
| 3534 | * is responsible for clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3535 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3536 | 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] | 3537 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3538 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3539 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | b685ad0 | 2023-02-10 16:53:35 +0100 | [diff] [blame] | 3540 | unsigned int up = (now.tv_sec - start_time.tv_sec); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3541 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3542 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 3543 | unsigned long long bps; |
| 3544 | int thr; |
| 3545 | |
| 3546 | for (bps = thr = 0; thr < global.nbthread; thr++) |
| 3547 | bps += 32ULL * read_freq_ctr(&ha_thread_ctx[thr].out_32bps); |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 3548 | |
| 3549 | /* Turn the bytes per second to bits per second and take care of the |
| 3550 | * usual ethernet overhead in order to help figure how far we are from |
| 3551 | * interface saturation since it's the only case which usually matters. |
| 3552 | * For this we count the total size of an Ethernet frame on the wire |
| 3553 | * including preamble and IFG (1538) for the largest TCP segment it |
| 3554 | * transports (1448 with TCP timestamps). This is not valid for smaller |
| 3555 | * packets (under-estimated), but it gives a reasonably accurate |
| 3556 | * estimation of how far we are from uplink saturation. |
| 3557 | */ |
| 3558 | bps = bps * 8 * 1538 / 1448; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3559 | |
| 3560 | /* WARNING! this has to fit the first packet too. |
| 3561 | * We are around 3.5 kB, add adding entries will |
| 3562 | * become tricky if we want to support 4kB buffers ! |
| 3563 | */ |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3564 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3565 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 3566 | PRODUCT_NAME "%s</a></h1>\n" |
| 3567 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 3568 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 3569 | "<h3>> General process information</h3>\n" |
| 3570 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 3571 | "<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] | 3572 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 3573 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 3574 | "<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] | 3575 | "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] | 3576 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 3577 | "</td><td align=\"center\" nowrap>\n" |
| 3578 | "<table class=\"lgd\"><tr>\n" |
| 3579 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 3580 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
| 3581 | "</tr><tr>\n" |
| 3582 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 3583 | "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 3584 | "</tr><tr>\n" |
| 3585 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 3586 | "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 3587 | "</tr><tr>\n" |
| 3588 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 3589 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
| 3590 | "</tr><tr>\n" |
| 3591 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
| 3592 | "</tr><tr>\n" |
| 3593 | "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance </td>" |
| 3594 | "</tr></table>\n" |
| 3595 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
| 3596 | "</td>" |
| 3597 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3598 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 3599 | "", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3600 | (ctx->flags & STAT_HIDEVER) ? "" : (stats_version_string), |
| 3601 | pid, (ctx->flags & STAT_SHNODE) ? " on " : "", |
| 3602 | (ctx->flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 3603 | (ctx->flags & STAT_SHDESC) ? ": " : "", |
| 3604 | (ctx->flags & STAT_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 3605 | pid, 1, 1, global.nbthread, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3606 | up / 86400, (up % 86400) / 3600, |
| 3607 | (up % 3600) / 60, (up % 60), |
| 3608 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 3609 | global.rlimit_memmax ? " MB" : "", |
| 3610 | global.rlimit_nofile, |
| 3611 | global.maxsock, global.maxconn, global.maxpipes, |
| 3612 | 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] | 3613 | bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0), |
| 3614 | bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k', |
Willy Tarreau | f9d5e10 | 2021-10-08 10:43:59 +0200 | [diff] [blame] | 3615 | total_run_queues(), total_allocated_tasks(), clock_report_idle() |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3616 | ); |
| 3617 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3618 | /* scope_txt = search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3619 | memcpy(scope_txt, scope_ptr, ctx->scope_len); |
| 3620 | scope_txt[ctx->scope_len] = '\0'; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3621 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3622 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3623 | "<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] | 3624 | (ctx->scope_len > 0) ? scope_txt : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3625 | STAT_SCOPE_TXT_MAXLEN); |
| 3626 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3627 | /* 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] | 3628 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3629 | if (ctx->scope_len) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3630 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3631 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 3632 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3633 | } |
| 3634 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3635 | if (ctx->flags & STAT_HIDE_DOWN) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3636 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3637 | "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n", |
| 3638 | uri->uri_prefix, |
| 3639 | "", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3640 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3641 | scope_txt); |
| 3642 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3643 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3644 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 3645 | uri->uri_prefix, |
| 3646 | ";up", |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3647 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3648 | scope_txt); |
| 3649 | |
| 3650 | if (uri->refresh > 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3651 | if (ctx->flags & STAT_NO_REFRESH) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3652 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3653 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
| 3654 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3655 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3656 | "", |
| 3657 | scope_txt); |
| 3658 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3659 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3660 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
| 3661 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3662 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3663 | ";norefresh", |
| 3664 | scope_txt); |
| 3665 | } |
| 3666 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3667 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3668 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
| 3669 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3670 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3671 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3672 | scope_txt); |
| 3673 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3674 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3675 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
| 3676 | uri->uri_prefix, |
| 3677 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3678 | scope_txt); |
| 3679 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3680 | chunk_appendf(&trash_chunk, |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3681 | "<li><a href=\"%s;json%s%s\">JSON export</a> (<a href=\"%s;json-schema\">schema</a>)<br>\n", |
| 3682 | uri->uri_prefix, |
| 3683 | (uri->refresh > 0) ? ";norefresh" : "", |
| 3684 | scope_txt, uri->uri_prefix); |
| 3685 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3686 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3687 | "</ul></td>" |
| 3688 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 3689 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 3690 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 3691 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 3692 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 3693 | "</ul>" |
| 3694 | "</td>" |
| 3695 | "</tr></table>\n" |
| 3696 | "" |
| 3697 | ); |
| 3698 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3699 | if (ctx->st_code) { |
| 3700 | switch (ctx->st_code) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3701 | case STAT_STATUS_DONE: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3702 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3703 | "<p><div class=active_up>" |
| 3704 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3705 | "Action processed successfully." |
| 3706 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3707 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3708 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3709 | scope_txt); |
| 3710 | break; |
| 3711 | case STAT_STATUS_NONE: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3712 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3713 | "<p><div class=active_going_down>" |
| 3714 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3715 | "Nothing has changed." |
| 3716 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3717 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3718 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3719 | scope_txt); |
| 3720 | break; |
| 3721 | case STAT_STATUS_PART: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3722 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3723 | "<p><div class=active_going_down>" |
| 3724 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3725 | "Action partially processed.<br>" |
| 3726 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
| 3727 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3728 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3729 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3730 | scope_txt); |
| 3731 | break; |
| 3732 | case STAT_STATUS_ERRP: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3733 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3734 | "<p><div class=active_down>" |
| 3735 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3736 | "Action not processed because of invalid parameters." |
| 3737 | "<ul>" |
| 3738 | "<li>The action is maybe unknown.</li>" |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 3739 | "<li>Invalid key parameter (empty or too long).</li>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3740 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 3741 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 3742 | "</ul>" |
| 3743 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3744 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3745 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3746 | scope_txt); |
| 3747 | break; |
| 3748 | case STAT_STATUS_EXCD: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3749 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3750 | "<p><div class=active_down>" |
| 3751 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3752 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 3753 | "You should retry with less servers at a time.</b>" |
| 3754 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3755 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3756 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3757 | scope_txt); |
| 3758 | break; |
| 3759 | case STAT_STATUS_DENY: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3760 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3761 | "<p><div class=active_down>" |
| 3762 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3763 | "<b>Action denied.</b>" |
| 3764 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3765 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3766 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3767 | scope_txt); |
| 3768 | break; |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3769 | case STAT_STATUS_IVAL: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3770 | chunk_appendf(&trash_chunk, |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3771 | "<p><div class=active_down>" |
| 3772 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3773 | "<b>Invalid requests (unsupported method or chunked encoded request).</b>" |
| 3774 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3775 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3776 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 3777 | scope_txt); |
| 3778 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3779 | default: |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3780 | chunk_appendf(&trash_chunk, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3781 | "<p><div class=active_no_check>" |
| 3782 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 3783 | "Unexpected result." |
| 3784 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3785 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3786 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3787 | scope_txt); |
| 3788 | } |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3789 | chunk_appendf(&trash_chunk, "<p>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3790 | } |
| 3791 | } |
| 3792 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3793 | /* Dumps the HTML stats trailer block to the local trash buffer. The caller is |
| 3794 | * responsible for clearing the local trash buffer if needed. |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3795 | */ |
| 3796 | static void stats_dump_html_end() |
| 3797 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3798 | chunk_appendf(&trash_chunk, "</body></html>\n"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3799 | } |
| 3800 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3801 | /* Dumps the stats JSON header to the local trash buffer buffer which. The |
| 3802 | * caller is responsible for clearing it if needed. |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3803 | */ |
| 3804 | static void stats_dump_json_header() |
| 3805 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3806 | chunk_strcat(&trash_chunk, "["); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3810 | /* Dumps the JSON stats trailer block to the local trash buffer. The caller is |
| 3811 | * responsible for clearing the local trash buffer if needed. |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3812 | */ |
| 3813 | static void stats_dump_json_end() |
| 3814 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3815 | chunk_strcat(&trash_chunk, "]\n"); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3816 | } |
| 3817 | |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3818 | /* Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as |
| 3819 | * a pointer to the current server/listener. |
| 3820 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3821 | static int stats_dump_proxies(struct stconn *sc, |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3822 | struct htx *htx, |
| 3823 | struct uri_auth *uri) |
| 3824 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3825 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3826 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3827 | struct channel *rep = sc_ic(sc); |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3828 | struct proxy *px; |
| 3829 | |
| 3830 | /* dump proxies */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3831 | while (ctx->obj1) { |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3832 | if (htx) { |
| 3833 | if (htx_almost_full(htx)) |
| 3834 | goto full; |
| 3835 | } |
| 3836 | else { |
| 3837 | if (buffer_almost_full(&rep->buf)) |
| 3838 | goto full; |
| 3839 | } |
| 3840 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3841 | px = ctx->obj1; |
Marno Krahmer | 07954fb | 2021-06-24 16:51:08 +0200 | [diff] [blame] | 3842 | /* Skip the global frontend proxies and non-networked ones. |
William Lallemand | 85a16b2 | 2021-08-03 13:18:11 +0200 | [diff] [blame] | 3843 | * Also skip proxies that were disabled in the configuration |
Marno Krahmer | 07954fb | 2021-06-24 16:51:08 +0200 | [diff] [blame] | 3844 | * This change allows retrieving stats from "old" proxies after a reload. |
| 3845 | */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 3846 | if (!(px->flags & PR_FL_DISABLED) && px->uuid > 0 && |
William Lallemand | e7f7462 | 2021-07-28 17:45:18 +0200 | [diff] [blame] | 3847 | (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] | 3848 | if (stats_dump_proxy_to_buffer(sc, htx, px, uri) == 0) |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3849 | return 0; |
| 3850 | } |
| 3851 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3852 | ctx->obj1 = px->next; |
| 3853 | ctx->px_st = STAT_PX_ST_INIT; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3854 | ctx->field = 0; |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | return 1; |
| 3858 | |
| 3859 | full: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3860 | sc_need_room(sc); |
Amaury Denoyelle | 98b81cb | 2020-10-02 18:32:04 +0200 | [diff] [blame] | 3861 | return 0; |
| 3862 | } |
| 3863 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 3864 | /* This function dumps statistics onto the stream connector's read buffer in |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3865 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
| 3866 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 3867 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 3868 | * and the stream must be closed, or -1 in case of any error. This function is |
| 3869 | * used by both the CLI and the HTTP handlers. |
| 3870 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3871 | 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] | 3872 | struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3873 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3874 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3875 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3876 | struct channel *rep = sc_ic(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3877 | enum stats_domain domain = ctx->domain; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3878 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3879 | chunk_reset(&trash_chunk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3880 | |
Willy Tarreau | 41f8852 | 2022-05-03 18:39:27 +0200 | [diff] [blame] | 3881 | switch (ctx->state) { |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3882 | case STAT_STATE_INIT: |
| 3883 | ctx->state = STAT_STATE_HEAD; /* let's start producing data */ |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3884 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3885 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3886 | case STAT_STATE_HEAD: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3887 | if (ctx->flags & STAT_FMT_HTML) |
Willy Tarreau | 676c29e | 2019-10-09 10:50:01 +0200 | [diff] [blame] | 3888 | stats_dump_html_head(appctx, uri); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3889 | else if (ctx->flags & STAT_JSON_SCHM) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 3890 | stats_dump_json_schema(&trash_chunk); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3891 | else if (ctx->flags & STAT_FMT_JSON) |
Willy Tarreau | 9d7fb63 | 2017-04-11 07:53:04 +0200 | [diff] [blame] | 3892 | stats_dump_json_header(); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3893 | else if (!(ctx->flags & STAT_FMT_TYPED)) |
| 3894 | stats_dump_csv_header(ctx->domain); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3895 | |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3896 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3897 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3898 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3899 | if (ctx->flags & STAT_JSON_SCHM) { |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3900 | ctx->state = STAT_STATE_FIN; |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 3901 | return 1; |
| 3902 | } |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3903 | ctx->state = STAT_STATE_INFO; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3904 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3905 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3906 | case STAT_STATE_INFO: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3907 | if (ctx->flags & STAT_FMT_HTML) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3908 | stats_dump_html_info(sc, uri); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3909 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3910 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3911 | } |
| 3912 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3913 | if (domain == STATS_DOMAIN_PROXY) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3914 | ctx->obj1 = proxies_list; |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3915 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3916 | ctx->px_st = STAT_PX_ST_INIT; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 3917 | ctx->field = 0; |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3918 | ctx->state = STAT_STATE_LIST; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3919 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3920 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3921 | case STAT_STATE_LIST: |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3922 | switch (domain) { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 3923 | case STATS_DOMAIN_RESOLVERS: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3924 | if (!stats_dump_resolvers(sc, stat_l[domain], |
Emeric Brun | d3b4495 | 2021-01-06 16:01:02 +0100 | [diff] [blame] | 3925 | stat_count[domain], |
| 3926 | &stats_module_list[domain])) { |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3927 | return 0; |
| 3928 | } |
| 3929 | break; |
| 3930 | |
| 3931 | case STATS_DOMAIN_PROXY: |
| 3932 | default: |
| 3933 | /* dump proxies */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3934 | if (!stats_dump_proxies(sc, htx, uri)) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 3935 | return 0; |
| 3936 | break; |
| 3937 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3938 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3939 | ctx->state = STAT_STATE_END; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3940 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3941 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3942 | case STAT_STATE_END: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3943 | if (ctx->flags & (STAT_FMT_HTML|STAT_FMT_JSON)) { |
| 3944 | if (ctx->flags & STAT_FMT_HTML) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3945 | stats_dump_html_end(); |
| 3946 | else |
| 3947 | stats_dump_json_end(); |
Aurelien DARRAGON | e5958d0 | 2023-02-02 17:27:27 +0100 | [diff] [blame] | 3948 | if (!stats_putchk(rep, htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3949 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3950 | } |
| 3951 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3952 | ctx->state = STAT_STATE_FIN; |
Willy Tarreau | 9eb93c0 | 2022-11-14 07:12:05 +0100 | [diff] [blame] | 3953 | __fallthrough; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3954 | |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3955 | case STAT_STATE_FIN: |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3956 | return 1; |
| 3957 | |
| 3958 | default: |
| 3959 | /* unknown state ! */ |
Willy Tarreau | 6ef1648 | 2022-05-06 18:07:53 +0200 | [diff] [blame] | 3960 | ctx->state = STAT_STATE_FIN; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3961 | return -1; |
| 3962 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3963 | |
| 3964 | full: |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3965 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3966 | return 0; |
| 3967 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | /* We reached the stats page through a POST request. The appctx is |
| 3971 | * expected to have already been allocated by the caller. |
| 3972 | * Parse the posted data and enable/disable servers if necessary. |
| 3973 | * Returns 1 if request was parsed or zero if it needs more data. |
| 3974 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3975 | static int stats_process_http_post(struct stconn *sc) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3976 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 3977 | struct stream *s = __sc_strm(sc); |
| 3978 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 3979 | struct show_stat_ctx *ctx = appctx->svcctx; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3980 | |
| 3981 | struct proxy *px = NULL; |
| 3982 | struct server *sv = NULL; |
| 3983 | |
| 3984 | char key[LINESIZE]; |
| 3985 | int action = ST_ADM_ACTION_NONE; |
| 3986 | int reprocess = 0; |
| 3987 | |
| 3988 | int total_servers = 0; |
| 3989 | int altered_servers = 0; |
| 3990 | |
| 3991 | char *first_param, *cur_param, *next_param, *end_params; |
| 3992 | char *st_cur_param = NULL; |
| 3993 | char *st_next_param = NULL; |
| 3994 | |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3995 | struct buffer *temp = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3996 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 3997 | struct htx *htx = htxbuf(&s->req.buf); |
| 3998 | struct htx_blk *blk; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 3999 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4000 | /* we need more data */ |
| 4001 | if (s->txn->req.msg_state < HTTP_MSG_DONE) { |
| 4002 | /* check if we can receive more */ |
| 4003 | if (htx_free_data_space(htx) <= global.tune.maxrewrite) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4004 | ctx->st_code = STAT_STATUS_EXCD; |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4005 | goto out; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4006 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4007 | goto wait; |
| 4008 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4009 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4010 | /* The request was fully received. Copy data */ |
| 4011 | blk = htx_get_head_blk(htx); |
| 4012 | while (blk) { |
| 4013 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4014 | |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 4015 | if (type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4016 | break; |
| 4017 | if (type == HTX_BLK_DATA) { |
| 4018 | struct ist v = htx_get_blk_value(htx, blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4019 | |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4020 | if (!chunk_memcat(temp, v.ptr, v.len)) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4021 | ctx->st_code = STAT_STATUS_EXCD; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4022 | goto out; |
| 4023 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4024 | } |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4025 | blk = htx_get_next_blk(htx, blk); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4026 | } |
| 4027 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4028 | first_param = temp->area; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 4029 | end_params = temp->area + temp->data; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4030 | cur_param = next_param = end_params; |
| 4031 | *end_params = '\0'; |
| 4032 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4033 | ctx->st_code = STAT_STATUS_NONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4034 | |
| 4035 | /* |
| 4036 | * Parse the parameters in reverse order to only store the last value. |
| 4037 | * From the html form, the backend and the action are at the end. |
| 4038 | */ |
| 4039 | while (cur_param > first_param) { |
| 4040 | char *value; |
| 4041 | int poffset, plen; |
| 4042 | |
| 4043 | cur_param--; |
| 4044 | |
| 4045 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 4046 | reprocess_servers: |
| 4047 | /* Parse the key */ |
| 4048 | poffset = (cur_param != first_param ? 1 : 0); |
| 4049 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 4050 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 4051 | strncpy(key, cur_param + poffset, plen); |
| 4052 | key[plen - 1] = '\0'; |
| 4053 | } else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4054 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4055 | goto out; |
| 4056 | } |
| 4057 | |
| 4058 | /* Parse the value */ |
| 4059 | value = key; |
| 4060 | while (*value != '\0' && *value != '=') { |
| 4061 | value++; |
| 4062 | } |
| 4063 | if (*value == '=') { |
| 4064 | /* Ok, a value is found, we can mark the end of the key */ |
| 4065 | *value++ = '\0'; |
| 4066 | } |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 4067 | if (url_decode(key, 1) < 0 || url_decode(value, 1) < 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4068 | break; |
| 4069 | |
| 4070 | /* Now we can check the key to see what to do */ |
| 4071 | if (!px && (strcmp(key, "b") == 0)) { |
| 4072 | if ((px = proxy_be_by_name(value)) == NULL) { |
| 4073 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4074 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4075 | goto out; |
| 4076 | } |
| 4077 | } |
| 4078 | else if (!action && (strcmp(key, "action") == 0)) { |
| 4079 | if (strcmp(value, "ready") == 0) { |
| 4080 | action = ST_ADM_ACTION_READY; |
| 4081 | } |
| 4082 | else if (strcmp(value, "drain") == 0) { |
| 4083 | action = ST_ADM_ACTION_DRAIN; |
| 4084 | } |
| 4085 | else if (strcmp(value, "maint") == 0) { |
| 4086 | action = ST_ADM_ACTION_MAINT; |
| 4087 | } |
| 4088 | else if (strcmp(value, "shutdown") == 0) { |
| 4089 | action = ST_ADM_ACTION_SHUTDOWN; |
| 4090 | } |
| 4091 | else if (strcmp(value, "dhlth") == 0) { |
| 4092 | action = ST_ADM_ACTION_DHLTH; |
| 4093 | } |
| 4094 | else if (strcmp(value, "ehlth") == 0) { |
| 4095 | action = ST_ADM_ACTION_EHLTH; |
| 4096 | } |
| 4097 | else if (strcmp(value, "hrunn") == 0) { |
| 4098 | action = ST_ADM_ACTION_HRUNN; |
| 4099 | } |
| 4100 | else if (strcmp(value, "hnolb") == 0) { |
| 4101 | action = ST_ADM_ACTION_HNOLB; |
| 4102 | } |
| 4103 | else if (strcmp(value, "hdown") == 0) { |
| 4104 | action = ST_ADM_ACTION_HDOWN; |
| 4105 | } |
| 4106 | else if (strcmp(value, "dagent") == 0) { |
| 4107 | action = ST_ADM_ACTION_DAGENT; |
| 4108 | } |
| 4109 | else if (strcmp(value, "eagent") == 0) { |
| 4110 | action = ST_ADM_ACTION_EAGENT; |
| 4111 | } |
| 4112 | else if (strcmp(value, "arunn") == 0) { |
| 4113 | action = ST_ADM_ACTION_ARUNN; |
| 4114 | } |
| 4115 | else if (strcmp(value, "adown") == 0) { |
| 4116 | action = ST_ADM_ACTION_ADOWN; |
| 4117 | } |
| 4118 | /* else these are the old supported methods */ |
| 4119 | else if (strcmp(value, "disable") == 0) { |
| 4120 | action = ST_ADM_ACTION_DISABLE; |
| 4121 | } |
| 4122 | else if (strcmp(value, "enable") == 0) { |
| 4123 | action = ST_ADM_ACTION_ENABLE; |
| 4124 | } |
| 4125 | else if (strcmp(value, "stop") == 0) { |
| 4126 | action = ST_ADM_ACTION_STOP; |
| 4127 | } |
| 4128 | else if (strcmp(value, "start") == 0) { |
| 4129 | action = ST_ADM_ACTION_START; |
| 4130 | } |
| 4131 | else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4132 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4133 | goto out; |
| 4134 | } |
| 4135 | } |
| 4136 | else if (strcmp(key, "s") == 0) { |
| 4137 | if (!(px && action)) { |
| 4138 | /* |
| 4139 | * Indicates that we'll need to reprocess the parameters |
| 4140 | * as soon as backend and action are known |
| 4141 | */ |
| 4142 | if (!reprocess) { |
| 4143 | st_cur_param = cur_param; |
| 4144 | st_next_param = next_param; |
| 4145 | } |
| 4146 | reprocess = 1; |
| 4147 | } |
| 4148 | else if ((sv = findserver(px, value)) != NULL) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4149 | HA_SPIN_LOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4150 | switch (action) { |
| 4151 | case ST_ADM_ACTION_DISABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4152 | if (!(sv->cur_admin & SRV_ADMF_FMAINT)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4153 | altered_servers++; |
| 4154 | total_servers++; |
| 4155 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page"); |
| 4156 | } |
| 4157 | break; |
| 4158 | case ST_ADM_ACTION_ENABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4159 | if (sv->cur_admin & SRV_ADMF_FMAINT) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4160 | altered_servers++; |
| 4161 | total_servers++; |
| 4162 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
| 4163 | } |
| 4164 | break; |
| 4165 | case ST_ADM_ACTION_STOP: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4166 | if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4167 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page"); |
| 4168 | altered_servers++; |
| 4169 | total_servers++; |
| 4170 | } |
| 4171 | break; |
| 4172 | case ST_ADM_ACTION_START: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 4173 | if (sv->cur_admin & SRV_ADMF_FDRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4174 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 4175 | altered_servers++; |
| 4176 | total_servers++; |
| 4177 | } |
| 4178 | break; |
| 4179 | case ST_ADM_ACTION_DHLTH: |
| 4180 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4181 | sv->check.state &= ~CHK_ST_ENABLED; |
| 4182 | altered_servers++; |
| 4183 | total_servers++; |
| 4184 | } |
| 4185 | break; |
| 4186 | case ST_ADM_ACTION_EHLTH: |
| 4187 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 4188 | sv->check.state |= CHK_ST_ENABLED; |
| 4189 | altered_servers++; |
| 4190 | total_servers++; |
| 4191 | } |
| 4192 | break; |
| 4193 | case ST_ADM_ACTION_HRUNN: |
| 4194 | if (!(sv->track)) { |
| 4195 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4196 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4197 | altered_servers++; |
| 4198 | total_servers++; |
| 4199 | } |
| 4200 | break; |
| 4201 | case ST_ADM_ACTION_HNOLB: |
| 4202 | if (!(sv->track)) { |
| 4203 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4204 | srv_set_stopping(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4205 | altered_servers++; |
| 4206 | total_servers++; |
| 4207 | } |
| 4208 | break; |
| 4209 | case ST_ADM_ACTION_HDOWN: |
| 4210 | if (!(sv->track)) { |
| 4211 | sv->check.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4212 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4213 | altered_servers++; |
| 4214 | total_servers++; |
| 4215 | } |
| 4216 | break; |
| 4217 | case ST_ADM_ACTION_DAGENT: |
| 4218 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4219 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 4220 | altered_servers++; |
| 4221 | total_servers++; |
| 4222 | } |
| 4223 | break; |
| 4224 | case ST_ADM_ACTION_EAGENT: |
| 4225 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 4226 | sv->agent.state |= CHK_ST_ENABLED; |
| 4227 | altered_servers++; |
| 4228 | total_servers++; |
| 4229 | } |
| 4230 | break; |
| 4231 | case ST_ADM_ACTION_ARUNN: |
| 4232 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4233 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4234 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4235 | altered_servers++; |
| 4236 | total_servers++; |
| 4237 | } |
| 4238 | break; |
| 4239 | case ST_ADM_ACTION_ADOWN: |
| 4240 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 4241 | sv->agent.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 4242 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4243 | altered_servers++; |
| 4244 | total_servers++; |
| 4245 | } |
| 4246 | break; |
| 4247 | case ST_ADM_ACTION_READY: |
| 4248 | srv_adm_set_ready(sv); |
| 4249 | altered_servers++; |
| 4250 | total_servers++; |
| 4251 | break; |
| 4252 | case ST_ADM_ACTION_DRAIN: |
| 4253 | srv_adm_set_drain(sv); |
| 4254 | altered_servers++; |
| 4255 | total_servers++; |
| 4256 | break; |
| 4257 | case ST_ADM_ACTION_MAINT: |
| 4258 | srv_adm_set_maint(sv); |
| 4259 | altered_servers++; |
| 4260 | total_servers++; |
| 4261 | break; |
| 4262 | case ST_ADM_ACTION_SHUTDOWN: |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 4263 | if (!(px->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) { |
Willy Tarreau | af7ea81 | 2019-11-14 16:42:04 +0100 | [diff] [blame] | 4264 | srv_shutdown_streams(sv, SF_ERR_KILLED); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4265 | altered_servers++; |
| 4266 | total_servers++; |
| 4267 | } |
| 4268 | break; |
| 4269 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 4270 | HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4271 | } else { |
| 4272 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 4273 | total_servers++; |
| 4274 | } |
| 4275 | } |
| 4276 | if (reprocess && px && action) { |
| 4277 | /* Now, we know the backend and the action chosen by the user. |
| 4278 | * We can safely restart from the first server parameter |
| 4279 | * to reprocess them |
| 4280 | */ |
| 4281 | cur_param = st_cur_param; |
| 4282 | next_param = st_next_param; |
| 4283 | reprocess = 0; |
| 4284 | goto reprocess_servers; |
| 4285 | } |
| 4286 | |
| 4287 | next_param = cur_param; |
| 4288 | } |
| 4289 | } |
| 4290 | |
| 4291 | if (total_servers == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4292 | ctx->st_code = STAT_STATUS_NONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4293 | } |
| 4294 | else if (altered_servers == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4295 | ctx->st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4296 | } |
| 4297 | else if (altered_servers == total_servers) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4298 | ctx->st_code = STAT_STATUS_DONE; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4299 | } |
| 4300 | else { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4301 | ctx->st_code = STAT_STATUS_PART; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4302 | } |
| 4303 | out: |
| 4304 | return 1; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4305 | wait: |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4306 | ctx->st_code = STAT_STATUS_NONE; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 4307 | return 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4311 | static int stats_send_http_headers(struct stconn *sc, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4312 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4313 | struct stream *s = __sc_strm(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4314 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4315 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4316 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4317 | struct htx_sl *sl; |
| 4318 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4319 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4320 | 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); |
| 4321 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 4322 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4323 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4324 | sl->info.res.status = 200; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4325 | |
Christopher Faulet | b829f4c | 2019-03-29 16:13:55 +0100 | [diff] [blame] | 4326 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache"))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4327 | goto full; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4328 | if (ctx->flags & STAT_FMT_HTML) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4329 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/html"))) |
| 4330 | goto full; |
| 4331 | } |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4332 | else if (ctx->flags & (STAT_FMT_JSON|STAT_JSON_SCHM)) { |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 4333 | if (!htx_add_header(htx, ist("Content-Type"), ist("application/json"))) |
| 4334 | goto full; |
| 4335 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4336 | else { |
| 4337 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain"))) |
| 4338 | goto full; |
| 4339 | } |
| 4340 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4341 | if (uri->refresh > 0 && !(ctx->flags & STAT_NO_REFRESH)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4342 | const char *refresh = U2A(uri->refresh); |
Tim Duesterhus | dcf753a | 2021-03-04 17:31:47 +0100 | [diff] [blame] | 4343 | if (!htx_add_header(htx, ist("Refresh"), ist(refresh))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4344 | goto full; |
| 4345 | } |
| 4346 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4347 | if (ctx->flags & STAT_CHUNKED) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4348 | if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked"))) |
| 4349 | goto full; |
| 4350 | } |
| 4351 | |
| 4352 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 4353 | goto full; |
| 4354 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 4355 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4356 | return 1; |
| 4357 | |
| 4358 | full: |
| 4359 | htx_reset(htx); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4360 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4361 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4362 | } |
| 4363 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4364 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4365 | static int stats_send_http_redirect(struct stconn *sc, struct htx *htx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4366 | { |
| 4367 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4368 | struct stream *s = __sc_strm(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4369 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4370 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4371 | struct show_stat_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4372 | struct htx_sl *sl; |
| 4373 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4374 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4375 | /* 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] | 4376 | scope_txt[0] = 0; |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4377 | if (ctx->scope_len) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4378 | const char *scope_ptr = stats_scope_ptr(appctx, sc); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 4379 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4380 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4381 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len); |
| 4382 | scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4383 | } |
| 4384 | |
| 4385 | /* We don't want to land on the posted stats page because a refresh will |
| 4386 | * repost the data. We don't want this to happen on accident so we redirect |
| 4387 | * the browse to the stats page with a GET. |
| 4388 | */ |
| 4389 | chunk_printf(&trash, "%s;st=%s%s%s%s", |
| 4390 | uri->uri_prefix, |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4391 | ((ctx->st_code > STAT_STATUS_INIT) && |
| 4392 | (ctx->st_code < STAT_STATUS_SIZE) && |
| 4393 | stat_status_codes[ctx->st_code]) ? |
| 4394 | stat_status_codes[ctx->st_code] : |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4395 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4396 | (ctx->flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4397 | (ctx->flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4398 | scope_txt); |
| 4399 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4400 | flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK); |
| 4401 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other")); |
| 4402 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4403 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 4404 | sl->info.res.status = 303; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4405 | |
| 4406 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4407 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) || |
| 4408 | !htx_add_header(htx, ist("Content-Length"), ist("0")) || |
| 4409 | !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data))) |
| 4410 | goto full; |
| 4411 | |
| 4412 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 4413 | goto full; |
| 4414 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 4415 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4416 | return 1; |
| 4417 | |
| 4418 | full: |
| 4419 | htx_reset(htx); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4420 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4421 | return 0; |
| 4422 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4423 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 4424 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4425 | /* 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] | 4426 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 4427 | * appctx->st0 contains the operation in progress (dump, done). The handler |
| 4428 | * automatically unregisters itself once transfer is complete. |
| 4429 | */ |
Christopher Faulet | b7f8890 | 2019-07-15 21:56:43 +0200 | [diff] [blame] | 4430 | static void http_stats_io_handler(struct appctx *appctx) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4431 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4432 | struct show_stat_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 4433 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4434 | struct stream *s = __sc_strm(sc); |
| 4435 | struct channel *req = sc_oc(sc); |
| 4436 | struct channel *res = sc_ic(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4437 | struct htx *req_htx, *res_htx; |
| 4438 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4439 | /* only proxy stats are available via http */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4440 | ctx->domain = STATS_DOMAIN_PROXY; |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 4441 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4442 | res_htx = htx_from_buf(&res->buf); |
| 4443 | |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4444 | if (unlikely(sc->state == SC_ST_DIS || sc->state == SC_ST_CLO)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4445 | goto out; |
| 4446 | |
Ilya Shipitsin | 856aabc | 2020-04-16 23:51:34 +0500 | [diff] [blame] | 4447 | /* Check if the input buffer is available. */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4448 | if (!b_size(&res->buf)) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4449 | sc_need_room(sc); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4450 | goto out; |
| 4451 | } |
| 4452 | |
| 4453 | /* check that the output is not closed */ |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4454 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_SHUTR)) |
| 4455 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4456 | |
| 4457 | /* all states are processed in sequence */ |
| 4458 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4459 | if (stats_send_http_headers(sc, res_htx)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4460 | if (s->txn->meth == HTTP_METH_HEAD) |
| 4461 | appctx->st0 = STAT_HTTP_DONE; |
| 4462 | else |
| 4463 | appctx->st0 = STAT_HTTP_DUMP; |
| 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Aurelien DARRAGON | 1465684 | 2023-02-03 08:31:42 +0100 | [diff] [blame] | 4468 | trash_chunk = b_make(trash.area, res->buf.size, 0, 0); |
Aurelien DARRAGON | 5e7ecbe | 2023-02-02 15:03:12 +0100 | [diff] [blame] | 4469 | /* adjust buffer size to take htx overhead into account, |
| 4470 | * make sure to perform this call on an empty buffer |
| 4471 | */ |
| 4472 | trash_chunk.size = buf_room_for_htx_data(&trash_chunk); |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4473 | 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] | 4474 | appctx->st0 = STAT_HTTP_DONE; |
| 4475 | } |
| 4476 | |
| 4477 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4478 | if (stats_process_http_post(sc)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4479 | appctx->st0 = STAT_HTTP_LAST; |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4480 | else if (req->flags & CF_SHUTR) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4481 | appctx->st0 = STAT_HTTP_DONE; |
| 4482 | } |
| 4483 | |
| 4484 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4485 | if (stats_send_http_redirect(sc, res_htx)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4486 | appctx->st0 = STAT_HTTP_DONE; |
| 4487 | } |
| 4488 | |
| 4489 | if (appctx->st0 == STAT_HTTP_DONE) { |
Christopher Faulet | 08b45cb | 2022-04-07 09:25:13 +0200 | [diff] [blame] | 4490 | /* no more data are expected. If the response buffer is empty, |
| 4491 | * be sure to add something (EOT block in this case) to have |
| 4492 | * something to send. It is important to be sure the EOM flags |
| 4493 | * will be handled by the endpoint. |
| 4494 | */ |
| 4495 | if (htx_is_empty(res_htx)) { |
| 4496 | if (!htx_add_endof(res_htx, HTX_BLK_EOT)) { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4497 | sc_need_room(sc); |
Christopher Faulet | 08b45cb | 2022-04-07 09:25:13 +0200 | [diff] [blame] | 4498 | goto out; |
| 4499 | } |
| 4500 | channel_add_input(res, 1); |
| 4501 | } |
Christopher Faulet | d1ac2b9 | 2020-12-02 19:12:22 +0100 | [diff] [blame] | 4502 | res_htx->flags |= HTX_FL_EOM; |
Christopher Faulet | 3fa5d19 | 2022-03-07 15:52:42 +0100 | [diff] [blame] | 4503 | res->flags |= CF_EOI; |
Willy Tarreau | d869e13 | 2022-05-17 18:05:31 +0200 | [diff] [blame] | 4504 | se_fl_set(appctx->sedesc, SE_FL_EOI); |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4505 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4506 | } |
| 4507 | |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4508 | if (appctx->st0 == STAT_HTTP_END) { |
Christopher Faulet | 41a454d | 2023-03-28 12:02:03 +0200 | [diff] [blame] | 4509 | if (!(res->flags & CF_SHUTR)) |
| 4510 | sc_shutr(sc); |
Christopher Faulet | c2c043e | 2023-03-22 09:30:40 +0100 | [diff] [blame] | 4511 | applet_will_consume(appctx); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4512 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 4513 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4514 | out: |
| 4515 | /* we have left the request in the buffer for the case where we |
| 4516 | * process a POST, and this automatically re-enables activity on |
| 4517 | * read. It's better to indicate that we want to stop reading when |
| 4518 | * we're sending, so that we know there's at most one direction |
| 4519 | * deciding to wake the applet up. It saves it from looping when |
| 4520 | * emitting large blocks into small TCP windows. |
| 4521 | */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 4522 | htx_to_buf(res_htx, &res->buf); |
Christopher Faulet | c2c043e | 2023-03-22 09:30:40 +0100 | [diff] [blame] | 4523 | if (appctx->st0 == STAT_HTTP_END) { |
| 4524 | /* eat the whole request */ |
| 4525 | if (co_data(req)) { |
| 4526 | req_htx = htx_from_buf(&req->buf); |
| 4527 | co_htx_skip(req, req_htx, co_data(req)); |
| 4528 | htx_to_buf(req_htx, &req->buf); |
| 4529 | } |
| 4530 | } |
| 4531 | else if (!channel_is_empty(res)) |
Willy Tarreau | 75a8f8e | 2022-05-25 18:12:11 +0200 | [diff] [blame] | 4532 | applet_wont_consume(appctx); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4533 | } |
| 4534 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4535 | /* 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] | 4536 | static int stats_dump_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4537 | const struct field *info, |
| 4538 | struct show_stat_ctx *ctx) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4539 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4540 | int flags = ctx->flags; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4541 | int field; |
| 4542 | |
| 4543 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 4544 | if (!field_format(info, field)) |
| 4545 | continue; |
| 4546 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 4547 | if (!chunk_appendf(out, "%s: ", info_fields[field].name)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4548 | return 0; |
| 4549 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 4550 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 4551 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 4552 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4553 | if (!chunk_strcat(out, "\n")) |
| 4554 | return 0; |
| 4555 | } |
| 4556 | return 1; |
| 4557 | } |
| 4558 | |
| 4559 | /* 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] | 4560 | static int stats_dump_typed_info_fields(struct buffer *out, |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4561 | const struct field *info, |
| 4562 | struct show_stat_ctx *ctx) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4563 | { |
Aurelien DARRAGON | e76a027 | 2022-12-15 12:10:03 +0100 | [diff] [blame] | 4564 | int flags = ctx->flags; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4565 | int field; |
| 4566 | |
| 4567 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 4568 | if (!field_format(info, field)) |
| 4569 | continue; |
| 4570 | |
Willy Tarreau | eaa5537 | 2019-10-09 07:39:11 +0200 | [diff] [blame] | 4571 | 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] | 4572 | return 0; |
| 4573 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 4574 | return 0; |
| 4575 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 4576 | return 0; |
Willy Tarreau | 6b19b14 | 2019-10-09 15:44:21 +0200 | [diff] [blame] | 4577 | if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc)) |
| 4578 | return 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4579 | if (!chunk_strcat(out, "\n")) |
| 4580 | return 0; |
| 4581 | } |
| 4582 | return 1; |
| 4583 | } |
| 4584 | |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 4585 | /* Fill <info> with HAProxy global info. <info> is preallocated array of length |
| 4586 | * <len>. The length of the array must be INF_TOTAL_FIELDS. If this length is |
| 4587 | * less then this value, the function returns 0, otherwise, it returns 1. Some |
| 4588 | * fields' presence or precision may depend on some of the STAT_* flags present |
| 4589 | * in <flags>. |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4590 | */ |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 4591 | int stats_fill_info(struct field *info, int len, uint flags) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4592 | { |
Willy Tarreau | d37e26e | 2021-05-08 07:40:52 +0200 | [diff] [blame] | 4593 | struct timeval up; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4594 | struct buffer *out = get_trash_chunk(); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4595 | uint64_t glob_out_bytes, glob_spl_bytes, glob_out_b32; |
| 4596 | int thr; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4597 | |
| 4598 | #ifdef USE_OPENSSL |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4599 | double ssl_sess_rate = read_freq_ctr_flt(&global.ssl_per_sec); |
| 4600 | double ssl_key_rate = read_freq_ctr_flt(&global.ssl_fe_keys_per_sec); |
| 4601 | double ssl_reuse = 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4602 | |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4603 | if (ssl_key_rate < ssl_sess_rate) |
| 4604 | ssl_reuse = 100.0 * (1.0 - ssl_key_rate / ssl_sess_rate); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4605 | #endif |
| 4606 | |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4607 | /* sum certain per-thread totals (mostly byte counts) */ |
| 4608 | glob_out_bytes = glob_spl_bytes = glob_out_b32 = 0; |
| 4609 | for (thr = 0; thr < global.nbthread; thr++) { |
| 4610 | glob_out_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].out_bytes); |
| 4611 | glob_spl_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].spliced_out_bytes); |
| 4612 | glob_out_b32 += read_freq_ctr(&ha_thread_ctx[thr].out_32bps); |
| 4613 | } |
| 4614 | glob_out_b32 *= 32; // values are 32-byte units |
| 4615 | |
Willy Tarreau | 6093ba4 | 2023-02-07 15:52:14 +0100 | [diff] [blame] | 4616 | tv_remain(&start_time, &now, &up); |
Willy Tarreau | d37e26e | 2021-05-08 07:40:52 +0200 | [diff] [blame] | 4617 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4618 | if (len < INF_TOTAL_FIELDS) |
| 4619 | return 0; |
| 4620 | |
| 4621 | chunk_reset(out); |
| 4622 | memset(info, 0, sizeof(*info) * len); |
| 4623 | |
| 4624 | 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] | 4625 | 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] | 4626 | 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] | 4627 | 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] | 4628 | |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 4629 | info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread); |
Willy Tarreau | 9135859 | 2021-06-15 08:08:04 +0200 | [diff] [blame] | 4630 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, 1); |
Willy Tarreau | e8422bf | 2021-06-15 09:08:18 +0200 | [diff] [blame] | 4631 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, 1); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4632 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 4633 | |
| 4634 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
Willy Tarreau | d37e26e | 2021-05-08 07:40:52 +0200 | [diff] [blame] | 4635 | 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] | 4636 | |
Willy Tarreau | e8abc32 | 2021-05-08 07:56:56 +0200 | [diff] [blame] | 4637 | info[INF_UPTIME_SEC] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, up.tv_sec + up.tv_usec / 1000000.0) : mkf_u32(FN_DURATION, up.tv_sec); |
Willy Tarreau | 6093ba4 | 2023-02-07 15:52:14 +0100 | [diff] [blame] | 4638 | info[INF_START_TIME_SEC] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_DURATION, start_time.tv_sec + start_time.tv_usec / 1000000.0) : mkf_u32(FN_DURATION, start_time.tv_sec); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4639 | 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] | 4640 | 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] | 4641 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
Christopher Faulet | c960a3b | 2022-12-22 11:05:48 +0100 | [diff] [blame] | 4642 | info[INF_POOL_ALLOC_BYTES] = mkf_u64(0, pool_total_allocated()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4643 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
Christopher Faulet | c960a3b | 2022-12-22 11:05:48 +0100 | [diff] [blame] | 4644 | info[INF_POOL_USED_BYTES] = mkf_u64(0, pool_total_used()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4645 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 4646 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 4647 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 4648 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 4649 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 4650 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 4651 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 4652 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 4653 | #ifdef USE_OPENSSL |
| 4654 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
Willy Tarreau | 82531f6 | 2021-10-06 12:15:18 +0200 | [diff] [blame] | 4655 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, global.sslconns); |
| 4656 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, global.totalsslconns); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4657 | #endif |
| 4658 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 4659 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 4660 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4661 | 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] | 4662 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 4663 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4664 | 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] | 4665 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 4666 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 4667 | |
| 4668 | #ifdef USE_OPENSSL |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4669 | 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] | 4670 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 4671 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4672 | 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] | 4673 | 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] | 4674 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = (flags & STAT_USE_FLOAT) ? mkf_flt(FN_RATE, ssl_reuse) : mkf_u32(0, ssl_reuse); |
| 4675 | 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] | 4676 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 4677 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 4678 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 4679 | #endif |
Willy Tarreau | c597772 | 2021-05-08 08:14:04 +0200 | [diff] [blame] | 4680 | 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)); |
| 4681 | 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] | 4682 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 4683 | #ifdef USE_ZLIB |
| 4684 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 4685 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 4686 | #endif |
Willy Tarreau | 955a11e | 2021-02-24 17:03:30 +0100 | [diff] [blame] | 4687 | info[INF_TASKS] = mkf_u32(0, total_allocated_tasks()); |
Willy Tarreau | 9c7b808 | 2021-02-24 15:10:07 +0100 | [diff] [blame] | 4688 | info[INF_RUN_QUEUE] = mkf_u32(0, total_run_queues()); |
Willy Tarreau | f9d5e10 | 2021-10-08 10:43:59 +0200 | [diff] [blame] | 4689 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, clock_report_idle()); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4690 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 4691 | if (global.desc) |
| 4692 | 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] | 4693 | info[INF_STOPPING] = mkf_u32(0, stopping); |
| 4694 | info[INF_JOBS] = mkf_u32(0, jobs); |
William Lallemand | a719926 | 2018-11-16 16:57:20 +0100 | [diff] [blame] | 4695 | info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs); |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 4696 | info[INF_LISTENERS] = mkf_u32(0, listeners); |
Willy Tarreau | 199ad24 | 2018-11-05 16:31:22 +0100 | [diff] [blame] | 4697 | info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers); |
Willy Tarreau | 2d372c2 | 2018-11-05 17:12:27 +0100 | [diff] [blame] | 4698 | info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers); |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 4699 | info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs); |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 4700 | 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] | 4701 | info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, resolv_failed_resolutions); |
Willy Tarreau | 6be8d09 | 2023-01-12 16:08:41 +0100 | [diff] [blame] | 4702 | info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, glob_out_bytes); |
| 4703 | info[INF_TOTAL_SPLICED_BYTES_OUT] = mkf_u64(0, glob_spl_bytes); |
| 4704 | info[INF_BYTES_OUT_RATE] = mkf_u64(FN_RATE, glob_out_b32); |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 4705 | info[INF_DEBUG_COMMANDS_ISSUED] = mkf_u32(0, debug_commands_issued); |
Emeric Brun | 45c457a | 2020-07-09 23:23:34 +0200 | [diff] [blame] | 4706 | info[INF_CUM_LOG_MSGS] = mkf_u32(FN_COUNTER, cum_log_messages); |
Amaury Denoyelle | 5dfdf3e | 2021-05-05 17:09:12 +0200 | [diff] [blame] | 4707 | |
| 4708 | info[INF_TAINTED] = mkf_str(FO_STATUS, chunk_newstr(out)); |
| 4709 | chunk_appendf(out, "%#x", get_tainted()); |
| 4710 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4711 | return 1; |
| 4712 | } |
| 4713 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4714 | /* This function dumps information onto the stream connector's read buffer. |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4715 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4716 | * No state is used. |
| 4717 | */ |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4718 | static int stats_dump_info_to_buffer(struct stconn *sc) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4719 | { |
Willy Tarreau | caff631 | 2022-05-27 10:17:46 +0200 | [diff] [blame] | 4720 | struct appctx *appctx = __sc_appctx(sc); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4721 | struct show_stat_ctx *ctx = appctx->svcctx; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4722 | int ret; |
| 4723 | int current_field; |
Christopher Faulet | 2da02ae | 2022-02-24 13:45:27 +0100 | [diff] [blame] | 4724 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4725 | if (!stats_fill_info(info, INF_TOTAL_FIELDS, ctx->flags)) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4726 | return 0; |
| 4727 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4728 | chunk_reset(&trash_chunk); |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4729 | more: |
| 4730 | current_field = ctx->field; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4731 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4732 | if (ctx->flags & STAT_FMT_TYPED) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4733 | ret = stats_dump_typed_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 4734 | else if (ctx->flags & STAT_FMT_JSON) |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4735 | ret = stats_dump_json_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4736 | else |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4737 | ret = stats_dump_info_fields(&trash_chunk, info, ctx); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4738 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4739 | if (applet_putchk(appctx, &trash_chunk) == -1) { |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4740 | /* restore previous field */ |
| 4741 | ctx->field = current_field; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4742 | return 0; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 4743 | } |
| 4744 | if (ret && ctx->field) { |
| 4745 | /* partial dump */ |
| 4746 | goto more; |
| 4747 | } |
| 4748 | ctx->field = 0; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4749 | return 1; |
| 4750 | } |
| 4751 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4752 | /* This function dumps the schema onto the stream connector's read buffer. |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4753 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4754 | * No state is used. |
| 4755 | * |
Ilya Shipitsin | f38a018 | 2020-12-21 01:16:17 +0500 | [diff] [blame] | 4756 | * 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] | 4757 | * per the recommendation for interoperable integers in section 6 of RFC 7159. |
| 4758 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 4759 | static void stats_dump_json_schema(struct buffer *out) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4760 | { |
| 4761 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4762 | int old_len = out->data; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4763 | |
| 4764 | chunk_strcat(out, |
| 4765 | "{" |
| 4766 | "\"$schema\":\"http://json-schema.org/draft-04/schema#\"," |
| 4767 | "\"oneOf\":[" |
| 4768 | "{" |
| 4769 | "\"title\":\"Info\"," |
| 4770 | "\"type\":\"array\"," |
| 4771 | "\"items\":{" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 4772 | "\"title\":\"InfoItem\"," |
| 4773 | "\"type\":\"object\"," |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4774 | "\"properties\":{" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4775 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 4776 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 4777 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 4778 | "\"value\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 4779 | "}," |
| 4780 | "\"required\":[\"field\",\"processNum\",\"tags\"," |
| 4781 | "\"value\"]" |
| 4782 | "}" |
| 4783 | "}," |
| 4784 | "{" |
| 4785 | "\"title\":\"Stat\"," |
| 4786 | "\"type\":\"array\"," |
| 4787 | "\"items\":{" |
| 4788 | "\"title\":\"InfoItem\"," |
| 4789 | "\"type\":\"object\"," |
| 4790 | "\"properties\":{" |
| 4791 | "\"objType\":{" |
| 4792 | "\"enum\":[\"Frontend\",\"Backend\",\"Listener\"," |
| 4793 | "\"Server\",\"Unknown\"]" |
| 4794 | "}," |
| 4795 | "\"proxyId\":{" |
| 4796 | "\"type\":\"integer\"," |
| 4797 | "\"minimum\":0" |
| 4798 | "}," |
| 4799 | "\"id\":{" |
| 4800 | "\"type\":\"integer\"," |
| 4801 | "\"minimum\":0" |
| 4802 | "}," |
| 4803 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 4804 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 4805 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 4806 | "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 4807 | "}," |
| 4808 | "\"required\":[\"objType\",\"proxyId\",\"id\"," |
| 4809 | "\"field\",\"processNum\",\"tags\"," |
| 4810 | "\"value\"]" |
| 4811 | "}" |
| 4812 | "}," |
| 4813 | "{" |
| 4814 | "\"title\":\"Error\"," |
| 4815 | "\"type\":\"object\"," |
| 4816 | "\"properties\":{" |
| 4817 | "\"errorStr\":{" |
| 4818 | "\"type\":\"string\"" |
Amaury Denoyelle | a53ce4c | 2020-10-02 18:31:59 +0200 | [diff] [blame] | 4819 | "}" |
| 4820 | "}," |
| 4821 | "\"required\":[\"errorStr\"]" |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4822 | "}" |
| 4823 | "]," |
| 4824 | "\"definitions\":{" |
| 4825 | "\"field\":{" |
| 4826 | "\"type\":\"object\"," |
| 4827 | "\"pos\":{" |
| 4828 | "\"type\":\"integer\"," |
| 4829 | "\"minimum\":0" |
| 4830 | "}," |
| 4831 | "\"name\":{" |
| 4832 | "\"type\":\"string\"" |
| 4833 | "}," |
| 4834 | "\"required\":[\"pos\",\"name\"]" |
| 4835 | "}," |
| 4836 | "\"processNum\":{" |
| 4837 | "\"type\":\"integer\"," |
| 4838 | "\"minimum\":1" |
| 4839 | "}," |
| 4840 | "\"tags\":{" |
| 4841 | "\"type\":\"object\"," |
| 4842 | "\"origin\":{" |
| 4843 | "\"type\":\"string\"," |
| 4844 | "\"enum\":[\"Metric\",\"Status\",\"Key\"," |
| 4845 | "\"Config\",\"Product\",\"Unknown\"]" |
| 4846 | "}," |
| 4847 | "\"nature\":{" |
| 4848 | "\"type\":\"string\"," |
| 4849 | "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\"," |
| 4850 | "\"Rate\",\"Counter\",\"Duration\"," |
| 4851 | "\"Age\",\"Time\",\"Name\",\"Output\"," |
| 4852 | "\"Avg\", \"Unknown\"]" |
| 4853 | "}," |
| 4854 | "\"scope\":{" |
| 4855 | "\"type\":\"string\"," |
| 4856 | "\"enum\":[\"Cluster\",\"Process\",\"Service\"," |
| 4857 | "\"System\",\"Unknown\"]" |
| 4858 | "}," |
| 4859 | "\"required\":[\"origin\",\"nature\",\"scope\"]" |
| 4860 | "}," |
| 4861 | "\"typedValue\":{" |
| 4862 | "\"type\":\"object\"," |
| 4863 | "\"oneOf\":[" |
| 4864 | "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"}," |
| 4865 | "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"}," |
| 4866 | "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"}," |
| 4867 | "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"}," |
| 4868 | "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}" |
| 4869 | "]," |
| 4870 | "\"definitions\":{" |
| 4871 | "\"s32Value\":{" |
| 4872 | "\"properties\":{" |
| 4873 | "\"type\":{" |
| 4874 | "\"type\":\"string\"," |
| 4875 | "\"enum\":[\"s32\"]" |
| 4876 | "}," |
| 4877 | "\"value\":{" |
| 4878 | "\"type\":\"integer\"," |
| 4879 | "\"minimum\":-2147483648," |
| 4880 | "\"maximum\":2147483647" |
| 4881 | "}" |
| 4882 | "}," |
| 4883 | "\"required\":[\"type\",\"value\"]" |
| 4884 | "}," |
| 4885 | "\"s64Value\":{" |
| 4886 | "\"properties\":{" |
| 4887 | "\"type\":{" |
| 4888 | "\"type\":\"string\"," |
| 4889 | "\"enum\":[\"s64\"]" |
| 4890 | "}," |
| 4891 | "\"value\":{" |
| 4892 | "\"type\":\"integer\"," |
| 4893 | "\"minimum\":-9007199254740991," |
| 4894 | "\"maximum\":9007199254740991" |
| 4895 | "}" |
| 4896 | "}," |
| 4897 | "\"required\":[\"type\",\"value\"]" |
| 4898 | "}," |
| 4899 | "\"u32Value\":{" |
| 4900 | "\"properties\":{" |
| 4901 | "\"type\":{" |
| 4902 | "\"type\":\"string\"," |
| 4903 | "\"enum\":[\"u32\"]" |
| 4904 | "}," |
| 4905 | "\"value\":{" |
| 4906 | "\"type\":\"integer\"," |
| 4907 | "\"minimum\":0," |
| 4908 | "\"maximum\":4294967295" |
| 4909 | "}" |
| 4910 | "}," |
| 4911 | "\"required\":[\"type\",\"value\"]" |
| 4912 | "}," |
| 4913 | "\"u64Value\":{" |
| 4914 | "\"properties\":{" |
| 4915 | "\"type\":{" |
| 4916 | "\"type\":\"string\"," |
| 4917 | "\"enum\":[\"u64\"]" |
| 4918 | "}," |
| 4919 | "\"value\":{" |
| 4920 | "\"type\":\"integer\"," |
| 4921 | "\"minimum\":0," |
| 4922 | "\"maximum\":9007199254740991" |
| 4923 | "}" |
| 4924 | "}," |
| 4925 | "\"required\":[\"type\",\"value\"]" |
| 4926 | "}," |
| 4927 | "\"strValue\":{" |
| 4928 | "\"properties\":{" |
| 4929 | "\"type\":{" |
| 4930 | "\"type\":\"string\"," |
| 4931 | "\"enum\":[\"str\"]" |
| 4932 | "}," |
| 4933 | "\"value\":{\"type\":\"string\"}" |
| 4934 | "}," |
| 4935 | "\"required\":[\"type\",\"value\"]" |
| 4936 | "}," |
| 4937 | "\"unknownValue\":{" |
| 4938 | "\"properties\":{" |
| 4939 | "\"type\":{" |
| 4940 | "\"type\":\"integer\"," |
| 4941 | "\"minimum\":0" |
| 4942 | "}," |
| 4943 | "\"value\":{" |
| 4944 | "\"type\":\"string\"," |
| 4945 | "\"enum\":[\"unknown\"]" |
| 4946 | "}" |
| 4947 | "}," |
| 4948 | "\"required\":[\"type\",\"value\"]" |
| 4949 | "}" |
| 4950 | "}" |
| 4951 | "}" |
| 4952 | "}" |
| 4953 | "}"); |
| 4954 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 4955 | if (old_len == out->data) { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4956 | chunk_reset(out); |
| 4957 | chunk_appendf(out, |
| 4958 | "{\"errorStr\":\"output buffer too short\"}"); |
| 4959 | } |
Willy Tarreau | 5a0e7ca | 2022-06-10 09:21:22 +0200 | [diff] [blame] | 4960 | chunk_appendf(out, "\n"); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4961 | } |
| 4962 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 4963 | /* This function dumps the schema onto the stream connector's read buffer. |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4964 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 4965 | * No state is used. |
| 4966 | */ |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 4967 | static int stats_dump_json_schema_to_buffer(struct appctx *appctx) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4968 | { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4969 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4970 | chunk_reset(&trash_chunk); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4971 | |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 4972 | stats_dump_json_schema(&trash_chunk); |
| 4973 | |
| 4974 | if (applet_putchk(appctx, &trash_chunk) == -1) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4975 | return 0; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4976 | |
| 4977 | return 1; |
| 4978 | } |
| 4979 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 4980 | 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] | 4981 | { |
| 4982 | struct proxy *px; |
| 4983 | struct server *sv; |
| 4984 | struct listener *li; |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 4985 | struct stats_module *mod; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4986 | int clrall = 0; |
| 4987 | |
| 4988 | if (strcmp(args[2], "all") == 0) |
| 4989 | clrall = 1; |
| 4990 | |
| 4991 | /* check permissions */ |
| 4992 | if (!cli_has_level(appctx, ACCESS_LVL_OPER) || |
| 4993 | (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN))) |
| 4994 | return 1; |
| 4995 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 4996 | for (px = proxies_list; px; px = px->next) { |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4997 | if (clrall) { |
| 4998 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 4999 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 5000 | } |
| 5001 | else { |
| 5002 | px->be_counters.conn_max = 0; |
| 5003 | px->be_counters.p.http.rps_max = 0; |
| 5004 | px->be_counters.sps_max = 0; |
| 5005 | px->be_counters.cps_max = 0; |
| 5006 | px->be_counters.nbpend_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 5007 | px->be_counters.qtime_max = 0; |
| 5008 | px->be_counters.ctime_max = 0; |
| 5009 | px->be_counters.dtime_max = 0; |
| 5010 | px->be_counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5011 | |
| 5012 | px->fe_counters.conn_max = 0; |
| 5013 | px->fe_counters.p.http.rps_max = 0; |
| 5014 | px->fe_counters.sps_max = 0; |
| 5015 | px->fe_counters.cps_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | for (sv = px->srv; sv; sv = sv->next) |
| 5019 | if (clrall) |
| 5020 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 5021 | else { |
| 5022 | sv->counters.cur_sess_max = 0; |
| 5023 | sv->counters.nbpend_max = 0; |
| 5024 | sv->counters.sps_max = 0; |
Christopher Faulet | efb41f0 | 2019-11-08 14:53:15 +0100 | [diff] [blame] | 5025 | sv->counters.qtime_max = 0; |
| 5026 | sv->counters.ctime_max = 0; |
| 5027 | sv->counters.dtime_max = 0; |
| 5028 | sv->counters.ttime_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
| 5032 | if (li->counters) { |
| 5033 | if (clrall) |
| 5034 | memset(li->counters, 0, sizeof(*li->counters)); |
| 5035 | else |
| 5036 | li->counters->conn_max = 0; |
| 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | global.cps_max = 0; |
| 5041 | global.sps_max = 0; |
Olivier Houchard | 00bc3cb | 2017-10-17 19:23:25 +0200 | [diff] [blame] | 5042 | global.ssl_max = 0; |
| 5043 | global.ssl_fe_keys_max = 0; |
| 5044 | global.ssl_be_keys_max = 0; |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 5045 | |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 5046 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5047 | if (!mod->clearable && !clrall) |
| 5048 | continue; |
| 5049 | |
| 5050 | for (px = proxies_list; px; px = px->next) { |
| 5051 | enum stats_domain_px_cap mod_cap = stats_px_get_cap(mod->domain_flags); |
| 5052 | |
| 5053 | if (px->cap & PR_CAP_FE && mod_cap & STATS_PX_CAP_FE) { |
| 5054 | EXTRA_COUNTERS_INIT(px->extra_counters_fe, |
| 5055 | mod, |
| 5056 | mod->counters, |
| 5057 | mod->counters_size); |
| 5058 | } |
| 5059 | |
| 5060 | if (px->cap & PR_CAP_BE && mod_cap & STATS_PX_CAP_BE) { |
| 5061 | EXTRA_COUNTERS_INIT(px->extra_counters_be, |
| 5062 | mod, |
| 5063 | mod->counters, |
| 5064 | mod->counters_size); |
| 5065 | } |
| 5066 | |
| 5067 | if (mod_cap & STATS_PX_CAP_SRV) { |
| 5068 | for (sv = px->srv; sv; sv = sv->next) { |
| 5069 | EXTRA_COUNTERS_INIT(sv->extra_counters, |
| 5070 | mod, |
| 5071 | mod->counters, |
| 5072 | mod->counters_size); |
| 5073 | } |
| 5074 | } |
| 5075 | |
| 5076 | if (mod_cap & STATS_PX_CAP_LI) { |
| 5077 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 5078 | EXTRA_COUNTERS_INIT(li->extra_counters, |
| 5079 | mod, |
| 5080 | mod->counters, |
| 5081 | mod->counters_size); |
| 5082 | } |
| 5083 | } |
| 5084 | } |
| 5085 | } |
| 5086 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5087 | resolv_stats_clear_counters(clrall, &stats_module_list[STATS_DOMAIN_RESOLVERS]); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5088 | |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 5089 | memset(activity, 0, sizeof(activity)); |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 5090 | return 1; |
| 5091 | } |
| 5092 | |
| 5093 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 5094 | 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] | 5095 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5096 | struct show_stat_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5097 | int arg = 2; |
| 5098 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5099 | ctx->scope_str = 0; |
| 5100 | ctx->scope_len = 0; |
| 5101 | ctx->flags = 0; |
Aurelien DARRAGON | 5594184 | 2022-12-15 14:01:04 +0100 | [diff] [blame] | 5102 | ctx->field = 0; /* explicit default value */ |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 5103 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5104 | while (*args[arg]) { |
| 5105 | if (strcmp(args[arg], "typed") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5106 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5107 | else if (strcmp(args[arg], "json") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5108 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5109 | else if (strcmp(args[arg], "desc") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5110 | ctx->flags |= STAT_SHOW_FDESC; |
Willy Tarreau | 2745620 | 2021-05-08 07:54:24 +0200 | [diff] [blame] | 5111 | else if (strcmp(args[arg], "float") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5112 | ctx->flags |= STAT_USE_FLOAT; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5113 | arg++; |
| 5114 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5115 | return 0; |
| 5116 | } |
| 5117 | |
| 5118 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 5119 | 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] | 5120 | { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5121 | struct show_stat_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5122 | int arg = 2; |
| 5123 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5124 | ctx->scope_str = 0; |
| 5125 | ctx->scope_len = 0; |
| 5126 | ctx->flags = STAT_SHNODE | STAT_SHDESC; |
Willy Tarreau | 578d6e4 | 2019-10-09 11:00:22 +0200 | [diff] [blame] | 5127 | |
Willy Tarreau | 0698c80 | 2022-05-11 14:09:57 +0200 | [diff] [blame] | 5128 | 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] | 5129 | ctx->flags |= STAT_SHLGNDS; |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 5130 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5131 | /* proxy is the default domain */ |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5132 | ctx->domain = STATS_DOMAIN_PROXY; |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 5133 | if (strcmp(args[arg], "domain") == 0) { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5134 | ++args; |
| 5135 | |
Tim Duesterhus | e5ff141 | 2021-01-02 22:31:53 +0100 | [diff] [blame] | 5136 | if (strcmp(args[arg], "proxy") == 0) { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5137 | ++args; |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5138 | } else if (strcmp(args[arg], "resolvers") == 0) { |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5139 | ctx->domain = STATS_DOMAIN_RESOLVERS; |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5140 | ++args; |
| 5141 | } else { |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5142 | return cli_err(appctx, "Invalid statistics domain.\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5143 | } |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5144 | } |
| 5145 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5146 | if (ctx->domain == STATS_DOMAIN_PROXY |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 5147 | && *args[arg] && *args[arg+1] && *args[arg+2]) { |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5148 | struct proxy *px; |
| 5149 | |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5150 | px = proxy_find_by_name(args[arg], 0, 0); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5151 | if (px) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5152 | ctx->iid = px->uuid; |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5153 | else |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5154 | ctx->iid = atoi(args[arg]); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5155 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5156 | if (!ctx->iid) |
Willy Tarreau | 9d00869 | 2019-08-09 11:21:01 +0200 | [diff] [blame] | 5157 | return cli_err(appctx, "No such proxy.\n"); |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 5158 | |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5159 | ctx->flags |= STAT_BOUND; |
| 5160 | ctx->type = atoi(args[arg+1]); |
| 5161 | ctx->sid = atoi(args[arg+2]); |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5162 | arg += 3; |
| 5163 | } |
| 5164 | |
| 5165 | while (*args[arg]) { |
| 5166 | if (strcmp(args[arg], "typed") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5167 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5168 | else if (strcmp(args[arg], "json") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5169 | ctx->flags = (ctx->flags & ~STAT_FMT_MASK) | STAT_FMT_JSON; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5170 | else if (strcmp(args[arg], "desc") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5171 | ctx->flags |= STAT_SHOW_FDESC; |
Willy Tarreau | 3e32036 | 2020-10-23 17:28:57 +0200 | [diff] [blame] | 5172 | else if (strcmp(args[arg], "no-maint") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5173 | ctx->flags |= STAT_HIDE_MAINT; |
Willy Tarreau | 65141ff | 2020-10-23 17:19:48 +0200 | [diff] [blame] | 5174 | else if (strcmp(args[arg], "up") == 0) |
Willy Tarreau | 91cefca | 2022-05-03 17:08:29 +0200 | [diff] [blame] | 5175 | ctx->flags |= STAT_HIDE_DOWN; |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 5176 | arg++; |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5177 | } |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5178 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5179 | return 0; |
| 5180 | } |
| 5181 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5182 | static int cli_io_handler_dump_info(struct appctx *appctx) |
| 5183 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5184 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5185 | return stats_dump_info_to_buffer(appctx_sc(appctx)); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 5186 | } |
| 5187 | |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 5188 | /* 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] | 5189 | * used to send raw stats over a socket. |
| 5190 | */ |
| 5191 | static int cli_io_handler_dump_stat(struct appctx *appctx) |
| 5192 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5193 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 5194 | return stats_dump_stat_to_buffer(appctx_sc(appctx), NULL, NULL); |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5195 | } |
| 5196 | |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5197 | static int cli_io_handler_dump_json_schema(struct appctx *appctx) |
| 5198 | { |
Christopher Faulet | a8b7684 | 2022-12-16 15:08:36 +0100 | [diff] [blame] | 5199 | trash_chunk = b_make(trash.area, trash.size, 0, 0); |
Willy Tarreau | d0a06d5 | 2022-05-18 15:07:19 +0200 | [diff] [blame] | 5200 | return stats_dump_json_schema_to_buffer(appctx); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 5201 | } |
| 5202 | |
Amaury Denoyelle | 216a1ce | 2021-03-18 15:48:14 +0100 | [diff] [blame] | 5203 | int stats_allocate_proxy_counters_internal(struct extra_counters **counters, |
| 5204 | int type, int px_cap) |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5205 | { |
| 5206 | struct stats_module *mod; |
| 5207 | |
| 5208 | EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed); |
| 5209 | |
| 5210 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5211 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 5212 | continue; |
| 5213 | |
| 5214 | EXTRA_COUNTERS_ADD(mod, *counters, mod->counters, mod->counters_size); |
| 5215 | } |
| 5216 | |
| 5217 | EXTRA_COUNTERS_ALLOC(*counters, alloc_failed); |
| 5218 | |
| 5219 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5220 | if (!(stats_px_get_cap(mod->domain_flags) & px_cap)) |
| 5221 | continue; |
| 5222 | |
| 5223 | EXTRA_COUNTERS_INIT(*counters, mod, mod->counters, mod->counters_size); |
| 5224 | } |
| 5225 | |
| 5226 | return 1; |
| 5227 | |
| 5228 | alloc_failed: |
| 5229 | return 0; |
| 5230 | } |
| 5231 | |
| 5232 | /* Initialize and allocate all extra counters for a proxy and its attached |
| 5233 | * servers/listeners with all already registered stats module |
| 5234 | */ |
| 5235 | int stats_allocate_proxy_counters(struct proxy *px) |
| 5236 | { |
| 5237 | struct server *sv; |
| 5238 | struct listener *li; |
| 5239 | |
| 5240 | if (px->cap & PR_CAP_FE) { |
| 5241 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_fe, |
| 5242 | COUNTERS_FE, |
| 5243 | STATS_PX_CAP_FE)) { |
| 5244 | return 0; |
| 5245 | } |
| 5246 | } |
| 5247 | |
| 5248 | if (px->cap & PR_CAP_BE) { |
| 5249 | if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be, |
| 5250 | COUNTERS_BE, |
| 5251 | STATS_PX_CAP_BE)) { |
| 5252 | return 0; |
| 5253 | } |
| 5254 | } |
| 5255 | |
| 5256 | for (sv = px->srv; sv; sv = sv->next) { |
| 5257 | if (!stats_allocate_proxy_counters_internal(&sv->extra_counters, |
| 5258 | COUNTERS_SV, |
| 5259 | STATS_PX_CAP_SRV)) { |
| 5260 | return 0; |
| 5261 | } |
| 5262 | } |
| 5263 | |
| 5264 | list_for_each_entry(li, &px->conf.listeners, by_fe) { |
| 5265 | if (!stats_allocate_proxy_counters_internal(&li->extra_counters, |
| 5266 | COUNTERS_LI, |
| 5267 | STATS_PX_CAP_LI)) { |
| 5268 | return 0; |
| 5269 | } |
| 5270 | } |
| 5271 | |
| 5272 | return 1; |
| 5273 | } |
| 5274 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 5275 | void stats_register_module(struct stats_module *m) |
| 5276 | { |
| 5277 | const uint8_t domain = stats_get_domain(m->domain_flags); |
| 5278 | |
Willy Tarreau | 2b71810 | 2021-04-21 07:32:39 +0200 | [diff] [blame] | 5279 | LIST_APPEND(&stats_module_list[domain], &m->list); |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5280 | stat_count[domain] += m->stats_count; |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 5281 | } |
| 5282 | |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5283 | static int allocate_stats_px_postcheck(void) |
| 5284 | { |
| 5285 | struct stats_module *mod; |
| 5286 | size_t i = ST_F_TOTAL_FIELDS; |
| 5287 | int err_code = 0; |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 5288 | struct proxy *px; |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5289 | |
| 5290 | stat_count[STATS_DOMAIN_PROXY] += ST_F_TOTAL_FIELDS; |
| 5291 | |
| 5292 | stat_f[STATS_DOMAIN_PROXY] = malloc(stat_count[STATS_DOMAIN_PROXY] * sizeof(struct name_desc)); |
| 5293 | if (!stat_f[STATS_DOMAIN_PROXY]) { |
| 5294 | ha_alert("stats: cannot allocate all fields for proxy statistics\n"); |
| 5295 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5296 | return err_code; |
| 5297 | } |
| 5298 | |
| 5299 | memcpy(stat_f[STATS_DOMAIN_PROXY], stat_fields, |
| 5300 | ST_F_TOTAL_FIELDS * sizeof(struct name_desc)); |
| 5301 | |
| 5302 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) { |
| 5303 | memcpy(stat_f[STATS_DOMAIN_PROXY] + i, |
| 5304 | mod->stats, |
| 5305 | mod->stats_count * sizeof(struct name_desc)); |
| 5306 | i += mod->stats_count; |
| 5307 | } |
| 5308 | |
Amaury Denoyelle | 27373f7 | 2020-10-05 16:57:33 +0200 | [diff] [blame] | 5309 | for (px = proxies_list; px; px = px->next) { |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5310 | if (!stats_allocate_proxy_counters(px)) { |
| 5311 | ha_alert("stats: cannot allocate all counters for proxy statistics\n"); |
| 5312 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5313 | return err_code; |
| 5314 | } |
| 5315 | } |
| 5316 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5317 | /* wait per-thread alloc to perform corresponding stat_l allocation */ |
Amaury Denoyelle | ee63d4b | 2020-10-05 11:49:42 +0200 | [diff] [blame] | 5318 | |
| 5319 | return err_code; |
| 5320 | } |
| 5321 | |
| 5322 | REGISTER_CONFIG_POSTPARSER("allocate-stats-px", allocate_stats_px_postcheck); |
| 5323 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5324 | static int allocate_stats_rslv_postcheck(void) |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5325 | { |
| 5326 | struct stats_module *mod; |
| 5327 | size_t i = 0; |
| 5328 | int err_code = 0; |
| 5329 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5330 | stat_f[STATS_DOMAIN_RESOLVERS] = malloc(stat_count[STATS_DOMAIN_RESOLVERS] * sizeof(struct name_desc)); |
| 5331 | if (!stat_f[STATS_DOMAIN_RESOLVERS]) { |
| 5332 | ha_alert("stats: cannot allocate all fields for resolver statistics\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5333 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5334 | return err_code; |
| 5335 | } |
| 5336 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5337 | list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_RESOLVERS], list) { |
| 5338 | memcpy(stat_f[STATS_DOMAIN_RESOLVERS] + i, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5339 | mod->stats, |
| 5340 | mod->stats_count * sizeof(struct name_desc)); |
| 5341 | i += mod->stats_count; |
| 5342 | } |
| 5343 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5344 | if (!resolv_allocate_counters(&stats_module_list[STATS_DOMAIN_RESOLVERS])) { |
| 5345 | ha_alert("stats: cannot allocate all counters for resolver statistics\n"); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5346 | err_code |= ERR_ALERT | ERR_FATAL; |
| 5347 | return err_code; |
| 5348 | } |
| 5349 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5350 | /* wait per-thread alloc to perform corresponding stat_l allocation */ |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5351 | |
| 5352 | return err_code; |
| 5353 | } |
| 5354 | |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5355 | REGISTER_CONFIG_POSTPARSER("allocate-stats-resolver", allocate_stats_rslv_postcheck); |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame] | 5356 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5357 | static int allocate_stat_lines_per_thread(void) |
| 5358 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5359 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5360 | |
| 5361 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5362 | const int domain = domains[i]; |
| 5363 | |
| 5364 | stat_l[domain] = malloc(stat_count[domain] * sizeof(struct field)); |
| 5365 | if (!stat_l[domain]) |
| 5366 | return 0; |
| 5367 | } |
| 5368 | return 1; |
| 5369 | } |
| 5370 | |
| 5371 | REGISTER_PER_THREAD_ALLOC(allocate_stat_lines_per_thread); |
| 5372 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5373 | static int allocate_trash_counters(void) |
| 5374 | { |
| 5375 | struct stats_module *mod; |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5376 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5377 | size_t max_counters_size = 0; |
| 5378 | |
| 5379 | /* calculate the greatest counters used by any stats modules */ |
| 5380 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5381 | list_for_each_entry(mod, &stats_module_list[domains[i]], list) { |
| 5382 | max_counters_size = mod->counters_size > max_counters_size ? |
| 5383 | mod->counters_size : max_counters_size; |
| 5384 | } |
| 5385 | } |
| 5386 | |
| 5387 | /* allocate the trash with the size of the greatest counters */ |
| 5388 | if (max_counters_size) { |
| 5389 | trash_counters = malloc(max_counters_size); |
| 5390 | if (!trash_counters) { |
| 5391 | ha_alert("stats: cannot allocate trash counters for statistics\n"); |
| 5392 | return 0; |
| 5393 | } |
| 5394 | } |
| 5395 | |
| 5396 | return 1; |
| 5397 | } |
| 5398 | |
| 5399 | REGISTER_PER_THREAD_ALLOC(allocate_trash_counters); |
| 5400 | |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5401 | static void deinit_stat_lines_per_thread(void) |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5402 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5403 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5404 | |
| 5405 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5406 | const int domain = domains[i]; |
| 5407 | |
Willy Tarreau | 61cfdf4 | 2021-02-20 10:46:51 +0100 | [diff] [blame] | 5408 | ha_free(&stat_l[domain]); |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5409 | } |
| 5410 | } |
| 5411 | |
| 5412 | |
| 5413 | REGISTER_PER_THREAD_FREE(deinit_stat_lines_per_thread); |
| 5414 | |
| 5415 | static void deinit_stats(void) |
| 5416 | { |
Emeric Brun | f8642ee | 2021-10-29 17:59:18 +0200 | [diff] [blame] | 5417 | int domains[] = { STATS_DOMAIN_PROXY, STATS_DOMAIN_RESOLVERS }, i; |
Christopher Faulet | de79cd2 | 2021-01-06 07:41:56 +0100 | [diff] [blame] | 5418 | |
| 5419 | for (i = 0; i < STATS_DOMAIN_COUNT; ++i) { |
| 5420 | const int domain = domains[i]; |
Amaury Denoyelle | a2a6899 | 2020-11-10 14:24:30 +0100 | [diff] [blame] | 5421 | |
| 5422 | if (stat_f[domain]) |
| 5423 | free(stat_f[domain]); |
| 5424 | } |
| 5425 | } |
| 5426 | |
| 5427 | REGISTER_POST_DEINIT(deinit_stats); |
| 5428 | |
Amaury Denoyelle | 7f8f6cb | 2020-11-10 14:24:31 +0100 | [diff] [blame] | 5429 | static void free_trash_counters(void) |
| 5430 | { |
| 5431 | if (trash_counters) |
| 5432 | free(trash_counters); |
| 5433 | } |
| 5434 | |
| 5435 | REGISTER_PER_THREAD_FREE(free_trash_counters); |
| 5436 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 5437 | /* register cli keywords */ |
| 5438 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | b205bfd | 2021-05-07 11:38:37 +0200 | [diff] [blame] | 5439 | { { "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] | 5440 | { { "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] | 5441 | { { "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 }, |
| 5442 | { { "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] | 5443 | {{},} |
| 5444 | }}; |
| 5445 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 5446 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 5447 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 5448 | struct applet http_stats_applet = { |
| 5449 | .obj_type = OBJ_TYPE_APPLET, |
| 5450 | .name = "<STATS>", /* used for logging */ |
| 5451 | .fct = http_stats_io_handler, |
| 5452 | .release = NULL, |
| 5453 | }; |
| 5454 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 5455 | /* |
| 5456 | * Local variables: |
| 5457 | * c-indent-level: 8 |
| 5458 | * c-basic-offset: 8 |
| 5459 | * End: |
| 5460 | */ |