blob: c152a7a3372a1ad99a89a672a88b6734485998c8 [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 Tarreau0baac8c2016-11-22 16:36:53 +0100155};
156
Willy Tarreaueaa55372019-10-09 07:39:11 +0200157const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
Willy Tarreau6d4897e2019-10-11 16:31:46 +0200158 [ST_F_PXNAME] = { .name = "pxname", .desc = "Proxy name" },
159 [ST_F_SVNAME] = { .name = "svname", .desc = "Server name" },
160 [ST_F_QCUR] = { .name = "qcur", .desc = "Current number of connections waiting in the server of backend queue" },
161 [ST_F_QMAX] = { .name = "qmax", .desc = "Highest value of qcur encountered since process started" },
162 [ST_F_SCUR] = { .name = "scur", .desc = "Current number of sessions on the frontend, backend or server" },
163 [ST_F_SMAX] = { .name = "smax", .desc = "Highest value of scur encountered since process started" },
164 [ST_F_SLIM] = { .name = "slim", .desc = "Frontend/listener/server's maxconn, backend's fullconn" },
165 [ST_F_STOT] = { .name = "stot", .desc = "Total number of sessions since process started" },
166 [ST_F_BIN] = { .name = "bin", .desc = "Total number of request bytes since process started" },
167 [ST_F_BOUT] = { .name = "bout", .desc = "Total number of response bytes since process started" },
168 [ST_F_DREQ] = { .name = "dreq", .desc = "Total number of denied requests since process started" },
169 [ST_F_DRESP] = { .name = "dresp", .desc = "Total number of denied responses since process started" },
170 [ST_F_EREQ] = { .name = "ereq", .desc = "Total number of invalid requests since process started" },
171 [ST_F_ECON] = { .name = "econ", .desc = "Total number of failed connections to server since the worker process started" },
172 [ST_F_ERESP] = { .name = "eresp", .desc = "Total number of invalid responses since the worker process started" },
173 [ST_F_WRETR] = { .name = "wretr", .desc = "Total number of server connection retries since the worker process started" },
174 [ST_F_WREDIS] = { .name = "wredis", .desc = "Total number of server redispatches due to connection failures since the worker process started" },
175 [ST_F_STATUS] = { .name = "status", .desc = "Frontend/listen status: OPEN/WAITING/FULL/STOP; backend: UP/DOWN; server: last check status" },
176 [ST_F_WEIGHT] = { .name = "weight", .desc = "Server weight, or sum of active servers' weights for a backend" },
177 [ST_F_ACT] = { .name = "act", .desc = "Total number of active UP servers with a non-zero weight" },
178 [ST_F_BCK] = { .name = "bck", .desc = "Total number of backup UP servers with a non-zero weight" },
179 [ST_F_CHKFAIL] = { .name = "chkfail", .desc = "Total number of failed individual health checks per server/backend, since the worker process started" },
180 [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" },
181 [ST_F_LASTCHG] = { .name = "lastchg", .desc = "How long ago the last server state changed, in seconds" },
182 [ST_F_DOWNTIME] = { .name = "downtime", .desc = "Total time spent in DOWN state, for server or backend" },
183 [ST_F_QLIMIT] = { .name = "qlimit", .desc = "Limit on the number of connections in queue, for servers only (maxqueue argument)" },
184 [ST_F_PID] = { .name = "pid", .desc = "Relative worker process number (1..nbproc)" },
185 [ST_F_IID] = { .name = "iid", .desc = "Frontend or Backend numeric identifier ('id' setting)" },
186 [ST_F_SID] = { .name = "sid", .desc = "Server numeric identifier ('id' setting)" },
187 [ST_F_THROTTLE] = { .name = "throttle", .desc = "Throttling ratio applied to a server's maxconn and weight during the slowstart period (0 to 100%)" },
188 [ST_F_LBTOT] = { .name = "lbtot", .desc = "Total number of requests routed by load balancing since the worker process started (ignores queue pop and stickiness)" },
189 [ST_F_TRACKED] = { .name = "tracked", .desc = "Name of the other server this server tracks for its state" },
190 [ST_F_TYPE] = { .name = "type", .desc = "Type of the object (Listener, Frontend, Backend, Server)" },
191 [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)" },
192 [ST_F_RATE_LIM] = { .name = "rate_lim", .desc = "Limit on the number of sessions accepted in a second (frontend only, 'rate-limit sessions' setting)" },
193 [ST_F_RATE_MAX] = { .name = "rate_max", .desc = "Highest value of 'rate' observed since the worker process started" },
194 [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" },
195 [ST_F_CHECK_CODE] = { .name = "check_code", .desc = "HTTP/SMTP/LDAP status code reported by the latest server health check" },
196 [ST_F_CHECK_DURATION] = { .name = "check_duration", .desc = "Total duration of the latest server health check, in milliseconds" },
197 [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" },
198 [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" },
199 [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" },
200 [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" },
201 [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" },
202 [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)" },
203 [ST_F_HANAFAIL] = { .name = "hanafail", .desc = "Total number of failed checks caused by an 'on-error' directive after an 'observe' condition matched" },
204 [ST_F_REQ_RATE] = { .name = "req_rate", .desc = "Number of HTTP requests processed over the last second on this object" },
205 [ST_F_REQ_RATE_MAX] = { .name = "req_rate_max", .desc = "Highest value of 'req_rate' observed since the worker process started" },
206 [ST_F_REQ_TOT] = { .name = "req_tot", .desc = "Total number of HTTP requests processed by this object since the worker process started" },
207 [ST_F_CLI_ABRT] = { .name = "cli_abrt", .desc = "Total number of requests or connections aborted by the client since the worker process started" },
208 [ST_F_SRV_ABRT] = { .name = "srv_abrt", .desc = "Total number of requests or connections aborted by the server since the worker process started" },
209 [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" },
210 [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" },
211 [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)" },
212 [ST_F_COMP_RSP] = { .name = "comp_rsp", .desc = "Total number of HTTP responses that were compressed for this object since the worker process started" },
213 [ST_F_LASTSESS] = { .name = "lastsess", .desc = "How long ago some traffic was seen on this object on this worker process, in seconds" },
214 [ST_F_LAST_CHK] = { .name = "last_chk", .desc = "Short description of the latest health check report for this server (see also check_desc)" },
215 [ST_F_LAST_AGT] = { .name = "last_agt", .desc = "Short description of the latest agent check report for this server (see also agent_desc)" },
216 [ST_F_QTIME] = { .name = "qtime", .desc = "Time spent in the queue, in milliseconds, averaged over the 1024 last requests (backend/server)" },
217 [ST_F_CTIME] = { .name = "ctime", .desc = "Time spent waiting for a connection to complete, in milliseconds, averaged over the 1024 last requests (backend/server)" },
218 [ST_F_RTIME] = { .name = "rtime", .desc = "Time spent waiting for a server response, in milliseconds, averaged over the 1024 last requests (backend/server)" },
219 [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)" },
220 [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" },
221 [ST_F_AGENT_CODE] = { .name = "agent_code", .desc = "Status code reported by the latest server agent check" },
222 [ST_F_AGENT_DURATION] = { .name = "agent_duration", .desc = "Total duration of the latest server agent check, in milliseconds" },
223 [ST_F_CHECK_DESC] = { .name = "check_desc", .desc = "Textual description of the latest health check report for this server" },
224 [ST_F_AGENT_DESC] = { .name = "agent_desc", .desc = "Textual description of the latest agent check report for this server" },
225 [ST_F_CHECK_RISE] = { .name = "check_rise", .desc = "Number of successful health checks before declaring a server UP (server 'rise' setting)" },
226 [ST_F_CHECK_FALL] = { .name = "check_fall", .desc = "Number of failed health checks before declaring a server DOWN (server 'fall' setting)" },
227 [ST_F_CHECK_HEALTH] = { .name = "check_health", .desc = "Current server health check level (0..fall-1=DOWN, fall..rise-1=UP)" },
228 [ST_F_AGENT_RISE] = { .name = "agent_rise", .desc = "Number of successful agent checks before declaring a server UP (server 'rise' setting)" },
229 [ST_F_AGENT_FALL] = { .name = "agent_fall", .desc = "Number of failed agent checks before declaring a server DOWN (server 'fall' setting)" },
230 [ST_F_AGENT_HEALTH] = { .name = "agent_health", .desc = "Current server agent check level (0..fall-1=DOWN, fall..rise-1=UP)" },
231 [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" },
232 [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" },
233 [ST_F_MODE] = { .name = "mode", .desc = "'mode' setting (tcp/http/health/cli)" },
234 [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" },
235 [ST_F_CONN_RATE] = { .name = "conn_rate", .desc = "Number of new connections accepted over the last second on the frontend for this worker process" },
236 [ST_F_CONN_RATE_MAX] = { .name = "conn_rate_max", .desc = "Highest value of 'conn_rate' observed since the worker process started" },
237 [ST_F_CONN_TOT] = { .name = "conn_tot", .desc = "Total number of new connections accepted on this frontend since the worker process started" },
238 [ST_F_INTERCEPTED] = { .name = "intercepted", .desc = "Total number of HTTP requests intercepted on the frontend (redirects/stats/services) since the worker process started" },
239 [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" },
240 [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" },
241 [ST_F_WREW] = { .name = "wrew", .desc = "Total number of failed HTTP header rewrites since the worker process started" },
242 [ST_F_CONNECT] = { .name = "connect", .desc = "Total number of outgoing connection attempts on this backend/server since the worker process started" },
243 [ST_F_REUSE] = { .name = "reuse", .desc = "Total number of reused connection on this backend/server since the worker process started" },
244 [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" },
245 [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" },
246 [ST_F_SRV_ICUR] = { .name = "srv_icur", .desc = "Current number of idle connections available for reuse on this server" },
247 [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 +0100248};
249
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100250/* one line of info */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100251static THREAD_LOCAL struct field info[INF_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100252/* one line of stats */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100253static THREAD_LOCAL struct field stats[ST_F_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100254
Christopher Faulet6338a082019-09-09 15:50:54 +0200255static void stats_dump_json_schema(struct buffer *out);
William Lallemand74c24fb2016-11-21 17:18:36 +0100256
Christopher Fauletef779222018-10-31 08:47:01 +0100257static int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk)
258{
259 if (htx) {
Christopher Faulet69fc88c2019-01-07 14:27:53 +0100260 if (chk->data >= channel_htx_recv_max(chn, htx))
261 return 0;
Willy Tarreau0a7ef022019-05-28 10:30:11 +0200262 if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data)))
Christopher Fauletef779222018-10-31 08:47:01 +0100263 return 0;
Christopher Faulet5adbeeb2019-01-02 14:34:39 +0100264 channel_add_input(chn, chk->data);
Christopher Fauletef779222018-10-31 08:47:01 +0100265 chk->data = 0;
Christopher Fauletef779222018-10-31 08:47:01 +0100266 }
267 else {
268 if (ci_putchk(chn, chk) == -1)
269 return 0;
270 }
271 return 1;
272}
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100273
Christopher Fauleted7a0662019-01-14 11:07:34 +0100274static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interface *si)
275{
Christopher Fauletb7f88902019-07-15 21:56:43 +0200276 struct channel *req = si_oc(si);
277 struct htx *htx = htxbuf(&req->buf);
278 struct htx_blk *blk;
279 struct ist uri;
Christopher Fauleted7a0662019-01-14 11:07:34 +0100280
Christopher Fauletb7f88902019-07-15 21:56:43 +0200281 blk = htx_get_head_blk(htx);
282 BUG_ON(htx_get_blk_type(blk) != HTX_BLK_REQ_SL);
283 ALREADY_CHECKED(blk);
284 uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk));
285 return uri.ptr + appctx->ctx.stats.scope_str;
Christopher Fauleted7a0662019-01-14 11:07:34 +0100286}
287
William Lallemand74c24fb2016-11-21 17:18:36 +0100288/*
289 * http_stats_io_handler()
290 * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
291 * -> stats_dump_csv_header() // emits the CSV headers (same as above)
Simon Horman05ee2132017-01-04 09:37:25 +0100292 * -> stats_dump_json_header() // emits the JSON headers (same as above)
William Lallemand74c24fb2016-11-21 17:18:36 +0100293 * -> stats_dump_html_head() // emits the HTML headers
294 * -> stats_dump_html_info() // emits the equivalent of "show info" at the top
295 * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML
296 * -> stats_dump_html_px_hdr()
297 * -> stats_dump_fe_stats()
298 * -> stats_dump_li_stats()
299 * -> stats_dump_sv_stats()
300 * -> stats_dump_be_stats()
301 * -> stats_dump_html_px_end()
302 * -> stats_dump_html_end() // emits HTML trailer
Simon Horman05ee2132017-01-04 09:37:25 +0100303 * -> stats_dump_json_end() // emits JSON trailer
William Lallemand74c24fb2016-11-21 17:18:36 +0100304 */
305
306
William Lallemand74c24fb2016-11-21 17:18:36 +0100307/* Dumps the stats CSV header to the trash buffer which. The caller is responsible
308 * for clearing it if needed.
309 * NOTE: Some tools happen to rely on the field position instead of its name,
310 * so please only append new fields at the end, never in the middle.
311 */
312static void stats_dump_csv_header()
313{
314 int field;
315
316 chunk_appendf(&trash, "# ");
317 for (field = 0; field < ST_F_TOTAL_FIELDS; field++)
Willy Tarreaueaa55372019-10-09 07:39:11 +0200318 chunk_appendf(&trash, "%s,", stat_fields[field].name);
William Lallemand74c24fb2016-11-21 17:18:36 +0100319
320 chunk_appendf(&trash, "\n");
321}
322
323
324/* Emits a stats field without any surrounding element and properly encoded to
325 * resist CSV output. Returns non-zero on success, 0 if the buffer is full.
326 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200327int stats_emit_raw_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100328{
329 switch (field_format(f, 0)) {
330 case FF_EMPTY: return 1;
331 case FF_S32: return chunk_appendf(out, "%d", f->u.s32);
332 case FF_U32: return chunk_appendf(out, "%u", f->u.u32);
333 case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64);
334 case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64);
Christopher Faulet88a0db22019-09-24 16:35:10 +0200335 case FF_FLT: return chunk_appendf(out, "%f", f->u.flt);
William Lallemand74c24fb2016-11-21 17:18:36 +0100336 case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL;
337 default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type);
338 }
339}
340
341/* Emits a stats field prefixed with its type. No CSV encoding is prepared, the
342 * output is supposed to be used on its own line. Returns non-zero on success, 0
343 * if the buffer is full.
344 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200345int stats_emit_typed_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100346{
347 switch (field_format(f, 0)) {
348 case FF_EMPTY: return 1;
349 case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32);
350 case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32);
351 case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64);
352 case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64);
Christopher Faulet88a0db22019-09-24 16:35:10 +0200353 case FF_FLT: return chunk_appendf(out, "flt:%f", f->u.flt);
William Lallemand74c24fb2016-11-21 17:18:36 +0100354 case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0));
355 default: return chunk_appendf(out, "%08x:?", f->type);
356 }
357}
358
Simon Horman05ee2132017-01-04 09:37:25 +0100359/* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per
360 * the recommendation for interoperable integers in section 6 of RFC 7159.
361 */
362#define JSON_INT_MAX ((1ULL << 53) - 1)
363#define JSON_INT_MIN (0 - JSON_INT_MAX)
364
365/* Emits a stats field value and its type in JSON.
366 * Returns non-zero on success, 0 on error.
367 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200368int stats_emit_json_data_field(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100369{
370 int old_len;
371 char buf[20];
372 const char *type, *value = buf, *quote = "";
373
374 switch (field_format(f, 0)) {
375 case FF_EMPTY: return 1;
376 case FF_S32: type = "\"s32\"";
377 snprintf(buf, sizeof(buf), "%d", f->u.s32);
378 break;
379 case FF_U32: type = "\"u32\"";
380 snprintf(buf, sizeof(buf), "%u", f->u.u32);
381 break;
382 case FF_S64: type = "\"s64\"";
383 if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX)
384 return 0;
385 type = "\"s64\"";
386 snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64);
387 break;
388 case FF_U64: if (f->u.u64 > JSON_INT_MAX)
389 return 0;
390 type = "\"u64\"";
391 snprintf(buf, sizeof(buf), "%llu",
392 (unsigned long long) f->u.u64);
Christopher Faulet52c91bb2019-09-28 10:37:31 +0200393 break;
Christopher Faulet88a0db22019-09-24 16:35:10 +0200394 case FF_FLT: type = "\"flt\"";
395 snprintf(buf, sizeof(buf), "%f", f->u.flt);
Simon Horman05ee2132017-01-04 09:37:25 +0100396 break;
397 case FF_STR: type = "\"str\"";
398 value = field_str(f, 0);
399 quote = "\"";
400 break;
401 default: snprintf(buf, sizeof(buf), "%u", f->type);
402 type = buf;
403 value = "unknown";
404 quote = "\"";
405 break;
406 }
407
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200408 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100409 chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}",
410 type, quote, value, quote);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200411 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100412}
413
William Lallemand74c24fb2016-11-21 17:18:36 +0100414/* Emits an encoding of the field type on 3 characters followed by a delimiter.
415 * Returns non-zero on success, 0 if the buffer is full.
416 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200417int stats_emit_field_tags(struct buffer *out, const struct field *f,
418 char delim)
William Lallemand74c24fb2016-11-21 17:18:36 +0100419{
420 char origin, nature, scope;
421
422 switch (field_origin(f, 0)) {
423 case FO_METRIC: origin = 'M'; break;
424 case FO_STATUS: origin = 'S'; break;
425 case FO_KEY: origin = 'K'; break;
426 case FO_CONFIG: origin = 'C'; break;
427 case FO_PRODUCT: origin = 'P'; break;
428 default: origin = '?'; break;
429 }
430
431 switch (field_nature(f, 0)) {
432 case FN_GAUGE: nature = 'G'; break;
433 case FN_LIMIT: nature = 'L'; break;
434 case FN_MIN: nature = 'm'; break;
435 case FN_MAX: nature = 'M'; break;
436 case FN_RATE: nature = 'R'; break;
437 case FN_COUNTER: nature = 'C'; break;
438 case FN_DURATION: nature = 'D'; break;
439 case FN_AGE: nature = 'A'; break;
440 case FN_TIME: nature = 'T'; break;
441 case FN_NAME: nature = 'N'; break;
442 case FN_OUTPUT: nature = 'O'; break;
443 case FN_AVG: nature = 'a'; break;
444 default: nature = '?'; break;
445 }
446
447 switch (field_scope(f, 0)) {
448 case FS_PROCESS: scope = 'P'; break;
449 case FS_SERVICE: scope = 'S'; break;
450 case FS_SYSTEM: scope = 's'; break;
451 case FS_CLUSTER: scope = 'C'; break;
452 default: scope = '?'; break;
453 }
454
455 return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim);
456}
457
Simon Horman05ee2132017-01-04 09:37:25 +0100458/* Emits an encoding of the field type as JSON.
459 * Returns non-zero on success, 0 if the buffer is full.
460 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200461int stats_emit_json_field_tags(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100462{
463 const char *origin, *nature, *scope;
464 int old_len;
465
466 switch (field_origin(f, 0)) {
467 case FO_METRIC: origin = "Metric"; break;
468 case FO_STATUS: origin = "Status"; break;
469 case FO_KEY: origin = "Key"; break;
470 case FO_CONFIG: origin = "Config"; break;
471 case FO_PRODUCT: origin = "Product"; break;
472 default: origin = "Unknown"; break;
473 }
474
475 switch (field_nature(f, 0)) {
476 case FN_GAUGE: nature = "Gauge"; break;
477 case FN_LIMIT: nature = "Limit"; break;
478 case FN_MIN: nature = "Min"; break;
479 case FN_MAX: nature = "Max"; break;
480 case FN_RATE: nature = "Rate"; break;
481 case FN_COUNTER: nature = "Counter"; break;
482 case FN_DURATION: nature = "Duration"; break;
483 case FN_AGE: nature = "Age"; break;
484 case FN_TIME: nature = "Time"; break;
485 case FN_NAME: nature = "Name"; break;
486 case FN_OUTPUT: nature = "Output"; break;
487 case FN_AVG: nature = "Avg"; break;
488 default: nature = "Unknown"; break;
489 }
490
491 switch (field_scope(f, 0)) {
492 case FS_PROCESS: scope = "Process"; break;
493 case FS_SERVICE: scope = "Service"; break;
494 case FS_SYSTEM: scope = "System"; break;
495 case FS_CLUSTER: scope = "Cluster"; break;
496 default: scope = "Unknown"; break;
497 }
498
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200499 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100500 chunk_appendf(out, "\"tags\":{"
501 "\"origin\":\"%s\","
502 "\"nature\":\"%s\","
503 "\"scope\":\"%s\""
504 "}", origin, nature, scope);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200505 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100506}
William Lallemand74c24fb2016-11-21 17:18:36 +0100507
508/* Dump all fields from <stats> into <out> using CSV format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200509static int stats_dump_fields_csv(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +0200510 const struct field *stats, unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100511{
512 int field;
513
514 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
515 if (!stats_emit_raw_data_field(out, &stats[field]))
516 return 0;
517 if (!chunk_strcat(out, ","))
518 return 0;
519 }
520 chunk_strcat(out, "\n");
521 return 1;
522}
523
524/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200525static int stats_dump_fields_typed(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +0200526 const struct field *stats, unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100527{
528 int field;
529
530 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
531 if (!stats[field].type)
532 continue;
533
534 chunk_appendf(out, "%c.%u.%u.%d.%s.%u:",
535 stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' :
536 stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' :
537 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' :
538 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' :
539 '?',
540 stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32,
Willy Tarreaueaa55372019-10-09 07:39:11 +0200541 field, stat_fields[field].name, stats[ST_F_PID].u.u32);
William Lallemand74c24fb2016-11-21 17:18:36 +0100542
543 if (!stats_emit_field_tags(out, &stats[field], ':'))
544 return 0;
545 if (!stats_emit_typed_data_field(out, &stats[field]))
546 return 0;
Willy Tarreau6b19b142019-10-09 15:44:21 +0200547 if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", stat_fields[field].desc))
548 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +0100549 if (!chunk_strcat(out, "\n"))
550 return 0;
551 }
552 return 1;
553}
554
Simon Horman05ee2132017-01-04 09:37:25 +0100555/* Dump all fields from <stats> into <out> using the "show info json" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200556static int stats_dump_json_info_fields(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +0200557 const struct field *info, unsigned int flags)
Simon Horman05ee2132017-01-04 09:37:25 +0100558{
559 int field;
560 int started = 0;
561
562 if (!chunk_strcat(out, "["))
563 return 0;
564
565 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
566 int old_len;
567
568 if (!field_format(info, field))
569 continue;
570
571 if (started && !chunk_strcat(out, ","))
572 goto err;
573 started = 1;
574
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200575 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100576 chunk_appendf(out,
577 "{\"field\":{\"pos\":%d,\"name\":\"%s\"},"
578 "\"processNum\":%u,",
Willy Tarreaueaa55372019-10-09 07:39:11 +0200579 field, info_fields[field].name,
Simon Horman05ee2132017-01-04 09:37:25 +0100580 info[INF_PROCESS_NUM].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200581 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100582 goto err;
583
584 if (!stats_emit_json_field_tags(out, &info[field]))
585 goto err;
586
587 if (!stats_emit_json_data_field(out, &info[field]))
588 goto err;
589
590 if (!chunk_strcat(out, "}"))
591 goto err;
592 }
593
594 if (!chunk_strcat(out, "]"))
595 goto err;
596 return 1;
597
598err:
599 chunk_reset(out);
600 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
601 return 0;
602}
603
604/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200605static int stats_dump_fields_json(struct buffer *out,
606 const struct field *stats,
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +0200607 unsigned int flags)
Simon Horman05ee2132017-01-04 09:37:25 +0100608{
609 int field;
610 int started = 0;
611
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +0200612 if ((flags & STAT_STARTED) && !chunk_strcat(out, ","))
Simon Horman05ee2132017-01-04 09:37:25 +0100613 return 0;
614 if (!chunk_strcat(out, "["))
615 return 0;
616
617 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
618 const char *obj_type;
619 int old_len;
620
621 if (!stats[field].type)
622 continue;
623
624 if (started && !chunk_strcat(out, ","))
625 goto err;
626 started = 1;
627
628 switch (stats[ST_F_TYPE].u.u32) {
629 case STATS_TYPE_FE: obj_type = "Frontend"; break;
630 case STATS_TYPE_BE: obj_type = "Backend"; break;
631 case STATS_TYPE_SO: obj_type = "Listener"; break;
632 case STATS_TYPE_SV: obj_type = "Server"; break;
633 default: obj_type = "Unknown"; break;
634 }
635
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200636 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100637 chunk_appendf(out,
638 "{"
639 "\"objType\":\"%s\","
640 "\"proxyId\":%d,"
641 "\"id\":%d,"
642 "\"field\":{\"pos\":%d,\"name\":\"%s\"},"
643 "\"processNum\":%u,",
644 obj_type, stats[ST_F_IID].u.u32,
645 stats[ST_F_SID].u.u32, field,
Willy Tarreaueaa55372019-10-09 07:39:11 +0200646 stat_fields[field].name, stats[ST_F_PID].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200647 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100648 goto err;
649
650 if (!stats_emit_json_field_tags(out, &stats[field]))
651 goto err;
652
653 if (!stats_emit_json_data_field(out, &stats[field]))
654 goto err;
655
656 if (!chunk_strcat(out, "}"))
657 goto err;
658 }
659
660 if (!chunk_strcat(out, "]"))
661 goto err;
662
663 return 1;
664
665err:
666 chunk_reset(out);
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +0200667 if (flags & STAT_STARTED)
668 chunk_strcat(out, ",");
Simon Horman05ee2132017-01-04 09:37:25 +0100669 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
670 return 0;
671}
672
William Lallemand74c24fb2016-11-21 17:18:36 +0100673/* Dump all fields from <stats> into <out> using the HTML format. A column is
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200674 * reserved for the checkbox is STAT_ADMIN is set in <flags>. Some extra info
Willy Tarreau708c4162019-10-09 10:19:16 +0200675 * are provided if STAT_SHLGNDS is present in <flags>.
William Lallemand74c24fb2016-11-21 17:18:36 +0100676 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200677static int stats_dump_fields_html(struct buffer *out,
678 const struct field *stats,
679 unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100680{
Willy Tarreau83061a82018-07-13 11:56:34 +0200681 struct buffer src;
William Lallemand74c24fb2016-11-21 17:18:36 +0100682
683 if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) {
684 chunk_appendf(out,
685 /* name, queue */
686 "<tr class=\"frontend\">");
687
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200688 if (flags & STAT_ADMIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100689 /* Column sub-heading for Enable or Disable server */
690 chunk_appendf(out, "<td></td>");
691 }
692
693 chunk_appendf(out,
694 "<td class=ac>"
695 "<a name=\"%s/Frontend\"></a>"
696 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
697 "<td colspan=3></td>"
698 "",
699 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
700
701 chunk_appendf(out,
702 /* sessions rate : current */
703 "<td><u>%s<div class=tips><table class=det>"
704 "<tr><th>Current connection rate:</th><td>%s/s</td></tr>"
705 "<tr><th>Current session rate:</th><td>%s/s</td></tr>"
706 "",
707 U2H(stats[ST_F_RATE].u.u32),
708 U2H(stats[ST_F_CONN_RATE].u.u32),
709 U2H(stats[ST_F_RATE].u.u32));
710
711 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
712 chunk_appendf(out,
713 "<tr><th>Current request rate:</th><td>%s/s</td></tr>",
714 U2H(stats[ST_F_REQ_RATE].u.u32));
715
716 chunk_appendf(out,
717 "</table></div></u></td>"
718 /* sessions rate : max */
719 "<td><u>%s<div class=tips><table class=det>"
720 "<tr><th>Max connection rate:</th><td>%s/s</td></tr>"
721 "<tr><th>Max session rate:</th><td>%s/s</td></tr>"
722 "",
723 U2H(stats[ST_F_RATE_MAX].u.u32),
724 U2H(stats[ST_F_CONN_RATE_MAX].u.u32),
725 U2H(stats[ST_F_RATE_MAX].u.u32));
726
727 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
728 chunk_appendf(out,
729 "<tr><th>Max request rate:</th><td>%s/s</td></tr>",
730 U2H(stats[ST_F_REQ_RATE_MAX].u.u32));
731
732 chunk_appendf(out,
733 "</table></div></u></td>"
734 /* sessions rate : limit */
735 "<td>%s</td>",
736 LIM2A(stats[ST_F_RATE_LIM].u.u32, "-"));
737
738 chunk_appendf(out,
739 /* sessions: current, max, limit, total */
740 "<td>%s</td><td>%s</td><td>%s</td>"
741 "<td><u>%s<div class=tips><table class=det>"
742 "<tr><th>Cum. connections:</th><td>%s</td></tr>"
743 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
744 "",
745 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
746 U2H(stats[ST_F_STOT].u.u64),
747 U2H(stats[ST_F_CONN_TOT].u.u64),
748 U2H(stats[ST_F_STOT].u.u64));
749
750 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
751 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
752 chunk_appendf(out,
753 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
754 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
755 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
756 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
757 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
758 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
759 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
760 "<tr><th>- other responses:</th><td>%s</td></tr>"
761 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
Willy Tarreaua1214a52018-12-14 14:00:25 +0100762 "<tr><th>Cache lookups:</th><td>%s</td></tr>"
763 "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200764 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100765 "",
766 U2H(stats[ST_F_REQ_TOT].u.u64),
767 U2H(stats[ST_F_HRSP_1XX].u.u64),
768 U2H(stats[ST_F_HRSP_2XX].u.u64),
769 U2H(stats[ST_F_COMP_RSP].u.u64),
770 stats[ST_F_HRSP_2XX].u.u64 ?
771 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
772 U2H(stats[ST_F_HRSP_3XX].u.u64),
773 U2H(stats[ST_F_HRSP_4XX].u.u64),
774 U2H(stats[ST_F_HRSP_5XX].u.u64),
775 U2H(stats[ST_F_HRSP_OTHER].u.u64),
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200776 U2H(stats[ST_F_INTERCEPTED].u.u64),
Willy Tarreaua1214a52018-12-14 14:00:25 +0100777 U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
778 U2H(stats[ST_F_CACHE_HITS].u.u64),
779 stats[ST_F_CACHE_LOOKUPS].u.u64 ?
780 (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200781 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +0100782 }
783
784 chunk_appendf(out,
785 "</table></div></u></td>"
786 /* sessions: lbtot, lastsess */
787 "<td></td><td></td>"
788 /* bytes : in */
789 "<td>%s</td>"
790 "",
791 U2H(stats[ST_F_BIN].u.u64));
792
793 chunk_appendf(out,
794 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
795 "<td>%s%s<div class=tips><table class=det>"
796 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
797 "<tr><th>Compression in:</th><td>%s</td></tr>"
798 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
799 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
800 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
801 "</table></div>%s</td>",
802 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
803 U2H(stats[ST_F_BOUT].u.u64),
804 U2H(stats[ST_F_BOUT].u.u64),
805 U2H(stats[ST_F_COMP_IN].u.u64),
806 U2H(stats[ST_F_COMP_OUT].u.u64),
807 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
808 U2H(stats[ST_F_COMP_BYP].u.u64),
809 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
810 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,
811 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
812
813 chunk_appendf(out,
814 /* denied: req, resp */
815 "<td>%s</td><td>%s</td>"
816 /* errors : request, connect, response */
817 "<td>%s</td><td></td><td></td>"
818 /* warnings: retries, redispatches */
819 "<td></td><td></td>"
820 /* server status : reflect frontend status */
821 "<td class=ac>%s</td>"
822 /* rest of server: nothing */
823 "<td class=ac colspan=8></td></tr>"
824 "",
825 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
826 U2H(stats[ST_F_EREQ].u.u64),
827 field_str(stats, ST_F_STATUS));
828 }
829 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) {
830 chunk_appendf(out, "<tr class=socket>");
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200831 if (flags & STAT_ADMIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100832 /* Column sub-heading for Enable or Disable server */
833 chunk_appendf(out, "<td></td>");
834 }
835
836 chunk_appendf(out,
837 /* frontend name, listener name */
838 "<td class=ac><a name=\"%s/+%s\"></a>%s"
839 "<a class=lfsb href=\"#%s/+%s\">%s</a>"
840 "",
841 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
Willy Tarreau708c4162019-10-09 10:19:16 +0200842 (flags & STAT_SHLGNDS)?"<u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +0100843 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
844
Willy Tarreau708c4162019-10-09 10:19:16 +0200845 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100846 chunk_appendf(out, "<div class=tips>");
847
848 if (isdigit(*field_str(stats, ST_F_ADDR)))
849 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
850 else if (*field_str(stats, ST_F_ADDR) == '[')
851 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
852 else if (*field_str(stats, ST_F_ADDR))
853 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
854
855 /* id */
856 chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32);
857 }
858
859 chunk_appendf(out,
860 /* queue */
861 "%s</td><td colspan=3></td>"
862 /* sessions rate: current, max, limit */
863 "<td colspan=3>&nbsp;</td>"
864 /* sessions: current, max, limit, total, lbtot, lastsess */
865 "<td>%s</td><td>%s</td><td>%s</td>"
866 "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
867 /* bytes: in, out */
868 "<td>%s</td><td>%s</td>"
869 "",
Willy Tarreau708c4162019-10-09 10:19:16 +0200870 (flags & STAT_SHLGNDS)?"</u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +0100871 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
872 U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64));
873
874 chunk_appendf(out,
875 /* denied: req, resp */
876 "<td>%s</td><td>%s</td>"
877 /* errors: request, connect, response */
878 "<td>%s</td><td></td><td></td>"
879 /* warnings: retries, redispatches */
880 "<td></td><td></td>"
881 /* server status: reflect listener status */
882 "<td class=ac>%s</td>"
883 /* rest of server: nothing */
884 "<td class=ac colspan=8></td></tr>"
885 "",
886 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
887 U2H(stats[ST_F_EREQ].u.u64),
888 field_str(stats, ST_F_STATUS));
889 }
890 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) {
891 const char *style;
892
893 /* determine the style to use depending on the server's state,
894 * its health and weight. There isn't a 1-to-1 mapping between
895 * state and styles for the cases where the server is (still)
896 * up. The reason is that we don't want to report nolb and
897 * drain with the same color.
898 */
899
900 if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 ||
901 strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) {
902 style = "down";
903 }
904 else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) {
905 style = "going_up";
906 }
907 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) {
908 style = "going_down";
909 }
910 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) {
911 style = "nolb";
912 }
913 else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) {
914 style = "no_check";
915 }
916 else if (!stats[ST_F_CHKFAIL].type ||
917 stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) {
918 /* no check or max health = UP */
919 if (stats[ST_F_WEIGHT].u.u32)
920 style = "up";
921 else
922 style = "draining";
923 }
924 else {
925 style = "going_down";
926 }
927
928 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0)
929 chunk_appendf(out, "<tr class=\"maintain\">");
930 else
931 chunk_appendf(out,
932 "<tr class=\"%s_%s\">",
933 (stats[ST_F_BCK].u.u32) ? "backup" : "active", style);
934
935
Willy Tarreauab02b3f2019-10-09 11:11:46 +0200936 if (flags & STAT_ADMIN)
William Lallemand74c24fb2016-11-21 17:18:36 +0100937 chunk_appendf(out,
David Harrigand3db35a2016-12-30 12:12:49 +0000938 "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
939 field_str(stats, ST_F_PXNAME),
William Lallemand74c24fb2016-11-21 17:18:36 +0100940 field_str(stats, ST_F_SVNAME));
941
942 chunk_appendf(out,
943 "<td class=ac><a name=\"%s/%s\"></a>%s"
944 "<a class=lfsb href=\"#%s/%s\">%s</a>"
945 "",
946 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
Willy Tarreau708c4162019-10-09 10:19:16 +0200947 (flags & STAT_SHLGNDS) ? "<u>" : "",
William Lallemand74c24fb2016-11-21 17:18:36 +0100948 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
949
Willy Tarreau708c4162019-10-09 10:19:16 +0200950 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +0100951 chunk_appendf(out, "<div class=tips>");
952
953 if (isdigit(*field_str(stats, ST_F_ADDR)))
954 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
955 else if (*field_str(stats, ST_F_ADDR) == '[')
956 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
957 else if (*field_str(stats, ST_F_ADDR))
958 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
959
960 /* id */
961 chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32);
962
963 /* cookie */
964 if (stats[ST_F_COOKIE].type) {
965 chunk_appendf(out, ", cookie: '");
966 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
967 chunk_htmlencode(out, &src);
968 chunk_appendf(out, "'");
969 }
970
971 chunk_appendf(out, "</div>");
972 }
973
974 chunk_appendf(out,
975 /* queue : current, max, limit */
976 "%s</td><td>%s</td><td>%s</td><td>%s</td>"
977 /* sessions rate : current, max, limit */
978 "<td>%s</td><td>%s</td><td></td>"
979 "",
Willy Tarreau708c4162019-10-09 10:19:16 +0200980 (flags & STAT_SHLGNDS) ? "</u>" : "",
William Lallemand74c24fb2016-11-21 17:18:36 +0100981 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"),
982 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
983
984 chunk_appendf(out,
985 /* sessions: current, max, limit, total */
Willy Tarreauf21d17b2019-09-08 09:24:56 +0200986 "<td><u>%s<div class=tips>"
987 "<table class=det>"
988 "<tr><th>Current active connections:</th><td>%s</td></tr>"
989 "<tr><th>Current idle connections:</th><td>%s</td></tr>"
990 "<tr><th>Active connections limit:</th><td>%s</td></tr>"
991 "<tr><th>Idle connections limit:</th><td>%s</td></tr>"
992 "</table></div></u>"
993 "</td><td>%s</td><td>%s</td>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100994 "<td><u>%s<div class=tips><table class=det>"
995 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
996 "",
Willy Tarreauf21d17b2019-09-08 09:24:56 +0200997 U2H(stats[ST_F_SCUR].u.u32),
998 U2H(stats[ST_F_SCUR].u.u32),
999 U2H(stats[ST_F_SRV_ICUR].u.u32),
1000 LIM2A(stats[ST_F_SLIM].u.u32, "-"),
1001 stats[ST_F_SRV_ILIM].type ? U2H(stats[ST_F_SRV_ILIM].u.u32) : "-",
1002 U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"),
William Lallemand74c24fb2016-11-21 17:18:36 +01001003 U2H(stats[ST_F_STOT].u.u64),
1004 U2H(stats[ST_F_STOT].u.u64));
1005
1006 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1007 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
1008 unsigned long long tot;
1009
1010 tot = stats[ST_F_HRSP_OTHER].u.u64;
1011 tot += stats[ST_F_HRSP_1XX].u.u64;
1012 tot += stats[ST_F_HRSP_2XX].u.u64;
1013 tot += stats[ST_F_HRSP_3XX].u.u64;
1014 tot += stats[ST_F_HRSP_4XX].u.u64;
1015 tot += stats[ST_F_HRSP_5XX].u.u64;
1016
1017 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +01001018 "<tr><th>New connections:</th><td>%s</td></tr>"
1019 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001020 "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
1021 "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1022 "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1023 "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1024 "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1025 "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1026 "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001027 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001028 "",
Willy Tarreauf1573842018-12-14 11:35:36 +01001029 U2H(stats[ST_F_CONNECT].u.u64),
1030 U2H(stats[ST_F_REUSE].u.u64),
1031 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
1032 (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 +01001033 U2H(tot),
1034 U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0,
1035 U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0,
1036 U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0,
1037 U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0,
1038 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 +02001039 U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0,
1040 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +01001041 }
1042
1043 chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>");
1044 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
1045 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
1046 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
1047 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
1048 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
1049
1050 chunk_appendf(out,
1051 "</table></div></u></td>"
1052 /* sessions: lbtot, last */
1053 "<td>%s</td><td>%s</td>",
1054 U2H(stats[ST_F_LBTOT].u.u64),
1055 human_time(stats[ST_F_LASTSESS].u.s32, 1));
1056
1057 chunk_appendf(out,
1058 /* bytes : in, out */
1059 "<td>%s</td><td>%s</td>"
1060 /* denied: req, resp */
1061 "<td></td><td>%s</td>"
1062 /* errors : request, connect */
1063 "<td></td><td>%s</td>"
1064 /* errors : response */
1065 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1066 /* warnings: retries, redispatches */
1067 "<td>%lld</td><td>%lld</td>"
1068 "",
1069 U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64),
1070 U2H(stats[ST_F_DRESP].u.u64),
1071 U2H(stats[ST_F_ECON].u.u64),
1072 U2H(stats[ST_F_ERESP].u.u64),
1073 (long long)stats[ST_F_CLI_ABRT].u.u64,
1074 (long long)stats[ST_F_SRV_ABRT].u.u64,
1075 (long long)stats[ST_F_WRETR].u.u64,
1076 (long long)stats[ST_F_WREDIS].u.u64);
1077
1078 /* status, last change */
1079 chunk_appendf(out, "<td class=ac>");
1080
1081 /* FIXME!!!!
1082 * LASTCHG should contain the last change for *this* server and must be computed
1083 * properly above, as was done below, ie: this server if maint, otherwise ref server
1084 * if tracking. Note that ref is either local or remote depending on tracking.
1085 */
1086
1087
1088 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) {
1089 chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1));
1090 }
1091 else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) {
1092 chunk_strcat(out, "<i>no check</i>");
1093 }
1094 else {
1095 chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS));
1096 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) {
1097 if (stats[ST_F_CHECK_HEALTH].u.u32)
1098 chunk_strcat(out, " &uarr;");
1099 }
1100 else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1)
1101 chunk_strcat(out, " &darr;");
1102 }
1103
1104 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 &&
1105 stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) {
1106 chunk_appendf(out,
1107 "</td><td class=ac><u> %s",
1108 field_str(stats, ST_F_AGENT_STATUS));
1109
1110 if (stats[ST_F_AGENT_CODE].type)
1111 chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32);
1112
1113 if (stats[ST_F_AGENT_DURATION].type)
1114 chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64);
1115
1116 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC));
1117
1118 if (*field_str(stats, ST_F_LAST_AGT)) {
1119 chunk_appendf(out, ": ");
1120 chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT));
1121 chunk_htmlencode(out, &src);
1122 }
1123 chunk_appendf(out, "</div></u>");
1124 }
1125 else if (stats[ST_F_CHECK_STATUS].type) {
1126 chunk_appendf(out,
1127 "</td><td class=ac><u> %s",
1128 field_str(stats, ST_F_CHECK_STATUS));
1129
1130 if (stats[ST_F_CHECK_CODE].type)
1131 chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32);
1132
1133 if (stats[ST_F_CHECK_DURATION].type)
1134 chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64);
1135
1136 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC));
1137
1138 if (*field_str(stats, ST_F_LAST_CHK)) {
1139 chunk_appendf(out, ": ");
1140 chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK));
1141 chunk_htmlencode(out, &src);
1142 }
1143 chunk_appendf(out, "</div></u>");
1144 }
1145 else
1146 chunk_appendf(out, "</td><td>");
1147
1148 chunk_appendf(out,
1149 /* weight */
1150 "</td><td class=ac>%d</td>"
1151 /* act, bck */
1152 "<td class=ac>%s</td><td class=ac>%s</td>"
1153 "",
1154 stats[ST_F_WEIGHT].u.u32,
1155 stats[ST_F_BCK].u.u32 ? "-" : "Y",
1156 stats[ST_F_BCK].u.u32 ? "Y" : "-");
1157
1158 /* check failures: unique, fatal, down time */
1159 if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) {
1160 chunk_appendf(out, "<td class=ac colspan=3>resolution</td>");
1161 }
1162 else if (stats[ST_F_CHKFAIL].type) {
1163 chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64);
1164
1165 if (stats[ST_F_HANAFAIL].type)
1166 chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64);
1167
1168 chunk_appendf(out,
1169 "<div class=tips>Failed Health Checks%s</div></u></td>"
1170 "<td>%lld</td><td>%s</td>"
1171 "",
1172 stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "",
1173 (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1));
1174 }
1175 else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) {
1176 /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */
1177 chunk_appendf(out,
1178 "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>",
1179 field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED));
1180 }
1181 else
1182 chunk_appendf(out, "<td colspan=3></td>");
1183
1184 /* throttle */
1185 if (stats[ST_F_THROTTLE].type)
1186 chunk_appendf(out, "<td class=ac>%d %%</td></tr>\n", stats[ST_F_THROTTLE].u.u32);
1187 else
1188 chunk_appendf(out, "<td class=ac>-</td></tr>\n");
1189 }
1190 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) {
1191 chunk_appendf(out, "<tr class=\"backend\">");
Willy Tarreauab02b3f2019-10-09 11:11:46 +02001192 if (flags & STAT_ADMIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001193 /* Column sub-heading for Enable or Disable server */
1194 chunk_appendf(out, "<td></td>");
1195 }
1196 chunk_appendf(out,
1197 "<td class=ac>"
1198 /* name */
1199 "%s<a name=\"%s/Backend\"></a>"
1200 "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
1201 "",
Willy Tarreau708c4162019-10-09 10:19:16 +02001202 (flags & STAT_SHLGNDS)?"<u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001203 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
1204
Willy Tarreau708c4162019-10-09 10:19:16 +02001205 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001206 /* balancing */
1207 chunk_appendf(out, "<div class=tips>balancing: %s",
1208 field_str(stats, ST_F_ALGO));
1209
1210 /* cookie */
1211 if (stats[ST_F_COOKIE].type) {
1212 chunk_appendf(out, ", cookie: '");
1213 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
1214 chunk_htmlencode(out, &src);
1215 chunk_appendf(out, "'");
1216 }
1217 chunk_appendf(out, "</div>");
1218 }
1219
1220 chunk_appendf(out,
1221 "%s</td>"
1222 /* queue : current, max */
1223 "<td>%s</td><td>%s</td><td></td>"
1224 /* sessions rate : current, max, limit */
1225 "<td>%s</td><td>%s</td><td></td>"
1226 "",
Willy Tarreau708c4162019-10-09 10:19:16 +02001227 (flags & STAT_SHLGNDS)?"</u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001228 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32),
1229 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
1230
1231 chunk_appendf(out,
1232 /* sessions: current, max, limit, total */
1233 "<td>%s</td><td>%s</td><td>%s</td>"
1234 "<td><u>%s<div class=tips><table class=det>"
1235 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
1236 "",
Willy Tarreau8e0f1752016-12-12 15:07:29 +01001237 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 +01001238 U2H(stats[ST_F_STOT].u.u64),
1239 U2H(stats[ST_F_STOT].u.u64));
1240
1241 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1242 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
1243 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +01001244 "<tr><th>New connections:</th><td>%s</td></tr>"
1245 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001246 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
1247 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
1248 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
1249 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
1250 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
1251 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
1252 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
1253 "<tr><th>- other responses:</th><td>%s</td></tr>"
Willy Tarreaua1214a52018-12-14 14:00:25 +01001254 "<tr><th>Cache lookups:</th><td>%s</td></tr>"
1255 "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001256 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001257 "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
1258 "",
Willy Tarreauf1573842018-12-14 11:35:36 +01001259 U2H(stats[ST_F_CONNECT].u.u64),
1260 U2H(stats[ST_F_REUSE].u.u64),
1261 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
1262 (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 +01001263 U2H(stats[ST_F_REQ_TOT].u.u64),
1264 U2H(stats[ST_F_HRSP_1XX].u.u64),
1265 U2H(stats[ST_F_HRSP_2XX].u.u64),
1266 U2H(stats[ST_F_COMP_RSP].u.u64),
1267 stats[ST_F_HRSP_2XX].u.u64 ?
1268 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
1269 U2H(stats[ST_F_HRSP_3XX].u.u64),
1270 U2H(stats[ST_F_HRSP_4XX].u.u64),
1271 U2H(stats[ST_F_HRSP_5XX].u.u64),
Willy Tarreaufeead3a2018-12-14 13:48:44 +01001272 U2H(stats[ST_F_HRSP_OTHER].u.u64),
Willy Tarreaua1214a52018-12-14 14:00:25 +01001273 U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
1274 U2H(stats[ST_F_CACHE_HITS].u.u64),
1275 stats[ST_F_CACHE_LOOKUPS].u.u64 ?
1276 (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
Willy Tarreaufeead3a2018-12-14 13:48:44 +01001277 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +01001278 }
1279
1280 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
1281 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
1282 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
1283 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
1284 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
1285
1286 chunk_appendf(out,
1287 "</table></div></u></td>"
1288 /* sessions: lbtot, last */
1289 "<td>%s</td><td>%s</td>"
1290 /* bytes: in */
1291 "<td>%s</td>"
1292 "",
1293 U2H(stats[ST_F_LBTOT].u.u64),
1294 human_time(stats[ST_F_LASTSESS].u.s32, 1),
1295 U2H(stats[ST_F_BIN].u.u64));
1296
1297 chunk_appendf(out,
1298 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
1299 "<td>%s%s<div class=tips><table class=det>"
1300 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
1301 "<tr><th>Compression in:</th><td>%s</td></tr>"
1302 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
1303 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
1304 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
1305 "</table></div>%s</td>",
1306 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
1307 U2H(stats[ST_F_BOUT].u.u64),
1308 U2H(stats[ST_F_BOUT].u.u64),
1309 U2H(stats[ST_F_COMP_IN].u.u64),
1310 U2H(stats[ST_F_COMP_OUT].u.u64),
1311 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
1312 U2H(stats[ST_F_COMP_BYP].u.u64),
1313 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
1314 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,
1315 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
1316
1317 chunk_appendf(out,
1318 /* denied: req, resp */
1319 "<td>%s</td><td>%s</td>"
1320 /* errors : request, connect */
1321 "<td></td><td>%s</td>"
1322 /* errors : response */
1323 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1324 /* warnings: retries, redispatches */
1325 "<td>%lld</td><td>%lld</td>"
1326 /* backend status: reflect backend status (up/down): we display UP
1327 * if the backend has known working servers or if it has no server at
1328 * all (eg: for stats). Then we display the total weight, number of
1329 * active and backups. */
1330 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
1331 "<td class=ac>%d</td><td class=ac>%d</td>"
1332 "",
1333 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
1334 U2H(stats[ST_F_ECON].u.u64),
1335 U2H(stats[ST_F_ERESP].u.u64),
1336 (long long)stats[ST_F_CLI_ABRT].u.u64,
1337 (long long)stats[ST_F_SRV_ABRT].u.u64,
1338 (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64,
1339 human_time(stats[ST_F_LASTCHG].u.u32, 1),
1340 strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>",
1341 stats[ST_F_WEIGHT].u.u32,
1342 stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32);
1343
1344 chunk_appendf(out,
1345 /* rest of backend: nothing, down transitions, total downtime, throttle */
1346 "<td class=ac>&nbsp;</td><td>%d</td>"
1347 "<td>%s</td>"
1348 "<td></td>"
1349 "</tr>",
1350 stats[ST_F_CHKDOWN].u.u32,
1351 stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : "&nbsp;");
1352 }
1353 return 1;
1354}
1355
Willy Tarreau43241ff2019-10-09 11:27:51 +02001356static int stats_dump_one_line(const struct field *stats, struct proxy *px, struct appctx *appctx)
William Lallemand74c24fb2016-11-21 17:18:36 +01001357{
Simon Horman05ee2132017-01-04 09:37:25 +01001358 int ret;
1359
William Lallemand74c24fb2016-11-21 17:18:36 +01001360 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Willy Tarreau43241ff2019-10-09 11:27:51 +02001361 ret = stats_dump_fields_html(&trash, stats, appctx->ctx.stats.flags);
William Lallemand74c24fb2016-11-21 17:18:36 +01001362 else if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
Willy Tarreau43241ff2019-10-09 11:27:51 +02001363 ret = stats_dump_fields_typed(&trash, stats, appctx->ctx.stats.flags);
Simon Horman05ee2132017-01-04 09:37:25 +01001364 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreaub0ce3ad2019-10-09 11:19:29 +02001365 ret = stats_dump_fields_json(&trash, stats, appctx->ctx.stats.flags);
William Lallemand74c24fb2016-11-21 17:18:36 +01001366 else
Willy Tarreau43241ff2019-10-09 11:27:51 +02001367 ret = stats_dump_fields_csv(&trash, stats, appctx->ctx.stats.flags);
Simon Horman05ee2132017-01-04 09:37:25 +01001368
1369 if (ret)
1370 appctx->ctx.stats.flags |= STAT_STARTED;
1371
1372 return ret;
William Lallemand74c24fb2016-11-21 17:18:36 +01001373}
1374
1375/* Fill <stats> with the frontend statistics. <stats> is
1376 * preallocated array of length <len>. The length of the array
1377 * must be at least ST_F_TOTAL_FIELDS. If this length is less then
1378 * this value, the function returns 0, otherwise, it returns 1.
1379 */
1380int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len)
1381{
1382 if (len < ST_F_TOTAL_FIELDS)
1383 return 0;
1384
1385 memset(stats, 0, sizeof(*stats) * len);
1386
1387 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1388 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND");
1389 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1390 stats[ST_F_SCUR] = mkf_u32(0, px->feconn);
1391 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1392 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1393 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1394 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1395 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1396 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1397 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1398 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1399 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1400 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1401 stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP");
1402 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1403 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1404 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1405 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE);
1406 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec));
1407 stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1408 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001409 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001410
1411 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1412 if (px->mode == PR_MODE_HTTP) {
1413 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1414 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1415 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1416 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1417 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1418 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1419 stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
Willy Tarreaua1214a52018-12-14 14:00:25 +01001420 stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1421 stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
William Lallemand74c24fb2016-11-21 17:18:36 +01001422 }
1423
1424 /* requests : req_rate, req_rate_max, req_tot, */
1425 stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec));
1426 stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1427 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1428
1429 /* compression: in, out, bypassed, responses */
1430 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1431 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1432 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1433 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1434
1435 /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */
1436 stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec));
1437 stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1438 stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1439
1440 return 1;
1441}
1442
1443/* Dumps a frontend's line to the trash for the current proxy <px> and uses
1444 * the state from stream interface <si>. The caller is responsible for clearing
1445 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
1446 */
1447static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
1448{
1449 struct appctx *appctx = __objt_appctx(si->end);
1450
1451 if (!(px->cap & PR_CAP_FE))
1452 return 0;
1453
1454 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE)))
1455 return 0;
1456
1457 if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS))
1458 return 0;
1459
Willy Tarreau43241ff2019-10-09 11:27:51 +02001460 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001461}
1462
1463/* Fill <stats> with the listener statistics. <stats> is
1464 * preallocated array of length <len>. The length of the array
1465 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1466 * then this value, the function returns 0, otherwise, it
Willy Tarreau708c4162019-10-09 10:19:16 +02001467 * returns 1. <flags> can take the value STAT_SHLGNDS.
William Lallemand74c24fb2016-11-21 17:18:36 +01001468 */
1469int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
1470 struct field *stats, int len)
1471{
Willy Tarreau83061a82018-07-13 11:56:34 +02001472 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001473
1474 if (len < ST_F_TOTAL_FIELDS)
1475 return 0;
1476
1477 if (!l->counters)
1478 return 0;
1479
1480 chunk_reset(out);
1481 memset(stats, 0, sizeof(*stats) * len);
1482
1483 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1484 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name);
1485 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1486 stats[ST_F_SCUR] = mkf_u32(0, l->nbconn);
1487 stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max);
1488 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn);
1489 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn);
1490 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in);
1491 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out);
1492 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req);
1493 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp);
1494 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req);
1495 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn);
1496 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess);
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001497 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 +01001498 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1499 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1500 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid);
1501 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001502 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, l->counters->failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001503
Willy Tarreau708c4162019-10-09 10:19:16 +02001504 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001505 char str[INET6_ADDRSTRLEN];
1506 int port;
1507
1508 port = get_host_port(&l->addr);
1509 switch (addr_to_str(&l->addr, str, sizeof(str))) {
1510 case AF_INET:
1511 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1512 chunk_appendf(out, "%s:%d", str, port);
1513 break;
1514 case AF_INET6:
1515 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1516 chunk_appendf(out, "[%s]:%d", str, port);
1517 break;
1518 case AF_UNIX:
1519 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1520 break;
1521 case -1:
1522 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1523 chunk_strcat(out, strerror(errno));
1524 break;
1525 default: /* address family not supported */
1526 break;
1527 }
1528 }
1529
1530 return 1;
1531}
1532
1533/* Dumps a line for listener <l> and proxy <px> to the trash and uses the state
Willy Tarreau43241ff2019-10-09 11:27:51 +02001534 * from stream interface <si>. The caller is responsible for clearing the trash
1535 * if needed. Returns non-zero if it emits anything, zero otherwise.
William Lallemand74c24fb2016-11-21 17:18:36 +01001536 */
Willy Tarreau43241ff2019-10-09 11:27:51 +02001537static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l)
William Lallemand74c24fb2016-11-21 17:18:36 +01001538{
1539 struct appctx *appctx = __objt_appctx(si->end);
1540
Willy Tarreau43241ff2019-10-09 11:27:51 +02001541 if (!stats_fill_li_stats(px, l, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
William Lallemand74c24fb2016-11-21 17:18:36 +01001542 return 0;
1543
Willy Tarreau43241ff2019-10-09 11:27:51 +02001544 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001545}
1546
1547enum srv_stats_state {
1548 SRV_STATS_STATE_DOWN = 0,
1549 SRV_STATS_STATE_DOWN_AGENT,
1550 SRV_STATS_STATE_GOING_UP,
1551 SRV_STATS_STATE_UP_GOING_DOWN,
1552 SRV_STATS_STATE_UP,
1553 SRV_STATS_STATE_NOLB_GOING_DOWN,
1554 SRV_STATS_STATE_NOLB,
1555 SRV_STATS_STATE_DRAIN_GOING_DOWN,
1556 SRV_STATS_STATE_DRAIN,
1557 SRV_STATS_STATE_DRAIN_AGENT,
1558 SRV_STATS_STATE_NO_CHECK,
1559
1560 SRV_STATS_STATE_COUNT, /* Must be last */
1561};
1562
1563static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
1564 [SRV_STATS_STATE_DOWN] = "DOWN",
1565 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)",
1566 [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d",
1567 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d",
1568 [SRV_STATS_STATE_UP] = "UP",
1569 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d",
1570 [SRV_STATS_STATE_NOLB] = "NOLB",
1571 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d",
1572 [SRV_STATS_STATE_DRAIN] = "DRAIN",
1573 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
1574 [SRV_STATS_STATE_NO_CHECK] = "no check"
1575};
1576
1577/* Fill <stats> with the server statistics. <stats> is
1578 * preallocated array of length <len>. The length of the array
1579 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1580 * then this value, the function returns 0, otherwise, it
Willy Tarreau708c4162019-10-09 10:19:16 +02001581 * returns 1. <flags> can take the value STAT_SHLGNDS.
William Lallemand74c24fb2016-11-21 17:18:36 +01001582 */
1583int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
1584 struct field *stats, int len)
1585{
1586 struct server *via, *ref;
1587 char str[INET6_ADDRSTRLEN];
Willy Tarreau83061a82018-07-13 11:56:34 +02001588 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001589 enum srv_stats_state state;
1590 char *fld_status;
1591
1592 if (len < ST_F_TOTAL_FIELDS)
1593 return 0;
1594
1595 memset(stats, 0, sizeof(*stats) * len);
1596
1597 /* we have "via" which is the tracked server as described in the configuration,
1598 * and "ref" which is the checked server and the end of the chain.
1599 */
1600 via = sv->track ? sv->track : sv;
1601 ref = via;
1602 while (ref->track)
1603 ref = ref->track;
1604
Emeric Brun52a91d32017-08-31 14:41:55 +02001605 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001606 if ((ref->check.state & CHK_ST_ENABLED) &&
1607 (ref->check.health < ref->check.rise + ref->check.fall - 1)) {
1608 state = SRV_STATS_STATE_UP_GOING_DOWN;
1609 } else {
1610 state = SRV_STATS_STATE_UP;
1611 }
1612
Emeric Brun52a91d32017-08-31 14:41:55 +02001613 if (sv->cur_admin & SRV_ADMF_DRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001614 if (ref->agent.state & CHK_ST_ENABLED)
1615 state = SRV_STATS_STATE_DRAIN_AGENT;
1616 else if (state == SRV_STATS_STATE_UP_GOING_DOWN)
1617 state = SRV_STATS_STATE_DRAIN_GOING_DOWN;
1618 else
1619 state = SRV_STATS_STATE_DRAIN;
1620 }
1621
1622 if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) {
1623 state = SRV_STATS_STATE_NO_CHECK;
1624 }
1625 }
Emeric Brun52a91d32017-08-31 14:41:55 +02001626 else if (sv->cur_state == SRV_ST_STOPPING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001627 if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) ||
1628 (ref->check.health == ref->check.rise + ref->check.fall - 1)) {
1629 state = SRV_STATS_STATE_NOLB;
1630 } else {
1631 state = SRV_STATS_STATE_NOLB_GOING_DOWN;
1632 }
1633 }
1634 else { /* stopped */
1635 if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) {
1636 state = SRV_STATS_STATE_DOWN_AGENT;
1637 } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) {
1638 state = SRV_STATS_STATE_DOWN; /* DOWN */
1639 } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) {
1640 state = SRV_STATS_STATE_GOING_UP;
1641 } else {
1642 state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */
1643 }
1644 }
1645
1646 chunk_reset(out);
1647
1648 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1649 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id);
1650 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1651 stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend);
1652 stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1653 stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess);
1654 stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1655
1656 if (sv->maxconn)
1657 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1658
Willy Tarreauf21d17b2019-09-08 09:24:56 +02001659 stats[ST_F_SRV_ICUR] = mkf_u32(0, sv->curr_idle_conns);
1660 if (sv->max_idle_conns != -1)
1661 stats[ST_F_SRV_ILIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->max_idle_conns);
1662
William Lallemand74c24fb2016-11-21 17:18:36 +01001663 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1664 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1665 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1666 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu);
1667 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1668 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1669 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries);
1670 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001671 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001672 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, sv->counters.connect);
1673 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, sv->counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001674
1675 /* status */
1676 fld_status = chunk_newstr(out);
Emeric Brun52a91d32017-08-31 14:41:55 +02001677 if (sv->cur_admin & SRV_ADMF_RMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001678 chunk_appendf(out, "MAINT (resolution)");
Emeric Brun52a91d32017-08-31 14:41:55 +02001679 else if (sv->cur_admin & SRV_ADMF_IMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001680 chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id);
Emeric Brun52a91d32017-08-31 14:41:55 +02001681 else if (sv->cur_admin & SRV_ADMF_MAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001682 chunk_appendf(out, "MAINT");
1683 else
1684 chunk_appendf(out,
1685 srv_hlt_st[state],
Emeric Brun52a91d32017-08-31 14:41:55 +02001686 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
1687 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
William Lallemand74c24fb2016-11-21 17:18:36 +01001688
1689 stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status);
1690 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
Emeric Brun52a91d32017-08-31 14:41:55 +02001691 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 +01001692 stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1);
1693 stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0);
1694
1695 /* check failures: unique, fatal; last change, total downtime */
1696 if (sv->check.state & CHK_ST_ENABLED) {
1697 stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1698 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1699 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv));
1700 }
1701
1702 if (sv->maxqueue)
1703 stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1704
1705 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1706 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1707 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid);
1708
Emeric Brun52a91d32017-08-31 14:41:55 +02001709 if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv))
William Lallemand74c24fb2016-11-21 17:18:36 +01001710 stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv));
1711
1712 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1713
1714 if (sv->track) {
1715 char *fld_track = chunk_newstr(out);
1716
1717 chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id);
1718 stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track);
1719 }
1720
1721 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV);
1722 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec));
1723 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max);
1724
1725 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1726 const char *fld_chksts;
1727
1728 fld_chksts = chunk_newstr(out);
1729 chunk_strcat(out, "* "); // for check in progress
1730 chunk_strcat(out, get_check_status_info(sv->check.status));
1731 if (!(sv->check.state & CHK_ST_INPROGRESS))
1732 fld_chksts += 2; // skip "* "
1733 stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1734
1735 if (sv->check.status >= HCHK_STATUS_L57DATA)
1736 stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code);
1737
1738 if (sv->check.status >= HCHK_STATUS_CHECKED)
1739 stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration);
1740
1741 stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status));
1742 stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc);
1743 stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise);
1744 stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall);
1745 stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health);
1746 }
1747
1748 if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1749 const char *fld_chksts;
1750
1751 fld_chksts = chunk_newstr(out);
1752 chunk_strcat(out, "* "); // for check in progress
1753 chunk_strcat(out, get_check_status_info(sv->agent.status));
1754 if (!(sv->agent.state & CHK_ST_INPROGRESS))
1755 fld_chksts += 2; // skip "* "
1756 stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1757
1758 if (sv->agent.status >= HCHK_STATUS_L57DATA)
1759 stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code);
1760
1761 if (sv->agent.status >= HCHK_STATUS_CHECKED)
1762 stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration);
1763
1764 stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status));
1765 stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc);
1766 stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise);
1767 stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall);
1768 stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health);
1769 }
1770
1771 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1772 if (px->mode == PR_MODE_HTTP) {
1773 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1774 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1775 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1776 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1777 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
1778 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
1779 }
1780
1781 if (ref->observe)
1782 stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana);
1783
1784 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1785 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1786 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv));
1787
1788 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES));
1789 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES));
1790 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
1791 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
1792
Willy Tarreau708c4162019-10-09 10:19:16 +02001793 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001794 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
1795 case AF_INET:
1796 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001797 chunk_appendf(out, "%s:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001798 break;
1799 case AF_INET6:
1800 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001801 chunk_appendf(out, "[%s]:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001802 break;
1803 case AF_UNIX:
1804 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1805 break;
1806 case -1:
1807 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1808 chunk_strcat(out, strerror(errno));
1809 break;
1810 default: /* address family not supported */
1811 break;
1812 }
1813
1814 if (sv->cookie)
1815 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie);
1816 }
1817
1818 return 1;
1819}
1820
1821/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
Willy Tarreau43241ff2019-10-09 11:27:51 +02001822 * from stream interface <si>, and server state <state>. The caller is
1823 * responsible for clearing the trash if needed. Returns non-zero if it emits
1824 * anything, zero otherwise.
William Lallemand74c24fb2016-11-21 17:18:36 +01001825 */
Willy Tarreau43241ff2019-10-09 11:27:51 +02001826static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, struct server *sv)
William Lallemand74c24fb2016-11-21 17:18:36 +01001827{
1828 struct appctx *appctx = __objt_appctx(si->end);
1829
Willy Tarreau43241ff2019-10-09 11:27:51 +02001830 if (!stats_fill_sv_stats(px, sv, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
William Lallemand74c24fb2016-11-21 17:18:36 +01001831 return 0;
1832
Willy Tarreau43241ff2019-10-09 11:27:51 +02001833 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001834}
1835
1836/* Fill <stats> with the backend statistics. <stats> is
1837 * preallocated array of length <len>. The length of the array
1838 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1839 * then this value, the function returns 0, otherwise, it
Willy Tarreau708c4162019-10-09 10:19:16 +02001840 * returns 1. <flags> can take the value STAT_SHLGNDS.
William Lallemand74c24fb2016-11-21 17:18:36 +01001841 */
1842int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len)
1843{
1844 if (len < ST_F_TOTAL_FIELDS)
1845 return 0;
1846
1847 memset(stats, 0, sizeof(*stats) * len);
1848
1849 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1850 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND");
1851 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1852 stats[ST_F_QCUR] = mkf_u32(0, px->nbpend);
1853 stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
Thierry FOURNIER0ff98a42016-12-19 16:50:42 +01001854 stats[ST_F_SCUR] = mkf_u32(0, px->beconn);
William Lallemand74c24fb2016-11-21 17:18:36 +01001855 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max);
1856 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1857 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1858 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1859 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1860 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1861 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1862 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1863 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1864 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries);
1865 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001866 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001867 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, px->be_counters.connect);
1868 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, px->be_counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001869 stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN");
1870 stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv);
1871 stats[ST_F_ACT] = mkf_u32(0, px->srv_act);
1872 stats[ST_F_BCK] = mkf_u32(0, px->srv_bck);
1873 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans);
1874 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1875 if (px->srv)
1876 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px));
1877
1878 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1879 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1880 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1881 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1882 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE);
1883 stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec));
1884 stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max);
1885
Willy Tarreau708c4162019-10-09 10:19:16 +02001886 if (flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001887 if (px->cookie_name)
1888 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name);
1889 stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
1890 }
1891
1892 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1893 if (px->mode == PR_MODE_HTTP) {
1894 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1895 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1896 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1897 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1898 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1899 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1900 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
Willy Tarreaua1214a52018-12-14 14:00:25 +01001901 stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1902 stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
William Lallemand74c24fb2016-11-21 17:18:36 +01001903 }
1904
1905 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1906 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1907
1908 /* compression: in, out, bypassed, responses */
1909 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1910 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1911 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1912 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1913 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px));
1914
1915 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES));
1916 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES));
1917 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES));
1918 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
1919
1920 return 1;
1921}
1922
1923/* Dumps a line for backend <px> to the trash for and uses the state from stream
Willy Tarreau43241ff2019-10-09 11:27:51 +02001924 * interface <si>. The caller is responsible for clearing the trash if needed.
1925 * Returns non-zero if it emits anything, zero otherwise.
William Lallemand74c24fb2016-11-21 17:18:36 +01001926 */
Willy Tarreau43241ff2019-10-09 11:27:51 +02001927static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px)
William Lallemand74c24fb2016-11-21 17:18:36 +01001928{
1929 struct appctx *appctx = __objt_appctx(si->end);
1930
1931 if (!(px->cap & PR_CAP_BE))
1932 return 0;
1933
1934 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
1935 return 0;
1936
Willy Tarreau43241ff2019-10-09 11:27:51 +02001937 if (!stats_fill_be_stats(px, appctx->ctx.stats.flags, stats, ST_F_TOTAL_FIELDS))
William Lallemand74c24fb2016-11-21 17:18:36 +01001938 return 0;
1939
Willy Tarreau43241ff2019-10-09 11:27:51 +02001940 return stats_dump_one_line(stats, px, appctx);
William Lallemand74c24fb2016-11-21 17:18:36 +01001941}
1942
1943/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from
1944 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
1945 * for clearing the trash if needed.
1946 */
Willy Tarreau676c29e2019-10-09 10:50:01 +02001947static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px)
William Lallemand74c24fb2016-11-21 17:18:36 +01001948{
1949 struct appctx *appctx = __objt_appctx(si->end);
1950 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
1951
1952 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
1953 /* A form to enable/disable this proxy servers */
1954
1955 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
1956 scope_txt[0] = 0;
1957 if (appctx->ctx.stats.scope_len) {
Christopher Fauleted7a0662019-01-14 11:07:34 +01001958 const char *scope_ptr = stats_scope_ptr(appctx, si);
1959
William Lallemand74c24fb2016-11-21 17:18:36 +01001960 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01001961 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01001962 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
1963 }
1964
1965 chunk_appendf(&trash,
1966 "<form method=\"post\">");
1967 }
1968
1969 /* print a new table */
1970 chunk_appendf(&trash,
1971 "<table class=\"tbl\" width=\"100%%\">\n"
1972 "<tr class=\"titre\">"
1973 "<th class=\"pxname\" width=\"10%%\">");
1974
1975 chunk_appendf(&trash,
1976 "<a name=\"%s\"></a>%s"
1977 "<a class=px href=\"#%s\">%s</a>",
1978 px->id,
Willy Tarreau676c29e2019-10-09 10:50:01 +02001979 (appctx->ctx.stats.flags & STAT_SHLGNDS) ? "<u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001980 px->id, px->id);
1981
Willy Tarreau676c29e2019-10-09 10:50:01 +02001982 if (appctx->ctx.stats.flags & STAT_SHLGNDS) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001983 /* cap, mode, id */
1984 chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
1985 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
1986 px->uuid);
1987 chunk_appendf(&trash, "</div>");
1988 }
1989
1990 chunk_appendf(&trash,
1991 "%s</th>"
1992 "<th class=\"%s\" width=\"90%%\">%s</th>"
1993 "</tr>\n"
1994 "</table>\n"
1995 "<table class=\"tbl\" width=\"100%%\">\n"
1996 "<tr class=\"titre\">",
Willy Tarreau676c29e2019-10-09 10:50:01 +02001997 (appctx->ctx.stats.flags & STAT_SHLGNDS) ? "</u>":"",
William Lallemand74c24fb2016-11-21 17:18:36 +01001998 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
1999
2000 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
2001 /* Column heading for Enable or Disable server */
David Harrigand3db35a2016-12-30 12:12:49 +00002002 chunk_appendf(&trash,
2003 "<th rowspan=2 width=1><input type=\"checkbox\" \
2004 onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) \
2005 document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>",
2006 px->id,
2007 px->id);
William Lallemand74c24fb2016-11-21 17:18:36 +01002008 }
2009
2010 chunk_appendf(&trash,
2011 "<th rowspan=2></th>"
2012 "<th colspan=3>Queue</th>"
2013 "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
2014 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
2015 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
2016 "<th colspan=9>Server</th>"
2017 "</tr>\n"
2018 "<tr class=\"titre\">"
2019 "<th>Cur</th><th>Max</th><th>Limit</th>"
2020 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
2021 "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>"
2022 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
2023 "<th>Resp</th><th>Retr</th><th>Redis</th>"
2024 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
2025 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
2026 "<th>Thrtle</th>\n"
2027 "</tr>");
2028}
2029
2030/* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from
2031 * stream interface <si>. The caller is responsible for clearing the trash if needed.
2032 */
2033static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px)
2034{
2035 struct appctx *appctx = __objt_appctx(si->end);
2036 chunk_appendf(&trash, "</table>");
2037
2038 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
2039 /* close the form used to enable/disable this proxy servers */
2040 chunk_appendf(&trash,
2041 "Choose the action to perform on the checked servers : "
2042 "<select name=action>"
2043 "<option value=\"\"></option>"
2044 "<option value=\"ready\">Set state to READY</option>"
2045 "<option value=\"drain\">Set state to DRAIN</option>"
2046 "<option value=\"maint\">Set state to MAINT</option>"
2047 "<option value=\"dhlth\">Health: disable checks</option>"
2048 "<option value=\"ehlth\">Health: enable checks</option>"
2049 "<option value=\"hrunn\">Health: force UP</option>"
2050 "<option value=\"hnolb\">Health: force NOLB</option>"
2051 "<option value=\"hdown\">Health: force DOWN</option>"
2052 "<option value=\"dagent\">Agent: disable checks</option>"
2053 "<option value=\"eagent\">Agent: enable checks</option>"
2054 "<option value=\"arunn\">Agent: force UP</option>"
2055 "<option value=\"adown\">Agent: force DOWN</option>"
2056 "<option value=\"shutdown\">Kill Sessions</option>"
2057 "</select>"
2058 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
2059 "&nbsp;<input type=\"submit\" value=\"Apply\">"
2060 "</form>",
2061 px->uuid);
2062 }
2063
2064 chunk_appendf(&trash, "<p>\n");
2065}
2066
2067/*
2068 * Dumps statistics for a proxy. The output is sent to the stream interface's
2069 * input buffer. Returns 0 if it had to stop dumping data because of lack of
2070 * buffer space, or non-zero if everything completed. This function is used
2071 * both by the CLI and the HTTP entry points, and is able to dump the output
2072 * in HTML or CSV formats. If the later, <uri> must be NULL.
2073 */
Christopher Fauletef779222018-10-31 08:47:01 +01002074int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
2075 struct proxy *px, struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002076{
2077 struct appctx *appctx = __objt_appctx(si->end);
2078 struct stream *s = si_strm(si);
2079 struct channel *rep = si_ic(si);
2080 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
2081 struct listener *l;
William Lallemand74c24fb2016-11-21 17:18:36 +01002082
2083 chunk_reset(&trash);
2084
2085 switch (appctx->ctx.stats.px_st) {
2086 case STAT_PX_ST_INIT:
2087 /* we are on a new proxy */
2088 if (uri && uri->scope) {
2089 /* we have a limited scope, we have to check the proxy name */
2090 struct stat_scope *scope;
2091 int len;
2092
2093 len = strlen(px->id);
2094 scope = uri->scope;
2095
2096 while (scope) {
2097 /* match exact proxy name */
2098 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2099 break;
2100
2101 /* match '.' which means 'self' proxy */
2102 if (!strcmp(scope->px_id, ".") && px == s->be)
2103 break;
2104 scope = scope->next;
2105 }
2106
2107 /* proxy name not found : don't dump anything */
2108 if (scope == NULL)
2109 return 1;
2110 }
2111
2112 /* if the user has requested a limited output and the proxy
2113 * name does not match, skip it.
2114 */
Christopher Fauleted7a0662019-01-14 11:07:34 +01002115 if (appctx->ctx.stats.scope_len) {
2116 const char *scope_ptr = stats_scope_ptr(appctx, si);
2117
2118 if (strnistr(px->id, strlen(px->id), scope_ptr, appctx->ctx.stats.scope_len) == NULL)
2119 return 1;
2120 }
William Lallemand74c24fb2016-11-21 17:18:36 +01002121
2122 if ((appctx->ctx.stats.flags & STAT_BOUND) &&
2123 (appctx->ctx.stats.iid != -1) &&
2124 (px->uuid != appctx->ctx.stats.iid))
2125 return 1;
2126
2127 appctx->ctx.stats.px_st = STAT_PX_ST_TH;
2128 /* fall through */
2129
2130 case STAT_PX_ST_TH:
2131 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
Willy Tarreau676c29e2019-10-09 10:50:01 +02002132 stats_dump_html_px_hdr(si, px);
Christopher Fauletef779222018-10-31 08:47:01 +01002133 if (!stats_putchk(rep, htx, &trash))
2134 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002135 }
2136
2137 appctx->ctx.stats.px_st = STAT_PX_ST_FE;
2138 /* fall through */
2139
2140 case STAT_PX_ST_FE:
2141 /* print the frontend */
2142 if (stats_dump_fe_stats(si, px)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002143 if (!stats_putchk(rep, htx, &trash))
2144 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002145 }
2146
2147 appctx->ctx.stats.l = px->conf.listeners.n;
2148 appctx->ctx.stats.px_st = STAT_PX_ST_LI;
2149 /* fall through */
2150
2151 case STAT_PX_ST_LI:
2152 /* stats.l has been initialized above */
2153 for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) {
Christopher Fauletef779222018-10-31 08:47:01 +01002154 if (htx) {
2155 if (htx_almost_full(htx))
2156 goto full;
2157 }
2158 else {
2159 if (buffer_almost_full(&rep->buf))
2160 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002161 }
2162
2163 l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe);
2164 if (!l->counters)
2165 continue;
2166
2167 if (appctx->ctx.stats.flags & STAT_BOUND) {
2168 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO)))
2169 break;
2170
2171 if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid)
2172 continue;
2173 }
2174
2175 /* print the frontend */
Willy Tarreau43241ff2019-10-09 11:27:51 +02002176 if (stats_dump_li_stats(si, px, l)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002177 if (!stats_putchk(rep, htx, &trash))
2178 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002179 }
2180 }
2181
2182 appctx->ctx.stats.sv = px->srv; /* may be NULL */
2183 appctx->ctx.stats.px_st = STAT_PX_ST_SV;
2184 /* fall through */
2185
2186 case STAT_PX_ST_SV:
2187 /* stats.sv has been initialized above */
2188 for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) {
Christopher Fauletef779222018-10-31 08:47:01 +01002189 if (htx) {
2190 if (htx_almost_full(htx))
2191 goto full;
2192 }
2193 else {
2194 if (buffer_almost_full(&rep->buf))
2195 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002196 }
2197
2198 sv = appctx->ctx.stats.sv;
2199
2200 if (appctx->ctx.stats.flags & STAT_BOUND) {
2201 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV)))
2202 break;
2203
2204 if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid)
2205 continue;
2206 }
2207
2208 svs = sv;
2209 while (svs->track)
2210 svs = svs->track;
2211
2212 /* do not report servers which are DOWN and not changing state */
2213 if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) &&
Emeric Brun52a91d32017-08-31 14:41:55 +02002214 ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */
2215 (sv->cur_state == SRV_ST_STOPPED && /* server is down */
William Lallemand74c24fb2016-11-21 17:18:36 +01002216 (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) ||
2217 ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) ||
2218 ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) {
2219 continue;
2220 }
2221
Willy Tarreau43241ff2019-10-09 11:27:51 +02002222 if (stats_dump_sv_stats(si, px, sv)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002223 if (!stats_putchk(rep, htx, &trash))
2224 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002225 }
2226 } /* for sv */
2227
2228 appctx->ctx.stats.px_st = STAT_PX_ST_BE;
2229 /* fall through */
2230
2231 case STAT_PX_ST_BE:
2232 /* print the backend */
Willy Tarreau43241ff2019-10-09 11:27:51 +02002233 if (stats_dump_be_stats(si, px)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002234 if (!stats_putchk(rep, htx, &trash))
2235 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002236 }
2237
2238 appctx->ctx.stats.px_st = STAT_PX_ST_END;
2239 /* fall through */
2240
2241 case STAT_PX_ST_END:
2242 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2243 stats_dump_html_px_end(si, px);
Christopher Fauletef779222018-10-31 08:47:01 +01002244 if (!stats_putchk(rep, htx, &trash))
2245 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002246 }
2247
2248 appctx->ctx.stats.px_st = STAT_PX_ST_FIN;
2249 /* fall through */
2250
2251 case STAT_PX_ST_FIN:
2252 return 1;
2253
2254 default:
2255 /* unknown state, we should put an abort() here ! */
2256 return 1;
2257 }
Christopher Fauletef779222018-10-31 08:47:01 +01002258
2259 full:
2260 si_rx_room_blk(si);
2261 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01002262}
2263
2264/* Dumps the HTTP stats head block to the trash for and uses the per-uri
2265 * parameters <uri>. The caller is responsible for clearing the trash if needed.
2266 */
Willy Tarreau676c29e2019-10-09 10:50:01 +02002267static void stats_dump_html_head(struct appctx *appctx, struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002268{
2269 /* WARNING! This must fit in the first buffer !!! */
2270 chunk_appendf(&trash,
2271 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
2272 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
2273 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
2274 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
2275 "<style type=\"text/css\"><!--\n"
2276 "body {"
2277 " font-family: arial, helvetica, sans-serif;"
2278 " font-size: 12px;"
2279 " font-weight: normal;"
2280 " color: black;"
2281 " background: white;"
2282 "}\n"
2283 "th,td {"
2284 " font-size: 10px;"
2285 "}\n"
2286 "h1 {"
2287 " font-size: x-large;"
2288 " margin-bottom: 0.5em;"
2289 "}\n"
2290 "h2 {"
2291 " font-family: helvetica, arial;"
2292 " font-size: x-large;"
2293 " font-weight: bold;"
2294 " font-style: italic;"
2295 " color: #6020a0;"
2296 " margin-top: 0em;"
2297 " margin-bottom: 0em;"
2298 "}\n"
2299 "h3 {"
2300 " font-family: helvetica, arial;"
2301 " font-size: 16px;"
2302 " font-weight: bold;"
2303 " color: #b00040;"
2304 " background: #e8e8d0;"
2305 " margin-top: 0em;"
2306 " margin-bottom: 0em;"
2307 "}\n"
2308 "li {"
2309 " margin-top: 0.25em;"
2310 " margin-right: 2em;"
2311 "}\n"
2312 ".hr {margin-top: 0.25em;"
2313 " border-color: black;"
2314 " border-bottom-style: solid;"
2315 "}\n"
2316 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
2317 ".total {background: #20D0D0;color: #ffff80;}\n"
2318 ".frontend {background: #e8e8d0;}\n"
2319 ".socket {background: #d0d0d0;}\n"
2320 ".backend {background: #e8e8d0;}\n"
2321 ".active_down {background: #ff9090;}\n"
2322 ".active_going_up {background: #ffd020;}\n"
2323 ".active_going_down {background: #ffffa0;}\n"
2324 ".active_up {background: #c0ffc0;}\n"
2325 ".active_nolb {background: #20a0ff;}\n"
2326 ".active_draining {background: #20a0FF;}\n"
2327 ".active_no_check {background: #e0e0e0;}\n"
2328 ".backup_down {background: #ff9090;}\n"
2329 ".backup_going_up {background: #ff80ff;}\n"
2330 ".backup_going_down {background: #c060ff;}\n"
2331 ".backup_up {background: #b0d0ff;}\n"
2332 ".backup_nolb {background: #90b0e0;}\n"
2333 ".backup_draining {background: #cc9900;}\n"
2334 ".backup_no_check {background: #e0e0e0;}\n"
2335 ".maintain {background: #c07820;}\n"
2336 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
2337 "\n"
2338 "a.px:link {color: #ffff40; text-decoration: none;}"
2339 "a.px:visited {color: #ffff40; text-decoration: none;}"
2340 "a.px:hover {color: #ffffff; text-decoration: none;}"
2341 "a.lfsb:link {color: #000000; text-decoration: none;}"
2342 "a.lfsb:visited {color: #000000; text-decoration: none;}"
2343 "a.lfsb:hover {color: #505050; text-decoration: none;}"
2344 "\n"
2345 "table.tbl { border-collapse: collapse; border-style: none;}\n"
2346 "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"
2347 "table.tbl td.ac { text-align: center;}\n"
2348 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
2349 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
2350 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
2351 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
2352 "\n"
2353 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
2354 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
2355 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
2356 "table.det { border-collapse: collapse; border-style: none; }\n"
2357 "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"
2358 "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"
2359 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
2360 "div.tips {\n"
2361 " display:block;\n"
2362 " visibility:hidden;\n"
2363 " z-index:2147483647;\n"
2364 " position:absolute;\n"
2365 " padding:2px 4px 3px;\n"
2366 " background:#f0f060; color:#000000;\n"
2367 " border:1px solid #7040c0;\n"
2368 " white-space:nowrap;\n"
2369 " font-style:normal;font-size:11px;font-weight:normal;\n"
2370 " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n"
2371 " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n"
2372 "}\n"
2373 "u:hover div.tips {visibility:visible;}\n"
2374 "-->\n"
2375 "</style></head>\n",
Willy Tarreau676c29e2019-10-09 10:50:01 +02002376 (appctx->ctx.stats.flags & STAT_SHNODE) ? " on " : "",
2377 (appctx->ctx.stats.flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : ""
William Lallemand74c24fb2016-11-21 17:18:36 +01002378 );
2379}
2380
2381/* Dumps the HTML stats information block to the trash for and uses the state from
2382 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
2383 * for clearing the trash if needed.
2384 */
2385static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri)
2386{
2387 struct appctx *appctx = __objt_appctx(si->end);
2388 unsigned int up = (now.tv_sec - start_date.tv_sec);
2389 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Christopher Fauleted7a0662019-01-14 11:07:34 +01002390 const char *scope_ptr = stats_scope_ptr(appctx, si);
Willy Tarreau1713c032019-05-23 12:23:55 +02002391 unsigned long long bps = (unsigned long long)read_freq_ctr(&global.out_32bps) * 32;
2392
2393 /* Turn the bytes per second to bits per second and take care of the
2394 * usual ethernet overhead in order to help figure how far we are from
2395 * interface saturation since it's the only case which usually matters.
2396 * For this we count the total size of an Ethernet frame on the wire
2397 * including preamble and IFG (1538) for the largest TCP segment it
2398 * transports (1448 with TCP timestamps). This is not valid for smaller
2399 * packets (under-estimated), but it gives a reasonably accurate
2400 * estimation of how far we are from uplink saturation.
2401 */
2402 bps = bps * 8 * 1538 / 1448;
William Lallemand74c24fb2016-11-21 17:18:36 +01002403
2404 /* WARNING! this has to fit the first packet too.
2405 * We are around 3.5 kB, add adding entries will
2406 * become tricky if we want to support 4kB buffers !
2407 */
2408 chunk_appendf(&trash,
2409 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
2410 PRODUCT_NAME "%s</a></h1>\n"
2411 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
2412 "<hr width=\"100%%\" class=\"hr\">\n"
2413 "<h3>&gt; General process information</h3>\n"
2414 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Yves Lafon95317282018-02-26 11:10:37 +01002415 "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n"
William Lallemand74c24fb2016-11-21 17:18:36 +01002416 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
2417 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
2418 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
Willy Tarreau1713c032019-05-23 12:23:55 +02002419 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec; bit rate = %.3f %cbps<br>\n"
William Lallemand74c24fb2016-11-21 17:18:36 +01002420 "Running tasks: %d/%d; idle = %d %%<br>\n"
2421 "</td><td align=\"center\" nowrap>\n"
2422 "<table class=\"lgd\"><tr>\n"
2423 "<td class=\"active_up\">&nbsp;</td><td class=\"noborder\">active UP </td>"
2424 "<td class=\"backup_up\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
2425 "</tr><tr>\n"
2426 "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>"
2427 "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>"
2428 "</tr><tr>\n"
2429 "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>"
2430 "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>"
2431 "</tr><tr>\n"
2432 "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
2433 "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>"
2434 "</tr><tr>\n"
2435 "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) &nbsp;</td>"
2436 "</tr><tr>\n"
2437 "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance &nbsp;</td>"
2438 "</tr></table>\n"
2439 "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled."
2440 "</td>"
2441 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2442 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
2443 "",
Willy Tarreau676c29e2019-10-09 10:50:01 +02002444 (appctx->ctx.stats.flags & STAT_HIDEVER) ? "" : (stats_version_string),
2445 pid, (appctx->ctx.stats.flags & STAT_SHNODE) ? " on " : "",
2446 (appctx->ctx.stats.flags & STAT_SHNODE) ? (uri->node ? uri->node : global.node) : "",
2447 (appctx->ctx.stats.flags & STAT_SHDESC) ? ": " : "",
2448 (appctx->ctx.stats.flags & STAT_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
Yves Lafon95317282018-02-26 11:10:37 +01002449 pid, relative_pid, global.nbproc, global.nbthread,
William Lallemand74c24fb2016-11-21 17:18:36 +01002450 up / 86400, (up % 86400) / 3600,
2451 (up % 3600) / 60, (up % 60),
2452 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
2453 global.rlimit_memmax ? " MB" : "",
2454 global.rlimit_nofile,
2455 global.maxsock, global.maxconn, global.maxpipes,
2456 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Willy Tarreau1713c032019-05-23 12:23:55 +02002457 bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0),
2458 bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k',
Willy Tarreau81036f22019-05-20 19:24:50 +02002459 tasks_run_queue_cur, nb_tasks_cur, ti->idle_pct
William Lallemand74c24fb2016-11-21 17:18:36 +01002460 );
2461
2462 /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Christopher Fauleted7a0662019-01-14 11:07:34 +01002463 memcpy(scope_txt, scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002464 scope_txt[appctx->ctx.stats.scope_len] = '\0';
2465
2466 chunk_appendf(&trash,
2467 "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n",
2468 (appctx->ctx.stats.scope_len > 0) ? scope_txt : "",
2469 STAT_SCOPE_TXT_MAXLEN);
2470
2471 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
2472 scope_txt[0] = 0;
2473 if (appctx->ctx.stats.scope_len) {
2474 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01002475 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002476 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
2477 }
2478
2479 if (appctx->ctx.stats.flags & STAT_HIDE_DOWN)
2480 chunk_appendf(&trash,
2481 "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n",
2482 uri->uri_prefix,
2483 "",
2484 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2485 scope_txt);
2486 else
2487 chunk_appendf(&trash,
2488 "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n",
2489 uri->uri_prefix,
2490 ";up",
2491 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2492 scope_txt);
2493
2494 if (uri->refresh > 0) {
2495 if (appctx->ctx.stats.flags & STAT_NO_REFRESH)
2496 chunk_appendf(&trash,
2497 "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n",
2498 uri->uri_prefix,
2499 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2500 "",
2501 scope_txt);
2502 else
2503 chunk_appendf(&trash,
2504 "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n",
2505 uri->uri_prefix,
2506 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2507 ";norefresh",
2508 scope_txt);
2509 }
2510
2511 chunk_appendf(&trash,
2512 "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n",
2513 uri->uri_prefix,
2514 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2515 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2516 scope_txt);
2517
2518 chunk_appendf(&trash,
2519 "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n",
2520 uri->uri_prefix,
2521 (uri->refresh > 0) ? ";norefresh" : "",
2522 scope_txt);
2523
2524 chunk_appendf(&trash,
Christopher Faulet6338a082019-09-09 15:50:54 +02002525 "<li><a href=\"%s;json%s%s\">JSON export</a> (<a href=\"%s;json-schema\">schema</a>)<br>\n",
2526 uri->uri_prefix,
2527 (uri->refresh > 0) ? ";norefresh" : "",
2528 scope_txt, uri->uri_prefix);
2529
2530 chunk_appendf(&trash,
William Lallemand74c24fb2016-11-21 17:18:36 +01002531 "</ul></td>"
2532 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2533 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
2534 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2535 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2536 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2537 "</ul>"
2538 "</td>"
2539 "</tr></table>\n"
2540 ""
2541 );
2542
2543 if (appctx->ctx.stats.st_code) {
2544 switch (appctx->ctx.stats.st_code) {
2545 case STAT_STATUS_DONE:
2546 chunk_appendf(&trash,
2547 "<p><div class=active_up>"
2548 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2549 "Action processed successfully."
2550 "</div>\n", uri->uri_prefix,
2551 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2552 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2553 scope_txt);
2554 break;
2555 case STAT_STATUS_NONE:
2556 chunk_appendf(&trash,
2557 "<p><div class=active_going_down>"
2558 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2559 "Nothing has changed."
2560 "</div>\n", uri->uri_prefix,
2561 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2562 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2563 scope_txt);
2564 break;
2565 case STAT_STATUS_PART:
2566 chunk_appendf(&trash,
2567 "<p><div class=active_going_down>"
2568 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2569 "Action partially processed.<br>"
2570 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2571 "</div>\n", uri->uri_prefix,
2572 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2573 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2574 scope_txt);
2575 break;
2576 case STAT_STATUS_ERRP:
2577 chunk_appendf(&trash,
2578 "<p><div class=active_down>"
2579 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2580 "Action not processed because of invalid parameters."
2581 "<ul>"
2582 "<li>The action is maybe unknown.</li>"
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002583 "<li>Invalid key parameter (empty or too long).</li>"
William Lallemand74c24fb2016-11-21 17:18:36 +01002584 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2585 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2586 "</ul>"
2587 "</div>\n", uri->uri_prefix,
2588 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2589 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2590 scope_txt);
2591 break;
2592 case STAT_STATUS_EXCD:
2593 chunk_appendf(&trash,
2594 "<p><div class=active_down>"
2595 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2596 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2597 "You should retry with less servers at a time.</b>"
2598 "</div>\n", uri->uri_prefix,
2599 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2600 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2601 scope_txt);
2602 break;
2603 case STAT_STATUS_DENY:
2604 chunk_appendf(&trash,
2605 "<p><div class=active_down>"
2606 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2607 "<b>Action denied.</b>"
2608 "</div>\n", uri->uri_prefix,
2609 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2610 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2611 scope_txt);
2612 break;
Christopher Faulet3c2ecf72019-02-27 16:41:27 +01002613 case STAT_STATUS_IVAL:
2614 chunk_appendf(&trash,
2615 "<p><div class=active_down>"
2616 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2617 "<b>Invalid requests (unsupported method or chunked encoded request).</b>"
2618 "</div>\n", uri->uri_prefix,
2619 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2620 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2621 scope_txt);
2622 break;
William Lallemand74c24fb2016-11-21 17:18:36 +01002623 default:
2624 chunk_appendf(&trash,
2625 "<p><div class=active_no_check>"
2626 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2627 "Unexpected result."
2628 "</div>\n", uri->uri_prefix,
2629 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2630 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2631 scope_txt);
2632 }
2633 chunk_appendf(&trash, "<p>\n");
2634 }
2635}
2636
2637/* Dumps the HTML stats trailer block to the trash. The caller is responsible
2638 * for clearing the trash if needed.
2639 */
2640static void stats_dump_html_end()
2641{
2642 chunk_appendf(&trash, "</body></html>\n");
2643}
2644
Simon Horman05ee2132017-01-04 09:37:25 +01002645/* Dumps the stats JSON header to the trash buffer which. The caller is responsible
2646 * for clearing it if needed.
2647 */
2648static void stats_dump_json_header()
2649{
2650 chunk_strcat(&trash, "[");
2651}
2652
2653
2654/* Dumps the JSON stats trailer block to the trash. The caller is responsible
2655 * for clearing the trash if needed.
2656 */
2657static void stats_dump_json_end()
2658{
2659 chunk_strcat(&trash, "]");
2660}
2661
William Lallemand74c24fb2016-11-21 17:18:36 +01002662/* This function dumps statistics onto the stream interface's read buffer in
2663 * either CSV or HTML format. <uri> contains some HTML-specific parameters that
2664 * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if
2665 * it had to stop writing data and an I/O is needed, 1 if the dump is finished
2666 * and the stream must be closed, or -1 in case of any error. This function is
2667 * used by both the CLI and the HTTP handlers.
2668 */
Christopher Fauletef779222018-10-31 08:47:01 +01002669static int stats_dump_stat_to_buffer(struct stream_interface *si, struct htx *htx,
2670 struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002671{
2672 struct appctx *appctx = __objt_appctx(si->end);
2673 struct channel *rep = si_ic(si);
2674 struct proxy *px;
2675
2676 chunk_reset(&trash);
2677
2678 switch (appctx->st2) {
2679 case STAT_ST_INIT:
2680 appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
2681 /* fall through */
2682
2683 case STAT_ST_HEAD:
2684 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Willy Tarreau676c29e2019-10-09 10:50:01 +02002685 stats_dump_html_head(appctx, uri);
Christopher Faulet6338a082019-09-09 15:50:54 +02002686 else if (appctx->ctx.stats.flags & STAT_JSON_SCHM)
2687 stats_dump_json_schema(&trash);
Simon Horman05ee2132017-01-04 09:37:25 +01002688 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreau9d7fb632017-04-11 07:53:04 +02002689 stats_dump_json_header();
William Lallemand74c24fb2016-11-21 17:18:36 +01002690 else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED))
2691 stats_dump_csv_header();
2692
Christopher Fauletef779222018-10-31 08:47:01 +01002693 if (!stats_putchk(rep, htx, &trash))
2694 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002695
Christopher Faulet6338a082019-09-09 15:50:54 +02002696 if (appctx->ctx.stats.flags & STAT_JSON_SCHM) {
2697 appctx->st2 = STAT_ST_FIN;
2698 return 1;
2699 }
William Lallemand74c24fb2016-11-21 17:18:36 +01002700 appctx->st2 = STAT_ST_INFO;
2701 /* fall through */
2702
2703 case STAT_ST_INFO:
2704 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2705 stats_dump_html_info(si, uri);
Christopher Fauletef779222018-10-31 08:47:01 +01002706 if (!stats_putchk(rep, htx, &trash))
2707 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002708 }
2709
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002710 appctx->ctx.stats.px = proxies_list;
William Lallemand74c24fb2016-11-21 17:18:36 +01002711 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2712 appctx->st2 = STAT_ST_LIST;
2713 /* fall through */
2714
2715 case STAT_ST_LIST:
2716 /* dump proxies */
2717 while (appctx->ctx.stats.px) {
Christopher Fauletef779222018-10-31 08:47:01 +01002718 if (htx) {
2719 if (htx_almost_full(htx))
2720 goto full;
2721 }
2722 else {
2723 if (buffer_almost_full(&rep->buf))
2724 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002725 }
2726
2727 px = appctx->ctx.stats.px;
2728 /* skip the disabled proxies, global frontend and non-networked ones */
2729 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Christopher Fauletef779222018-10-31 08:47:01 +01002730 if (stats_dump_proxy_to_buffer(si, htx, px, uri) == 0)
William Lallemand74c24fb2016-11-21 17:18:36 +01002731 return 0;
2732
2733 appctx->ctx.stats.px = px->next;
2734 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2735 }
2736 /* here, we just have reached the last proxy */
2737
2738 appctx->st2 = STAT_ST_END;
2739 /* fall through */
2740
2741 case STAT_ST_END:
Simon Horman05ee2132017-01-04 09:37:25 +01002742 if (appctx->ctx.stats.flags & (STAT_FMT_HTML|STAT_FMT_JSON)) {
2743 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
2744 stats_dump_html_end();
2745 else
2746 stats_dump_json_end();
Christopher Fauletef779222018-10-31 08:47:01 +01002747 if (!stats_putchk(rep, htx, &trash))
2748 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002749 }
2750
2751 appctx->st2 = STAT_ST_FIN;
2752 /* fall through */
2753
2754 case STAT_ST_FIN:
2755 return 1;
2756
2757 default:
2758 /* unknown state ! */
2759 appctx->st2 = STAT_ST_FIN;
2760 return -1;
2761 }
Christopher Fauletef779222018-10-31 08:47:01 +01002762
2763 full:
2764 si_rx_room_blk(si);
2765 return 0;
2766
William Lallemand74c24fb2016-11-21 17:18:36 +01002767}
2768
2769/* We reached the stats page through a POST request. The appctx is
2770 * expected to have already been allocated by the caller.
2771 * Parse the posted data and enable/disable servers if necessary.
2772 * Returns 1 if request was parsed or zero if it needs more data.
2773 */
2774static int stats_process_http_post(struct stream_interface *si)
2775{
2776 struct stream *s = si_strm(si);
2777 struct appctx *appctx = objt_appctx(si->end);
2778
2779 struct proxy *px = NULL;
2780 struct server *sv = NULL;
2781
2782 char key[LINESIZE];
2783 int action = ST_ADM_ACTION_NONE;
2784 int reprocess = 0;
2785
2786 int total_servers = 0;
2787 int altered_servers = 0;
2788
2789 char *first_param, *cur_param, *next_param, *end_params;
2790 char *st_cur_param = NULL;
2791 char *st_next_param = NULL;
2792
Christopher Fauleta3618372018-12-13 21:59:56 +01002793 struct buffer *temp = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01002794
Christopher Fauletb7f88902019-07-15 21:56:43 +02002795 struct htx *htx = htxbuf(&s->req.buf);
2796 struct htx_blk *blk;
Christopher Fauleta3618372018-12-13 21:59:56 +01002797
Christopher Fauletb7f88902019-07-15 21:56:43 +02002798 /* we need more data */
2799 if (s->txn->req.msg_state < HTTP_MSG_DONE) {
2800 /* check if we can receive more */
2801 if (htx_free_data_space(htx) <= global.tune.maxrewrite) {
2802 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2803 goto out;
Christopher Fauleta3618372018-12-13 21:59:56 +01002804 }
Christopher Fauletb7f88902019-07-15 21:56:43 +02002805 goto wait;
2806 }
Christopher Fauleta3618372018-12-13 21:59:56 +01002807
Christopher Fauletb7f88902019-07-15 21:56:43 +02002808 /* The request was fully received. Copy data */
2809 blk = htx_get_head_blk(htx);
2810 while (blk) {
2811 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauleta3618372018-12-13 21:59:56 +01002812
Christopher Fauletb7f88902019-07-15 21:56:43 +02002813 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
2814 break;
2815 if (type == HTX_BLK_DATA) {
2816 struct ist v = htx_get_blk_value(htx, blk);
Christopher Fauleta3618372018-12-13 21:59:56 +01002817
Christopher Fauletb7f88902019-07-15 21:56:43 +02002818 if (!chunk_memcat(temp, v.ptr, v.len)) {
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002819 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2820 goto out;
2821 }
Christopher Fauleta3618372018-12-13 21:59:56 +01002822 }
Christopher Fauletb7f88902019-07-15 21:56:43 +02002823 blk = htx_get_next_blk(htx, blk);
William Lallemand74c24fb2016-11-21 17:18:36 +01002824 }
2825
Willy Tarreau843b7cb2018-07-13 10:54:26 +02002826 first_param = temp->area;
Christopher Fauleta3618372018-12-13 21:59:56 +01002827 end_params = temp->area + temp->data;
William Lallemand74c24fb2016-11-21 17:18:36 +01002828 cur_param = next_param = end_params;
2829 *end_params = '\0';
2830
2831 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
2832
2833 /*
2834 * Parse the parameters in reverse order to only store the last value.
2835 * From the html form, the backend and the action are at the end.
2836 */
2837 while (cur_param > first_param) {
2838 char *value;
2839 int poffset, plen;
2840
2841 cur_param--;
2842
2843 if ((*cur_param == '&') || (cur_param == first_param)) {
2844 reprocess_servers:
2845 /* Parse the key */
2846 poffset = (cur_param != first_param ? 1 : 0);
2847 plen = next_param - cur_param + (cur_param == first_param ? 1 : 0);
2848 if ((plen > 0) && (plen <= sizeof(key))) {
2849 strncpy(key, cur_param + poffset, plen);
2850 key[plen - 1] = '\0';
2851 } else {
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002852 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
William Lallemand74c24fb2016-11-21 17:18:36 +01002853 goto out;
2854 }
2855
2856 /* Parse the value */
2857 value = key;
2858 while (*value != '\0' && *value != '=') {
2859 value++;
2860 }
2861 if (*value == '=') {
2862 /* Ok, a value is found, we can mark the end of the key */
2863 *value++ = '\0';
2864 }
2865 if (url_decode(key) < 0 || url_decode(value) < 0)
2866 break;
2867
2868 /* Now we can check the key to see what to do */
2869 if (!px && (strcmp(key, "b") == 0)) {
2870 if ((px = proxy_be_by_name(value)) == NULL) {
2871 /* the backend name is unknown or ambiguous (duplicate names) */
2872 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2873 goto out;
2874 }
2875 }
2876 else if (!action && (strcmp(key, "action") == 0)) {
2877 if (strcmp(value, "ready") == 0) {
2878 action = ST_ADM_ACTION_READY;
2879 }
2880 else if (strcmp(value, "drain") == 0) {
2881 action = ST_ADM_ACTION_DRAIN;
2882 }
2883 else if (strcmp(value, "maint") == 0) {
2884 action = ST_ADM_ACTION_MAINT;
2885 }
2886 else if (strcmp(value, "shutdown") == 0) {
2887 action = ST_ADM_ACTION_SHUTDOWN;
2888 }
2889 else if (strcmp(value, "dhlth") == 0) {
2890 action = ST_ADM_ACTION_DHLTH;
2891 }
2892 else if (strcmp(value, "ehlth") == 0) {
2893 action = ST_ADM_ACTION_EHLTH;
2894 }
2895 else if (strcmp(value, "hrunn") == 0) {
2896 action = ST_ADM_ACTION_HRUNN;
2897 }
2898 else if (strcmp(value, "hnolb") == 0) {
2899 action = ST_ADM_ACTION_HNOLB;
2900 }
2901 else if (strcmp(value, "hdown") == 0) {
2902 action = ST_ADM_ACTION_HDOWN;
2903 }
2904 else if (strcmp(value, "dagent") == 0) {
2905 action = ST_ADM_ACTION_DAGENT;
2906 }
2907 else if (strcmp(value, "eagent") == 0) {
2908 action = ST_ADM_ACTION_EAGENT;
2909 }
2910 else if (strcmp(value, "arunn") == 0) {
2911 action = ST_ADM_ACTION_ARUNN;
2912 }
2913 else if (strcmp(value, "adown") == 0) {
2914 action = ST_ADM_ACTION_ADOWN;
2915 }
2916 /* else these are the old supported methods */
2917 else if (strcmp(value, "disable") == 0) {
2918 action = ST_ADM_ACTION_DISABLE;
2919 }
2920 else if (strcmp(value, "enable") == 0) {
2921 action = ST_ADM_ACTION_ENABLE;
2922 }
2923 else if (strcmp(value, "stop") == 0) {
2924 action = ST_ADM_ACTION_STOP;
2925 }
2926 else if (strcmp(value, "start") == 0) {
2927 action = ST_ADM_ACTION_START;
2928 }
2929 else {
2930 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2931 goto out;
2932 }
2933 }
2934 else if (strcmp(key, "s") == 0) {
2935 if (!(px && action)) {
2936 /*
2937 * Indicates that we'll need to reprocess the parameters
2938 * as soon as backend and action are known
2939 */
2940 if (!reprocess) {
2941 st_cur_param = cur_param;
2942 st_next_param = next_param;
2943 }
2944 reprocess = 1;
2945 }
2946 else if ((sv = findserver(px, value)) != NULL) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002947 HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01002948 switch (action) {
2949 case ST_ADM_ACTION_DISABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002950 if (!(sv->cur_admin & SRV_ADMF_FMAINT)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002951 altered_servers++;
2952 total_servers++;
2953 srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page");
2954 }
2955 break;
2956 case ST_ADM_ACTION_ENABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002957 if (sv->cur_admin & SRV_ADMF_FMAINT) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002958 altered_servers++;
2959 total_servers++;
2960 srv_clr_admin_flag(sv, SRV_ADMF_FMAINT);
2961 }
2962 break;
2963 case ST_ADM_ACTION_STOP:
Emeric Brun52a91d32017-08-31 14:41:55 +02002964 if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002965 srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page");
2966 altered_servers++;
2967 total_servers++;
2968 }
2969 break;
2970 case ST_ADM_ACTION_START:
Emeric Brun52a91d32017-08-31 14:41:55 +02002971 if (sv->cur_admin & SRV_ADMF_FDRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002972 srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN);
2973 altered_servers++;
2974 total_servers++;
2975 }
2976 break;
2977 case ST_ADM_ACTION_DHLTH:
2978 if (sv->check.state & CHK_ST_CONFIGURED) {
2979 sv->check.state &= ~CHK_ST_ENABLED;
2980 altered_servers++;
2981 total_servers++;
2982 }
2983 break;
2984 case ST_ADM_ACTION_EHLTH:
2985 if (sv->check.state & CHK_ST_CONFIGURED) {
2986 sv->check.state |= CHK_ST_ENABLED;
2987 altered_servers++;
2988 total_servers++;
2989 }
2990 break;
2991 case ST_ADM_ACTION_HRUNN:
2992 if (!(sv->track)) {
2993 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02002994 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002995 altered_servers++;
2996 total_servers++;
2997 }
2998 break;
2999 case ST_ADM_ACTION_HNOLB:
3000 if (!(sv->track)) {
3001 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02003002 srv_set_stopping(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003003 altered_servers++;
3004 total_servers++;
3005 }
3006 break;
3007 case ST_ADM_ACTION_HDOWN:
3008 if (!(sv->track)) {
3009 sv->check.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02003010 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003011 altered_servers++;
3012 total_servers++;
3013 }
3014 break;
3015 case ST_ADM_ACTION_DAGENT:
3016 if (sv->agent.state & CHK_ST_CONFIGURED) {
3017 sv->agent.state &= ~CHK_ST_ENABLED;
3018 altered_servers++;
3019 total_servers++;
3020 }
3021 break;
3022 case ST_ADM_ACTION_EAGENT:
3023 if (sv->agent.state & CHK_ST_CONFIGURED) {
3024 sv->agent.state |= CHK_ST_ENABLED;
3025 altered_servers++;
3026 total_servers++;
3027 }
3028 break;
3029 case ST_ADM_ACTION_ARUNN:
3030 if (sv->agent.state & CHK_ST_ENABLED) {
3031 sv->agent.health = sv->agent.rise + sv->agent.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02003032 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003033 altered_servers++;
3034 total_servers++;
3035 }
3036 break;
3037 case ST_ADM_ACTION_ADOWN:
3038 if (sv->agent.state & CHK_ST_ENABLED) {
3039 sv->agent.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02003040 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003041 altered_servers++;
3042 total_servers++;
3043 }
3044 break;
3045 case ST_ADM_ACTION_READY:
3046 srv_adm_set_ready(sv);
3047 altered_servers++;
3048 total_servers++;
3049 break;
3050 case ST_ADM_ACTION_DRAIN:
3051 srv_adm_set_drain(sv);
3052 altered_servers++;
3053 total_servers++;
3054 break;
3055 case ST_ADM_ACTION_MAINT:
3056 srv_adm_set_maint(sv);
3057 altered_servers++;
3058 total_servers++;
3059 break;
3060 case ST_ADM_ACTION_SHUTDOWN:
3061 if (px->state != PR_STSTOPPED) {
3062 struct stream *sess, *sess_bck;
3063
3064 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
3065 if (sess->srv_conn == sv)
3066 stream_shutdown(sess, SF_ERR_KILLED);
3067
3068 altered_servers++;
3069 total_servers++;
3070 }
3071 break;
3072 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003073 HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01003074 } else {
3075 /* the server name is unknown or ambiguous (duplicate names) */
3076 total_servers++;
3077 }
3078 }
3079 if (reprocess && px && action) {
3080 /* Now, we know the backend and the action chosen by the user.
3081 * We can safely restart from the first server parameter
3082 * to reprocess them
3083 */
3084 cur_param = st_cur_param;
3085 next_param = st_next_param;
3086 reprocess = 0;
3087 goto reprocess_servers;
3088 }
3089
3090 next_param = cur_param;
3091 }
3092 }
3093
3094 if (total_servers == 0) {
3095 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
3096 }
3097 else if (altered_servers == 0) {
3098 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
3099 }
3100 else if (altered_servers == total_servers) {
3101 appctx->ctx.stats.st_code = STAT_STATUS_DONE;
3102 }
3103 else {
3104 appctx->ctx.stats.st_code = STAT_STATUS_PART;
3105 }
3106 out:
3107 return 1;
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01003108 wait:
3109 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
3110 return 0;
Christopher Fauletef779222018-10-31 08:47:01 +01003111}
3112
3113
Christopher Fauletb7f88902019-07-15 21:56:43 +02003114static int stats_send_http_headers(struct stream_interface *si, struct htx *htx)
Christopher Fauletef779222018-10-31 08:47:01 +01003115{
3116 struct stream *s = si_strm(si);
3117 struct uri_auth *uri = s->be->uri_auth;
3118 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003119 struct htx_sl *sl;
3120 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003121
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003122 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);
3123 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
3124 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003125 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003126 sl->info.res.status = 200;
Christopher Fauletef779222018-10-31 08:47:01 +01003127
Christopher Fauletb829f4c2019-03-29 16:13:55 +01003128 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")))
Christopher Fauletef779222018-10-31 08:47:01 +01003129 goto full;
3130 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
3131 if (!htx_add_header(htx, ist("Content-Type"), ist("text/html")))
3132 goto full;
3133 }
Christopher Faulet6338a082019-09-09 15:50:54 +02003134 else if (appctx->ctx.stats.flags & (STAT_FMT_JSON|STAT_JSON_SCHM)) {
3135 if (!htx_add_header(htx, ist("Content-Type"), ist("application/json")))
3136 goto full;
3137 }
Christopher Fauletef779222018-10-31 08:47:01 +01003138 else {
3139 if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain")))
3140 goto full;
3141 }
3142
3143 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) {
3144 const char *refresh = U2A(uri->refresh);
3145 if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh))))
3146 goto full;
3147 }
3148
3149 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
3150 if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")))
3151 goto full;
3152 }
3153
3154 if (!htx_add_endof(htx, HTX_BLK_EOH))
3155 goto full;
3156
Christopher Faulet1e2d6362019-02-27 16:28:48 +01003157 channel_add_input(&s->res, htx->data);
Christopher Fauletef779222018-10-31 08:47:01 +01003158 return 1;
3159
3160 full:
3161 htx_reset(htx);
3162 si_rx_room_blk(si);
3163 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01003164}
3165
Christopher Fauletef779222018-10-31 08:47:01 +01003166
Christopher Fauletb7f88902019-07-15 21:56:43 +02003167static int stats_send_http_redirect(struct stream_interface *si, struct htx *htx)
Christopher Fauletef779222018-10-31 08:47:01 +01003168{
3169 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
3170 struct stream *s = si_strm(si);
3171 struct uri_auth *uri = s->be->uri_auth;
3172 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003173 struct htx_sl *sl;
3174 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003175
3176 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
3177 scope_txt[0] = 0;
3178 if (appctx->ctx.stats.scope_len) {
Christopher Fauleted7a0662019-01-14 11:07:34 +01003179 const char *scope_ptr = stats_scope_ptr(appctx, si);
3180
Christopher Fauletef779222018-10-31 08:47:01 +01003181 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01003182 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
Christopher Fauletef779222018-10-31 08:47:01 +01003183 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
3184 }
3185
3186 /* We don't want to land on the posted stats page because a refresh will
3187 * repost the data. We don't want this to happen on accident so we redirect
3188 * the browse to the stats page with a GET.
3189 */
3190 chunk_printf(&trash, "%s;st=%s%s%s%s",
3191 uri->uri_prefix,
3192 ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) &&
3193 (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) &&
3194 stat_status_codes[appctx->ctx.stats.st_code]) ?
3195 stat_status_codes[appctx->ctx.stats.st_code] :
3196 stat_status_codes[STAT_STATUS_UNKN],
3197 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3198 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
3199 scope_txt);
3200
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003201 flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK);
3202 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other"));
3203 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003204 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003205 sl->info.res.status = 303;
Christopher Fauletef779222018-10-31 08:47:01 +01003206
3207 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
Christopher Fauletef779222018-10-31 08:47:01 +01003208 !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) ||
3209 !htx_add_header(htx, ist("Content-Length"), ist("0")) ||
3210 !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data)))
3211 goto full;
3212
3213 if (!htx_add_endof(htx, HTX_BLK_EOH))
3214 goto full;
3215
Christopher Faulet1e2d6362019-02-27 16:28:48 +01003216 channel_add_input(&s->res, htx->data);
Christopher Fauletef779222018-10-31 08:47:01 +01003217 return 1;
3218
3219full:
3220 htx_reset(htx);
3221 si_rx_room_blk(si);
3222 return 0;
3223}
William Lallemand74c24fb2016-11-21 17:18:36 +01003224
Simon Horman05ee2132017-01-04 09:37:25 +01003225
William Lallemand74c24fb2016-11-21 17:18:36 +01003226/* This I/O handler runs as an applet embedded in a stream interface. It is
3227 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
3228 * appctx->st0 contains the operation in progress (dump, done). The handler
3229 * automatically unregisters itself once transfer is complete.
3230 */
Christopher Fauletb7f88902019-07-15 21:56:43 +02003231static void http_stats_io_handler(struct appctx *appctx)
Christopher Fauletef779222018-10-31 08:47:01 +01003232{
3233 struct stream_interface *si = appctx->owner;
3234 struct stream *s = si_strm(si);
3235 struct channel *req = si_oc(si);
3236 struct channel *res = si_ic(si);
3237 struct htx *req_htx, *res_htx;
3238
3239 res_htx = htx_from_buf(&res->buf);
3240
3241 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
3242 goto out;
3243
3244 /* Check if the input buffer is avalaible. */
3245 if (!b_size(&res->buf)) {
3246 si_rx_room_blk(si);
3247 goto out;
3248 }
3249
3250 /* check that the output is not closed */
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003251 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_SHUTR))
3252 appctx->st0 = STAT_HTTP_END;
Christopher Fauletef779222018-10-31 08:47:01 +01003253
3254 /* all states are processed in sequence */
3255 if (appctx->st0 == STAT_HTTP_HEAD) {
Christopher Fauletb7f88902019-07-15 21:56:43 +02003256 if (stats_send_http_headers(si, res_htx)) {
Christopher Fauletef779222018-10-31 08:47:01 +01003257 if (s->txn->meth == HTTP_METH_HEAD)
3258 appctx->st0 = STAT_HTTP_DONE;
3259 else
3260 appctx->st0 = STAT_HTTP_DUMP;
3261 }
3262 }
3263
3264 if (appctx->st0 == STAT_HTTP_DUMP) {
3265 if (stats_dump_stat_to_buffer(si, res_htx, s->be->uri_auth))
3266 appctx->st0 = STAT_HTTP_DONE;
3267 }
3268
3269 if (appctx->st0 == STAT_HTTP_POST) {
3270 if (stats_process_http_post(si))
3271 appctx->st0 = STAT_HTTP_LAST;
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003272 else if (req->flags & CF_SHUTR)
Christopher Fauletef779222018-10-31 08:47:01 +01003273 appctx->st0 = STAT_HTTP_DONE;
3274 }
3275
3276 if (appctx->st0 == STAT_HTTP_LAST) {
Christopher Fauletb7f88902019-07-15 21:56:43 +02003277 if (stats_send_http_redirect(si, res_htx))
Christopher Fauletef779222018-10-31 08:47:01 +01003278 appctx->st0 = STAT_HTTP_DONE;
3279 }
3280
3281 if (appctx->st0 == STAT_HTTP_DONE) {
Christopher Faulet54b5e212019-06-04 10:08:28 +02003282 /* Don't add TLR because mux-h1 will take care of it */
Christopher Fauletef779222018-10-31 08:47:01 +01003283 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
3284 si_rx_room_blk(si);
3285 goto out;
3286 }
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003287 channel_add_input(&s->res, 1);
3288 appctx->st0 = STAT_HTTP_END;
Christopher Fauletef779222018-10-31 08:47:01 +01003289 }
3290
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003291 if (appctx->st0 == STAT_HTTP_END) {
3292 if (!(res->flags & CF_SHUTR)) {
Christopher Fauletef779222018-10-31 08:47:01 +01003293 res->flags |= CF_READ_NULL;
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003294 si_shutr(si);
3295 }
3296
3297 /* eat the whole request */
3298 if (co_data(req)) {
3299 req_htx = htx_from_buf(&req->buf);
3300 co_htx_skip(req, req_htx, co_data(req));
3301 htx_to_buf(req_htx, &req->buf);
Christopher Fauletef779222018-10-31 08:47:01 +01003302 }
3303 }
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003304
Christopher Fauletef779222018-10-31 08:47:01 +01003305 out:
3306 /* we have left the request in the buffer for the case where we
3307 * process a POST, and this automatically re-enables activity on
3308 * read. It's better to indicate that we want to stop reading when
3309 * we're sending, so that we know there's at most one direction
3310 * deciding to wake the applet up. It saves it from looping when
3311 * emitting large blocks into small TCP windows.
3312 */
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01003313 htx_to_buf(res_htx, &res->buf);
3314 if (!channel_is_empty(res))
Christopher Fauletef779222018-10-31 08:47:01 +01003315 si_stop_get(si);
Christopher Fauletef779222018-10-31 08:47:01 +01003316}
3317
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003318/* Dump all fields from <info> into <out> using the "show info" format (name: value) */
Willy Tarreau83061a82018-07-13 11:56:34 +02003319static int stats_dump_info_fields(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +02003320 const struct field *info, unsigned int flags)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003321{
3322 int field;
3323
3324 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3325 if (!field_format(info, field))
3326 continue;
3327
Willy Tarreaueaa55372019-10-09 07:39:11 +02003328 if (!chunk_appendf(out, "%s: ", info_fields[field].name))
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003329 return 0;
3330 if (!stats_emit_raw_data_field(out, &info[field]))
3331 return 0;
Willy Tarreau6b19b142019-10-09 15:44:21 +02003332 if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc))
3333 return 0;
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003334 if (!chunk_strcat(out, "\n"))
3335 return 0;
3336 }
3337 return 1;
3338}
3339
3340/* Dump all fields from <info> into <out> using the "show info typed" format */
Willy Tarreau83061a82018-07-13 11:56:34 +02003341static int stats_dump_typed_info_fields(struct buffer *out,
Willy Tarreau43241ff2019-10-09 11:27:51 +02003342 const struct field *info, unsigned int flags)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003343{
3344 int field;
3345
3346 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3347 if (!field_format(info, field))
3348 continue;
3349
Willy Tarreaueaa55372019-10-09 07:39:11 +02003350 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 +01003351 return 0;
3352 if (!stats_emit_field_tags(out, &info[field], ':'))
3353 return 0;
3354 if (!stats_emit_typed_data_field(out, &info[field]))
3355 return 0;
Willy Tarreau6b19b142019-10-09 15:44:21 +02003356 if ((flags & STAT_SHOW_FDESC) && !chunk_appendf(out, ":\"%s\"", info_fields[field].desc))
3357 return 0;
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003358 if (!chunk_strcat(out, "\n"))
3359 return 0;
3360 }
3361 return 1;
3362}
3363
3364/* Fill <info> with HAProxy global info. <info> is preallocated
3365 * array of length <len>. The length of the aray must be
3366 * INF_TOTAL_FIELDS. If this length is less then this value, the
3367 * function returns 0, otherwise, it returns 1.
3368 */
3369int stats_fill_info(struct field *info, int len)
3370{
3371 unsigned int up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau83061a82018-07-13 11:56:34 +02003372 struct buffer *out = get_trash_chunk();
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003373
3374#ifdef USE_OPENSSL
3375 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
3376 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
3377 int ssl_reuse = 0;
3378
3379 if (ssl_key_rate < ssl_sess_rate) {
3380 /* count the ssl reuse ratio and avoid overflows in both directions */
3381 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
3382 }
3383#endif
3384
3385 if (len < INF_TOTAL_FIELDS)
3386 return 0;
3387
3388 chunk_reset(out);
3389 memset(info, 0, sizeof(*info) * len);
3390
3391 info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME);
Willy Tarreau909b9d82019-01-04 18:20:32 +01003392 info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version);
3393 info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_date);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003394
Yves Lafon95317282018-02-26 11:10:37 +01003395 info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003396 info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
3397 info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid);
3398 info[INF_PID] = mkf_u32(FO_STATUS, pid);
3399
3400 info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out));
3401 chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
3402
3403 info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up);
3404 info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
3405 info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L));
3406 info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L));
3407 info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures());
3408 info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
3409 info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
3410 info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
3411 info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
3412 info[INF_CURR_CONN] = mkf_u32(0, actconn);
3413 info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn);
3414 info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count);
3415#ifdef USE_OPENSSL
3416 info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn);
3417 info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns);
3418 info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns);
3419#endif
3420 info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
3421 info[INF_PIPES_USED] = mkf_u32(0, pipes_used);
3422 info[INF_PIPES_FREE] = mkf_u32(0, pipes_free);
3423 info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
3424 info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
3425 info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max);
3426 info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
3427 info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
3428 info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max);
3429
3430#ifdef USE_OPENSSL
3431 info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate);
3432 info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
3433 info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max);
3434 info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate);
3435 info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
3436 info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse);
3437 info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
3438 info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max);
3439 info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups);
3440 info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses);
3441#endif
3442 info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
3443 info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
3444 info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
3445#ifdef USE_ZLIB
3446 info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory);
3447 info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
3448#endif
3449 info[INF_TASKS] = mkf_u32(0, nb_tasks_cur);
Christopher Faulet34c5cc92016-12-06 09:15:30 +01003450 info[INF_RUN_QUEUE] = mkf_u32(0, tasks_run_queue_cur);
Willy Tarreau81036f22019-05-20 19:24:50 +02003451 info[INF_IDLE_PCT] = mkf_u32(FN_AVG, ti->idle_pct);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003452 info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node);
3453 if (global.desc)
3454 info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003455 info[INF_STOPPING] = mkf_u32(0, stopping);
3456 info[INF_JOBS] = mkf_u32(0, jobs);
William Lallemanda7199262018-11-16 16:57:20 +01003457 info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003458 info[INF_LISTENERS] = mkf_u32(0, listeners);
Willy Tarreau199ad242018-11-05 16:31:22 +01003459 info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers);
Willy Tarreau2d372c22018-11-05 17:12:27 +01003460 info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers);
Willy Tarreau13ef7732018-11-12 07:25:28 +01003461 info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs);
Willy Tarreaubeb859a2018-11-22 18:07:59 +01003462 info[INF_BUSY_POLLING] = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
Baptiste Assmann333939c2019-01-21 08:34:50 +01003463 info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, dns_failed_resolutions);
Willy Tarreau7cf0e452019-05-23 11:39:14 +02003464 info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, global.out_bytes);
3465 info[INF_BYTES_OUT_RATE] = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003466
3467 return 1;
3468}
3469
3470/* This function dumps information onto the stream interface's read buffer.
3471 * It returns 0 as long as it does not complete, non-zero upon completion.
3472 * No state is used.
3473 */
3474static int stats_dump_info_to_buffer(struct stream_interface *si)
3475{
3476 struct appctx *appctx = __objt_appctx(si->end);
3477
3478 if (!stats_fill_info(info, INF_TOTAL_FIELDS))
3479 return 0;
3480
3481 chunk_reset(&trash);
3482
3483 if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
Willy Tarreau43241ff2019-10-09 11:27:51 +02003484 stats_dump_typed_info_fields(&trash, info, appctx->ctx.stats.flags);
Simon Horman05ee2132017-01-04 09:37:25 +01003485 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreau43241ff2019-10-09 11:27:51 +02003486 stats_dump_json_info_fields(&trash, info, appctx->ctx.stats.flags);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003487 else
Willy Tarreau43241ff2019-10-09 11:27:51 +02003488 stats_dump_info_fields(&trash, info, appctx->ctx.stats.flags);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003489
Willy Tarreau06d80a92017-10-19 14:32:15 +02003490 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003491 si_rx_room_blk(si);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003492 return 0;
3493 }
3494
3495 return 1;
3496}
3497
Simon Horman6f6bb382017-01-04 09:37:26 +01003498/* This function dumps the schema onto the stream interface's read buffer.
3499 * It returns 0 as long as it does not complete, non-zero upon completion.
3500 * No state is used.
3501 *
3502 * Integer values bouned to the range [-(2**53)+1, (2**53)-1] as
3503 * per the recommendation for interoperable integers in section 6 of RFC 7159.
3504 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003505static void stats_dump_json_schema(struct buffer *out)
Simon Horman6f6bb382017-01-04 09:37:26 +01003506{
3507
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003508 int old_len = out->data;
Simon Horman6f6bb382017-01-04 09:37:26 +01003509
3510 chunk_strcat(out,
3511 "{"
3512 "\"$schema\":\"http://json-schema.org/draft-04/schema#\","
3513 "\"oneOf\":["
3514 "{"
3515 "\"title\":\"Info\","
3516 "\"type\":\"array\","
3517 "\"items\":{"
3518 "\"properties\":{"
3519 "\"title\":\"InfoItem\","
3520 "\"type\":\"object\","
3521 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3522 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3523 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3524 "\"value\":{\"$ref\":\"#/definitions/typedValue\"}"
3525 "},"
3526 "\"required\":[\"field\",\"processNum\",\"tags\","
3527 "\"value\"]"
3528 "}"
3529 "},"
3530 "{"
3531 "\"title\":\"Stat\","
3532 "\"type\":\"array\","
3533 "\"items\":{"
3534 "\"title\":\"InfoItem\","
3535 "\"type\":\"object\","
3536 "\"properties\":{"
3537 "\"objType\":{"
3538 "\"enum\":[\"Frontend\",\"Backend\",\"Listener\","
3539 "\"Server\",\"Unknown\"]"
3540 "},"
3541 "\"proxyId\":{"
3542 "\"type\":\"integer\","
3543 "\"minimum\":0"
3544 "},"
3545 "\"id\":{"
3546 "\"type\":\"integer\","
3547 "\"minimum\":0"
3548 "},"
3549 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3550 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3551 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3552 "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}"
3553 "},"
3554 "\"required\":[\"objType\",\"proxyId\",\"id\","
3555 "\"field\",\"processNum\",\"tags\","
3556 "\"value\"]"
3557 "}"
3558 "},"
3559 "{"
3560 "\"title\":\"Error\","
3561 "\"type\":\"object\","
3562 "\"properties\":{"
3563 "\"errorStr\":{"
3564 "\"type\":\"string\""
3565 "},"
3566 "\"required\":[\"errorStr\"]"
3567 "}"
3568 "}"
3569 "],"
3570 "\"definitions\":{"
3571 "\"field\":{"
3572 "\"type\":\"object\","
3573 "\"pos\":{"
3574 "\"type\":\"integer\","
3575 "\"minimum\":0"
3576 "},"
3577 "\"name\":{"
3578 "\"type\":\"string\""
3579 "},"
3580 "\"required\":[\"pos\",\"name\"]"
3581 "},"
3582 "\"processNum\":{"
3583 "\"type\":\"integer\","
3584 "\"minimum\":1"
3585 "},"
3586 "\"tags\":{"
3587 "\"type\":\"object\","
3588 "\"origin\":{"
3589 "\"type\":\"string\","
3590 "\"enum\":[\"Metric\",\"Status\",\"Key\","
3591 "\"Config\",\"Product\",\"Unknown\"]"
3592 "},"
3593 "\"nature\":{"
3594 "\"type\":\"string\","
3595 "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\","
3596 "\"Rate\",\"Counter\",\"Duration\","
3597 "\"Age\",\"Time\",\"Name\",\"Output\","
3598 "\"Avg\", \"Unknown\"]"
3599 "},"
3600 "\"scope\":{"
3601 "\"type\":\"string\","
3602 "\"enum\":[\"Cluster\",\"Process\",\"Service\","
3603 "\"System\",\"Unknown\"]"
3604 "},"
3605 "\"required\":[\"origin\",\"nature\",\"scope\"]"
3606 "},"
3607 "\"typedValue\":{"
3608 "\"type\":\"object\","
3609 "\"oneOf\":["
3610 "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"},"
3611 "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"},"
3612 "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"},"
3613 "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"},"
3614 "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}"
3615 "],"
3616 "\"definitions\":{"
3617 "\"s32Value\":{"
3618 "\"properties\":{"
3619 "\"type\":{"
3620 "\"type\":\"string\","
3621 "\"enum\":[\"s32\"]"
3622 "},"
3623 "\"value\":{"
3624 "\"type\":\"integer\","
3625 "\"minimum\":-2147483648,"
3626 "\"maximum\":2147483647"
3627 "}"
3628 "},"
3629 "\"required\":[\"type\",\"value\"]"
3630 "},"
3631 "\"s64Value\":{"
3632 "\"properties\":{"
3633 "\"type\":{"
3634 "\"type\":\"string\","
3635 "\"enum\":[\"s64\"]"
3636 "},"
3637 "\"value\":{"
3638 "\"type\":\"integer\","
3639 "\"minimum\":-9007199254740991,"
3640 "\"maximum\":9007199254740991"
3641 "}"
3642 "},"
3643 "\"required\":[\"type\",\"value\"]"
3644 "},"
3645 "\"u32Value\":{"
3646 "\"properties\":{"
3647 "\"type\":{"
3648 "\"type\":\"string\","
3649 "\"enum\":[\"u32\"]"
3650 "},"
3651 "\"value\":{"
3652 "\"type\":\"integer\","
3653 "\"minimum\":0,"
3654 "\"maximum\":4294967295"
3655 "}"
3656 "},"
3657 "\"required\":[\"type\",\"value\"]"
3658 "},"
3659 "\"u64Value\":{"
3660 "\"properties\":{"
3661 "\"type\":{"
3662 "\"type\":\"string\","
3663 "\"enum\":[\"u64\"]"
3664 "},"
3665 "\"value\":{"
3666 "\"type\":\"integer\","
3667 "\"minimum\":0,"
3668 "\"maximum\":9007199254740991"
3669 "}"
3670 "},"
3671 "\"required\":[\"type\",\"value\"]"
3672 "},"
3673 "\"strValue\":{"
3674 "\"properties\":{"
3675 "\"type\":{"
3676 "\"type\":\"string\","
3677 "\"enum\":[\"str\"]"
3678 "},"
3679 "\"value\":{\"type\":\"string\"}"
3680 "},"
3681 "\"required\":[\"type\",\"value\"]"
3682 "},"
3683 "\"unknownValue\":{"
3684 "\"properties\":{"
3685 "\"type\":{"
3686 "\"type\":\"integer\","
3687 "\"minimum\":0"
3688 "},"
3689 "\"value\":{"
3690 "\"type\":\"string\","
3691 "\"enum\":[\"unknown\"]"
3692 "}"
3693 "},"
3694 "\"required\":[\"type\",\"value\"]"
3695 "}"
3696 "}"
3697 "}"
3698 "}"
3699 "}");
3700
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003701 if (old_len == out->data) {
Simon Horman6f6bb382017-01-04 09:37:26 +01003702 chunk_reset(out);
3703 chunk_appendf(out,
3704 "{\"errorStr\":\"output buffer too short\"}");
3705 }
3706}
3707
3708/* This function dumps the schema onto the stream interface's read buffer.
3709 * It returns 0 as long as it does not complete, non-zero upon completion.
3710 * No state is used.
3711 */
3712static int stats_dump_json_schema_to_buffer(struct stream_interface *si)
3713{
3714 chunk_reset(&trash);
3715
3716 stats_dump_json_schema(&trash);
3717
Willy Tarreau06d80a92017-10-19 14:32:15 +02003718 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003719 si_rx_room_blk(si);
Simon Horman6f6bb382017-01-04 09:37:26 +01003720 return 0;
3721 }
3722
3723 return 1;
3724}
3725
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003726static int cli_parse_clear_counters(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau89d467c2016-11-23 11:02:40 +01003727{
3728 struct proxy *px;
3729 struct server *sv;
3730 struct listener *li;
3731 int clrall = 0;
3732
3733 if (strcmp(args[2], "all") == 0)
3734 clrall = 1;
3735
3736 /* check permissions */
3737 if (!cli_has_level(appctx, ACCESS_LVL_OPER) ||
3738 (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN)))
3739 return 1;
3740
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003741 for (px = proxies_list; px; px = px->next) {
Willy Tarreau89d467c2016-11-23 11:02:40 +01003742 if (clrall) {
3743 memset(&px->be_counters, 0, sizeof(px->be_counters));
3744 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
3745 }
3746 else {
3747 px->be_counters.conn_max = 0;
3748 px->be_counters.p.http.rps_max = 0;
3749 px->be_counters.sps_max = 0;
3750 px->be_counters.cps_max = 0;
3751 px->be_counters.nbpend_max = 0;
3752
3753 px->fe_counters.conn_max = 0;
3754 px->fe_counters.p.http.rps_max = 0;
3755 px->fe_counters.sps_max = 0;
3756 px->fe_counters.cps_max = 0;
Willy Tarreau89d467c2016-11-23 11:02:40 +01003757 }
3758
3759 for (sv = px->srv; sv; sv = sv->next)
3760 if (clrall)
3761 memset(&sv->counters, 0, sizeof(sv->counters));
3762 else {
3763 sv->counters.cur_sess_max = 0;
3764 sv->counters.nbpend_max = 0;
3765 sv->counters.sps_max = 0;
3766 }
3767
3768 list_for_each_entry(li, &px->conf.listeners, by_fe)
3769 if (li->counters) {
3770 if (clrall)
3771 memset(li->counters, 0, sizeof(*li->counters));
3772 else
3773 li->counters->conn_max = 0;
3774 }
3775 }
3776
3777 global.cps_max = 0;
3778 global.sps_max = 0;
Olivier Houchard00bc3cb2017-10-17 19:23:25 +02003779 global.ssl_max = 0;
3780 global.ssl_fe_keys_max = 0;
3781 global.ssl_be_keys_max = 0;
Willy Tarreaud80cb4e2018-01-20 19:30:13 +01003782
3783 memset(activity, 0, sizeof(activity));
Willy Tarreau89d467c2016-11-23 11:02:40 +01003784 return 1;
3785}
3786
3787
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003788static int cli_parse_show_info(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003789{
Willy Tarreau2f397382019-10-09 11:43:59 +02003790 int arg = 2;
3791
Willy Tarreaud25fc792016-12-16 12:33:47 +01003792 appctx->ctx.stats.scope_str = 0;
3793 appctx->ctx.stats.scope_len = 0;
3794 appctx->ctx.stats.flags = 0;
3795
Willy Tarreau2f397382019-10-09 11:43:59 +02003796 while (*args[arg]) {
3797 if (strcmp(args[arg], "typed") == 0)
3798 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED;
3799 else if (strcmp(args[arg], "json") == 0)
3800 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON;
3801 else if (strcmp(args[arg], "desc") == 0)
3802 appctx->ctx.stats.flags |= STAT_SHOW_FDESC;
3803 arg++;
3804 }
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003805 return 0;
3806}
3807
3808
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003809static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau2b812e22016-11-22 16:18:05 +01003810{
Willy Tarreau2f397382019-10-09 11:43:59 +02003811 int arg = 2;
3812
Willy Tarreaud25fc792016-12-16 12:33:47 +01003813 appctx->ctx.stats.scope_str = 0;
3814 appctx->ctx.stats.scope_len = 0;
Willy Tarreau578d6e42019-10-09 11:00:22 +02003815 appctx->ctx.stats.flags = STAT_SHNODE | STAT_SHDESC;
3816
3817 if ((strm_li(si_strm(appctx->owner))->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER)
3818 appctx->ctx.stats.flags |= STAT_SHLGNDS;
Willy Tarreaud25fc792016-12-16 12:33:47 +01003819
Willy Tarreau2f397382019-10-09 11:43:59 +02003820 if (*args[arg] && *args[arg+1] && *args[arg+2]) {
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003821 struct proxy *px;
3822
Willy Tarreau2f397382019-10-09 11:43:59 +02003823 px = proxy_find_by_name(args[arg], 0, 0);
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003824 if (px)
3825 appctx->ctx.stats.iid = px->uuid;
3826 else
Willy Tarreau2f397382019-10-09 11:43:59 +02003827 appctx->ctx.stats.iid = atoi(args[arg]);
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003828
Willy Tarreau9d008692019-08-09 11:21:01 +02003829 if (!appctx->ctx.stats.iid)
3830 return cli_err(appctx, "No such proxy.\n");
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003831
Willy Tarreau2b812e22016-11-22 16:18:05 +01003832 appctx->ctx.stats.flags |= STAT_BOUND;
Willy Tarreau2f397382019-10-09 11:43:59 +02003833 appctx->ctx.stats.type = atoi(args[arg+1]);
3834 appctx->ctx.stats.sid = atoi(args[arg+2]);
3835 arg += 3;
3836 }
3837
3838 while (*args[arg]) {
3839 if (strcmp(args[arg], "typed") == 0)
3840 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_TYPED;
3841 else if (strcmp(args[arg], "json") == 0)
3842 appctx->ctx.stats.flags = (appctx->ctx.stats.flags & ~STAT_FMT_MASK) | STAT_FMT_JSON;
3843 else if (strcmp(args[arg], "desc") == 0)
3844 appctx->ctx.stats.flags |= STAT_SHOW_FDESC;
3845 arg++;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003846 }
Willy Tarreau2b812e22016-11-22 16:18:05 +01003847
Willy Tarreau2b812e22016-11-22 16:18:05 +01003848 return 0;
3849}
3850
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003851static int cli_io_handler_dump_info(struct appctx *appctx)
3852{
3853 return stats_dump_info_to_buffer(appctx->owner);
3854}
3855
Willy Tarreau2b812e22016-11-22 16:18:05 +01003856/* This I/O handler runs as an applet embedded in a stream interface. It is
3857 * used to send raw stats over a socket.
3858 */
3859static int cli_io_handler_dump_stat(struct appctx *appctx)
3860{
Christopher Fauletef779222018-10-31 08:47:01 +01003861 return stats_dump_stat_to_buffer(appctx->owner, NULL, NULL);
Willy Tarreau2b812e22016-11-22 16:18:05 +01003862}
3863
Simon Horman6f6bb382017-01-04 09:37:26 +01003864static int cli_io_handler_dump_json_schema(struct appctx *appctx)
3865{
3866 return stats_dump_json_schema_to_buffer(appctx->owner);
3867}
3868
Willy Tarreau2b812e22016-11-22 16:18:05 +01003869/* register cli keywords */
3870static struct cli_kw_list cli_kws = {{ },{
Willy Tarreau89d467c2016-11-23 11:02:40 +01003871 { { "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 +02003872 { { "show", "info", NULL }, "show info : report information about the running process [desc|json|typed]*", cli_parse_show_info, cli_io_handler_dump_info, NULL },
3873 { { "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 +01003874 { { "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 +01003875 {{},}
3876}};
3877
Willy Tarreau0108d902018-11-25 19:14:37 +01003878INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
3879
William Lallemand74c24fb2016-11-21 17:18:36 +01003880struct applet http_stats_applet = {
3881 .obj_type = OBJ_TYPE_APPLET,
3882 .name = "<STATS>", /* used for logging */
3883 .fct = http_stats_io_handler,
3884 .release = NULL,
3885};
3886
William Lallemand74c24fb2016-11-21 17:18:36 +01003887/*
3888 * Local variables:
3889 * c-indent-level: 8
3890 * c-basic-offset: 8
3891 * End:
3892 */