blob: 7ebf2e567cb6c3932ae819d8ec2d179a01d74e89 [file] [log] [blame]
William Lallemand74c24fb2016-11-21 17:18:36 +01001/*
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
27#include <common/cfgparse.h>
28#include <common/compat.h>
29#include <common/config.h>
30#include <common/debug.h>
Willy Tarreau35b51c62018-09-10 15:38:55 +020031#include <common/http.h>
Willy Tarreaub96b77e2018-12-11 10:22:41 +010032#include <common/htx.h>
Willy Tarreau0108d902018-11-25 19:14:37 +010033#include <common/initcall.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010034#include <common/memory.h>
35#include <common/mini-clist.h>
36#include <common/standard.h>
37#include <common/ticks.h>
38#include <common/time.h>
39#include <common/uri_auth.h>
40#include <common/version.h>
41#include <common/base64.h>
42
43#include <types/applet.h>
Willy Tarreau2b812e22016-11-22 16:18:05 +010044#include <types/cli.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010045#include <types/global.h>
46#include <types/dns.h>
William Lallemand9ed62032016-11-21 17:49:11 +010047#include <types/stats.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010048
49#include <proto/backend.h>
50#include <proto/channel.h>
51#include <proto/checks.h>
Willy Tarreau2b812e22016-11-22 16:18:05 +010052#include <proto/cli.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010053#include <proto/compression.h>
Baptiste Assmann333939c2019-01-21 08:34:50 +010054#include <proto/dns.h>
William Lallemand9ed62032016-11-21 17:49:11 +010055#include <proto/stats.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010056#include <proto/fd.h>
57#include <proto/freq_ctr.h>
58#include <proto/frontend.h>
Christopher Fauleted7a0662019-01-14 11:07:34 +010059#include <proto/http_htx.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010060#include <proto/log.h>
61#include <proto/pattern.h>
62#include <proto/pipe.h>
63#include <proto/listener.h>
64#include <proto/map.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010065#include <proto/proxy.h>
66#include <proto/sample.h>
67#include <proto/session.h>
Willy Tarreauc125cef2019-05-10 09:58:43 +020068#include <proto/ssl_sock.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010069#include <proto/stream.h>
70#include <proto/server.h>
71#include <proto/raw_sock.h>
72#include <proto/stream_interface.h>
73#include <proto/task.h>
74
Christopher Faulet2b9b6782019-02-27 16:42:58 +010075/* status codes available for the stats admin page (strictly 4 chars length) */
76const char *stat_status_codes[STAT_STATUS_SIZE] = {
77 [STAT_STATUS_DENY] = "DENY",
78 [STAT_STATUS_DONE] = "DONE",
79 [STAT_STATUS_ERRP] = "ERRP",
80 [STAT_STATUS_EXCD] = "EXCD",
81 [STAT_STATUS_NONE] = "NONE",
82 [STAT_STATUS_PART] = "PART",
83 [STAT_STATUS_UNKN] = "UNKN",
84 [STAT_STATUS_IVAL] = "IVAL",
85};
86
Willy Tarreau0baac8c2016-11-22 16:36:53 +010087/* These are the field names for each INF_* field position. Please pay attention
88 * to always use the exact same name except that the strings for new names must
89 * be lower case or CamelCase while the enum entries must be upper case.
90 */
Willy Tarreaueaa55372019-10-09 07:39:11 +020091const struct name_desc info_fields[INF_TOTAL_FIELDS] = {
Willy Tarreau6d4897e2019-10-11 16:31:46 +020092 [INF_NAME] = { .name = "Name", .desc = "Product name" },
93 [INF_VERSION] = { .name = "Version", .desc = "Product version" },
94 [INF_RELEASE_DATE] = { .name = "Release_date", .desc = "Date of latest source code update" },
95 [INF_NBTHREAD] = { .name = "Nbthread", .desc = "Number of started threads (global.nbthread)" },
96 [INF_NBPROC] = { .name = "Nbproc", .desc = "Number of started worker processes (global.nbproc)" },
97 [INF_PROCESS_NUM] = { .name = "Process_num", .desc = "Relative worker process number (1..Nbproc)" },
98 [INF_PID] = { .name = "Pid", .desc = "This worker process identifier for the system" },
99 [INF_UPTIME] = { .name = "Uptime", .desc = "How long ago this worker process was started (days+hours+minutes+seconds)" },
100 [INF_UPTIME_SEC] = { .name = "Uptime_sec", .desc = "How long ago this worker process was started (seconds)" },
101 [INF_MEMMAX_MB] = { .name = "Memmax_MB", .desc = "Worker process's hard limit on memory usage in MB (-m on command line)" },
102 [INF_POOL_ALLOC_MB] = { .name = "PoolAlloc_MB", .desc = "Amount of memory allocated in pools (in MB)" },
103 [INF_POOL_USED_MB] = { .name = "PoolUsed_MB", .desc = "Amount of pool memory currently used (in MB)" },
104 [INF_POOL_FAILED] = { .name = "PoolFailed", .desc = "Number of failed pool allocations since this worker was started" },
105 [INF_ULIMIT_N] = { .name = "Ulimit-n", .desc = "Hard limit on the number of per-process file descriptors" },
106 [INF_MAXSOCK] = { .name = "Maxsock", .desc = "Hard limit on the number of per-process sockets" },
107 [INF_MAXCONN] = { .name = "Maxconn", .desc = "Hard limit on the number of per-process connections (configured or imposed by Ulimit-n)" },
108 [INF_HARD_MAXCONN] = { .name = "Hard_maxconn", .desc = "Hard limit on the number of per-process connections (imposed by Memmax_MB or Ulimit-n)" },
109 [INF_CURR_CONN] = { .name = "CurrConns", .desc = "Current number of connections on this worker process" },
110 [INF_CUM_CONN] = { .name = "CumConns", .desc = "Total number of connections on this worker process since started" },
111 [INF_CUM_REQ] = { .name = "CumReq", .desc = "Total number of requests on this worker process since started" },
112 [INF_MAX_SSL_CONNS] = { .name = "MaxSslConns", .desc = "Hard limit on the number of per-process SSL endpoints (front+back), 0=unlimited" },
113 [INF_CURR_SSL_CONNS] = { .name = "CurrSslConns", .desc = "Current number of SSL endpoints on this worker process (front+back)" },
114 [INF_CUM_SSL_CONNS] = { .name = "CumSslConns", .desc = "Total number of SSL endpoints on this worker process since started (front+back)" },
115 [INF_MAXPIPES] = { .name = "Maxpipes", .desc = "Hard limit on the number of pipes for splicing, 0=unlimited" },
116 [INF_PIPES_USED] = { .name = "PipesUsed", .desc = "Current number of pipes in use in this worker process" },
117 [INF_PIPES_FREE] = { .name = "PipesFree", .desc = "Current number of allocated and available pipes in this worker process" },
118 [INF_CONN_RATE] = { .name = "ConnRate", .desc = "Number of front connections created on this worker process over the last second" },
119 [INF_CONN_RATE_LIMIT] = { .name = "ConnRateLimit", .desc = "Hard limit for ConnRate (global.maxconnrate)" },
120 [INF_MAX_CONN_RATE] = { .name = "MaxConnRate", .desc = "Highest ConnRate reached on this worker process since started (in connections per second)" },
121 [INF_SESS_RATE] = { .name = "SessRate", .desc = "Number of sessions created on this worker process over the last second" },
122 [INF_SESS_RATE_LIMIT] = { .name = "SessRateLimit", .desc = "Hard limit for SessRate (global.maxsessrate)" },
123 [INF_MAX_SESS_RATE] = { .name = "MaxSessRate", .desc = "Highest SessRate reached on this worker process since started (in sessions per second)" },
124 [INF_SSL_RATE] = { .name = "SslRate", .desc = "Number of SSL connections created on this worker process over the last second" },
125 [INF_SSL_RATE_LIMIT] = { .name = "SslRateLimit", .desc = "Hard limit for SslRate (global.maxsslrate)" },
126 [INF_MAX_SSL_RATE] = { .name = "MaxSslRate", .desc = "Highest SslRate reached on this worker process since started (in connections per second)" },
127 [INF_SSL_FRONTEND_KEY_RATE] = { .name = "SslFrontendKeyRate", .desc = "Number of SSL keys created on frontends in this worker process over the last second" },
128 [INF_SSL_FRONTEND_MAX_KEY_RATE] = { .name = "SslFrontendMaxKeyRate", .desc = "Highest SslFrontendKeyRate reached on this worker process since started (in SSL keys per second)" },
129 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = { .name = "SslFrontendSessionReuse_pct", .desc = "Percent of frontend SSL connections which did not require a new key" },
130 [INF_SSL_BACKEND_KEY_RATE] = { .name = "SslBackendKeyRate", .desc = "Number of SSL keys created on backends in this worker process over the last second" },
131 [INF_SSL_BACKEND_MAX_KEY_RATE] = { .name = "SslBackendMaxKeyRate", .desc = "Highest SslBackendKeyRate reached on this worker process since started (in SSL keys per second)" },
132 [INF_SSL_CACHE_LOOKUPS] = { .name = "SslCacheLookups", .desc = "Total number of SSL session ID lookups in the SSL session cache on this worker since started" },
133 [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" },
134 [INF_COMPRESS_BPS_IN] = { .name = "CompressBpsIn", .desc = "Number of bytes submitted to the HTTP compressor in this worker process over the last second" },
135 [INF_COMPRESS_BPS_OUT] = { .name = "CompressBpsOut", .desc = "Number of bytes emitted by the HTTP compressor in this worker process over the last second" },
136 [INF_COMPRESS_BPS_RATE_LIM] = { .name = "CompressBpsRateLim", .desc = "Limit of CompressBpsOut beyond which HTTP compression is automatically disabled" },
137 [INF_ZLIB_MEM_USAGE] = { .name = "ZlibMemUsage", .desc = "Amount of memory currently used by HTTP compression on the current worker process (in bytes)" },
138 [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)" },
139 [INF_TASKS] = { .name = "Tasks", .desc = "Total number of tasks in the current worker process (active + sleeping)" },
140 [INF_RUN_QUEUE] = { .name = "Run_queue", .desc = "Total number of active tasks+tasklets in the current worker process" },
141 [INF_IDLE_PCT] = { .name = "Idle_pct", .desc = "Percentage of last second spent waiting in the current worker thread" },
142 [INF_NODE] = { .name = "node", .desc = "Node name (global.node)" },
143 [INF_DESCRIPTION] = { .name = "description", .desc = "Node description (global.description)" },
144 [INF_STOPPING] = { .name = "Stopping", .desc = "1 if the worker process is currently stopping, otherwise zero" },
145 [INF_JOBS] = { .name = "Jobs", .desc = "Current number of active jobs on the current worker process (frontend connections, master connections, listeners)" },
146 [INF_UNSTOPPABLE_JOBS] = { .name = "Unstoppable Jobs", .desc = "Current number of unstoppable jobs on the current worker process (master connections)" },
147 [INF_LISTENERS] = { .name = "Listeners", .desc = "Current number of active listeners on the current worker process" },
148 [INF_ACTIVE_PEERS] = { .name = "ActivePeers", .desc = "Current number of verified active peers connections on the current worker process" },
149 [INF_CONNECTED_PEERS] = { .name = "ConnectedPeers", .desc = "Current number of peers having passed the connection step on the current worker process" },
150 [INF_DROPPED_LOGS] = { .name = "DroppedLogs", .desc = "Total number of dropped logs for current worker process since started" },
151 [INF_BUSY_POLLING] = { .name = "BusyPolling", .desc = "1 if busy-polling is currently in use on the worker process, otherwise zero (config.busy-polling)" },
152 [INF_FAILED_RESOLUTIONS] = { .name = "FailedResolutions", .desc = "Total number of failed DNS resolutions in current worker process since started" },
153 [INF_TOTAL_BYTES_OUT] = { .name = "TotalBytesOut", .desc = "Total number of bytes emitted by current worker process since started" },
154 [INF_BYTES_OUT_RATE] = { .name = "BytesOutRate", .desc = "Number of bytes emitted by current worker process over the last second" },
Willy Tarreau9b013702019-10-24 18:18:02 +0200155 [INF_DEBUG_COMMANDS_ISSUED] = { .name = "DebugCommandsIssued", .desc = "Number of debug commands issued on this process (anything > 0 is unsafe)" },
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100156};
157
Willy Tarreaueaa55372019-10-09 07:39:11 +0200158const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
Willy Tarreau6d4897e2019-10-11 16:31:46 +0200159 [ST_F_PXNAME] = { .name = "pxname", .desc = "Proxy name" },
160 [ST_F_SVNAME] = { .name = "svname", .desc = "Server name" },
161 [ST_F_QCUR] = { .name = "qcur", .desc = "Current number of connections waiting in the server of backend queue" },
162 [ST_F_QMAX] = { .name = "qmax", .desc = "Highest value of qcur encountered since process started" },
163 [ST_F_SCUR] = { .name = "scur", .desc = "Current number of sessions on the frontend, backend or server" },
164 [ST_F_SMAX] = { .name = "smax", .desc = "Highest value of scur encountered since process started" },
165 [ST_F_SLIM] = { .name = "slim", .desc = "Frontend/listener/server's maxconn, backend's fullconn" },
166 [ST_F_STOT] = { .name = "stot", .desc = "Total number of sessions since process started" },
167 [ST_F_BIN] = { .name = "bin", .desc = "Total number of request bytes since process started" },
168 [ST_F_BOUT] = { .name = "bout", .desc = "Total number of response bytes since process started" },
169 [ST_F_DREQ] = { .name = "dreq", .desc = "Total number of denied requests since process started" },
170 [ST_F_DRESP] = { .name = "dresp", .desc = "Total number of denied responses since process started" },
171 [ST_F_EREQ] = { .name = "ereq", .desc = "Total number of invalid requests since process started" },
172 [ST_F_ECON] = { .name = "econ", .desc = "Total number of failed connections to server since the worker process started" },
173 [ST_F_ERESP] = { .name = "eresp", .desc = "Total number of invalid responses since the worker process started" },
174 [ST_F_WRETR] = { .name = "wretr", .desc = "Total number of server connection retries since the worker process started" },
175 [ST_F_WREDIS] = { .name = "wredis", .desc = "Total number of server redispatches due to connection failures since the worker process started" },
176 [ST_F_STATUS] = { .name = "status", .desc = "Frontend/listen status: OPEN/WAITING/FULL/STOP; backend: UP/DOWN; server: last check status" },
177 [ST_F_WEIGHT] = { .name = "weight", .desc = "Server weight, or sum of active servers' weights for a backend" },
178 [ST_F_ACT] = { .name = "act", .desc = "Total number of active UP servers with a non-zero weight" },
179 [ST_F_BCK] = { .name = "bck", .desc = "Total number of backup UP servers with a non-zero weight" },
180 [ST_F_CHKFAIL] = { .name = "chkfail", .desc = "Total number of failed individual health checks per server/backend, since the worker process started" },
181 [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" },
182 [ST_F_LASTCHG] = { .name = "lastchg", .desc = "How long ago the last server state changed, in seconds" },
183 [ST_F_DOWNTIME] = { .name = "downtime", .desc = "Total time spent in DOWN state, for server or backend" },
184 [ST_F_QLIMIT] = { .name = "qlimit", .desc = "Limit on the number of connections in queue, for servers only (maxqueue argument)" },
185 [ST_F_PID] = { .name = "pid", .desc = "Relative worker process number (1..nbproc)" },
186 [ST_F_IID] = { .name = "iid", .desc = "Frontend or Backend numeric identifier ('id' setting)" },
187 [ST_F_SID] = { .name = "sid", .desc = "Server numeric identifier ('id' setting)" },
188 [ST_F_THROTTLE] = { .name = "throttle", .desc = "Throttling ratio applied to a server's maxconn and weight during the slowstart period (0 to 100%)" },
189 [ST_F_LBTOT] = { .name = "lbtot", .desc = "Total number of requests routed by load balancing since the worker process started (ignores queue pop and stickiness)" },
190 [ST_F_TRACKED] = { .name = "tracked", .desc = "Name of the other server this server tracks for its state" },
191 [ST_F_TYPE] = { .name = "type", .desc = "Type of the object (Listener, Frontend, Backend, Server)" },
192 [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)" },
193 [ST_F_RATE_LIM] = { .name = "rate_lim", .desc = "Limit on the number of sessions accepted in a second (frontend only, 'rate-limit sessions' setting)" },
194 [ST_F_RATE_MAX] = { .name = "rate_max", .desc = "Highest value of 'rate' observed since the worker process started" },
195 [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" },
196 [ST_F_CHECK_CODE] = { .name = "check_code", .desc = "HTTP/SMTP/LDAP status code reported by the latest server health check" },
197 [ST_F_CHECK_DURATION] = { .name = "check_duration", .desc = "Total duration of the latest server health check, in milliseconds" },
198 [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" },
199 [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" },
200 [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" },
201 [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" },
202 [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" },
203 [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)" },
204 [ST_F_HANAFAIL] = { .name = "hanafail", .desc = "Total number of failed checks caused by an 'on-error' directive after an 'observe' condition matched" },
205 [ST_F_REQ_RATE] = { .name = "req_rate", .desc = "Number of HTTP requests processed over the last second on this object" },
206 [ST_F_REQ_RATE_MAX] = { .name = "req_rate_max", .desc = "Highest value of 'req_rate' observed since the worker process started" },
207 [ST_F_REQ_TOT] = { .name = "req_tot", .desc = "Total number of HTTP requests processed by this object since the worker process started" },
208 [ST_F_CLI_ABRT] = { .name = "cli_abrt", .desc = "Total number of requests or connections aborted by the client since the worker process started" },
209 [ST_F_SRV_ABRT] = { .name = "srv_abrt", .desc = "Total number of requests or connections aborted by the server since the worker process started" },
210 [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" },
211 [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" },
212 [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)" },
213 [ST_F_COMP_RSP] = { .name = "comp_rsp", .desc = "Total number of HTTP responses that were compressed for this object since the worker process started" },
214 [ST_F_LASTSESS] = { .name = "lastsess", .desc = "How long ago some traffic was seen on this object on this worker process, in seconds" },
215 [ST_F_LAST_CHK] = { .name = "last_chk", .desc = "Short description of the latest health check report for this server (see also check_desc)" },
216 [ST_F_LAST_AGT] = { .name = "last_agt", .desc = "Short description of the latest agent check report for this server (see also agent_desc)" },
217 [ST_F_QTIME] = { .name = "qtime", .desc = "Time spent in the queue, in milliseconds, averaged over the 1024 last requests (backend/server)" },
218 [ST_F_CTIME] = { .name = "ctime", .desc = "Time spent waiting for a connection to complete, in milliseconds, averaged over the 1024 last requests (backend/server)" },
219 [ST_F_RTIME] = { .name = "rtime", .desc = "Time spent waiting for a server response, in milliseconds, averaged over the 1024 last requests (backend/server)" },
220 [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)" },
221 [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" },
222 [ST_F_AGENT_CODE] = { .name = "agent_code", .desc = "Status code reported by the latest server agent check" },
223 [ST_F_AGENT_DURATION] = { .name = "agent_duration", .desc = "Total duration of the latest server agent check, in milliseconds" },
224 [ST_F_CHECK_DESC] = { .name = "check_desc", .desc = "Textual description of the latest health check report for this server" },
225 [ST_F_AGENT_DESC] = { .name = "agent_desc", .desc = "Textual description of the latest agent check report for this server" },
226 [ST_F_CHECK_RISE] = { .name = "check_rise", .desc = "Number of successful health checks before declaring a server UP (server 'rise' setting)" },
227 [ST_F_CHECK_FALL] = { .name = "check_fall", .desc = "Number of failed health checks before declaring a server DOWN (server 'fall' setting)" },
228 [ST_F_CHECK_HEALTH] = { .name = "check_health", .desc = "Current server health check level (0..fall-1=DOWN, fall..rise-1=UP)" },
229 [ST_F_AGENT_RISE] = { .name = "agent_rise", .desc = "Number of successful agent checks before declaring a server UP (server 'rise' setting)" },
230 [ST_F_AGENT_FALL] = { .name = "agent_fall", .desc = "Number of failed agent checks before declaring a server DOWN (server 'fall' setting)" },
231 [ST_F_AGENT_HEALTH] = { .name = "agent_health", .desc = "Current server agent check level (0..fall-1=DOWN, fall..rise-1=UP)" },
232 [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" },
233 [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" },
234 [ST_F_MODE] = { .name = "mode", .desc = "'mode' setting (tcp/http/health/cli)" },
235 [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" },
236 [ST_F_CONN_RATE] = { .name = "conn_rate", .desc = "Number of new connections accepted over the last second on the frontend for this worker process" },
237 [ST_F_CONN_RATE_MAX] = { .name = "conn_rate_max", .desc = "Highest value of 'conn_rate' observed since the worker process started" },
238 [ST_F_CONN_TOT] = { .name = "conn_tot", .desc = "Total number of new connections accepted on this frontend since the worker process started" },
239 [ST_F_INTERCEPTED] = { .name = "intercepted", .desc = "Total number of HTTP requests intercepted on the frontend (redirects/stats/services) since the worker process started" },
240 [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" },
241 [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" },
242 [ST_F_WREW] = { .name = "wrew", .desc = "Total number of failed HTTP header rewrites since the worker process started" },
243 [ST_F_CONNECT] = { .name = "connect", .desc = "Total number of outgoing connection attempts on this backend/server since the worker process started" },
244 [ST_F_REUSE] = { .name = "reuse", .desc = "Total number of reused connection on this backend/server since the worker process started" },
245 [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" },
246 [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" },
247 [ST_F_SRV_ICUR] = { .name = "srv_icur", .desc = "Current number of idle connections available for reuse on this server" },
248 [ST_F_SRV_ILIM] = { .name = "src_ilim", .desc = "Limit on the number of available idle connections on this server (server 'pool_max_conn' directive)" },
William Lallemand74c24fb2016-11-21 17:18:36 +0100249};
250
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100251/* one line of info */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100252static THREAD_LOCAL struct field info[INF_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100253/* one line of stats */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100254static THREAD_LOCAL struct field stats[ST_F_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100255
Christopher Faulet6338a082019-09-09 15:50:54 +0200256static void stats_dump_json_schema(struct buffer *out);
William Lallemand74c24fb2016-11-21 17:18:36 +0100257
Christopher Fauletef779222018-10-31 08:47:01 +0100258static int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk)
259{
260 if (htx) {
Christopher Faulet69fc88c2019-01-07 14:27:53 +0100261 if (chk->data >= channel_htx_recv_max(chn, htx))
262 return 0;
Willy Tarreau0a7ef022019-05-28 10:30:11 +0200263 if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data)))
Christopher Fauletef779222018-10-31 08:47:01 +0100264 return 0;
Christopher Faulet5adbeeb2019-01-02 14:34:39 +0100265 channel_add_input(chn, chk->data);
Christopher Fauletef779222018-10-31 08:47:01 +0100266 chk->data = 0;
Christopher Fauletef779222018-10-31 08:47:01 +0100267 }
268 else {
269 if (ci_putchk(chn, chk) == -1)
270 return 0;
271 }
272 return 1;
273}
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100274
Christopher Fauleted7a0662019-01-14 11:07:34 +0100275static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interface *si)
276{
Christopher Fauletb7f88902019-07-15 21:56:43 +0200277 struct channel *req = si_oc(si);
278 struct htx *htx = htxbuf(&req->buf);
279 struct htx_blk *blk;
280 struct ist uri;
Christopher Fauleted7a0662019-01-14 11:07:34 +0100281
Christopher Fauletb7f88902019-07-15 21:56:43 +0200282 blk = htx_get_head_blk(htx);
283 BUG_ON(htx_get_blk_type(blk) != HTX_BLK_REQ_SL);
284 ALREADY_CHECKED(blk);
285 uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk));
286 return uri.ptr + appctx->ctx.stats.scope_str;
Christopher Fauleted7a0662019-01-14 11:07:34 +0100287}
288
William Lallemand74c24fb2016-11-21 17:18:36 +0100289/*
290 * http_stats_io_handler()
291 * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
292 * -> stats_dump_csv_header() // emits the CSV headers (same as above)
Simon Horman05ee2132017-01-04 09:37:25 +0100293 * -> stats_dump_json_header() // emits the JSON headers (same as above)
William Lallemand74c24fb2016-11-21 17:18:36 +0100294 * -> stats_dump_html_head() // emits the HTML headers
295 * -> stats_dump_html_info() // emits the equivalent of "show info" at the top
296 * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML
297 * -> stats_dump_html_px_hdr()
298 * -> stats_dump_fe_stats()
299 * -> stats_dump_li_stats()
300 * -> stats_dump_sv_stats()
301 * -> stats_dump_be_stats()
302 * -> stats_dump_html_px_end()
303 * -> stats_dump_html_end() // emits HTML trailer
Simon Horman05ee2132017-01-04 09:37:25 +0100304 * -> stats_dump_json_end() // emits JSON trailer
William Lallemand74c24fb2016-11-21 17:18:36 +0100305 */
306
307
William Lallemand74c24fb2016-11-21 17:18:36 +0100308/* Dumps the stats CSV header to the trash buffer which. The caller is responsible
309 * for clearing it if needed.
310 * NOTE: Some tools happen to rely on the field position instead of its name,
311 * so please only append new fields at the end, never in the middle.
312 */
313static void stats_dump_csv_header()
314{
315 int field;
316
317 chunk_appendf(&trash, "# ");
318 for (field = 0; field < ST_F_TOTAL_FIELDS; field++)
Willy Tarreaueaa55372019-10-09 07:39:11 +0200319 chunk_appendf(&trash, "%s,", stat_fields[field].name);
William Lallemand74c24fb2016-11-21 17:18:36 +0100320
321 chunk_appendf(&trash, "\n");
322}
323
324
325/* Emits a stats field without any surrounding element and properly encoded to
326 * resist CSV output. Returns non-zero on success, 0 if the buffer is full.
327 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200328int stats_emit_raw_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100329{
330 switch (field_format(f, 0)) {
331 case FF_EMPTY: return 1;
332 case FF_S32: return chunk_appendf(out, "%d", f->u.s32);
333 case FF_U32: return chunk_appendf(out, "%u", f->u.u32);
334 case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64);
335 case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64);
Christopher Faulet88a0db22019-09-24 16:35:10 +0200336 case FF_FLT: return chunk_appendf(out, "%f", f->u.flt);
William Lallemand74c24fb2016-11-21 17:18:36 +0100337 case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL;
338 default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type);
339 }
340}
341
342/* Emits a stats field prefixed with its type. No CSV encoding is prepared, the
343 * output is supposed to be used on its own line. Returns non-zero on success, 0
344 * if the buffer is full.
345 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200346int stats_emit_typed_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100347{
348 switch (field_format(f, 0)) {
349 case FF_EMPTY: return 1;
350 case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32);
351 case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32);
352 case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64);
353 case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64);
Christopher Faulet88a0db22019-09-24 16:35:10 +0200354 case FF_FLT: return chunk_appendf(out, "flt:%f", f->u.flt);
William Lallemand74c24fb2016-11-21 17:18:36 +0100355 case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0));
356 default: return chunk_appendf(out, "%08x:?", f->type);
357 }
358}
359
Simon Horman05ee2132017-01-04 09:37:25 +0100360/* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per
361 * the recommendation for interoperable integers in section 6 of RFC 7159.
362 */
363#define JSON_INT_MAX ((1ULL << 53) - 1)
364#define JSON_INT_MIN (0 - JSON_INT_MAX)
365
366/* Emits a stats field value and its type in JSON.
367 * Returns non-zero on success, 0 on error.
368 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200369int stats_emit_json_data_field(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100370{
371 int old_len;
372 char buf[20];
373 const char *type, *value = buf, *quote = "";
374
375 switch (field_format(f, 0)) {
376 case FF_EMPTY: return 1;
377 case FF_S32: type = "\"s32\"";
378 snprintf(buf, sizeof(buf), "%d", f->u.s32);
379 break;
380 case FF_U32: type = "\"u32\"";
381 snprintf(buf, sizeof(buf), "%u", f->u.u32);
382 break;
383 case FF_S64: type = "\"s64\"";
384 if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX)
385 return 0;
386 type = "\"s64\"";
387 snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64);
388 break;
389 case FF_U64: if (f->u.u64 > JSON_INT_MAX)
390 return 0;
391 type = "\"u64\"";
392 snprintf(buf, sizeof(buf), "%llu",
393 (unsigned long long) f->u.u64);
Christopher Faulet52c91bb2019-09-28 10:37:31 +0200394 break;
Christopher Faulet88a0db22019-09-24 16:35:10 +0200395 case FF_FLT: type = "\"flt\"";
396 snprintf(buf, sizeof(buf), "%f", f->u.flt);
Simon Horman05ee2132017-01-04 09:37:25 +0100397 break;
398 case FF_STR: type = "\"str\"";
399 value = field_str(f, 0);
400 quote = "\"";
401 break;
402 default: snprintf(buf, sizeof(buf), "%u", f->type);
403 type = buf;
404 value = "unknown";
405 quote = "\"";
406 break;
407 }
408
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200409 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100410 chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}",
411 type, quote, value, quote);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200412 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100413}
414
William Lallemand74c24fb2016-11-21 17:18:36 +0100415/* Emits an encoding of the field type on 3 characters followed by a delimiter.
416 * Returns non-zero on success, 0 if the buffer is full.
417 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200418int stats_emit_field_tags(struct buffer *out, const struct field *f,
419 char delim)
William Lallemand74c24fb2016-11-21 17:18:36 +0100420{
421 char origin, nature, scope;
422
423 switch (field_origin(f, 0)) {
424 case FO_METRIC: origin = 'M'; break;
425 case FO_STATUS: origin = 'S'; break;
426 case FO_KEY: origin = 'K'; break;
427 case FO_CONFIG: origin = 'C'; break;
428 case FO_PRODUCT: origin = 'P'; break;
429 default: origin = '?'; break;
430 }
431
432 switch (field_nature(f, 0)) {
433 case FN_GAUGE: nature = 'G'; break;
434 case FN_LIMIT: nature = 'L'; break;
435 case FN_MIN: nature = 'm'; break;
436 case FN_MAX: nature = 'M'; break;
437 case FN_RATE: nature = 'R'; break;
438 case FN_COUNTER: nature = 'C'; break;
439 case FN_DURATION: nature = 'D'; break;
440 case FN_AGE: nature = 'A'; break;
441 case FN_TIME: nature = 'T'; break;
442 case FN_NAME: nature = 'N'; break;
443 case FN_OUTPUT: nature = 'O'; break;
444 case FN_AVG: nature = 'a'; break;
445 default: nature = '?'; break;
446 }
447
448 switch (field_scope(f, 0)) {
449 case FS_PROCESS: scope = 'P'; break;
450 case FS_SERVICE: scope = 'S'; break;
451 case FS_SYSTEM: scope = 's'; break;
452 case FS_CLUSTER: scope = 'C'; break;
453 default: scope = '?'; break;
454 }
455
456 return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim);
457}
458
Simon Horman05ee2132017-01-04 09:37:25 +0100459/* Emits an encoding of the field type as JSON.
460 * Returns non-zero on success, 0 if the buffer is full.
461 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200462int stats_emit_json_field_tags(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100463{
464 const char *origin, *nature, *scope;
465 int old_len;
466
467 switch (field_origin(f, 0)) {
468 case FO_METRIC: origin = "Metric"; break;
469 case FO_STATUS: origin = "Status"; break;
470 case FO_KEY: origin = "Key"; break;
471 case FO_CONFIG: origin = "Config"; break;
472 case FO_PRODUCT: origin = "Product"; break;
473 default: origin = "Unknown"; break;
474 }
475
476 switch (field_nature(f, 0)) {
477 case FN_GAUGE: nature = "Gauge"; break;
478 case FN_LIMIT: nature = "Limit"; break;
479 case FN_MIN: nature = "Min"; break;
480 case FN_MAX: nature = "Max"; break;
481 case FN_RATE: nature = "Rate"; break;
482 case FN_COUNTER: nature = "Counter"; break;
483 case FN_DURATION: nature = "Duration"; break;
484 case FN_AGE: nature = "Age"; break;
485 case FN_TIME: nature = "Time"; break;
486 case FN_NAME: nature = "Name"; break;
487 case FN_OUTPUT: nature = "Output"; break;
488 case FN_AVG: nature = "Avg"; break;
489 default: nature = "Unknown"; break;
490 }
491
492 switch (field_scope(f, 0)) {
493 case FS_PROCESS: scope = "Process"; break;
494 case FS_SERVICE: scope = "Service"; break;
495 case FS_SYSTEM: scope = "System"; break;
496 case FS_CLUSTER: scope = "Cluster"; break;
497 default: scope = "Unknown"; break;
498 }
499
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200500 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100501 chunk_appendf(out, "\"tags\":{"
502 "\"origin\":\"%s\","
503 "\"nature\":\"%s\","
504 "\"scope\":\"%s\""
505 "}", origin, nature, scope);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200506 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100507}
William Lallemand74c24fb2016-11-21 17:18:36 +0100508
509/* Dump all fields from <stats> into <out> using CSV format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200510static int stats_dump_fields_csv(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +0200511 const struct field *stats, unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100512{
513 int field;
514
515 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
516 if (!stats_emit_raw_data_field(out, &stats[field]))
517 return 0;
518 if (!chunk_strcat(out, ","))
519 return 0;
520 }
521 chunk_strcat(out, "\n");
522 return 1;
523}
524
525/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200526static int stats_dump_fields_typed(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +0200527 const struct field *stats, unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100528{
529 int field;
530
531 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
532 if (!stats[field].type)
533 continue;
534
535 chunk_appendf(out, "%c.%u.%u.%d.%s.%u:",
536 stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' :
537 stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' :
538 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' :
539 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' :
540 '?',
541 stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32,
Willy Tarreaueaa55372019-10-09 07:39:11 +0200542 field, stat_fields[field].name, stats[ST_F_PID].u.u32);
William Lallemand74c24fb2016-11-21 17:18:36 +0100543
544 if (!stats_emit_field_tags(out, &stats[field], ':'))
545 return 0;
546 if (!stats_emit_typed_data_field(out, &stats[field]))
547 return 0;
Willy Tarreau6b19b142019-10-09 15:44:21 +0200548 if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", stat_fields[field].desc))
549 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +0100550 if (!chunk_strcat(out, "\n"))
551 return 0;
552 }
553 return 1;
554}
555
Simon Horman05ee2132017-01-04 09:37:25 +0100556/* Dump all fields from <stats> into <out> using the "show info json" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200557static int stats_dump_json_info_fields(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +0200558 const struct field *info, unsigned int flags)
Simon Horman05ee2132017-01-04 09:37:25 +0100559{
560 int field;
561 int started = 0;
562
563 if (!chunk_strcat(out, "["))
564 return 0;
565
566 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
567 int old_len;
568
569 if (!field_format(info, field))
570 continue;
571
572 if (started && !chunk_strcat(out, ","))
573 goto err;
574 started = 1;
575
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200576 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100577 chunk_appendf(out,
578 "{\"field\":{\"pos\":%d,\"name\":\"%s\"},"
579 "\"processNum\":%u,",
Willy Tarreaueaa55372019-10-09 07:39:11 +0200580 field, info_fields[field].name,
Simon Horman05ee2132017-01-04 09:37:25 +0100581 info[INF_PROCESS_NUM].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200582 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100583 goto err;
584
585 if (!stats_emit_json_field_tags(out, &info[field]))
586 goto err;
587
588 if (!stats_emit_json_data_field(out, &info[field]))
589 goto err;
590
591 if (!chunk_strcat(out, "}"))
592 goto err;
593 }
594
595 if (!chunk_strcat(out, "]"))
596 goto err;
597 return 1;
598
599err:
600 chunk_reset(out);
601 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
602 return 0;
603}
604
605/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200606static int stats_dump_fields_json(struct buffer *out,
607 const struct field *stats,
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +0200608 unsigned int flags)
Simon Horman05ee2132017-01-04 09:37:25 +0100609{
610 int field;
611 int started = 0;
612
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +0200613 if ((flags & STAT_STARTED) && !chunk_strcat(out, ","))
Simon Horman05ee2132017-01-04 09:37:25 +0100614 return 0;
615 if (!chunk_strcat(out, "["))
616 return 0;
617
618 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
619 const char *obj_type;
620 int old_len;
621
622 if (!stats[field].type)
623 continue;
624
625 if (started && !chunk_strcat(out, ","))
626 goto err;
627 started = 1;
628
629 switch (stats[ST_F_TYPE].u.u32) {
630 case STATS_TYPE_FE: obj_type = "Frontend"; break;
631 case STATS_TYPE_BE: obj_type = "Backend"; break;
632 case STATS_TYPE_SO: obj_type = "Listener"; break;
633 case STATS_TYPE_SV: obj_type = "Server"; break;
634 default: obj_type = "Unknown"; break;
635 }
636
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200637 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100638 chunk_appendf(out,
639 "{"
640 "\"objType\":\"%s\","
641 "\"proxyId\":%d,"
642 "\"id\":%d,"
643 "\"field\":{\"pos\":%d,\"name\":\"%s\"},"
644 "\"processNum\":%u,",
645 obj_type, stats[ST_F_IID].u.u32,
646 stats[ST_F_SID].u.u32, field,
Willy Tarreaueaa55372019-10-09 07:39:11 +0200647 stat_fields[field].name, stats[ST_F_PID].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200648 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100649 goto err;
650
651 if (!stats_emit_json_field_tags(out, &stats[field]))
652 goto err;
653
654 if (!stats_emit_json_data_field(out, &stats[field]))
655 goto err;
656
657 if (!chunk_strcat(out, "}"))
658 goto err;
659 }
660
661 if (!chunk_strcat(out, "]"))
662 goto err;
663
664 return 1;
665
666err:
667 chunk_reset(out);
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +0200668 if (flags & STAT_STARTED)
669 chunk_strcat(out, ",");
Simon Horman05ee2132017-01-04 09:37:25 +0100670 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
671 return 0;
672}
673
William Lallemand74c24fb2016-11-21 17:18:36 +0100674/* Dump all fields from <stats> into <out> using the HTML format. A column is
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200675 * reserved for the checkbox is STAT_ADMIN is set in <flags>. Some extra info
Willy Tarreau708c4162019-10-09 10:19:16 +0200676 * are provided if STAT_SHLGNDS is present in <flags>.
William Lallemand74c24fb2016-11-21 17:18:36 +0100677 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200678static int stats_dump_fields_html(struct buffer *out,
679 const struct field *stats,
680 unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100681{
Willy Tarreau83061a82018-07-13 11:56:34 +0200682 struct buffer src;
William Lallemand74c24fb2016-11-21 17:18:36 +0100683
684 if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) {
685 chunk_appendf(out,
686 /* name, queue */
687 "<tr class=\"frontend\">");
688
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200689 if (flags & STAT_ADMIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100690 /* Column sub-heading for Enable or Disable server */
691 chunk_appendf(out, "<td></td>");
692 }
693
694 chunk_appendf(out,
695 "<td class=ac>"
696 "<a name=\"%s/Frontend\"></a>"
697 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
698 "<td colspan=3></td>"
699 "",
700 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
701
702 chunk_appendf(out,
703 /* sessions rate : current */
704 "<td><u>%s<div class=tips><table class=det>"
705 "<tr><th>Current connection rate:</th><td>%s/s</td></tr>"
706 "<tr><th>Current session rate:</th><td>%s/s</td></tr>"
707 "",
708 U2H(stats[ST_F_RATE].u.u32),
709 U2H(stats[ST_F_CONN_RATE].u.u32),
710 U2H(stats[ST_F_RATE].u.u32));
711
712 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
713 chunk_appendf(out,
714 "<tr><th>Current request rate:</th><td>%s/s</td></tr>",
715 U2H(stats[ST_F_REQ_RATE].u.u32));
716
717 chunk_appendf(out,
718 "</table></div></u></td>"
719 /* sessions rate : max */
720 "<td><u>%s<div class=tips><table class=det>"
721 "<tr><th>Max connection rate:</th><td>%s/s</td></tr>"
722 "<tr><th>Max session rate:</th><td>%s/s</td></tr>"
723 "",
724 U2H(stats[ST_F_RATE_MAX].u.u32),
725 U2H(stats[ST_F_CONN_RATE_MAX].u.u32),
726 U2H(stats[ST_F_RATE_MAX].u.u32));
727
728 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
729 chunk_appendf(out,
730 "<tr><th>Max request rate:</th><td>%s/s</td></tr>",
731 U2H(stats[ST_F_REQ_RATE_MAX].u.u32));
732
733 chunk_appendf(out,
734 "</table></div></u></td>"
735 /* sessions rate : limit */
736 "<td>%s</td>",
737 LIM2A(stats[ST_F_RATE_LIM].u.u32, "-"));
738
739 chunk_appendf(out,
740 /* sessions: current, max, limit, total */
741 "<td>%s</td><td>%s</td><td>%s</td>"
742 "<td><u>%s<div class=tips><table class=det>"
743 "<tr><th>Cum. connections:</th><td>%s</td></tr>"
744 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
745 "",
746 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
747 U2H(stats[ST_F_STOT].u.u64),
748 U2H(stats[ST_F_CONN_TOT].u.u64),
749 U2H(stats[ST_F_STOT].u.u64));
750
751 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
752 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
753 chunk_appendf(out,
754 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
755 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
756 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
757 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
758 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
759 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
760 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
761 "<tr><th>- other responses:</th><td>%s</td></tr>"
762 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
Willy Tarreaua1214a52018-12-14 14:00:25 +0100763 "<tr><th>Cache lookups:</th><td>%s</td></tr>"
764 "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200765 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100766 "",
767 U2H(stats[ST_F_REQ_TOT].u.u64),
768 U2H(stats[ST_F_HRSP_1XX].u.u64),
769 U2H(stats[ST_F_HRSP_2XX].u.u64),
770 U2H(stats[ST_F_COMP_RSP].u.u64),
771 stats[ST_F_HRSP_2XX].u.u64 ?
772 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
773 U2H(stats[ST_F_HRSP_3XX].u.u64),
774 U2H(stats[ST_F_HRSP_4XX].u.u64),
775 U2H(stats[ST_F_HRSP_5XX].u.u64),
776 U2H(stats[ST_F_HRSP_OTHER].u.u64),
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200777 U2H(stats[ST_F_INTERCEPTED].u.u64),
Willy Tarreaua1214a52018-12-14 14:00:25 +0100778 U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
779 U2H(stats[ST_F_CACHE_HITS].u.u64),
780 stats[ST_F_CACHE_LOOKUPS].u.u64 ?
781 (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200782 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +0100783 }
784
785 chunk_appendf(out,
786 "</table></div></u></td>"
787 /* sessions: lbtot, lastsess */
788 "<td></td><td></td>"
789 /* bytes : in */
790 "<td>%s</td>"
791 "",
792 U2H(stats[ST_F_BIN].u.u64));
793
794 chunk_appendf(out,
795 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
796 "<td>%s%s<div class=tips><table class=det>"
797 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
798 "<tr><th>Compression in:</th><td>%s</td></tr>"
799 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
800 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
801 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
802 "</table></div>%s</td>",
803 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
804 U2H(stats[ST_F_BOUT].u.u64),
805 U2H(stats[ST_F_BOUT].u.u64),
806 U2H(stats[ST_F_COMP_IN].u.u64),
807 U2H(stats[ST_F_COMP_OUT].u.u64),
808 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
809 U2H(stats[ST_F_COMP_BYP].u.u64),
810 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
811 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,
812 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
813
814 chunk_appendf(out,
815 /* denied: req, resp */
816 "<td>%s</td><td>%s</td>"
817 /* errors : request, connect, response */
818 "<td>%s</td><td></td><td></td>"
819 /* warnings: retries, redispatches */
820 "<td></td><td></td>"
821 /* server status : reflect frontend status */
822 "<td class=ac>%s</td>"
823 /* rest of server: nothing */
824 "<td class=ac colspan=8></td></tr>"
825 "",
826 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
827 U2H(stats[ST_F_EREQ].u.u64),
828 field_str(stats, ST_F_STATUS));
829 }
830 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) {
831 chunk_appendf(out, "<tr class=socket>");
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200832 if (flags & STAT_ADMIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100833 /* Column sub-heading for Enable or Disable server */
834 chunk_appendf(out, "<td></td>");
835 }
836
837 chunk_appendf(out,
838 /* frontend name, listener name */
839 "<td class=ac><a name=\"%s/+%s\"></a>%s"
840 "<a class=lfsb href=\"#%s/+%s\">%s</a>"
841 "",
842 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
Willy Tarreau708c4162019-10-09 10:19:16 +0200843 (flags & STAT_SHLGNDS)?"<u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +0100844 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
845
Willy Tarreau708c4162019-10-09 10:19:16 +0200846 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100847 chunk_appendf(out, "<div class=tips>");
848
849 if (isdigit(*field_str(stats, ST_F_ADDR)))
850 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
851 else if (*field_str(stats, ST_F_ADDR) == '[')
852 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
853 else if (*field_str(stats, ST_F_ADDR))
854 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
855
856 /* id */
857 chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32);
858 }
859
860 chunk_appendf(out,
861 /* queue */
862 "%s</td><td colspan=3></td>"
863 /* sessions rate: current, max, limit */
864 "<td colspan=3>&nbsp;</td>"
865 /* sessions: current, max, limit, total, lbtot, lastsess */
866 "<td>%s</td><td>%s</td><td>%s</td>"
867 "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
868 /* bytes: in, out */
869 "<td>%s</td><td>%s</td>"
870 "",
Willy Tarreau708c4162019-10-09 10:19:16 +0200871 (flags & STAT_SHLGNDS)?"</u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +0100872 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
873 U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64));
874
875 chunk_appendf(out,
876 /* denied: req, resp */
877 "<td>%s</td><td>%s</td>"
878 /* errors: request, connect, response */
879 "<td>%s</td><td></td><td></td>"
880 /* warnings: retries, redispatches */
881 "<td></td><td></td>"
882 /* server status: reflect listener status */
883 "<td class=ac>%s</td>"
884 /* rest of server: nothing */
885 "<td class=ac colspan=8></td></tr>"
886 "",
887 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
888 U2H(stats[ST_F_EREQ].u.u64),
889 field_str(stats, ST_F_STATUS));
890 }
891 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) {
892 const char *style;
893
894 /* determine the style to use depending on the server's state,
895 * its health and weight. There isn't a 1-to-1 mapping between
896 * state and styles for the cases where the server is (still)
897 * up. The reason is that we don't want to report nolb and
898 * drain with the same color.
899 */
900
901 if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 ||
902 strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) {
903 style = "down";
904 }
905 else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) {
906 style = "going_up";
907 }
908 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) {
909 style = "going_down";
910 }
911 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) {
912 style = "nolb";
913 }
914 else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) {
915 style = "no_check";
916 }
917 else if (!stats[ST_F_CHKFAIL].type ||
918 stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) {
919 /* no check or max health = UP */
920 if (stats[ST_F_WEIGHT].u.u32)
921 style = "up";
922 else
923 style = "draining";
924 }
925 else {
926 style = "going_down";
927 }
928
929 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0)
930 chunk_appendf(out, "<tr class=\"maintain\">");
931 else
932 chunk_appendf(out,
933 "<tr class=\"%s_%s\">",
934 (stats[ST_F_BCK].u.u32) ? "backup" : "active", style);
935
936
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200937 if (flags & STAT_ADMIN)
William Lallemand74c24fb2016-11-21 17:18:36 +0100938 chunk_appendf(out,
David Harrigand3db35a2016-12-30 12:12:49 +0000939 "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
940 field_str(stats, ST_F_PXNAME),
William Lallemand74c24fb2016-11-21 17:18:36 +0100941 field_str(stats, ST_F_SVNAME));
942
943 chunk_appendf(out,
944 "<td class=ac><a name=\"%s/%s\"></a>%s"
945 "<a class=lfsb href=\"#%s/%s\">%s</a>"
946 "",
947 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
Willy Tarreau708c4162019-10-09 10:19:16 +0200948 (flags & STAT_SHLGNDS) ? "<u>" : "",
William Lallemand74c24fb2016-11-21 17:18:36 +0100949 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
950
Willy Tarreau708c4162019-10-09 10:19:16 +0200951 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100952 chunk_appendf(out, "<div class=tips>");
953
954 if (isdigit(*field_str(stats, ST_F_ADDR)))
955 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
956 else if (*field_str(stats, ST_F_ADDR) == '[')
957 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
958 else if (*field_str(stats, ST_F_ADDR))
959 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
960
961 /* id */
962 chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32);
963
964 /* cookie */
965 if (stats[ST_F_COOKIE].type) {
966 chunk_appendf(out, ", cookie: '");
967 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
968 chunk_htmlencode(out, &src);
969 chunk_appendf(out, "'");
970 }
971
972 chunk_appendf(out, "</div>");
973 }
974
975 chunk_appendf(out,
976 /* queue : current, max, limit */
977 "%s</td><td>%s</td><td>%s</td><td>%s</td>"
978 /* sessions rate : current, max, limit */
979 "<td>%s</td><td>%s</td><td></td>"
980 "",
Willy Tarreau708c4162019-10-09 10:19:16 +0200981 (flags & STAT_SHLGNDS) ? "</u>" : "",
William Lallemand74c24fb2016-11-21 17:18:36 +0100982 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"),
983 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
984
985 chunk_appendf(out,
986 /* sessions: current, max, limit, total */
Willy Tarreauf21d17b2019-09-08 09:24:56 +0200987 "<td><u>%s<div class=tips>"
988 "<table class=det>"
989 "<tr><th>Current active connections:</th><td>%s</td></tr>"
990 "<tr><th>Current idle connections:</th><td>%s</td></tr>"
991 "<tr><th>Active connections limit:</th><td>%s</td></tr>"
992 "<tr><th>Idle connections limit:</th><td>%s</td></tr>"
993 "</table></div></u>"
994 "</td><td>%s</td><td>%s</td>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100995 "<td><u>%s<div class=tips><table class=det>"
996 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
997 "",
Willy Tarreauf21d17b2019-09-08 09:24:56 +0200998 U2H(stats[ST_F_SCUR].u.u32),
999 U2H(stats[ST_F_SCUR].u.u32),
1000 U2H(stats[ST_F_SRV_ICUR].u.u32),
1001 LIM2A(stats[ST_F_SLIM].u.u32, "-"),
1002 stats[ST_F_SRV_ILIM].type ? U2H(stats[ST_F_SRV_ILIM].u.u32) : "-",
1003 U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"),
William Lallemand74c24fb2016-11-21 17:18:36 +01001004 U2H(stats[ST_F_STOT].u.u64),
1005 U2H(stats[ST_F_STOT].u.u64));
1006
1007 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1008 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
1009 unsigned long long tot;
1010
1011 tot = stats[ST_F_HRSP_OTHER].u.u64;
1012 tot += stats[ST_F_HRSP_1XX].u.u64;
1013 tot += stats[ST_F_HRSP_2XX].u.u64;
1014 tot += stats[ST_F_HRSP_3XX].u.u64;
1015 tot += stats[ST_F_HRSP_4XX].u.u64;
1016 tot += stats[ST_F_HRSP_5XX].u.u64;
1017
1018 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +01001019 "<tr><th>New connections:</th><td>%s</td></tr>"
1020 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001021 "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
1022 "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1023 "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1024 "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1025 "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1026 "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1027 "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001028 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001029 "",
Willy Tarreauf1573842018-12-14 11:35:36 +01001030 U2H(stats[ST_F_CONNECT].u.u64),
1031 U2H(stats[ST_F_REUSE].u.u64),
1032 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
1033 (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0,
William Lallemand74c24fb2016-11-21 17:18:36 +01001034 U2H(tot),
1035 U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0,
1036 U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0,
1037 U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0,
1038 U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0,
1039 U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0,
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001040 U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0,
1041 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +01001042 }
1043
1044 chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>");
1045 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
1046 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
1047 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
1048 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
1049 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
1050
1051 chunk_appendf(out,
1052 "</table></div></u></td>"
1053 /* sessions: lbtot, last */
1054 "<td>%s</td><td>%s</td>",
1055 U2H(stats[ST_F_LBTOT].u.u64),
1056 human_time(stats[ST_F_LASTSESS].u.s32, 1));
1057
1058 chunk_appendf(out,
1059 /* bytes : in, out */
1060 "<td>%s</td><td>%s</td>"
1061 /* denied: req, resp */
1062 "<td></td><td>%s</td>"
1063 /* errors : request, connect */
1064 "<td></td><td>%s</td>"
1065 /* errors : response */
1066 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1067 /* warnings: retries, redispatches */
1068 "<td>%lld</td><td>%lld</td>"
1069 "",
1070 U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64),
1071 U2H(stats[ST_F_DRESP].u.u64),
1072 U2H(stats[ST_F_ECON].u.u64),
1073 U2H(stats[ST_F_ERESP].u.u64),
1074 (long long)stats[ST_F_CLI_ABRT].u.u64,
1075 (long long)stats[ST_F_SRV_ABRT].u.u64,
1076 (long long)stats[ST_F_WRETR].u.u64,
1077 (long long)stats[ST_F_WREDIS].u.u64);
1078
1079 /* status, last change */
1080 chunk_appendf(out, "<td class=ac>");
1081
1082 /* FIXME!!!!
1083 * LASTCHG should contain the last change for *this* server and must be computed
1084 * properly above, as was done below, ie: this server if maint, otherwise ref server
1085 * if tracking. Note that ref is either local or remote depending on tracking.
1086 */
1087
1088
1089 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) {
1090 chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1));
1091 }
1092 else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) {
1093 chunk_strcat(out, "<i>no check</i>");
1094 }
1095 else {
1096 chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS));
1097 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) {
1098 if (stats[ST_F_CHECK_HEALTH].u.u32)
1099 chunk_strcat(out, " &uarr;");
1100 }
1101 else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1)
1102 chunk_strcat(out, " &darr;");
1103 }
1104
1105 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 &&
1106 stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) {
1107 chunk_appendf(out,
1108 "</td><td class=ac><u> %s",
1109 field_str(stats, ST_F_AGENT_STATUS));
1110
1111 if (stats[ST_F_AGENT_CODE].type)
1112 chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32);
1113
1114 if (stats[ST_F_AGENT_DURATION].type)
1115 chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64);
1116
1117 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC));
1118
1119 if (*field_str(stats, ST_F_LAST_AGT)) {
1120 chunk_appendf(out, ": ");
1121 chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT));
1122 chunk_htmlencode(out, &src);
1123 }
1124 chunk_appendf(out, "</div></u>");
1125 }
1126 else if (stats[ST_F_CHECK_STATUS].type) {
1127 chunk_appendf(out,
1128 "</td><td class=ac><u> %s",
1129 field_str(stats, ST_F_CHECK_STATUS));
1130
1131 if (stats[ST_F_CHECK_CODE].type)
1132 chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32);
1133
1134 if (stats[ST_F_CHECK_DURATION].type)
1135 chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64);
1136
1137 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC));
1138
1139 if (*field_str(stats, ST_F_LAST_CHK)) {
1140 chunk_appendf(out, ": ");
1141 chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK));
1142 chunk_htmlencode(out, &src);
1143 }
1144 chunk_appendf(out, "</div></u>");
1145 }
1146 else
1147 chunk_appendf(out, "</td><td>");
1148
1149 chunk_appendf(out,
1150 /* weight */
1151 "</td><td class=ac>%d</td>"
1152 /* act, bck */
1153 "<td class=ac>%s</td><td class=ac>%s</td>"
1154 "",
1155 stats[ST_F_WEIGHT].u.u32,
1156 stats[ST_F_BCK].u.u32 ? "-" : "Y",
1157 stats[ST_F_BCK].u.u32 ? "Y" : "-");
1158
1159 /* check failures: unique, fatal, down time */
1160 if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) {
1161 chunk_appendf(out, "<td class=ac colspan=3>resolution</td>");
1162 }
1163 else if (stats[ST_F_CHKFAIL].type) {
1164 chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64);
1165
1166 if (stats[ST_F_HANAFAIL].type)
1167 chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64);
1168
1169 chunk_appendf(out,
1170 "<div class=tips>Failed Health Checks%s</div></u></td>"
1171 "<td>%lld</td><td>%s</td>"
1172 "",
1173 stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "",
1174 (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1));
1175 }
1176 else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) {
1177 /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */
1178 chunk_appendf(out,
1179 "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>",
1180 field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED));
1181 }
1182 else
1183 chunk_appendf(out, "<td colspan=3></td>");
1184
1185 /* throttle */
1186 if (stats[ST_F_THROTTLE].type)
1187 chunk_appendf(out, "<td class=ac>%d %%</td></tr>\n", stats[ST_F_THROTTLE].u.u32);
1188 else
1189 chunk_appendf(out, "<td class=ac>-</td></tr>\n");
1190 }
1191 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) {
1192 chunk_appendf(out, "<tr class=\"backend\">");
Willy Tarreauab02b3f2019-10-09 11:11:46 +02001193 if (flags & STAT_ADMIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001194 /* Column sub-heading for Enable or Disable server */
1195 chunk_appendf(out, "<td></td>");
1196 }
1197 chunk_appendf(out,
1198 "<td class=ac>"
1199 /* name */
1200 "%s<a name=\"%s/Backend\"></a>"
1201 "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
1202 "",
Willy Tarreau708c4162019-10-09 10:19:16 +02001203 (flags & STAT_SHLGNDS)?"<u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001204 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
1205
Willy Tarreau708c4162019-10-09 10:19:16 +02001206 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001207 /* balancing */
1208 chunk_appendf(out, "<div class=tips>balancing: %s",
1209 field_str(stats, ST_F_ALGO));
1210
1211 /* cookie */
1212 if (stats[ST_F_COOKIE].type) {
1213 chunk_appendf(out, ", cookie: '");
1214 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
1215 chunk_htmlencode(out, &src);
1216 chunk_appendf(out, "'");
1217 }
1218 chunk_appendf(out, "</div>");
1219 }
1220
1221 chunk_appendf(out,
1222 "%s</td>"
1223 /* queue : current, max */
1224 "<td>%s</td><td>%s</td><td></td>"
1225 /* sessions rate : current, max, limit */
1226 "<td>%s</td><td>%s</td><td></td>"
1227 "",
Willy Tarreau708c4162019-10-09 10:19:16 +02001228 (flags & STAT_SHLGNDS)?"</u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001229 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32),
1230 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
1231
1232 chunk_appendf(out,
1233 /* sessions: current, max, limit, total */
1234 "<td>%s</td><td>%s</td><td>%s</td>"
1235 "<td><u>%s<div class=tips><table class=det>"
1236 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
1237 "",
Willy Tarreau8e0f1752016-12-12 15:07:29 +01001238 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
William Lallemand74c24fb2016-11-21 17:18:36 +01001239 U2H(stats[ST_F_STOT].u.u64),
1240 U2H(stats[ST_F_STOT].u.u64));
1241
1242 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1243 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
1244 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +01001245 "<tr><th>New connections:</th><td>%s</td></tr>"
1246 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001247 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
1248 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
1249 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
1250 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
1251 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
1252 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
1253 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
1254 "<tr><th>- other responses:</th><td>%s</td></tr>"
Willy Tarreaua1214a52018-12-14 14:00:25 +01001255 "<tr><th>Cache lookups:</th><td>%s</td></tr>"
1256 "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001257 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001258 "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
1259 "",
Willy Tarreauf1573842018-12-14 11:35:36 +01001260 U2H(stats[ST_F_CONNECT].u.u64),
1261 U2H(stats[ST_F_REUSE].u.u64),
1262 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
1263 (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0,
William Lallemand74c24fb2016-11-21 17:18:36 +01001264 U2H(stats[ST_F_REQ_TOT].u.u64),
1265 U2H(stats[ST_F_HRSP_1XX].u.u64),
1266 U2H(stats[ST_F_HRSP_2XX].u.u64),
1267 U2H(stats[ST_F_COMP_RSP].u.u64),
1268 stats[ST_F_HRSP_2XX].u.u64 ?
1269 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
1270 U2H(stats[ST_F_HRSP_3XX].u.u64),
1271 U2H(stats[ST_F_HRSP_4XX].u.u64),
1272 U2H(stats[ST_F_HRSP_5XX].u.u64),
Willy Tarreaufeead3a2018-12-14 13:48:44 +01001273 U2H(stats[ST_F_HRSP_OTHER].u.u64),
Willy Tarreaua1214a52018-12-14 14:00:25 +01001274 U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
1275 U2H(stats[ST_F_CACHE_HITS].u.u64),
1276 stats[ST_F_CACHE_LOOKUPS].u.u64 ?
1277 (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
Willy Tarreaufeead3a2018-12-14 13:48:44 +01001278 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +01001279 }
1280
1281 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
1282 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
1283 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
1284 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
1285 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
1286
1287 chunk_appendf(out,
1288 "</table></div></u></td>"
1289 /* sessions: lbtot, last */
1290 "<td>%s</td><td>%s</td>"
1291 /* bytes: in */
1292 "<td>%s</td>"
1293 "",
1294 U2H(stats[ST_F_LBTOT].u.u64),
1295 human_time(stats[ST_F_LASTSESS].u.s32, 1),
1296 U2H(stats[ST_F_BIN].u.u64));
1297
1298 chunk_appendf(out,
1299 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
1300 "<td>%s%s<div class=tips><table class=det>"
1301 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
1302 "<tr><th>Compression in:</th><td>%s</td></tr>"
1303 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
1304 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
1305 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
1306 "</table></div>%s</td>",
1307 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
1308 U2H(stats[ST_F_BOUT].u.u64),
1309 U2H(stats[ST_F_BOUT].u.u64),
1310 U2H(stats[ST_F_COMP_IN].u.u64),
1311 U2H(stats[ST_F_COMP_OUT].u.u64),
1312 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
1313 U2H(stats[ST_F_COMP_BYP].u.u64),
1314 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
1315 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,
1316 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
1317
1318 chunk_appendf(out,
1319 /* denied: req, resp */
1320 "<td>%s</td><td>%s</td>"
1321 /* errors : request, connect */
1322 "<td></td><td>%s</td>"
1323 /* errors : response */
1324 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1325 /* warnings: retries, redispatches */
1326 "<td>%lld</td><td>%lld</td>"
1327 /* backend status: reflect backend status (up/down): we display UP
1328 * if the backend has known working servers or if it has no server at
1329 * all (eg: for stats). Then we display the total weight, number of
1330 * active and backups. */
1331 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
1332 "<td class=ac>%d</td><td class=ac>%d</td>"
1333 "",
1334 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
1335 U2H(stats[ST_F_ECON].u.u64),
1336 U2H(stats[ST_F_ERESP].u.u64),
1337 (long long)stats[ST_F_CLI_ABRT].u.u64,
1338 (long long)stats[ST_F_SRV_ABRT].u.u64,
1339 (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64,
1340 human_time(stats[ST_F_LASTCHG].u.u32, 1),
1341 strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>",
1342 stats[ST_F_WEIGHT].u.u32,
1343 stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32);
1344
1345 chunk_appendf(out,
1346 /* rest of backend: nothing, down transitions, total downtime, throttle */
1347 "<td class=ac>&nbsp;</td><td>%d</td>"
1348 "<td>%s</td>"
1349 "<td></td>"
1350 "</tr>",
1351 stats[ST_F_CHKDOWN].u.u32,
1352 stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : "&nbsp;");
1353 }
1354 return 1;
1355}
1356
Willy Tarreau43241ff2019-10-09 11:27:51 +02001357static int stats_dump_one_line(const struct field *stats, struct proxy *px, struct appctx *appctx)
William Lallemand74c24fb2016-11-21 17:18:36 +01001358{
Simon Horman05ee2132017-01-04 09:37:25 +01001359 int ret;
1360
William Lallemand74c24fb2016-11-21 17:18:36 +01001361 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Willy Tarreau43241ff2019-10-09 11:27:51 +02001362 ret = stats_dump_fields_html(&trash, stats, appctx->ctx.stats.flags);
William Lallemand74c24fb2016-11-21 17:18:36 +01001363 else if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
Willy Tarreau43241ff2019-10-09 11:27:51 +02001364 ret = stats_dump_fields_typed(&trash, stats, appctx->ctx.stats.flags);
Simon Horman05ee2132017-01-04 09:37:25 +01001365 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +02001366 ret = stats_dump_fields_json(&trash, stats, appctx->ctx.stats.flags);
William Lallemand74c24fb2016-11-21 17:18:36 +01001367 else
Willy Tarreau43241ff2019-10-09 11:27:51 +02001368 ret = stats_dump_fields_csv(&trash, stats, appctx->ctx.stats.flags);
Simon Horman05ee2132017-01-04 09:37:25 +01001369
1370 if (ret)
1371 appctx->ctx.stats.flags |= STAT_STARTED;
1372
1373 return ret;
William Lallemand74c24fb2016-11-21 17:18:36 +01001374}
1375
1376/* Fill <stats> with the frontend statistics. <stats> is
1377 * preallocated array of length <len>. The length of the array
1378 * must be at least ST_F_TOTAL_FIELDS. If this length is less then
1379 * this value, the function returns 0, otherwise, it returns 1.
1380 */
1381int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len)
1382{
1383 if (len < ST_F_TOTAL_FIELDS)
1384 return 0;
1385
1386 memset(stats, 0, sizeof(*stats) * len);
1387
1388 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1389 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND");
1390 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1391 stats[ST_F_SCUR] = mkf_u32(0, px->feconn);
1392 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1393 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1394 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1395 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1396 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1397 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1398 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1399 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1400 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1401 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1402 stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP");
1403 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1404 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1405 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1406 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE);
1407 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec));
1408 stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1409 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001410 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001411
1412 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1413 if (px->mode == PR_MODE_HTTP) {
1414 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1415 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1416 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1417 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1418 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1419 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1420 stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
Willy Tarreaua1214a52018-12-14 14:00:25 +01001421 stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1422 stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
William Lallemand74c24fb2016-11-21 17:18:36 +01001423 }
1424
1425 /* requests : req_rate, req_rate_max, req_tot, */
1426 stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec));
1427 stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1428 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1429
1430 /* compression: in, out, bypassed, responses */
1431 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1432 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1433 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1434 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1435
1436 /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */
1437 stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec));
1438 stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1439 stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1440
1441 return 1;
1442}
1443
1444/* Dumps a frontend's line to the trash for the current proxy <px> and uses
1445 * the state from stream interface <si>. The caller is responsible for clearing
1446 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
1447 */
1448static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
1449{
1450 struct appctx *appctx = __objt_appctx(si->end);
1451
1452 if (!(px->cap & PR_CAP_FE))
1453 return 0;
1454
1455 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE)))
1456 return 0;
1457
1458 if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS))
1459 return 0;
1460
Willy Tarreau43241ff2019-10-09 11:27:51 +02001461 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001462}
1463
1464/* Fill <stats> with the listener statistics. <stats> is
1465 * preallocated array of length <len>. The length of the array
1466 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1467 * then this value, the function returns 0, otherwise, it
Willy Tarreau708c4162019-10-09 10:19:16 +02001468 * returns 1. <flags> can take the value STAT_SHLGNDS.
William Lallemand74c24fb2016-11-21 17:18:36 +01001469 */
1470int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
1471 struct field *stats, int len)
1472{
Willy Tarreau83061a82018-07-13 11:56:34 +02001473 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001474
1475 if (len < ST_F_TOTAL_FIELDS)
1476 return 0;
1477
1478 if (!l->counters)
1479 return 0;
1480
1481 chunk_reset(out);
1482 memset(stats, 0, sizeof(*stats) * len);
1483
1484 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1485 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name);
1486 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1487 stats[ST_F_SCUR] = mkf_u32(0, l->nbconn);
1488 stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max);
1489 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn);
1490 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn);
1491 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in);
1492 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out);
1493 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req);
1494 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp);
1495 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req);
1496 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn);
1497 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess);
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001498 stats[ST_F_STATUS] = mkf_str(FO_STATUS, (!l->maxconn || l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
William Lallemand74c24fb2016-11-21 17:18:36 +01001499 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1500 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1501 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid);
1502 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001503 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, l->counters->failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001504
Willy Tarreau708c4162019-10-09 10:19:16 +02001505 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001506 char str[INET6_ADDRSTRLEN];
1507 int port;
1508
1509 port = get_host_port(&l->addr);
1510 switch (addr_to_str(&l->addr, str, sizeof(str))) {
1511 case AF_INET:
1512 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1513 chunk_appendf(out, "%s:%d", str, port);
1514 break;
1515 case AF_INET6:
1516 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1517 chunk_appendf(out, "[%s]:%d", str, port);
1518 break;
1519 case AF_UNIX:
1520 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1521 break;
1522 case -1:
1523 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1524 chunk_strcat(out, strerror(errno));
1525 break;
1526 default: /* address family not supported */
1527 break;
1528 }
1529 }
1530
1531 return 1;
1532}
1533
1534/* Dumps a line for listener <l> and proxy <px> to the trash and uses the state
Willy Tarreau43241ff2019-10-09 11:27:51 +02001535 * from stream interface <si>. The caller is responsible for clearing the trash
1536 * if needed. Returns non-zero if it emits anything, zero otherwise.
William Lallemand74c24fb2016-11-21 17:18:36 +01001537 */
Willy Tarreau43241ff2019-10-09 11:27:51 +02001538static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l)
William Lallemand74c24fb2016-11-21 17:18:36 +01001539{
1540 struct appctx *appctx = __objt_appctx(si->end);
1541
Willy Tarreau43241ff2019-10-09 11:27:51 +02001542 if (!stats_fill_li_stats(px, l, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
William Lallemand74c24fb2016-11-21 17:18:36 +01001543 return 0;
1544
Willy Tarreau43241ff2019-10-09 11:27:51 +02001545 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001546}
1547
1548enum srv_stats_state {
1549 SRV_STATS_STATE_DOWN = 0,
1550 SRV_STATS_STATE_DOWN_AGENT,
1551 SRV_STATS_STATE_GOING_UP,
1552 SRV_STATS_STATE_UP_GOING_DOWN,
1553 SRV_STATS_STATE_UP,
1554 SRV_STATS_STATE_NOLB_GOING_DOWN,
1555 SRV_STATS_STATE_NOLB,
1556 SRV_STATS_STATE_DRAIN_GOING_DOWN,
1557 SRV_STATS_STATE_DRAIN,
1558 SRV_STATS_STATE_DRAIN_AGENT,
1559 SRV_STATS_STATE_NO_CHECK,
1560
1561 SRV_STATS_STATE_COUNT, /* Must be last */
1562};
1563
1564static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
1565 [SRV_STATS_STATE_DOWN] = "DOWN",
1566 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)",
1567 [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d",
1568 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d",
1569 [SRV_STATS_STATE_UP] = "UP",
1570 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d",
1571 [SRV_STATS_STATE_NOLB] = "NOLB",
1572 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d",
1573 [SRV_STATS_STATE_DRAIN] = "DRAIN",
1574 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
1575 [SRV_STATS_STATE_NO_CHECK] = "no check"
1576};
1577
1578/* Fill <stats> with the server statistics. <stats> is
1579 * preallocated array of length <len>. The length of the array
1580 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1581 * then this value, the function returns 0, otherwise, it
Willy Tarreau708c4162019-10-09 10:19:16 +02001582 * returns 1. <flags> can take the value STAT_SHLGNDS.
William Lallemand74c24fb2016-11-21 17:18:36 +01001583 */
1584int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
1585 struct field *stats, int len)
1586{
1587 struct server *via, *ref;
1588 char str[INET6_ADDRSTRLEN];
Willy Tarreau83061a82018-07-13 11:56:34 +02001589 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001590 enum srv_stats_state state;
1591 char *fld_status;
1592
1593 if (len < ST_F_TOTAL_FIELDS)
1594 return 0;
1595
1596 memset(stats, 0, sizeof(*stats) * len);
1597
1598 /* we have "via" which is the tracked server as described in the configuration,
1599 * and "ref" which is the checked server and the end of the chain.
1600 */
1601 via = sv->track ? sv->track : sv;
1602 ref = via;
1603 while (ref->track)
1604 ref = ref->track;
1605
Emeric Brun52a91d32017-08-31 14:41:55 +02001606 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001607 if ((ref->check.state & CHK_ST_ENABLED) &&
1608 (ref->check.health < ref->check.rise + ref->check.fall - 1)) {
1609 state = SRV_STATS_STATE_UP_GOING_DOWN;
1610 } else {
1611 state = SRV_STATS_STATE_UP;
1612 }
1613
Emeric Brun52a91d32017-08-31 14:41:55 +02001614 if (sv->cur_admin & SRV_ADMF_DRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001615 if (ref->agent.state & CHK_ST_ENABLED)
1616 state = SRV_STATS_STATE_DRAIN_AGENT;
1617 else if (state == SRV_STATS_STATE_UP_GOING_DOWN)
1618 state = SRV_STATS_STATE_DRAIN_GOING_DOWN;
1619 else
1620 state = SRV_STATS_STATE_DRAIN;
1621 }
1622
1623 if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) {
1624 state = SRV_STATS_STATE_NO_CHECK;
1625 }
1626 }
Emeric Brun52a91d32017-08-31 14:41:55 +02001627 else if (sv->cur_state == SRV_ST_STOPPING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001628 if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) ||
1629 (ref->check.health == ref->check.rise + ref->check.fall - 1)) {
1630 state = SRV_STATS_STATE_NOLB;
1631 } else {
1632 state = SRV_STATS_STATE_NOLB_GOING_DOWN;
1633 }
1634 }
1635 else { /* stopped */
1636 if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) {
1637 state = SRV_STATS_STATE_DOWN_AGENT;
1638 } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) {
1639 state = SRV_STATS_STATE_DOWN; /* DOWN */
1640 } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) {
1641 state = SRV_STATS_STATE_GOING_UP;
1642 } else {
1643 state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */
1644 }
1645 }
1646
1647 chunk_reset(out);
1648
1649 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1650 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id);
1651 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1652 stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend);
1653 stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1654 stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess);
1655 stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1656
1657 if (sv->maxconn)
1658 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1659
Willy Tarreauf21d17b2019-09-08 09:24:56 +02001660 stats[ST_F_SRV_ICUR] = mkf_u32(0, sv->curr_idle_conns);
1661 if (sv->max_idle_conns != -1)
1662 stats[ST_F_SRV_ILIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->max_idle_conns);
1663
William Lallemand74c24fb2016-11-21 17:18:36 +01001664 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1665 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1666 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1667 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu);
1668 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1669 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1670 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries);
1671 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001672 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001673 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, sv->counters.connect);
1674 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, sv->counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001675
1676 /* status */
1677 fld_status = chunk_newstr(out);
Emeric Brun52a91d32017-08-31 14:41:55 +02001678 if (sv->cur_admin & SRV_ADMF_RMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001679 chunk_appendf(out, "MAINT (resolution)");
Emeric Brun52a91d32017-08-31 14:41:55 +02001680 else if (sv->cur_admin & SRV_ADMF_IMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001681 chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id);
Emeric Brun52a91d32017-08-31 14:41:55 +02001682 else if (sv->cur_admin & SRV_ADMF_MAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001683 chunk_appendf(out, "MAINT");
1684 else
1685 chunk_appendf(out,
1686 srv_hlt_st[state],
Emeric Brun52a91d32017-08-31 14:41:55 +02001687 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
1688 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
William Lallemand74c24fb2016-11-21 17:18:36 +01001689
1690 stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status);
1691 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
Emeric Brun52a91d32017-08-31 14:41:55 +02001692 stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv);
William Lallemand74c24fb2016-11-21 17:18:36 +01001693 stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1);
1694 stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0);
1695
1696 /* check failures: unique, fatal; last change, total downtime */
1697 if (sv->check.state & CHK_ST_ENABLED) {
1698 stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1699 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1700 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv));
1701 }
1702
1703 if (sv->maxqueue)
1704 stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1705
1706 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1707 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1708 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid);
1709
Emeric Brun52a91d32017-08-31 14:41:55 +02001710 if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv))
William Lallemand74c24fb2016-11-21 17:18:36 +01001711 stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv));
1712
1713 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1714
1715 if (sv->track) {
1716 char *fld_track = chunk_newstr(out);
1717
1718 chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id);
1719 stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track);
1720 }
1721
1722 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV);
1723 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec));
1724 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max);
1725
1726 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1727 const char *fld_chksts;
1728
1729 fld_chksts = chunk_newstr(out);
1730 chunk_strcat(out, "* "); // for check in progress
1731 chunk_strcat(out, get_check_status_info(sv->check.status));
1732 if (!(sv->check.state & CHK_ST_INPROGRESS))
1733 fld_chksts += 2; // skip "* "
1734 stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1735
1736 if (sv->check.status >= HCHK_STATUS_L57DATA)
1737 stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code);
1738
1739 if (sv->check.status >= HCHK_STATUS_CHECKED)
1740 stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration);
1741
1742 stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status));
1743 stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc);
1744 stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise);
1745 stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall);
1746 stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health);
1747 }
1748
1749 if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1750 const char *fld_chksts;
1751
1752 fld_chksts = chunk_newstr(out);
1753 chunk_strcat(out, "* "); // for check in progress
1754 chunk_strcat(out, get_check_status_info(sv->agent.status));
1755 if (!(sv->agent.state & CHK_ST_INPROGRESS))
1756 fld_chksts += 2; // skip "* "
1757 stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1758
1759 if (sv->agent.status >= HCHK_STATUS_L57DATA)
1760 stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code);
1761
1762 if (sv->agent.status >= HCHK_STATUS_CHECKED)
1763 stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration);
1764
1765 stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status));
1766 stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc);
1767 stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise);
1768 stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall);
1769 stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health);
1770 }
1771
1772 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1773 if (px->mode == PR_MODE_HTTP) {
1774 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1775 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1776 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1777 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1778 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
1779 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
1780 }
1781
1782 if (ref->observe)
1783 stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana);
1784
1785 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1786 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1787 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv));
1788
1789 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES));
1790 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES));
1791 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
1792 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
1793
Willy Tarreau708c4162019-10-09 10:19:16 +02001794 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001795 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
1796 case AF_INET:
1797 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001798 chunk_appendf(out, "%s:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001799 break;
1800 case AF_INET6:
1801 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001802 chunk_appendf(out, "[%s]:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001803 break;
1804 case AF_UNIX:
1805 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1806 break;
1807 case -1:
1808 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1809 chunk_strcat(out, strerror(errno));
1810 break;
1811 default: /* address family not supported */
1812 break;
1813 }
1814
1815 if (sv->cookie)
1816 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie);
1817 }
1818
1819 return 1;
1820}
1821
1822/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
Willy Tarreau43241ff2019-10-09 11:27:51 +02001823 * from stream interface <si>, and server state <state>. The caller is
1824 * responsible for clearing the trash if needed. Returns non-zero if it emits
1825 * anything, zero otherwise.
William Lallemand74c24fb2016-11-21 17:18:36 +01001826 */
Willy Tarreau43241ff2019-10-09 11:27:51 +02001827static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, struct server *sv)
William Lallemand74c24fb2016-11-21 17:18:36 +01001828{
1829 struct appctx *appctx = __objt_appctx(si->end);
1830
Willy Tarreau43241ff2019-10-09 11:27:51 +02001831 if (!stats_fill_sv_stats(px, sv, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
William Lallemand74c24fb2016-11-21 17:18:36 +01001832 return 0;
1833
Willy Tarreau43241ff2019-10-09 11:27:51 +02001834 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001835}
1836
1837/* Fill <stats> with the backend statistics. <stats> is
1838 * preallocated array of length <len>. The length of the array
1839 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1840 * then this value, the function returns 0, otherwise, it
Willy Tarreau708c4162019-10-09 10:19:16 +02001841 * returns 1. <flags> can take the value STAT_SHLGNDS.
William Lallemand74c24fb2016-11-21 17:18:36 +01001842 */
1843int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len)
1844{
1845 if (len < ST_F_TOTAL_FIELDS)
1846 return 0;
1847
1848 memset(stats, 0, sizeof(*stats) * len);
1849
1850 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1851 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND");
1852 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1853 stats[ST_F_QCUR] = mkf_u32(0, px->nbpend);
1854 stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
Thierry FOURNIER0ff98a42016-12-19 16:50:42 +01001855 stats[ST_F_SCUR] = mkf_u32(0, px->beconn);
William Lallemand74c24fb2016-11-21 17:18:36 +01001856 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max);
1857 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1858 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1859 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1860 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1861 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1862 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1863 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1864 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1865 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries);
1866 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001867 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001868 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, px->be_counters.connect);
1869 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, px->be_counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001870 stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN");
1871 stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv);
1872 stats[ST_F_ACT] = mkf_u32(0, px->srv_act);
1873 stats[ST_F_BCK] = mkf_u32(0, px->srv_bck);
1874 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans);
1875 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1876 if (px->srv)
1877 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px));
1878
1879 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1880 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1881 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1882 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1883 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE);
1884 stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec));
1885 stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max);
1886
Willy Tarreau708c4162019-10-09 10:19:16 +02001887 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001888 if (px->cookie_name)
1889 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name);
1890 stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
1891 }
1892
1893 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1894 if (px->mode == PR_MODE_HTTP) {
1895 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1896 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1897 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1898 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1899 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1900 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1901 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
Willy Tarreaua1214a52018-12-14 14:00:25 +01001902 stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1903 stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
William Lallemand74c24fb2016-11-21 17:18:36 +01001904 }
1905
1906 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1907 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1908
1909 /* compression: in, out, bypassed, responses */
1910 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1911 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1912 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1913 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1914 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px));
1915
1916 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES));
1917 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES));
1918 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES));
1919 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
1920
1921 return 1;
1922}
1923
1924/* Dumps a line for backend <px> to the trash for and uses the state from stream
Willy Tarreau43241ff2019-10-09 11:27:51 +02001925 * interface <si>. The caller is responsible for clearing the trash if needed.
1926 * Returns non-zero if it emits anything, zero otherwise.
William Lallemand74c24fb2016-11-21 17:18:36 +01001927 */
Willy Tarreau43241ff2019-10-09 11:27:51 +02001928static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px)
William Lallemand74c24fb2016-11-21 17:18:36 +01001929{
1930 struct appctx *appctx = __objt_appctx(si->end);
1931
1932 if (!(px->cap & PR_CAP_BE))
1933 return 0;
1934
1935 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
1936 return 0;
1937
Willy Tarreau43241ff2019-10-09 11:27:51 +02001938 if (!stats_fill_be_stats(px, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
William Lallemand74c24fb2016-11-21 17:18:36 +01001939 return 0;
1940
Willy Tarreau43241ff2019-10-09 11:27:51 +02001941 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001942}
1943
1944/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from
1945 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
1946 * for clearing the trash if needed.
1947 */
Willy Tarreau676c29e2019-10-09 10:50:01 +02001948static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px)
William Lallemand74c24fb2016-11-21 17:18:36 +01001949{
1950 struct appctx *appctx = __objt_appctx(si->end);
1951 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
1952
1953 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
1954 /* A form to enable/disable this proxy servers */
1955
1956 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
1957 scope_txt[0] = 0;
1958 if (appctx->ctx.stats.scope_len) {
Christopher Fauleted7a0662019-01-14 11:07:34 +01001959 const char *scope_ptr = stats_scope_ptr(appctx, si);
1960
William Lallemand74c24fb2016-11-21 17:18:36 +01001961 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01001962 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01001963 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
1964 }
1965
1966 chunk_appendf(&trash,
1967 "<form method=\"post\">");
1968 }
1969
1970 /* print a new table */
1971 chunk_appendf(&trash,
1972 "<table class=\"tbl\" width=\"100%%\">\n"
1973 "<tr class=\"titre\">"
1974 "<th class=\"pxname\" width=\"10%%\">");
1975
1976 chunk_appendf(&trash,
1977 "<a name=\"%s\"></a>%s"
1978 "<a class=px href=\"#%s\">%s</a>",
1979 px->id,
Willy Tarreau676c29e2019-10-09 10:50:01 +02001980 (appctx->ctx.stats.flags & STAT_SHLGNDS) ? "<u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001981 px->id, px->id);
1982
Willy Tarreau676c29e2019-10-09 10:50:01 +02001983 if (appctx->ctx.stats.flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001984 /* cap, mode, id */
1985 chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
1986 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
1987 px->uuid);
1988 chunk_appendf(&trash, "</div>");
1989 }
1990
1991 chunk_appendf(&trash,
1992 "%s</th>"
1993 "<th class=\"%s\" width=\"90%%\">%s</th>"
1994 "</tr>\n"
1995 "</table>\n"
1996 "<table class=\"tbl\" width=\"100%%\">\n"
1997 "<tr class=\"titre\">",
Willy Tarreau676c29e2019-10-09 10:50:01 +02001998 (appctx->ctx.stats.flags & STAT_SHLGNDS) ? "</u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001999 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
2000
2001 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
2002 /* Column heading for Enable or Disable server */
David Harrigand3db35a2016-12-30 12:12:49 +00002003 chunk_appendf(&trash,
2004 "<th rowspan=2 width=1><input type=\"checkbox\" \
2005 onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) \
2006 document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>",
2007 px->id,
2008 px->id);
William Lallemand74c24fb2016-11-21 17:18:36 +01002009 }
2010
2011 chunk_appendf(&trash,
2012 "<th rowspan=2></th>"
2013 "<th colspan=3>Queue</th>"
2014 "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
2015 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
2016 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
2017 "<th colspan=9>Server</th>"
2018 "</tr>\n"
2019 "<tr class=\"titre\">"
2020 "<th>Cur</th><th>Max</th><th>Limit</th>"
2021 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
2022 "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>"
2023 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
2024 "<th>Resp</th><th>Retr</th><th>Redis</th>"
2025 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
2026 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
2027 "<th>Thrtle</th>\n"
2028 "</tr>");
2029}
2030
2031/* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from
2032 * stream interface <si>. The caller is responsible for clearing the trash if needed.
2033 */
2034static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px)
2035{
2036 struct appctx *appctx = __objt_appctx(si->end);
2037 chunk_appendf(&trash, "</table>");
2038
2039 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
2040 /* close the form used to enable/disable this proxy servers */
2041 chunk_appendf(&trash,
2042 "Choose the action to perform on the checked servers : "
2043 "<select name=action>"
2044 "<option value=\"\"></option>"
2045 "<option value=\"ready\">Set state to READY</option>"
2046 "<option value=\"drain\">Set state to DRAIN</option>"
2047 "<option value=\"maint\">Set state to MAINT</option>"
2048 "<option value=\"dhlth\">Health: disable checks</option>"
2049 "<option value=\"ehlth\">Health: enable checks</option>"
2050 "<option value=\"hrunn\">Health: force UP</option>"
2051 "<option value=\"hnolb\">Health: force NOLB</option>"
2052 "<option value=\"hdown\">Health: force DOWN</option>"
2053 "<option value=\"dagent\">Agent: disable checks</option>"
2054 "<option value=\"eagent\">Agent: enable checks</option>"
2055 "<option value=\"arunn\">Agent: force UP</option>"
2056 "<option value=\"adown\">Agent: force DOWN</option>"
2057 "<option value=\"shutdown\">Kill Sessions</option>"
2058 "</select>"
2059 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
2060 "&nbsp;<input type=\"submit\" value=\"Apply\">"
2061 "</form>",
2062 px->uuid);
2063 }
2064
2065 chunk_appendf(&trash, "<p>\n");
2066}
2067
2068/*
2069 * Dumps statistics for a proxy. The output is sent to the stream interface's
2070 * input buffer. Returns 0 if it had to stop dumping data because of lack of
2071 * buffer space, or non-zero if everything completed. This function is used
2072 * both by the CLI and the HTTP entry points, and is able to dump the output
2073 * in HTML or CSV formats. If the later, <uri> must be NULL.
2074 */
Christopher Fauletef779222018-10-31 08:47:01 +01002075int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
2076 struct proxy *px, struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002077{
2078 struct appctx *appctx = __objt_appctx(si->end);
2079 struct stream *s = si_strm(si);
2080 struct channel *rep = si_ic(si);
2081 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
2082 struct listener *l;
William Lallemand74c24fb2016-11-21 17:18:36 +01002083
2084 chunk_reset(&trash);
2085
2086 switch (appctx->ctx.stats.px_st) {
2087 case STAT_PX_ST_INIT:
2088 /* we are on a new proxy */
2089 if (uri && uri->scope) {
2090 /* we have a limited scope, we have to check the proxy name */
2091 struct stat_scope *scope;
2092 int len;
2093
2094 len = strlen(px->id);
2095 scope = uri->scope;
2096
2097 while (scope) {
2098 /* match exact proxy name */
2099 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2100 break;
2101
2102 /* match '.' which means 'self' proxy */
2103 if (!strcmp(scope->px_id, ".") && px == s->be)
2104 break;
2105 scope = scope->next;
2106 }
2107
2108 /* proxy name not found : don't dump anything */
2109 if (scope == NULL)
2110 return 1;
2111 }
2112
2113 /* if the user has requested a limited output and the proxy
2114 * name does not match, skip it.
2115 */
Christopher Fauleted7a0662019-01-14 11:07:34 +01002116 if (appctx->ctx.stats.scope_len) {
2117 const char *scope_ptr = stats_scope_ptr(appctx, si);
2118
2119 if (strnistr(px->id, strlen(px->id), scope_ptr, appctx->ctx.stats.scope_len) == NULL)
2120 return 1;
2121 }
William Lallemand74c24fb2016-11-21 17:18:36 +01002122
2123 if ((appctx->ctx.stats.flags & STAT_BOUND) &&
2124 (appctx->ctx.stats.iid != -1) &&
2125 (px->uuid != appctx->ctx.stats.iid))
2126 return 1;
2127
2128 appctx->ctx.stats.px_st = STAT_PX_ST_TH;
2129 /* fall through */
2130
2131 case STAT_PX_ST_TH:
2132 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreau676c29e2019-10-09 10:50:01 +02002133 stats_dump_html_px_hdr(si, px);
Christopher Fauletef779222018-10-31 08:47:01 +01002134 if (!stats_putchk(rep, htx, &trash))
2135 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002136 }
2137
2138 appctx->ctx.stats.px_st = STAT_PX_ST_FE;
2139 /* fall through */
2140
2141 case STAT_PX_ST_FE:
2142 /* print the frontend */
2143 if (stats_dump_fe_stats(si, px)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002144 if (!stats_putchk(rep, htx, &trash))
2145 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002146 }
2147
2148 appctx->ctx.stats.l = px->conf.listeners.n;
2149 appctx->ctx.stats.px_st = STAT_PX_ST_LI;
2150 /* fall through */
2151
2152 case STAT_PX_ST_LI:
2153 /* stats.l has been initialized above */
2154 for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) {
Christopher Fauletef779222018-10-31 08:47:01 +01002155 if (htx) {
2156 if (htx_almost_full(htx))
2157 goto full;
2158 }
2159 else {
2160 if (buffer_almost_full(&rep->buf))
2161 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002162 }
2163
2164 l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe);
2165 if (!l->counters)
2166 continue;
2167
2168 if (appctx->ctx.stats.flags & STAT_BOUND) {
2169 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO)))
2170 break;
2171
2172 if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid)
2173 continue;
2174 }
2175
2176 /* print the frontend */
Willy Tarreau43241ff2019-10-09 11:27:51 +02002177 if (stats_dump_li_stats(si, px, l)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002178 if (!stats_putchk(rep, htx, &trash))
2179 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002180 }
2181 }
2182
2183 appctx->ctx.stats.sv = px->srv; /* may be NULL */
2184 appctx->ctx.stats.px_st = STAT_PX_ST_SV;
2185 /* fall through */
2186
2187 case STAT_PX_ST_SV:
2188 /* stats.sv has been initialized above */
2189 for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) {
Christopher Fauletef779222018-10-31 08:47:01 +01002190 if (htx) {
2191 if (htx_almost_full(htx))
2192 goto full;
2193 }
2194 else {
2195 if (buffer_almost_full(&rep->buf))
2196 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002197 }
2198
2199 sv = appctx->ctx.stats.sv;
2200
2201 if (appctx->ctx.stats.flags & STAT_BOUND) {
2202 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV)))
2203 break;
2204
2205 if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid)
2206 continue;
2207 }
2208
2209 svs = sv;
2210 while (svs->track)
2211 svs = svs->track;
2212
2213 /* do not report servers which are DOWN and not changing state */
2214 if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) &&
Emeric Brun52a91d32017-08-31 14:41:55 +02002215 ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */
2216 (sv->cur_state == SRV_ST_STOPPED && /* server is down */
William Lallemand74c24fb2016-11-21 17:18:36 +01002217 (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) ||
2218 ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) ||
2219 ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) {
2220 continue;
2221 }
2222
Willy Tarreau43241ff2019-10-09 11:27:51 +02002223 if (stats_dump_sv_stats(si, px, sv)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002224 if (!stats_putchk(rep, htx, &trash))
2225 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002226 }
2227 } /* for sv */
2228
2229 appctx->ctx.stats.px_st = STAT_PX_ST_BE;
2230 /* fall through */
2231
2232 case STAT_PX_ST_BE:
2233 /* print the backend */
Willy Tarreau43241ff2019-10-09 11:27:51 +02002234 if (stats_dump_be_stats(si, px)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002235 if (!stats_putchk(rep, htx, &trash))
2236 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002237 }
2238
2239 appctx->ctx.stats.px_st = STAT_PX_ST_END;
2240 /* fall through */
2241
2242 case STAT_PX_ST_END:
2243 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2244 stats_dump_html_px_end(si, px);
Christopher Fauletef779222018-10-31 08:47:01 +01002245 if (!stats_putchk(rep, htx, &trash))
2246 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002247 }
2248
2249 appctx->ctx.stats.px_st = STAT_PX_ST_FIN;
2250 /* fall through */
2251
2252 case STAT_PX_ST_FIN:
2253 return 1;
2254
2255 default:
2256 /* unknown state, we should put an abort() here ! */
2257 return 1;
2258 }
Christopher Fauletef779222018-10-31 08:47:01 +01002259
2260 full:
2261 si_rx_room_blk(si);
2262 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01002263}
2264
2265/* Dumps the HTTP stats head block to the trash for and uses the per-uri
2266 * parameters <uri>. The caller is responsible for clearing the trash if needed.
2267 */
Willy Tarreau676c29e2019-10-09 10:50:01 +02002268static void stats_dump_html_head(struct appctx *appctx, struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002269{
2270 /* WARNING! This must fit in the first buffer !!! */
2271 chunk_appendf(&trash,
2272 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
2273 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
2274 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
2275 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
2276 "<style type=\"text/css\"><!--\n"
2277 "body {"
2278 " font-family: arial, helvetica, sans-serif;"
2279 " font-size: 12px;"
2280 " font-weight: normal;"
2281 " color: black;"
2282 " background: white;"
2283 "}\n"
2284 "th,td {"
2285 " font-size: 10px;"
2286 "}\n"
2287 "h1 {"
2288 " font-size: x-large;"
2289 " margin-bottom: 0.5em;"
2290 "}\n"
2291 "h2 {"
2292 " font-family: helvetica, arial;"
2293 " font-size: x-large;"
2294 " font-weight: bold;"
2295 " font-style: italic;"
2296 " color: #6020a0;"
2297 " margin-top: 0em;"
2298 " margin-bottom: 0em;"
2299 "}\n"
2300 "h3 {"
2301 " font-family: helvetica, arial;"
2302 " font-size: 16px;"
2303 " font-weight: bold;"
2304 " color: #b00040;"
2305 " background: #e8e8d0;"
2306 " margin-top: 0em;"
2307 " margin-bottom: 0em;"
2308 "}\n"
2309 "li {"
2310 " margin-top: 0.25em;"
2311 " margin-right: 2em;"
2312 "}\n"
2313 ".hr {margin-top: 0.25em;"
2314 " border-color: black;"
2315 " border-bottom-style: solid;"
2316 "}\n"
2317 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
2318 ".total {background: #20D0D0;color: #ffff80;}\n"
2319 ".frontend {background: #e8e8d0;}\n"
2320 ".socket {background: #d0d0d0;}\n"
2321 ".backend {background: #e8e8d0;}\n"
2322 ".active_down {background: #ff9090;}\n"
2323 ".active_going_up {background: #ffd020;}\n"
2324 ".active_going_down {background: #ffffa0;}\n"
2325 ".active_up {background: #c0ffc0;}\n"
2326 ".active_nolb {background: #20a0ff;}\n"
2327 ".active_draining {background: #20a0FF;}\n"
2328 ".active_no_check {background: #e0e0e0;}\n"
2329 ".backup_down {background: #ff9090;}\n"
2330 ".backup_going_up {background: #ff80ff;}\n"
2331 ".backup_going_down {background: #c060ff;}\n"
2332 ".backup_up {background: #b0d0ff;}\n"
2333 ".backup_nolb {background: #90b0e0;}\n"
2334 ".backup_draining {background: #cc9900;}\n"
2335 ".backup_no_check {background: #e0e0e0;}\n"
2336 ".maintain {background: #c07820;}\n"
2337 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
2338 "\n"
2339 "a.px:link {color: #ffff40; text-decoration: none;}"
2340 "a.px:visited {color: #ffff40; text-decoration: none;}"
2341 "a.px:hover {color: #ffffff; text-decoration: none;}"
2342 "a.lfsb:link {color: #000000; text-decoration: none;}"
2343 "a.lfsb:visited {color: #000000; text-decoration: none;}"
2344 "a.lfsb:hover {color: #505050; text-decoration: none;}"
2345 "\n"
2346 "table.tbl { border-collapse: collapse; border-style: none;}\n"
2347 "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"
2348 "table.tbl td.ac { text-align: center;}\n"
2349 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
2350 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
2351 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
2352 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
2353 "\n"
2354 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
2355 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
2356 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
2357 "table.det { border-collapse: collapse; border-style: none; }\n"
2358 "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"
2359 "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"
2360 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
2361 "div.tips {\n"
2362 " display:block;\n"
2363 " visibility:hidden;\n"
2364 " z-index:2147483647;\n"
2365 " position:absolute;\n"
2366 " padding:2px 4px 3px;\n"
2367 " background:#f0f060; color:#000000;\n"
2368 " border:1px solid #7040c0;\n"
2369 " white-space:nowrap;\n"
2370 " font-style:normal;font-size:11px;font-weight:normal;\n"
2371 " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n"
2372 " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n"
2373 "}\n"
2374 "u:hover div.tips {visibility:visible;}\n"
2375 "-->\n"
2376 "</style></head>\n",
Willy Tarreau676c29e2019-10-09 10:50:01 +02002377 (appctx->ctx.stats.flags & STAT_SHNODE) ? " on " : "",
2378 (appctx->ctx.stats.flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : ""
William Lallemand74c24fb2016-11-21 17:18:36 +01002379 );
2380}
2381
2382/* Dumps the HTML stats information block to the trash for and uses the state from
2383 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
2384 * for clearing the trash if needed.
2385 */
2386static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri)
2387{
2388 struct appctx *appctx = __objt_appctx(si->end);
2389 unsigned int up = (now.tv_sec - start_date.tv_sec);
2390 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Christopher Fauleted7a0662019-01-14 11:07:34 +01002391 const char *scope_ptr = stats_scope_ptr(appctx, si);
Willy Tarreau1713c032019-05-23 12:23:55 +02002392 unsigned long long bps = (unsigned long long)read_freq_ctr(&global.out_32bps) * 32;
2393
2394 /* Turn the bytes per second to bits per second and take care of the
2395 * usual ethernet overhead in order to help figure how far we are from
2396 * interface saturation since it's the only case which usually matters.
2397 * For this we count the total size of an Ethernet frame on the wire
2398 * including preamble and IFG (1538) for the largest TCP segment it
2399 * transports (1448 with TCP timestamps). This is not valid for smaller
2400 * packets (under-estimated), but it gives a reasonably accurate
2401 * estimation of how far we are from uplink saturation.
2402 */
2403 bps = bps * 8 * 1538 / 1448;
William Lallemand74c24fb2016-11-21 17:18:36 +01002404
2405 /* WARNING! this has to fit the first packet too.
2406 * We are around 3.5 kB, add adding entries will
2407 * become tricky if we want to support 4kB buffers !
2408 */
2409 chunk_appendf(&trash,
2410 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
2411 PRODUCT_NAME "%s</a></h1>\n"
2412 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
2413 "<hr width=\"100%%\" class=\"hr\">\n"
2414 "<h3>&gt; General process information</h3>\n"
2415 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Yves Lafon95317282018-02-26 11:10:37 +01002416 "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n"
William Lallemand74c24fb2016-11-21 17:18:36 +01002417 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
2418 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
2419 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
Willy Tarreau1713c032019-05-23 12:23:55 +02002420 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec; bit rate = %.3f %cbps<br>\n"
William Lallemand74c24fb2016-11-21 17:18:36 +01002421 "Running tasks: %d/%d; idle = %d %%<br>\n"
2422 "</td><td align=\"center\" nowrap>\n"
2423 "<table class=\"lgd\"><tr>\n"
2424 "<td class=\"active_up\">&nbsp;</td><td class=\"noborder\">active UP </td>"
2425 "<td class=\"backup_up\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
2426 "</tr><tr>\n"
2427 "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>"
2428 "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>"
2429 "</tr><tr>\n"
2430 "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>"
2431 "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>"
2432 "</tr><tr>\n"
2433 "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
2434 "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>"
2435 "</tr><tr>\n"
2436 "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) &nbsp;</td>"
2437 "</tr><tr>\n"
2438 "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance &nbsp;</td>"
2439 "</tr></table>\n"
2440 "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled."
2441 "</td>"
2442 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2443 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
2444 "",
Willy Tarreau676c29e2019-10-09 10:50:01 +02002445 (appctx->ctx.stats.flags & STAT_HIDEVER) ? "" : (stats_version_string),
2446 pid, (appctx->ctx.stats.flags & STAT_SHNODE) ? " on " : "",
2447 (appctx->ctx.stats.flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : "",
2448 (appctx->ctx.stats.flags & STAT_SHDESC) ? ": " : "",
2449 (appctx->ctx.stats.flags & STAT_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
Yves Lafon95317282018-02-26 11:10:37 +01002450 pid, relative_pid, global.nbproc, global.nbthread,
William Lallemand74c24fb2016-11-21 17:18:36 +01002451 up / 86400, (up % 86400) / 3600,
2452 (up % 3600) / 60, (up % 60),
2453 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
2454 global.rlimit_memmax ? " MB" : "",
2455 global.rlimit_nofile,
2456 global.maxsock, global.maxconn, global.maxpipes,
2457 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Willy Tarreau1713c032019-05-23 12:23:55 +02002458 bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0),
2459 bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k',
Willy Tarreau81036f22019-05-20 19:24:50 +02002460 tasks_run_queue_cur, nb_tasks_cur, ti->idle_pct
William Lallemand74c24fb2016-11-21 17:18:36 +01002461 );
2462
2463 /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Christopher Fauleted7a0662019-01-14 11:07:34 +01002464 memcpy(scope_txt, scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002465 scope_txt[appctx->ctx.stats.scope_len] = '\0';
2466
2467 chunk_appendf(&trash,
2468 "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n",
2469 (appctx->ctx.stats.scope_len > 0) ? scope_txt : "",
2470 STAT_SCOPE_TXT_MAXLEN);
2471
2472 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
2473 scope_txt[0] = 0;
2474 if (appctx->ctx.stats.scope_len) {
2475 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01002476 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002477 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
2478 }
2479
2480 if (appctx->ctx.stats.flags & STAT_HIDE_DOWN)
2481 chunk_appendf(&trash,
2482 "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n",
2483 uri->uri_prefix,
2484 "",
2485 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2486 scope_txt);
2487 else
2488 chunk_appendf(&trash,
2489 "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n",
2490 uri->uri_prefix,
2491 ";up",
2492 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2493 scope_txt);
2494
2495 if (uri->refresh > 0) {
2496 if (appctx->ctx.stats.flags & STAT_NO_REFRESH)
2497 chunk_appendf(&trash,
2498 "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n",
2499 uri->uri_prefix,
2500 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2501 "",
2502 scope_txt);
2503 else
2504 chunk_appendf(&trash,
2505 "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n",
2506 uri->uri_prefix,
2507 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2508 ";norefresh",
2509 scope_txt);
2510 }
2511
2512 chunk_appendf(&trash,
2513 "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n",
2514 uri->uri_prefix,
2515 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2516 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2517 scope_txt);
2518
2519 chunk_appendf(&trash,
2520 "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n",
2521 uri->uri_prefix,
2522 (uri->refresh > 0) ? ";norefresh" : "",
2523 scope_txt);
2524
2525 chunk_appendf(&trash,
Christopher Faulet6338a082019-09-09 15:50:54 +02002526 "<li><a href=\"%s;json%s%s\">JSON export</a> (<a href=\"%s;json-schema\">schema</a>)<br>\n",
2527 uri->uri_prefix,
2528 (uri->refresh > 0) ? ";norefresh" : "",
2529 scope_txt, uri->uri_prefix);
2530
2531 chunk_appendf(&trash,
William Lallemand74c24fb2016-11-21 17:18:36 +01002532 "</ul></td>"
2533 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2534 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
2535 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2536 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2537 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2538 "</ul>"
2539 "</td>"
2540 "</tr></table>\n"
2541 ""
2542 );
2543
2544 if (appctx->ctx.stats.st_code) {
2545 switch (appctx->ctx.stats.st_code) {
2546 case STAT_STATUS_DONE:
2547 chunk_appendf(&trash,
2548 "<p><div class=active_up>"
2549 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2550 "Action processed successfully."
2551 "</div>\n", uri->uri_prefix,
2552 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2553 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2554 scope_txt);
2555 break;
2556 case STAT_STATUS_NONE:
2557 chunk_appendf(&trash,
2558 "<p><div class=active_going_down>"
2559 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2560 "Nothing has changed."
2561 "</div>\n", uri->uri_prefix,
2562 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2563 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2564 scope_txt);
2565 break;
2566 case STAT_STATUS_PART:
2567 chunk_appendf(&trash,
2568 "<p><div class=active_going_down>"
2569 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2570 "Action partially processed.<br>"
2571 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2572 "</div>\n", uri->uri_prefix,
2573 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2574 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2575 scope_txt);
2576 break;
2577 case STAT_STATUS_ERRP:
2578 chunk_appendf(&trash,
2579 "<p><div class=active_down>"
2580 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2581 "Action not processed because of invalid parameters."
2582 "<ul>"
2583 "<li>The action is maybe unknown.</li>"
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002584 "<li>Invalid key parameter (empty or too long).</li>"
William Lallemand74c24fb2016-11-21 17:18:36 +01002585 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2586 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2587 "</ul>"
2588 "</div>\n", uri->uri_prefix,
2589 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2590 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2591 scope_txt);
2592 break;
2593 case STAT_STATUS_EXCD:
2594 chunk_appendf(&trash,
2595 "<p><div class=active_down>"
2596 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2597 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2598 "You should retry with less servers at a time.</b>"
2599 "</div>\n", uri->uri_prefix,
2600 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2601 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2602 scope_txt);
2603 break;
2604 case STAT_STATUS_DENY:
2605 chunk_appendf(&trash,
2606 "<p><div class=active_down>"
2607 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2608 "<b>Action denied.</b>"
2609 "</div>\n", uri->uri_prefix,
2610 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2611 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2612 scope_txt);
2613 break;
Christopher Faulet3c2ecf72019-02-27 16:41:27 +01002614 case STAT_STATUS_IVAL:
2615 chunk_appendf(&trash,
2616 "<p><div class=active_down>"
2617 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2618 "<b>Invalid requests (unsupported method or chunked encoded request).</b>"
2619 "</div>\n", uri->uri_prefix,
2620 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2621 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2622 scope_txt);
2623 break;
William Lallemand74c24fb2016-11-21 17:18:36 +01002624 default:
2625 chunk_appendf(&trash,
2626 "<p><div class=active_no_check>"
2627 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2628 "Unexpected result."
2629 "</div>\n", uri->uri_prefix,
2630 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2631 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2632 scope_txt);
2633 }
2634 chunk_appendf(&trash, "<p>\n");
2635 }
2636}
2637
2638/* Dumps the HTML stats trailer block to the trash. The caller is responsible
2639 * for clearing the trash if needed.
2640 */
2641static void stats_dump_html_end()
2642{
2643 chunk_appendf(&trash, "</body></html>\n");
2644}
2645
Simon Horman05ee2132017-01-04 09:37:25 +01002646/* Dumps the stats JSON header to the trash buffer which. The caller is responsible
2647 * for clearing it if needed.
2648 */
2649static void stats_dump_json_header()
2650{
2651 chunk_strcat(&trash, "[");
2652}
2653
2654
2655/* Dumps the JSON stats trailer block to the trash. The caller is responsible
2656 * for clearing the trash if needed.
2657 */
2658static void stats_dump_json_end()
2659{
2660 chunk_strcat(&trash, "]");
2661}
2662
William Lallemand74c24fb2016-11-21 17:18:36 +01002663/* This function dumps statistics onto the stream interface's read buffer in
2664 * either CSV or HTML format. <uri> contains some HTML-specific parameters that
2665 * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if
2666 * it had to stop writing data and an I/O is needed, 1 if the dump is finished
2667 * and the stream must be closed, or -1 in case of any error. This function is
2668 * used by both the CLI and the HTTP handlers.
2669 */
Christopher Fauletef779222018-10-31 08:47:01 +01002670static int stats_dump_stat_to_buffer(struct stream_interface *si, struct htx *htx,
2671 struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002672{
2673 struct appctx *appctx = __objt_appctx(si->end);
2674 struct channel *rep = si_ic(si);
2675 struct proxy *px;
2676
2677 chunk_reset(&trash);
2678
2679 switch (appctx->st2) {
2680 case STAT_ST_INIT:
2681 appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
2682 /* fall through */
2683
2684 case STAT_ST_HEAD:
2685 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Willy Tarreau676c29e2019-10-09 10:50:01 +02002686 stats_dump_html_head(appctx, uri);
Christopher Faulet6338a082019-09-09 15:50:54 +02002687 else if (appctx->ctx.stats.flags & STAT_JSON_SCHM)
2688 stats_dump_json_schema(&trash);
Simon Horman05ee2132017-01-04 09:37:25 +01002689 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreau9d7fb632017-04-11 07:53:04 +02002690 stats_dump_json_header();
William Lallemand74c24fb2016-11-21 17:18:36 +01002691 else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED))
2692 stats_dump_csv_header();
2693
Christopher Fauletef779222018-10-31 08:47:01 +01002694 if (!stats_putchk(rep, htx, &trash))
2695 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002696
Christopher Faulet6338a082019-09-09 15:50:54 +02002697 if (appctx->ctx.stats.flags & STAT_JSON_SCHM) {
2698 appctx->st2 = STAT_ST_FIN;
2699 return 1;
2700 }
William Lallemand74c24fb2016-11-21 17:18:36 +01002701 appctx->st2 = STAT_ST_INFO;
2702 /* fall through */
2703
2704 case STAT_ST_INFO:
2705 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2706 stats_dump_html_info(si, uri);
Christopher Fauletef779222018-10-31 08:47:01 +01002707 if (!stats_putchk(rep, htx, &trash))
2708 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002709 }
2710
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002711 appctx->ctx.stats.px = proxies_list;
William Lallemand74c24fb2016-11-21 17:18:36 +01002712 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2713 appctx->st2 = STAT_ST_LIST;
2714 /* fall through */
2715
2716 case STAT_ST_LIST:
2717 /* dump proxies */
2718 while (appctx->ctx.stats.px) {
Christopher Fauletef779222018-10-31 08:47:01 +01002719 if (htx) {
2720 if (htx_almost_full(htx))
2721 goto full;
2722 }
2723 else {
2724 if (buffer_almost_full(&rep->buf))
2725 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002726 }
2727
2728 px = appctx->ctx.stats.px;
2729 /* skip the disabled proxies, global frontend and non-networked ones */
2730 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Christopher Fauletef779222018-10-31 08:47:01 +01002731 if (stats_dump_proxy_to_buffer(si, htx, px, uri) == 0)
William Lallemand74c24fb2016-11-21 17:18:36 +01002732 return 0;
2733
2734 appctx->ctx.stats.px = px->next;
2735 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2736 }
2737 /* here, we just have reached the last proxy */
2738
2739 appctx->st2 = STAT_ST_END;
2740 /* fall through */
2741
2742 case STAT_ST_END:
Simon Horman05ee2132017-01-04 09:37:25 +01002743 if (appctx->ctx.stats.flags & (STAT_FMT_HTML|STAT_FMT_JSON)) {
2744 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
2745 stats_dump_html_end();
2746 else
2747 stats_dump_json_end();
Christopher Fauletef779222018-10-31 08:47:01 +01002748 if (!stats_putchk(rep, htx, &trash))
2749 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002750 }
2751
2752 appctx->st2 = STAT_ST_FIN;
2753 /* fall through */
2754
2755 case STAT_ST_FIN:
2756 return 1;
2757
2758 default:
2759 /* unknown state ! */
2760 appctx->st2 = STAT_ST_FIN;
2761 return -1;
2762 }
Christopher Fauletef779222018-10-31 08:47:01 +01002763
2764 full:
2765 si_rx_room_blk(si);
2766 return 0;
2767
William Lallemand74c24fb2016-11-21 17:18:36 +01002768}
2769
2770/* We reached the stats page through a POST request. The appctx is
2771 * expected to have already been allocated by the caller.
2772 * Parse the posted data and enable/disable servers if necessary.
2773 * Returns 1 if request was parsed or zero if it needs more data.
2774 */
2775static int stats_process_http_post(struct stream_interface *si)
2776{
2777 struct stream *s = si_strm(si);
2778 struct appctx *appctx = objt_appctx(si->end);
2779
2780 struct proxy *px = NULL;
2781 struct server *sv = NULL;
2782
2783 char key[LINESIZE];
2784 int action = ST_ADM_ACTION_NONE;
2785 int reprocess = 0;
2786
2787 int total_servers = 0;
2788 int altered_servers = 0;
2789
2790 char *first_param, *cur_param, *next_param, *end_params;
2791 char *st_cur_param = NULL;
2792 char *st_next_param = NULL;
2793
Christopher Fauleta3618372018-12-13 21:59:56 +01002794 struct buffer *temp = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01002795
Christopher Fauletb7f88902019-07-15 21:56:43 +02002796 struct htx *htx = htxbuf(&s->req.buf);
2797 struct htx_blk *blk;
Christopher Fauleta3618372018-12-13 21:59:56 +01002798
Christopher Fauletb7f88902019-07-15 21:56:43 +02002799 /* we need more data */
2800 if (s->txn->req.msg_state < HTTP_MSG_DONE) {
2801 /* check if we can receive more */
2802 if (htx_free_data_space(htx) <= global.tune.maxrewrite) {
2803 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2804 goto out;
Christopher Fauleta3618372018-12-13 21:59:56 +01002805 }
Christopher Fauletb7f88902019-07-15 21:56:43 +02002806 goto wait;
2807 }
Christopher Fauleta3618372018-12-13 21:59:56 +01002808
Christopher Fauletb7f88902019-07-15 21:56:43 +02002809 /* The request was fully received. Copy data */
2810 blk = htx_get_head_blk(htx);
2811 while (blk) {
2812 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauleta3618372018-12-13 21:59:56 +01002813
Christopher Fauletb7f88902019-07-15 21:56:43 +02002814 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
2815 break;
2816 if (type == HTX_BLK_DATA) {
2817 struct ist v = htx_get_blk_value(htx, blk);
Christopher Fauleta3618372018-12-13 21:59:56 +01002818
Christopher Fauletb7f88902019-07-15 21:56:43 +02002819 if (!chunk_memcat(temp, v.ptr, v.len)) {
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002820 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2821 goto out;
2822 }
Christopher Fauleta3618372018-12-13 21:59:56 +01002823 }
Christopher Fauletb7f88902019-07-15 21:56:43 +02002824 blk = htx_get_next_blk(htx, blk);
William Lallemand74c24fb2016-11-21 17:18:36 +01002825 }
2826
Willy Tarreau843b7cb2018-07-13 10:54:26 +02002827 first_param = temp->area;
Christopher Fauleta3618372018-12-13 21:59:56 +01002828 end_params = temp->area + temp->data;
William Lallemand74c24fb2016-11-21 17:18:36 +01002829 cur_param = next_param = end_params;
2830 *end_params = '\0';
2831
2832 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
2833
2834 /*
2835 * Parse the parameters in reverse order to only store the last value.
2836 * From the html form, the backend and the action are at the end.
2837 */
2838 while (cur_param > first_param) {
2839 char *value;
2840 int poffset, plen;
2841
2842 cur_param--;
2843
2844 if ((*cur_param == '&') || (cur_param == first_param)) {
2845 reprocess_servers:
2846 /* Parse the key */
2847 poffset = (cur_param != first_param ? 1 : 0);
2848 plen = next_param - cur_param + (cur_param == first_param ? 1 : 0);
2849 if ((plen > 0) && (plen <= sizeof(key))) {
2850 strncpy(key, cur_param + poffset, plen);
2851 key[plen - 1] = '\0';
2852 } else {
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002853 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
William Lallemand74c24fb2016-11-21 17:18:36 +01002854 goto out;
2855 }
2856
2857 /* Parse the value */
2858 value = key;
2859 while (*value != '\0' && *value != '=') {
2860 value++;
2861 }
2862 if (*value == '=') {
2863 /* Ok, a value is found, we can mark the end of the key */
2864 *value++ = '\0';
2865 }
2866 if (url_decode(key) < 0 || url_decode(value) < 0)
2867 break;
2868
2869 /* Now we can check the key to see what to do */
2870 if (!px && (strcmp(key, "b") == 0)) {
2871 if ((px = proxy_be_by_name(value)) == NULL) {
2872 /* the backend name is unknown or ambiguous (duplicate names) */
2873 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2874 goto out;
2875 }
2876 }
2877 else if (!action && (strcmp(key, "action") == 0)) {
2878 if (strcmp(value, "ready") == 0) {
2879 action = ST_ADM_ACTION_READY;
2880 }
2881 else if (strcmp(value, "drain") == 0) {
2882 action = ST_ADM_ACTION_DRAIN;
2883 }
2884 else if (strcmp(value, "maint") == 0) {
2885 action = ST_ADM_ACTION_MAINT;
2886 }
2887 else if (strcmp(value, "shutdown") == 0) {
2888 action = ST_ADM_ACTION_SHUTDOWN;
2889 }
2890 else if (strcmp(value, "dhlth") == 0) {
2891 action = ST_ADM_ACTION_DHLTH;
2892 }
2893 else if (strcmp(value, "ehlth") == 0) {
2894 action = ST_ADM_ACTION_EHLTH;
2895 }
2896 else if (strcmp(value, "hrunn") == 0) {
2897 action = ST_ADM_ACTION_HRUNN;
2898 }
2899 else if (strcmp(value, "hnolb") == 0) {
2900 action = ST_ADM_ACTION_HNOLB;
2901 }
2902 else if (strcmp(value, "hdown") == 0) {
2903 action = ST_ADM_ACTION_HDOWN;
2904 }
2905 else if (strcmp(value, "dagent") == 0) {
2906 action = ST_ADM_ACTION_DAGENT;
2907 }
2908 else if (strcmp(value, "eagent") == 0) {
2909 action = ST_ADM_ACTION_EAGENT;
2910 }
2911 else if (strcmp(value, "arunn") == 0) {
2912 action = ST_ADM_ACTION_ARUNN;
2913 }
2914 else if (strcmp(value, "adown") == 0) {
2915 action = ST_ADM_ACTION_ADOWN;
2916 }
2917 /* else these are the old supported methods */
2918 else if (strcmp(value, "disable") == 0) {
2919 action = ST_ADM_ACTION_DISABLE;
2920 }
2921 else if (strcmp(value, "enable") == 0) {
2922 action = ST_ADM_ACTION_ENABLE;
2923 }
2924 else if (strcmp(value, "stop") == 0) {
2925 action = ST_ADM_ACTION_STOP;
2926 }
2927 else if (strcmp(value, "start") == 0) {
2928 action = ST_ADM_ACTION_START;
2929 }
2930 else {
2931 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2932 goto out;
2933 }
2934 }
2935 else if (strcmp(key, "s") == 0) {
2936 if (!(px && action)) {
2937 /*
2938 * Indicates that we'll need to reprocess the parameters
2939 * as soon as backend and action are known
2940 */
2941 if (!reprocess) {
2942 st_cur_param = cur_param;
2943 st_next_param = next_param;
2944 }
2945 reprocess = 1;
2946 }
2947 else if ((sv = findserver(px, value)) != NULL) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002948 HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01002949 switch (action) {
2950 case ST_ADM_ACTION_DISABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002951 if (!(sv->cur_admin & SRV_ADMF_FMAINT)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002952 altered_servers++;
2953 total_servers++;
2954 srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page");
2955 }
2956 break;
2957 case ST_ADM_ACTION_ENABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002958 if (sv->cur_admin & SRV_ADMF_FMAINT) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002959 altered_servers++;
2960 total_servers++;
2961 srv_clr_admin_flag(sv, SRV_ADMF_FMAINT);
2962 }
2963 break;
2964 case ST_ADM_ACTION_STOP:
Emeric Brun52a91d32017-08-31 14:41:55 +02002965 if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002966 srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page");
2967 altered_servers++;
2968 total_servers++;
2969 }
2970 break;
2971 case ST_ADM_ACTION_START:
Emeric Brun52a91d32017-08-31 14:41:55 +02002972 if (sv->cur_admin & SRV_ADMF_FDRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002973 srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN);
2974 altered_servers++;
2975 total_servers++;
2976 }
2977 break;
2978 case ST_ADM_ACTION_DHLTH:
2979 if (sv->check.state & CHK_ST_CONFIGURED) {
2980 sv->check.state &= ~CHK_ST_ENABLED;
2981 altered_servers++;
2982 total_servers++;
2983 }
2984 break;
2985 case ST_ADM_ACTION_EHLTH:
2986 if (sv->check.state & CHK_ST_CONFIGURED) {
2987 sv->check.state |= CHK_ST_ENABLED;
2988 altered_servers++;
2989 total_servers++;
2990 }
2991 break;
2992 case ST_ADM_ACTION_HRUNN:
2993 if (!(sv->track)) {
2994 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02002995 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002996 altered_servers++;
2997 total_servers++;
2998 }
2999 break;
3000 case ST_ADM_ACTION_HNOLB:
3001 if (!(sv->track)) {
3002 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02003003 srv_set_stopping(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003004 altered_servers++;
3005 total_servers++;
3006 }
3007 break;
3008 case ST_ADM_ACTION_HDOWN:
3009 if (!(sv->track)) {
3010 sv->check.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02003011 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003012 altered_servers++;
3013 total_servers++;
3014 }
3015 break;
3016 case ST_ADM_ACTION_DAGENT:
3017 if (sv->agent.state & CHK_ST_CONFIGURED) {
3018 sv->agent.state &= ~CHK_ST_ENABLED;
3019 altered_servers++;
3020 total_servers++;
3021 }
3022 break;
3023 case ST_ADM_ACTION_EAGENT:
3024 if (sv->agent.state & CHK_ST_CONFIGURED) {
3025 sv->agent.state |= CHK_ST_ENABLED;
3026 altered_servers++;
3027 total_servers++;
3028 }
3029 break;
3030 case ST_ADM_ACTION_ARUNN:
3031 if (sv->agent.state & CHK_ST_ENABLED) {
3032 sv->agent.health = sv->agent.rise + sv->agent.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02003033 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003034 altered_servers++;
3035 total_servers++;
3036 }
3037 break;
3038 case ST_ADM_ACTION_ADOWN:
3039 if (sv->agent.state & CHK_ST_ENABLED) {
3040 sv->agent.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02003041 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003042 altered_servers++;
3043 total_servers++;
3044 }
3045 break;
3046 case ST_ADM_ACTION_READY:
3047 srv_adm_set_ready(sv);
3048 altered_servers++;
3049 total_servers++;
3050 break;
3051 case ST_ADM_ACTION_DRAIN:
3052 srv_adm_set_drain(sv);
3053 altered_servers++;
3054 total_servers++;
3055 break;
3056 case ST_ADM_ACTION_MAINT:
3057 srv_adm_set_maint(sv);
3058 altered_servers++;
3059 total_servers++;
3060 break;
3061 case ST_ADM_ACTION_SHUTDOWN:
3062 if (px->state != PR_STSTOPPED) {
3063 struct stream *sess, *sess_bck;
3064
3065 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
3066 if (sess->srv_conn == sv)
3067 stream_shutdown(sess, SF_ERR_KILLED);
3068
3069 altered_servers++;
3070 total_servers++;
3071 }
3072 break;
3073 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003074 HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01003075 } else {
3076 /* the server name is unknown or ambiguous (duplicate names) */
3077 total_servers++;
3078 }
3079 }
3080 if (reprocess && px && action) {
3081 /* Now, we know the backend and the action chosen by the user.
3082 * We can safely restart from the first server parameter
3083 * to reprocess them
3084 */
3085 cur_param = st_cur_param;
3086 next_param = st_next_param;
3087 reprocess = 0;
3088 goto reprocess_servers;
3089 }
3090
3091 next_param = cur_param;
3092 }
3093 }
3094
3095 if (total_servers == 0) {
3096 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
3097 }
3098 else if (altered_servers == 0) {
3099 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
3100 }
3101 else if (altered_servers == total_servers) {
3102 appctx->ctx.stats.st_code = STAT_STATUS_DONE;
3103 }
3104 else {
3105 appctx->ctx.stats.st_code = STAT_STATUS_PART;
3106 }
3107 out:
3108 return 1;
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01003109 wait:
3110 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
3111 return 0;
Christopher Fauletef779222018-10-31 08:47:01 +01003112}
3113
3114
Christopher Fauletb7f88902019-07-15 21:56:43 +02003115static int stats_send_http_headers(struct stream_interface *si, struct htx *htx)
Christopher Fauletef779222018-10-31 08:47:01 +01003116{
3117 struct stream *s = si_strm(si);
3118 struct uri_auth *uri = s->be->uri_auth;
3119 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003120 struct htx_sl *sl;
3121 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003122
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003123 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);
3124 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
3125 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003126 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003127 sl->info.res.status = 200;
Christopher Fauletef779222018-10-31 08:47:01 +01003128
Christopher Fauletb829f4c2019-03-29 16:13:55 +01003129 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")))
Christopher Fauletef779222018-10-31 08:47:01 +01003130 goto full;
3131 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
3132 if (!htx_add_header(htx, ist("Content-Type"), ist("text/html")))
3133 goto full;
3134 }
Christopher Faulet6338a082019-09-09 15:50:54 +02003135 else if (appctx->ctx.stats.flags & (STAT_FMT_JSON|STAT_JSON_SCHM)) {
3136 if (!htx_add_header(htx, ist("Content-Type"), ist("application/json")))
3137 goto full;
3138 }
Christopher Fauletef779222018-10-31 08:47:01 +01003139 else {
3140 if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain")))
3141 goto full;
3142 }
3143
3144 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) {
3145 const char *refresh = U2A(uri->refresh);
3146 if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh))))
3147 goto full;
3148 }
3149
3150 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
3151 if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")))
3152 goto full;
3153 }
3154
3155 if (!htx_add_endof(htx, HTX_BLK_EOH))
3156 goto full;
3157
Christopher Faulet1e2d6362019-02-27 16:28:48 +01003158 channel_add_input(&s->res, htx->data);
Christopher Fauletef779222018-10-31 08:47:01 +01003159 return 1;
3160
3161 full:
3162 htx_reset(htx);
3163 si_rx_room_blk(si);
3164 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01003165}
3166
Christopher Fauletef779222018-10-31 08:47:01 +01003167
Christopher Fauletb7f88902019-07-15 21:56:43 +02003168static int stats_send_http_redirect(struct stream_interface *si, struct htx *htx)
Christopher Fauletef779222018-10-31 08:47:01 +01003169{
3170 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
3171 struct stream *s = si_strm(si);
3172 struct uri_auth *uri = s->be->uri_auth;
3173 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003174 struct htx_sl *sl;
3175 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003176
3177 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
3178 scope_txt[0] = 0;
3179 if (appctx->ctx.stats.scope_len) {
Christopher Fauleted7a0662019-01-14 11:07:34 +01003180 const char *scope_ptr = stats_scope_ptr(appctx, si);
3181
Christopher Fauletef779222018-10-31 08:47:01 +01003182 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01003183 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
Christopher Fauletef779222018-10-31 08:47:01 +01003184 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
3185 }
3186
3187 /* We don't want to land on the posted stats page because a refresh will
3188 * repost the data. We don't want this to happen on accident so we redirect
3189 * the browse to the stats page with a GET.
3190 */
3191 chunk_printf(&trash, "%s;st=%s%s%s%s",
3192 uri->uri_prefix,
3193 ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) &&
3194 (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) &&
3195 stat_status_codes[appctx->ctx.stats.st_code]) ?
3196 stat_status_codes[appctx->ctx.stats.st_code] :
3197 stat_status_codes[STAT_STATUS_UNKN],
3198 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3199 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
3200 scope_txt);
3201
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003202 flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK);
3203 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other"));
3204 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003205 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003206 sl->info.res.status = 303;
Christopher Fauletef779222018-10-31 08:47:01 +01003207
3208 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
Christopher Fauletef779222018-10-31 08:47:01 +01003209 !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) ||
3210 !htx_add_header(htx, ist("Content-Length"), ist("0")) ||
3211 !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data)))
3212 goto full;
3213
3214 if (!htx_add_endof(htx, HTX_BLK_EOH))
3215 goto full;
3216
Christopher Faulet1e2d6362019-02-27 16:28:48 +01003217 channel_add_input(&s->res, htx->data);
Christopher Fauletef779222018-10-31 08:47:01 +01003218 return 1;
3219
3220full:
3221 htx_reset(htx);
3222 si_rx_room_blk(si);
3223 return 0;
3224}
William Lallemand74c24fb2016-11-21 17:18:36 +01003225
Simon Horman05ee2132017-01-04 09:37:25 +01003226
William Lallemand74c24fb2016-11-21 17:18:36 +01003227/* This I/O handler runs as an applet embedded in a stream interface. It is
3228 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
3229 * appctx->st0 contains the operation in progress (dump, done). The handler
3230 * automatically unregisters itself once transfer is complete.
3231 */
Christopher Fauletb7f88902019-07-15 21:56:43 +02003232static void http_stats_io_handler(struct appctx *appctx)
Christopher Fauletef779222018-10-31 08:47:01 +01003233{
3234 struct stream_interface *si = appctx->owner;
3235 struct stream *s = si_strm(si);
3236 struct channel *req = si_oc(si);
3237 struct channel *res = si_ic(si);
3238 struct htx *req_htx, *res_htx;
3239
3240 res_htx = htx_from_buf(&res->buf);
3241
3242 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
3243 goto out;
3244
3245 /* Check if the input buffer is avalaible. */
3246 if (!b_size(&res->buf)) {
3247 si_rx_room_blk(si);
3248 goto out;
3249 }
3250
3251 /* check that the output is not closed */
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003252 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_SHUTR))
3253 appctx->st0 = STAT_HTTP_END;
Christopher Fauletef779222018-10-31 08:47:01 +01003254
3255 /* all states are processed in sequence */
3256 if (appctx->st0 == STAT_HTTP_HEAD) {
Christopher Fauletb7f88902019-07-15 21:56:43 +02003257 if (stats_send_http_headers(si, res_htx)) {
Christopher Fauletef779222018-10-31 08:47:01 +01003258 if (s->txn->meth == HTTP_METH_HEAD)
3259 appctx->st0 = STAT_HTTP_DONE;
3260 else
3261 appctx->st0 = STAT_HTTP_DUMP;
3262 }
3263 }
3264
3265 if (appctx->st0 == STAT_HTTP_DUMP) {
3266 if (stats_dump_stat_to_buffer(si, res_htx, s->be->uri_auth))
3267 appctx->st0 = STAT_HTTP_DONE;
3268 }
3269
3270 if (appctx->st0 == STAT_HTTP_POST) {
3271 if (stats_process_http_post(si))
3272 appctx->st0 = STAT_HTTP_LAST;
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003273 else if (req->flags & CF_SHUTR)
Christopher Fauletef779222018-10-31 08:47:01 +01003274 appctx->st0 = STAT_HTTP_DONE;
3275 }
3276
3277 if (appctx->st0 == STAT_HTTP_LAST) {
Christopher Fauletb7f88902019-07-15 21:56:43 +02003278 if (stats_send_http_redirect(si, res_htx))
Christopher Fauletef779222018-10-31 08:47:01 +01003279 appctx->st0 = STAT_HTTP_DONE;
3280 }
3281
3282 if (appctx->st0 == STAT_HTTP_DONE) {
Christopher Faulet54b5e212019-06-04 10:08:28 +02003283 /* Don't add TLR because mux-h1 will take care of it */
Christopher Fauletef779222018-10-31 08:47:01 +01003284 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
3285 si_rx_room_blk(si);
3286 goto out;
3287 }
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003288 channel_add_input(&s->res, 1);
3289 appctx->st0 = STAT_HTTP_END;
Christopher Fauletef779222018-10-31 08:47:01 +01003290 }
3291
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003292 if (appctx->st0 == STAT_HTTP_END) {
3293 if (!(res->flags & CF_SHUTR)) {
Christopher Fauletef779222018-10-31 08:47:01 +01003294 res->flags |= CF_READ_NULL;
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003295 si_shutr(si);
3296 }
3297
3298 /* eat the whole request */
3299 if (co_data(req)) {
3300 req_htx = htx_from_buf(&req->buf);
3301 co_htx_skip(req, req_htx, co_data(req));
3302 htx_to_buf(req_htx, &req->buf);
Christopher Fauletef779222018-10-31 08:47:01 +01003303 }
3304 }
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003305
Christopher Fauletef779222018-10-31 08:47:01 +01003306 out:
3307 /* we have left the request in the buffer for the case where we
3308 * process a POST, and this automatically re-enables activity on
3309 * read. It's better to indicate that we want to stop reading when
3310 * we're sending, so that we know there's at most one direction
3311 * deciding to wake the applet up. It saves it from looping when
3312 * emitting large blocks into small TCP windows.
3313 */
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01003314 htx_to_buf(res_htx, &res->buf);
3315 if (!channel_is_empty(res))
Christopher Fauletef779222018-10-31 08:47:01 +01003316 si_stop_get(si);
Christopher Fauletef779222018-10-31 08:47:01 +01003317}
3318
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003319/* Dump all fields from <info> into <out> using the "show info" format (name: value) */
Willy Tarreau83061a82018-07-13 11:56:34 +02003320static int stats_dump_info_fields(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +02003321 const struct field *info, unsigned int flags)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003322{
3323 int field;
3324
3325 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3326 if (!field_format(info, field))
3327 continue;
3328
Willy Tarreaueaa55372019-10-09 07:39:11 +02003329 if (!chunk_appendf(out, "%s: ", info_fields[field].name))
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003330 return 0;
3331 if (!stats_emit_raw_data_field(out, &info[field]))
3332 return 0;
Willy Tarreau6b19b142019-10-09 15:44:21 +02003333 if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc))
3334 return 0;
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003335 if (!chunk_strcat(out, "\n"))
3336 return 0;
3337 }
3338 return 1;
3339}
3340
3341/* Dump all fields from <info> into <out> using the "show info typed" format */
Willy Tarreau83061a82018-07-13 11:56:34 +02003342static int stats_dump_typed_info_fields(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +02003343 const struct field *info, unsigned int flags)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003344{
3345 int field;
3346
3347 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3348 if (!field_format(info, field))
3349 continue;
3350
Willy Tarreaueaa55372019-10-09 07:39:11 +02003351 if (!chunk_appendf(out, "%d.%s.%u:", field, info_fields[field].name, info[INF_PROCESS_NUM].u.u32))
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003352 return 0;
3353 if (!stats_emit_field_tags(out, &info[field], ':'))
3354 return 0;
3355 if (!stats_emit_typed_data_field(out, &info[field]))
3356 return 0;
Willy Tarreau6b19b142019-10-09 15:44:21 +02003357 if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc))
3358 return 0;
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003359 if (!chunk_strcat(out, "\n"))
3360 return 0;
3361 }
3362 return 1;
3363}
3364
3365/* Fill <info> with HAProxy global info. <info> is preallocated
3366 * array of length <len>. The length of the aray must be
3367 * INF_TOTAL_FIELDS. If this length is less then this value, the
3368 * function returns 0, otherwise, it returns 1.
3369 */
3370int stats_fill_info(struct field *info, int len)
3371{
3372 unsigned int up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau83061a82018-07-13 11:56:34 +02003373 struct buffer *out = get_trash_chunk();
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003374
3375#ifdef USE_OPENSSL
3376 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
3377 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
3378 int ssl_reuse = 0;
3379
3380 if (ssl_key_rate < ssl_sess_rate) {
3381 /* count the ssl reuse ratio and avoid overflows in both directions */
3382 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
3383 }
3384#endif
3385
3386 if (len < INF_TOTAL_FIELDS)
3387 return 0;
3388
3389 chunk_reset(out);
3390 memset(info, 0, sizeof(*info) * len);
3391
3392 info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME);
Willy Tarreau909b9d82019-01-04 18:20:32 +01003393 info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version);
3394 info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_date);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003395
Yves Lafon95317282018-02-26 11:10:37 +01003396 info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003397 info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
3398 info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid);
3399 info[INF_PID] = mkf_u32(FO_STATUS, pid);
3400
3401 info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out));
3402 chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
3403
3404 info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up);
3405 info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
3406 info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L));
3407 info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L));
3408 info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures());
3409 info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
3410 info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
3411 info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
3412 info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
3413 info[INF_CURR_CONN] = mkf_u32(0, actconn);
3414 info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn);
3415 info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count);
3416#ifdef USE_OPENSSL
3417 info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn);
3418 info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns);
3419 info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns);
3420#endif
3421 info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
3422 info[INF_PIPES_USED] = mkf_u32(0, pipes_used);
3423 info[INF_PIPES_FREE] = mkf_u32(0, pipes_free);
3424 info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
3425 info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
3426 info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max);
3427 info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
3428 info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
3429 info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max);
3430
3431#ifdef USE_OPENSSL
3432 info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate);
3433 info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
3434 info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max);
3435 info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate);
3436 info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
3437 info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse);
3438 info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
3439 info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max);
3440 info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups);
3441 info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses);
3442#endif
3443 info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
3444 info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
3445 info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
3446#ifdef USE_ZLIB
3447 info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory);
3448 info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
3449#endif
3450 info[INF_TASKS] = mkf_u32(0, nb_tasks_cur);
Christopher Faulet34c5cc92016-12-06 09:15:30 +01003451 info[INF_RUN_QUEUE] = mkf_u32(0, tasks_run_queue_cur);
Willy Tarreau81036f22019-05-20 19:24:50 +02003452 info[INF_IDLE_PCT] = mkf_u32(FN_AVG, ti->idle_pct);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003453 info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node);
3454 if (global.desc)
3455 info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003456 info[INF_STOPPING] = mkf_u32(0, stopping);
3457 info[INF_JOBS] = mkf_u32(0, jobs);
William Lallemanda7199262018-11-16 16:57:20 +01003458 info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003459 info[INF_LISTENERS] = mkf_u32(0, listeners);
Willy Tarreau199ad242018-11-05 16:31:22 +01003460 info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers);
Willy Tarreau2d372c22018-11-05 17:12:27 +01003461 info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers);
Willy Tarreau13ef7732018-11-12 07:25:28 +01003462 info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs);
Willy Tarreaubeb859a2018-11-22 18:07:59 +01003463 info[INF_BUSY_POLLING] = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
Baptiste Assmann333939c2019-01-21 08:34:50 +01003464 info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, dns_failed_resolutions);
Willy Tarreau7cf0e452019-05-23 11:39:14 +02003465 info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, global.out_bytes);
3466 info[INF_BYTES_OUT_RATE] = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32);
Willy Tarreau9b013702019-10-24 18:18:02 +02003467 info[INF_DEBUG_COMMANDS_ISSUED] = mkf_u32(0, debug_commands_issued);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003468
3469 return 1;
3470}
3471
3472/* This function dumps information onto the stream interface's read buffer.
3473 * It returns 0 as long as it does not complete, non-zero upon completion.
3474 * No state is used.
3475 */
3476static int stats_dump_info_to_buffer(struct stream_interface *si)
3477{
3478 struct appctx *appctx = __objt_appctx(si->end);
3479
3480 if (!stats_fill_info(info, INF_TOTAL_FIELDS))
3481 return 0;
3482
3483 chunk_reset(&trash);
3484
3485 if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
Willy Tarreau43241ff2019-10-09 11:27:51 +02003486 stats_dump_typed_info_fields(&trash, info, appctx->ctx.stats.flags);
Simon Horman05ee2132017-01-04 09:37:25 +01003487 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreau43241ff2019-10-09 11:27:51 +02003488 stats_dump_json_info_fields(&trash, info, appctx->ctx.stats.flags);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003489 else
Willy Tarreau43241ff2019-10-09 11:27:51 +02003490 stats_dump_info_fields(&trash, info, appctx->ctx.stats.flags);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003491
Willy Tarreau06d80a92017-10-19 14:32:15 +02003492 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003493 si_rx_room_blk(si);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003494 return 0;
3495 }
3496
3497 return 1;
3498}
3499
Simon Horman6f6bb382017-01-04 09:37:26 +01003500/* This function dumps the schema onto the stream interface's read buffer.
3501 * It returns 0 as long as it does not complete, non-zero upon completion.
3502 * No state is used.
3503 *
3504 * Integer values bouned to the range [-(2**53)+1, (2**53)-1] as
3505 * per the recommendation for interoperable integers in section 6 of RFC 7159.
3506 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003507static void stats_dump_json_schema(struct buffer *out)
Simon Horman6f6bb382017-01-04 09:37:26 +01003508{
3509
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003510 int old_len = out->data;
Simon Horman6f6bb382017-01-04 09:37:26 +01003511
3512 chunk_strcat(out,
3513 "{"
3514 "\"$schema\":\"http://json-schema.org/draft-04/schema#\","
3515 "\"oneOf\":["
3516 "{"
3517 "\"title\":\"Info\","
3518 "\"type\":\"array\","
3519 "\"items\":{"
3520 "\"properties\":{"
3521 "\"title\":\"InfoItem\","
3522 "\"type\":\"object\","
3523 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3524 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3525 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3526 "\"value\":{\"$ref\":\"#/definitions/typedValue\"}"
3527 "},"
3528 "\"required\":[\"field\",\"processNum\",\"tags\","
3529 "\"value\"]"
3530 "}"
3531 "},"
3532 "{"
3533 "\"title\":\"Stat\","
3534 "\"type\":\"array\","
3535 "\"items\":{"
3536 "\"title\":\"InfoItem\","
3537 "\"type\":\"object\","
3538 "\"properties\":{"
3539 "\"objType\":{"
3540 "\"enum\":[\"Frontend\",\"Backend\",\"Listener\","
3541 "\"Server\",\"Unknown\"]"
3542 "},"
3543 "\"proxyId\":{"
3544 "\"type\":\"integer\","
3545 "\"minimum\":0"
3546 "},"
3547 "\"id\":{"
3548 "\"type\":\"integer\","
3549 "\"minimum\":0"
3550 "},"
3551 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3552 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3553 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3554 "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}"
3555 "},"
3556 "\"required\":[\"objType\",\"proxyId\",\"id\","
3557 "\"field\",\"processNum\",\"tags\","
3558 "\"value\"]"
3559 "}"
3560 "},"
3561 "{"
3562 "\"title\":\"Error\","
3563 "\"type\":\"object\","
3564 "\"properties\":{"
3565 "\"errorStr\":{"
3566 "\"type\":\"string\""
3567 "},"
3568 "\"required\":[\"errorStr\"]"
3569 "}"
3570 "}"
3571 "],"
3572 "\"definitions\":{"
3573 "\"field\":{"
3574 "\"type\":\"object\","
3575 "\"pos\":{"
3576 "\"type\":\"integer\","
3577 "\"minimum\":0"
3578 "},"
3579 "\"name\":{"
3580 "\"type\":\"string\""
3581 "},"
3582 "\"required\":[\"pos\",\"name\"]"
3583 "},"
3584 "\"processNum\":{"
3585 "\"type\":\"integer\","
3586 "\"minimum\":1"
3587 "},"
3588 "\"tags\":{"
3589 "\"type\":\"object\","
3590 "\"origin\":{"
3591 "\"type\":\"string\","
3592 "\"enum\":[\"Metric\",\"Status\",\"Key\","
3593 "\"Config\",\"Product\",\"Unknown\"]"
3594 "},"
3595 "\"nature\":{"
3596 "\"type\":\"string\","
3597 "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\","
3598 "\"Rate\",\"Counter\",\"Duration\","
3599 "\"Age\",\"Time\",\"Name\",\"Output\","
3600 "\"Avg\", \"Unknown\"]"
3601 "},"
3602 "\"scope\":{"
3603 "\"type\":\"string\","
3604 "\"enum\":[\"Cluster\",\"Process\",\"Service\","
3605 "\"System\",\"Unknown\"]"
3606 "},"
3607 "\"required\":[\"origin\",\"nature\",\"scope\"]"
3608 "},"
3609 "\"typedValue\":{"
3610 "\"type\":\"object\","
3611 "\"oneOf\":["
3612 "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"},"
3613 "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"},"
3614 "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"},"
3615 "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"},"
3616 "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}"
3617 "],"
3618 "\"definitions\":{"
3619 "\"s32Value\":{"
3620 "\"properties\":{"
3621 "\"type\":{"
3622 "\"type\":\"string\","
3623 "\"enum\":[\"s32\"]"
3624 "},"
3625 "\"value\":{"
3626 "\"type\":\"integer\","
3627 "\"minimum\":-2147483648,"
3628 "\"maximum\":2147483647"
3629 "}"
3630 "},"
3631 "\"required\":[\"type\",\"value\"]"
3632 "},"
3633 "\"s64Value\":{"
3634 "\"properties\":{"
3635 "\"type\":{"
3636 "\"type\":\"string\","
3637 "\"enum\":[\"s64\"]"
3638 "},"
3639 "\"value\":{"
3640 "\"type\":\"integer\","
3641 "\"minimum\":-9007199254740991,"
3642 "\"maximum\":9007199254740991"
3643 "}"
3644 "},"
3645 "\"required\":[\"type\",\"value\"]"
3646 "},"
3647 "\"u32Value\":{"
3648 "\"properties\":{"
3649 "\"type\":{"
3650 "\"type\":\"string\","
3651 "\"enum\":[\"u32\"]"
3652 "},"
3653 "\"value\":{"
3654 "\"type\":\"integer\","
3655 "\"minimum\":0,"
3656 "\"maximum\":4294967295"
3657 "}"
3658 "},"
3659 "\"required\":[\"type\",\"value\"]"
3660 "},"
3661 "\"u64Value\":{"
3662 "\"properties\":{"
3663 "\"type\":{"
3664 "\"type\":\"string\","
3665 "\"enum\":[\"u64\"]"
3666 "},"
3667 "\"value\":{"
3668 "\"type\":\"integer\","
3669 "\"minimum\":0,"
3670 "\"maximum\":9007199254740991"
3671 "}"
3672 "},"
3673 "\"required\":[\"type\",\"value\"]"
3674 "},"
3675 "\"strValue\":{"
3676 "\"properties\":{"
3677 "\"type\":{"
3678 "\"type\":\"string\","
3679 "\"enum\":[\"str\"]"
3680 "},"
3681 "\"value\":{\"type\":\"string\"}"
3682 "},"
3683 "\"required\":[\"type\",\"value\"]"
3684 "},"
3685 "\"unknownValue\":{"
3686 "\"properties\":{"
3687 "\"type\":{"
3688 "\"type\":\"integer\","
3689 "\"minimum\":0"
3690 "},"
3691 "\"value\":{"
3692 "\"type\":\"string\","
3693 "\"enum\":[\"unknown\"]"
3694 "}"
3695 "},"
3696 "\"required\":[\"type\",\"value\"]"
3697 "}"
3698 "}"
3699 "}"
3700 "}"
3701 "}");
3702
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003703 if (old_len == out->data) {
Simon Horman6f6bb382017-01-04 09:37:26 +01003704 chunk_reset(out);
3705 chunk_appendf(out,
3706 "{\"errorStr\":\"output buffer too short\"}");
3707 }
3708}
3709
3710/* This function dumps the schema onto the stream interface's read buffer.
3711 * It returns 0 as long as it does not complete, non-zero upon completion.
3712 * No state is used.
3713 */
3714static int stats_dump_json_schema_to_buffer(struct stream_interface *si)
3715{
3716 chunk_reset(&trash);
3717
3718 stats_dump_json_schema(&trash);
3719
Willy Tarreau06d80a92017-10-19 14:32:15 +02003720 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003721 si_rx_room_blk(si);
Simon Horman6f6bb382017-01-04 09:37:26 +01003722 return 0;
3723 }
3724
3725 return 1;
3726}
3727
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003728static int cli_parse_clear_counters(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau89d467c2016-11-23 11:02:40 +01003729{
3730 struct proxy *px;
3731 struct server *sv;
3732 struct listener *li;
3733 int clrall = 0;
3734
3735 if (strcmp(args[2], "all") == 0)
3736 clrall = 1;
3737
3738 /* check permissions */
3739 if (!cli_has_level(appctx, ACCESS_LVL_OPER) ||
3740 (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN)))
3741 return 1;
3742
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003743 for (px = proxies_list; px; px = px->next) {
Willy Tarreau89d467c2016-11-23 11:02:40 +01003744 if (clrall) {
3745 memset(&px->be_counters, 0, sizeof(px->be_counters));
3746 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
3747 }
3748 else {
3749 px->be_counters.conn_max = 0;
3750 px->be_counters.p.http.rps_max = 0;
3751 px->be_counters.sps_max = 0;
3752 px->be_counters.cps_max = 0;
3753 px->be_counters.nbpend_max = 0;
3754
3755 px->fe_counters.conn_max = 0;
3756 px->fe_counters.p.http.rps_max = 0;
3757 px->fe_counters.sps_max = 0;
3758 px->fe_counters.cps_max = 0;
Willy Tarreau89d467c2016-11-23 11:02:40 +01003759 }
3760
3761 for (sv = px->srv; sv; sv = sv->next)
3762 if (clrall)
3763 memset(&sv->counters, 0, sizeof(sv->counters));
3764 else {
3765 sv->counters.cur_sess_max = 0;
3766 sv->counters.nbpend_max = 0;
3767 sv->counters.sps_max = 0;
3768 }
3769
3770 list_for_each_entry(li, &px->conf.listeners, by_fe)
3771 if (li->counters) {
3772 if (clrall)
3773 memset(li->counters, 0, sizeof(*li->counters));
3774 else
3775 li->counters->conn_max = 0;
3776 }
3777 }
3778
3779 global.cps_max = 0;
3780 global.sps_max = 0;
Olivier Houchard00bc3cb2017-10-17 19:23:25 +02003781 global.ssl_max = 0;
3782 global.ssl_fe_keys_max = 0;
3783 global.ssl_be_keys_max = 0;
Willy Tarreaud80cb4e2018-01-20 19:30:13 +01003784
3785 memset(activity, 0, sizeof(activity));
Willy Tarreau89d467c2016-11-23 11:02:40 +01003786 return 1;
3787}
3788
3789
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003790static int cli_parse_show_info(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003791{
Willy Tarreau2f397382019-10-09 11:43:59 +02003792 int arg = 2;
3793
Willy Tarreaud25fc792016-12-16 12:33:47 +01003794 appctx->ctx.stats.scope_str = 0;
3795 appctx->ctx.stats.scope_len = 0;
3796 appctx->ctx.stats.flags = 0;
3797
Willy Tarreau2f397382019-10-09 11:43:59 +02003798 while (*args[arg]) {
3799 if (strcmp(args[arg], "typed") == 0)
3800 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED;
3801 else if (strcmp(args[arg], "json") == 0)
3802 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON;
3803 else if (strcmp(args[arg], "desc") == 0)
3804 appctx->ctx.stats.flags |= STAT_SHOW_FDESC;
3805 arg++;
3806 }
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003807 return 0;
3808}
3809
3810
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003811static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau2b812e22016-11-22 16:18:05 +01003812{
Willy Tarreau2f397382019-10-09 11:43:59 +02003813 int arg = 2;
3814
Willy Tarreaud25fc792016-12-16 12:33:47 +01003815 appctx->ctx.stats.scope_str = 0;
3816 appctx->ctx.stats.scope_len = 0;
Willy Tarreau578d6e42019-10-09 11:00:22 +02003817 appctx->ctx.stats.flags = STAT_SHNODE | STAT_SHDESC;
3818
3819 if ((strm_li(si_strm(appctx->owner))->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER)
3820 appctx->ctx.stats.flags |= STAT_SHLGNDS;
Willy Tarreaud25fc792016-12-16 12:33:47 +01003821
Willy Tarreau2f397382019-10-09 11:43:59 +02003822 if (*args[arg] && *args[arg+1] && *args[arg+2]) {
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003823 struct proxy *px;
3824
Willy Tarreau2f397382019-10-09 11:43:59 +02003825 px = proxy_find_by_name(args[arg], 0, 0);
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003826 if (px)
3827 appctx->ctx.stats.iid = px->uuid;
3828 else
Willy Tarreau2f397382019-10-09 11:43:59 +02003829 appctx->ctx.stats.iid = atoi(args[arg]);
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003830
Willy Tarreau9d008692019-08-09 11:21:01 +02003831 if (!appctx->ctx.stats.iid)
3832 return cli_err(appctx, "No such proxy.\n");
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003833
Willy Tarreau2b812e22016-11-22 16:18:05 +01003834 appctx->ctx.stats.flags |= STAT_BOUND;
Willy Tarreau2f397382019-10-09 11:43:59 +02003835 appctx->ctx.stats.type = atoi(args[arg+1]);
3836 appctx->ctx.stats.sid = atoi(args[arg+2]);
3837 arg += 3;
3838 }
3839
3840 while (*args[arg]) {
3841 if (strcmp(args[arg], "typed") == 0)
3842 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED;
3843 else if (strcmp(args[arg], "json") == 0)
3844 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON;
3845 else if (strcmp(args[arg], "desc") == 0)
3846 appctx->ctx.stats.flags |= STAT_SHOW_FDESC;
3847 arg++;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003848 }
Willy Tarreau2b812e22016-11-22 16:18:05 +01003849
Willy Tarreau2b812e22016-11-22 16:18:05 +01003850 return 0;
3851}
3852
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003853static int cli_io_handler_dump_info(struct appctx *appctx)
3854{
3855 return stats_dump_info_to_buffer(appctx->owner);
3856}
3857
Willy Tarreau2b812e22016-11-22 16:18:05 +01003858/* This I/O handler runs as an applet embedded in a stream interface. It is
3859 * used to send raw stats over a socket.
3860 */
3861static int cli_io_handler_dump_stat(struct appctx *appctx)
3862{
Christopher Fauletef779222018-10-31 08:47:01 +01003863 return stats_dump_stat_to_buffer(appctx->owner, NULL, NULL);
Willy Tarreau2b812e22016-11-22 16:18:05 +01003864}
3865
Simon Horman6f6bb382017-01-04 09:37:26 +01003866static int cli_io_handler_dump_json_schema(struct appctx *appctx)
3867{
3868 return stats_dump_json_schema_to_buffer(appctx->owner);
3869}
3870
Willy Tarreau2b812e22016-11-22 16:18:05 +01003871/* register cli keywords */
3872static struct cli_kw_list cli_kws = {{ },{
Willy Tarreau89d467c2016-11-23 11:02:40 +01003873 { { "clear", "counters", NULL }, "clear counters : clear max statistics counters (add 'all' for all counters)", cli_parse_clear_counters, NULL, NULL },
Willy Tarreaueaa55372019-10-09 07:39:11 +02003874 { { "show", "info", NULL }, "show info : report information about the running process [desc|json|typed]*", cli_parse_show_info, cli_io_handler_dump_info, NULL },
3875 { { "show", "stat", NULL }, "show stat : report counters for each proxy and server [desc|json|typed]*", cli_parse_show_stat, cli_io_handler_dump_stat, NULL },
Simon Horman6f6bb382017-01-04 09:37:26 +01003876 { { "show", "schema", "json", NULL }, "show schema json : report schema used for stats", NULL, cli_io_handler_dump_json_schema, NULL },
Willy Tarreau2b812e22016-11-22 16:18:05 +01003877 {{},}
3878}};
3879
Willy Tarreau0108d902018-11-25 19:14:37 +01003880INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
3881
William Lallemand74c24fb2016-11-21 17:18:36 +01003882struct applet http_stats_applet = {
3883 .obj_type = OBJ_TYPE_APPLET,
3884 .name = "<STATS>", /* used for logging */
3885 .fct = http_stats_io_handler,
3886 .release = NULL,
3887};
3888
William Lallemand74c24fb2016-11-21 17:18:36 +01003889/*
3890 * Local variables:
3891 * c-indent-level: 8
3892 * c-basic-offset: 8
3893 * End:
3894 */