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