blob: 01fcb4586b53c4347abcf59543cc94cbc0bab0ba [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
William Lallemand74c24fb2016-11-21 17:18:36 +010075
Christopher Faulet2b9b6782019-02-27 16:42:58 +010076/* status codes available for the stats admin page (strictly 4 chars length) */
77const char *stat_status_codes[STAT_STATUS_SIZE] = {
78 [STAT_STATUS_DENY] = "DENY",
79 [STAT_STATUS_DONE] = "DONE",
80 [STAT_STATUS_ERRP] = "ERRP",
81 [STAT_STATUS_EXCD] = "EXCD",
82 [STAT_STATUS_NONE] = "NONE",
83 [STAT_STATUS_PART] = "PART",
84 [STAT_STATUS_UNKN] = "UNKN",
85 [STAT_STATUS_IVAL] = "IVAL",
86};
87
Willy Tarreau0baac8c2016-11-22 16:36:53 +010088/* These are the field names for each INF_* field position. Please pay attention
89 * to always use the exact same name except that the strings for new names must
90 * be lower case or CamelCase while the enum entries must be upper case.
91 */
92const char *info_field_names[INF_TOTAL_FIELDS] = {
93 [INF_NAME] = "Name",
94 [INF_VERSION] = "Version",
95 [INF_RELEASE_DATE] = "Release_date",
Yves Lafon95317282018-02-26 11:10:37 +010096 [INF_NBTHREAD] = "Nbthread",
Willy Tarreau0baac8c2016-11-22 16:36:53 +010097 [INF_NBPROC] = "Nbproc",
98 [INF_PROCESS_NUM] = "Process_num",
99 [INF_PID] = "Pid",
100 [INF_UPTIME] = "Uptime",
101 [INF_UPTIME_SEC] = "Uptime_sec",
102 [INF_MEMMAX_MB] = "Memmax_MB",
103 [INF_POOL_ALLOC_MB] = "PoolAlloc_MB",
104 [INF_POOL_USED_MB] = "PoolUsed_MB",
105 [INF_POOL_FAILED] = "PoolFailed",
106 [INF_ULIMIT_N] = "Ulimit-n",
107 [INF_MAXSOCK] = "Maxsock",
108 [INF_MAXCONN] = "Maxconn",
109 [INF_HARD_MAXCONN] = "Hard_maxconn",
110 [INF_CURR_CONN] = "CurrConns",
111 [INF_CUM_CONN] = "CumConns",
112 [INF_CUM_REQ] = "CumReq",
113 [INF_MAX_SSL_CONNS] = "MaxSslConns",
114 [INF_CURR_SSL_CONNS] = "CurrSslConns",
115 [INF_CUM_SSL_CONNS] = "CumSslConns",
116 [INF_MAXPIPES] = "Maxpipes",
117 [INF_PIPES_USED] = "PipesUsed",
118 [INF_PIPES_FREE] = "PipesFree",
119 [INF_CONN_RATE] = "ConnRate",
120 [INF_CONN_RATE_LIMIT] = "ConnRateLimit",
121 [INF_MAX_CONN_RATE] = "MaxConnRate",
122 [INF_SESS_RATE] = "SessRate",
123 [INF_SESS_RATE_LIMIT] = "SessRateLimit",
124 [INF_MAX_SESS_RATE] = "MaxSessRate",
125 [INF_SSL_RATE] = "SslRate",
126 [INF_SSL_RATE_LIMIT] = "SslRateLimit",
127 [INF_MAX_SSL_RATE] = "MaxSslRate",
128 [INF_SSL_FRONTEND_KEY_RATE] = "SslFrontendKeyRate",
129 [INF_SSL_FRONTEND_MAX_KEY_RATE] = "SslFrontendMaxKeyRate",
130 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = "SslFrontendSessionReuse_pct",
131 [INF_SSL_BACKEND_KEY_RATE] = "SslBackendKeyRate",
132 [INF_SSL_BACKEND_MAX_KEY_RATE] = "SslBackendMaxKeyRate",
133 [INF_SSL_CACHE_LOOKUPS] = "SslCacheLookups",
134 [INF_SSL_CACHE_MISSES] = "SslCacheMisses",
135 [INF_COMPRESS_BPS_IN] = "CompressBpsIn",
136 [INF_COMPRESS_BPS_OUT] = "CompressBpsOut",
137 [INF_COMPRESS_BPS_RATE_LIM] = "CompressBpsRateLim",
138 [INF_ZLIB_MEM_USAGE] = "ZlibMemUsage",
139 [INF_MAX_ZLIB_MEM_USAGE] = "MaxZlibMemUsage",
140 [INF_TASKS] = "Tasks",
141 [INF_RUN_QUEUE] = "Run_queue",
142 [INF_IDLE_PCT] = "Idle_pct",
143 [INF_NODE] = "node",
144 [INF_DESCRIPTION] = "description",
Willy Tarreau00098ea2018-11-05 14:38:13 +0100145 [INF_STOPPING] = "Stopping",
146 [INF_JOBS] = "Jobs",
William Lallemanda7199262018-11-16 16:57:20 +0100147 [INF_UNSTOPPABLE_JOBS] = "Unstoppable Jobs",
Willy Tarreau00098ea2018-11-05 14:38:13 +0100148 [INF_LISTENERS] = "Listeners",
Willy Tarreau199ad242018-11-05 16:31:22 +0100149 [INF_ACTIVE_PEERS] = "ActivePeers",
Willy Tarreau2d372c22018-11-05 17:12:27 +0100150 [INF_CONNECTED_PEERS] = "ConnectedPeers",
Willy Tarreau13ef7732018-11-12 07:25:28 +0100151 [INF_DROPPED_LOGS] = "DroppedLogs",
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100152 [INF_BUSY_POLLING] = "BusyPolling",
Baptiste Assmann333939c2019-01-21 08:34:50 +0100153 [INF_FAILED_RESOLUTIONS] = "FailedResolutions",
Willy Tarreau7cf0e452019-05-23 11:39:14 +0200154 [INF_TOTAL_BYTES_OUT] = "TotalBytesOut",
155 [INF_BYTES_OUT_RATE] = "BytesOutRate",
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100156};
157
William Lallemand74c24fb2016-11-21 17:18:36 +0100158const char *stat_field_names[ST_F_TOTAL_FIELDS] = {
159 [ST_F_PXNAME] = "pxname",
160 [ST_F_SVNAME] = "svname",
161 [ST_F_QCUR] = "qcur",
162 [ST_F_QMAX] = "qmax",
163 [ST_F_SCUR] = "scur",
164 [ST_F_SMAX] = "smax",
165 [ST_F_SLIM] = "slim",
166 [ST_F_STOT] = "stot",
167 [ST_F_BIN] = "bin",
168 [ST_F_BOUT] = "bout",
169 [ST_F_DREQ] = "dreq",
170 [ST_F_DRESP] = "dresp",
171 [ST_F_EREQ] = "ereq",
172 [ST_F_ECON] = "econ",
173 [ST_F_ERESP] = "eresp",
174 [ST_F_WRETR] = "wretr",
175 [ST_F_WREDIS] = "wredis",
176 [ST_F_STATUS] = "status",
177 [ST_F_WEIGHT] = "weight",
178 [ST_F_ACT] = "act",
179 [ST_F_BCK] = "bck",
180 [ST_F_CHKFAIL] = "chkfail",
181 [ST_F_CHKDOWN] = "chkdown",
182 [ST_F_LASTCHG] = "lastchg",
183 [ST_F_DOWNTIME] = "downtime",
184 [ST_F_QLIMIT] = "qlimit",
185 [ST_F_PID] = "pid",
186 [ST_F_IID] = "iid",
187 [ST_F_SID] = "sid",
188 [ST_F_THROTTLE] = "throttle",
189 [ST_F_LBTOT] = "lbtot",
190 [ST_F_TRACKED] = "tracked",
191 [ST_F_TYPE] = "type",
192 [ST_F_RATE] = "rate",
193 [ST_F_RATE_LIM] = "rate_lim",
194 [ST_F_RATE_MAX] = "rate_max",
195 [ST_F_CHECK_STATUS] = "check_status",
196 [ST_F_CHECK_CODE] = "check_code",
197 [ST_F_CHECK_DURATION] = "check_duration",
198 [ST_F_HRSP_1XX] = "hrsp_1xx",
199 [ST_F_HRSP_2XX] = "hrsp_2xx",
200 [ST_F_HRSP_3XX] = "hrsp_3xx",
201 [ST_F_HRSP_4XX] = "hrsp_4xx",
202 [ST_F_HRSP_5XX] = "hrsp_5xx",
203 [ST_F_HRSP_OTHER] = "hrsp_other",
204 [ST_F_HANAFAIL] = "hanafail",
205 [ST_F_REQ_RATE] = "req_rate",
206 [ST_F_REQ_RATE_MAX] = "req_rate_max",
207 [ST_F_REQ_TOT] = "req_tot",
208 [ST_F_CLI_ABRT] = "cli_abrt",
209 [ST_F_SRV_ABRT] = "srv_abrt",
210 [ST_F_COMP_IN] = "comp_in",
211 [ST_F_COMP_OUT] = "comp_out",
212 [ST_F_COMP_BYP] = "comp_byp",
213 [ST_F_COMP_RSP] = "comp_rsp",
214 [ST_F_LASTSESS] = "lastsess",
215 [ST_F_LAST_CHK] = "last_chk",
216 [ST_F_LAST_AGT] = "last_agt",
217 [ST_F_QTIME] = "qtime",
218 [ST_F_CTIME] = "ctime",
219 [ST_F_RTIME] = "rtime",
220 [ST_F_TTIME] = "ttime",
221 [ST_F_AGENT_STATUS] = "agent_status",
222 [ST_F_AGENT_CODE] = "agent_code",
223 [ST_F_AGENT_DURATION] = "agent_duration",
224 [ST_F_CHECK_DESC] = "check_desc",
225 [ST_F_AGENT_DESC] = "agent_desc",
226 [ST_F_CHECK_RISE] = "check_rise",
227 [ST_F_CHECK_FALL] = "check_fall",
228 [ST_F_CHECK_HEALTH] = "check_health",
229 [ST_F_AGENT_RISE] = "agent_rise",
230 [ST_F_AGENT_FALL] = "agent_fall",
231 [ST_F_AGENT_HEALTH] = "agent_health",
232 [ST_F_ADDR] = "addr",
233 [ST_F_COOKIE] = "cookie",
234 [ST_F_MODE] = "mode",
235 [ST_F_ALGO] = "algo",
236 [ST_F_CONN_RATE] = "conn_rate",
237 [ST_F_CONN_RATE_MAX] = "conn_rate_max",
238 [ST_F_CONN_TOT] = "conn_tot",
239 [ST_F_INTERCEPTED] = "intercepted",
240 [ST_F_DCON] = "dcon",
241 [ST_F_DSES] = "dses",
Tim Duesterhus3fd19732018-05-27 20:35:08 +0200242 [ST_F_WREW] = "wrew",
Willy Tarreauf1573842018-12-14 11:35:36 +0100243 [ST_F_CONNECT] = "connect",
244 [ST_F_REUSE] = "reuse",
Willy Tarreaua1214a52018-12-14 14:00:25 +0100245 [ST_F_CACHE_LOOKUPS] = "cache_lookups",
246 [ST_F_CACHE_HITS] = "cache_hits",
William Lallemand74c24fb2016-11-21 17:18:36 +0100247};
248
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100249/* one line of info */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100250static THREAD_LOCAL struct field info[INF_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100251/* one line of stats */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100252static THREAD_LOCAL struct field stats[ST_F_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100253
254
Christopher Fauletef779222018-10-31 08:47:01 +0100255static int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk)
256{
257 if (htx) {
Christopher Faulet69fc88c2019-01-07 14:27:53 +0100258 if (chk->data >= channel_htx_recv_max(chn, htx))
259 return 0;
Willy Tarreau0a7ef022019-05-28 10:30:11 +0200260 if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data)))
Christopher Fauletef779222018-10-31 08:47:01 +0100261 return 0;
Christopher Faulet5adbeeb2019-01-02 14:34:39 +0100262 channel_add_input(chn, chk->data);
Christopher Fauletef779222018-10-31 08:47:01 +0100263 chk->data = 0;
Christopher Fauletef779222018-10-31 08:47:01 +0100264 }
265 else {
266 if (ci_putchk(chn, chk) == -1)
267 return 0;
268 }
269 return 1;
270}
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100271
Christopher Fauleted7a0662019-01-14 11:07:34 +0100272static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interface *si)
273{
Christopher Fauletb7f88902019-07-15 21:56:43 +0200274 struct channel *req = si_oc(si);
275 struct htx *htx = htxbuf(&req->buf);
276 struct htx_blk *blk;
277 struct ist uri;
Christopher Fauleted7a0662019-01-14 11:07:34 +0100278
Christopher Fauletb7f88902019-07-15 21:56:43 +0200279 blk = htx_get_head_blk(htx);
280 BUG_ON(htx_get_blk_type(blk) != HTX_BLK_REQ_SL);
281 ALREADY_CHECKED(blk);
282 uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk));
283 return uri.ptr + appctx->ctx.stats.scope_str;
Christopher Fauleted7a0662019-01-14 11:07:34 +0100284}
285
William Lallemand74c24fb2016-11-21 17:18:36 +0100286/*
287 * http_stats_io_handler()
288 * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
289 * -> stats_dump_csv_header() // emits the CSV headers (same as above)
Simon Horman05ee2132017-01-04 09:37:25 +0100290 * -> stats_dump_json_header() // emits the JSON headers (same as above)
William Lallemand74c24fb2016-11-21 17:18:36 +0100291 * -> stats_dump_html_head() // emits the HTML headers
292 * -> stats_dump_html_info() // emits the equivalent of "show info" at the top
293 * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML
294 * -> stats_dump_html_px_hdr()
295 * -> stats_dump_fe_stats()
296 * -> stats_dump_li_stats()
297 * -> stats_dump_sv_stats()
298 * -> stats_dump_be_stats()
299 * -> stats_dump_html_px_end()
300 * -> stats_dump_html_end() // emits HTML trailer
Simon Horman05ee2132017-01-04 09:37:25 +0100301 * -> stats_dump_json_end() // emits JSON trailer
William Lallemand74c24fb2016-11-21 17:18:36 +0100302 */
303
304
William Lallemand74c24fb2016-11-21 17:18:36 +0100305/* Dumps the stats CSV header to the trash buffer which. The caller is responsible
306 * for clearing it if needed.
307 * NOTE: Some tools happen to rely on the field position instead of its name,
308 * so please only append new fields at the end, never in the middle.
309 */
310static void stats_dump_csv_header()
311{
312 int field;
313
314 chunk_appendf(&trash, "# ");
315 for (field = 0; field < ST_F_TOTAL_FIELDS; field++)
316 chunk_appendf(&trash, "%s,", stat_field_names[field]);
317
318 chunk_appendf(&trash, "\n");
319}
320
321
322/* Emits a stats field without any surrounding element and properly encoded to
323 * resist CSV output. Returns non-zero on success, 0 if the buffer is full.
324 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200325int stats_emit_raw_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100326{
327 switch (field_format(f, 0)) {
328 case FF_EMPTY: return 1;
329 case FF_S32: return chunk_appendf(out, "%d", f->u.s32);
330 case FF_U32: return chunk_appendf(out, "%u", f->u.u32);
331 case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64);
332 case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64);
333 case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL;
334 default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type);
335 }
336}
337
338/* Emits a stats field prefixed with its type. No CSV encoding is prepared, the
339 * output is supposed to be used on its own line. Returns non-zero on success, 0
340 * if the buffer is full.
341 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200342int stats_emit_typed_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100343{
344 switch (field_format(f, 0)) {
345 case FF_EMPTY: return 1;
346 case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32);
347 case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32);
348 case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64);
349 case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64);
350 case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0));
351 default: return chunk_appendf(out, "%08x:?", f->type);
352 }
353}
354
Simon Horman05ee2132017-01-04 09:37:25 +0100355/* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per
356 * the recommendation for interoperable integers in section 6 of RFC 7159.
357 */
358#define JSON_INT_MAX ((1ULL << 53) - 1)
359#define JSON_INT_MIN (0 - JSON_INT_MAX)
360
361/* Emits a stats field value and its type in JSON.
362 * Returns non-zero on success, 0 on error.
363 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200364int stats_emit_json_data_field(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100365{
366 int old_len;
367 char buf[20];
368 const char *type, *value = buf, *quote = "";
369
370 switch (field_format(f, 0)) {
371 case FF_EMPTY: return 1;
372 case FF_S32: type = "\"s32\"";
373 snprintf(buf, sizeof(buf), "%d", f->u.s32);
374 break;
375 case FF_U32: type = "\"u32\"";
376 snprintf(buf, sizeof(buf), "%u", f->u.u32);
377 break;
378 case FF_S64: type = "\"s64\"";
379 if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX)
380 return 0;
381 type = "\"s64\"";
382 snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64);
383 break;
384 case FF_U64: if (f->u.u64 > JSON_INT_MAX)
385 return 0;
386 type = "\"u64\"";
387 snprintf(buf, sizeof(buf), "%llu",
388 (unsigned long long) f->u.u64);
389 break;
390 case FF_STR: type = "\"str\"";
391 value = field_str(f, 0);
392 quote = "\"";
393 break;
394 default: snprintf(buf, sizeof(buf), "%u", f->type);
395 type = buf;
396 value = "unknown";
397 quote = "\"";
398 break;
399 }
400
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200401 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100402 chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}",
403 type, quote, value, quote);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200404 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100405}
406
William Lallemand74c24fb2016-11-21 17:18:36 +0100407/* Emits an encoding of the field type on 3 characters followed by a delimiter.
408 * Returns non-zero on success, 0 if the buffer is full.
409 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200410int stats_emit_field_tags(struct buffer *out, const struct field *f,
411 char delim)
William Lallemand74c24fb2016-11-21 17:18:36 +0100412{
413 char origin, nature, scope;
414
415 switch (field_origin(f, 0)) {
416 case FO_METRIC: origin = 'M'; break;
417 case FO_STATUS: origin = 'S'; break;
418 case FO_KEY: origin = 'K'; break;
419 case FO_CONFIG: origin = 'C'; break;
420 case FO_PRODUCT: origin = 'P'; break;
421 default: origin = '?'; break;
422 }
423
424 switch (field_nature(f, 0)) {
425 case FN_GAUGE: nature = 'G'; break;
426 case FN_LIMIT: nature = 'L'; break;
427 case FN_MIN: nature = 'm'; break;
428 case FN_MAX: nature = 'M'; break;
429 case FN_RATE: nature = 'R'; break;
430 case FN_COUNTER: nature = 'C'; break;
431 case FN_DURATION: nature = 'D'; break;
432 case FN_AGE: nature = 'A'; break;
433 case FN_TIME: nature = 'T'; break;
434 case FN_NAME: nature = 'N'; break;
435 case FN_OUTPUT: nature = 'O'; break;
436 case FN_AVG: nature = 'a'; break;
437 default: nature = '?'; break;
438 }
439
440 switch (field_scope(f, 0)) {
441 case FS_PROCESS: scope = 'P'; break;
442 case FS_SERVICE: scope = 'S'; break;
443 case FS_SYSTEM: scope = 's'; break;
444 case FS_CLUSTER: scope = 'C'; break;
445 default: scope = '?'; break;
446 }
447
448 return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim);
449}
450
Simon Horman05ee2132017-01-04 09:37:25 +0100451/* Emits an encoding of the field type as JSON.
452 * Returns non-zero on success, 0 if the buffer is full.
453 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200454int stats_emit_json_field_tags(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100455{
456 const char *origin, *nature, *scope;
457 int old_len;
458
459 switch (field_origin(f, 0)) {
460 case FO_METRIC: origin = "Metric"; break;
461 case FO_STATUS: origin = "Status"; break;
462 case FO_KEY: origin = "Key"; break;
463 case FO_CONFIG: origin = "Config"; break;
464 case FO_PRODUCT: origin = "Product"; break;
465 default: origin = "Unknown"; break;
466 }
467
468 switch (field_nature(f, 0)) {
469 case FN_GAUGE: nature = "Gauge"; break;
470 case FN_LIMIT: nature = "Limit"; break;
471 case FN_MIN: nature = "Min"; break;
472 case FN_MAX: nature = "Max"; break;
473 case FN_RATE: nature = "Rate"; break;
474 case FN_COUNTER: nature = "Counter"; break;
475 case FN_DURATION: nature = "Duration"; break;
476 case FN_AGE: nature = "Age"; break;
477 case FN_TIME: nature = "Time"; break;
478 case FN_NAME: nature = "Name"; break;
479 case FN_OUTPUT: nature = "Output"; break;
480 case FN_AVG: nature = "Avg"; break;
481 default: nature = "Unknown"; break;
482 }
483
484 switch (field_scope(f, 0)) {
485 case FS_PROCESS: scope = "Process"; break;
486 case FS_SERVICE: scope = "Service"; break;
487 case FS_SYSTEM: scope = "System"; break;
488 case FS_CLUSTER: scope = "Cluster"; break;
489 default: scope = "Unknown"; break;
490 }
491
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200492 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100493 chunk_appendf(out, "\"tags\":{"
494 "\"origin\":\"%s\","
495 "\"nature\":\"%s\","
496 "\"scope\":\"%s\""
497 "}", origin, nature, scope);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200498 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100499}
William Lallemand74c24fb2016-11-21 17:18:36 +0100500
501/* Dump all fields from <stats> into <out> using CSV format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200502static int stats_dump_fields_csv(struct buffer *out,
503 const struct field *stats)
William Lallemand74c24fb2016-11-21 17:18:36 +0100504{
505 int field;
506
507 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
508 if (!stats_emit_raw_data_field(out, &stats[field]))
509 return 0;
510 if (!chunk_strcat(out, ","))
511 return 0;
512 }
513 chunk_strcat(out, "\n");
514 return 1;
515}
516
517/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200518static int stats_dump_fields_typed(struct buffer *out,
519 const struct field *stats)
William Lallemand74c24fb2016-11-21 17:18:36 +0100520{
521 int field;
522
523 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
524 if (!stats[field].type)
525 continue;
526
527 chunk_appendf(out, "%c.%u.%u.%d.%s.%u:",
528 stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' :
529 stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' :
530 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' :
531 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' :
532 '?',
533 stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32,
534 field, stat_field_names[field], stats[ST_F_PID].u.u32);
535
536 if (!stats_emit_field_tags(out, &stats[field], ':'))
537 return 0;
538 if (!stats_emit_typed_data_field(out, &stats[field]))
539 return 0;
540 if (!chunk_strcat(out, "\n"))
541 return 0;
542 }
543 return 1;
544}
545
Simon Horman05ee2132017-01-04 09:37:25 +0100546/* Dump all fields from <stats> into <out> using the "show info json" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200547static int stats_dump_json_info_fields(struct buffer *out,
Simon Horman05ee2132017-01-04 09:37:25 +0100548 const struct field *info)
549{
550 int field;
551 int started = 0;
552
553 if (!chunk_strcat(out, "["))
554 return 0;
555
556 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
557 int old_len;
558
559 if (!field_format(info, field))
560 continue;
561
562 if (started && !chunk_strcat(out, ","))
563 goto err;
564 started = 1;
565
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200566 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100567 chunk_appendf(out,
568 "{\"field\":{\"pos\":%d,\"name\":\"%s\"},"
569 "\"processNum\":%u,",
570 field, info_field_names[field],
571 info[INF_PROCESS_NUM].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200572 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100573 goto err;
574
575 if (!stats_emit_json_field_tags(out, &info[field]))
576 goto err;
577
578 if (!stats_emit_json_data_field(out, &info[field]))
579 goto err;
580
581 if (!chunk_strcat(out, "}"))
582 goto err;
583 }
584
585 if (!chunk_strcat(out, "]"))
586 goto err;
587 return 1;
588
589err:
590 chunk_reset(out);
591 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
592 return 0;
593}
594
595/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200596static int stats_dump_fields_json(struct buffer *out,
597 const struct field *stats,
Simon Horman05ee2132017-01-04 09:37:25 +0100598 int first_stat)
599{
600 int field;
601 int started = 0;
602
603 if (!first_stat && !chunk_strcat(out, ","))
604 return 0;
605 if (!chunk_strcat(out, "["))
606 return 0;
607
608 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
609 const char *obj_type;
610 int old_len;
611
612 if (!stats[field].type)
613 continue;
614
615 if (started && !chunk_strcat(out, ","))
616 goto err;
617 started = 1;
618
619 switch (stats[ST_F_TYPE].u.u32) {
620 case STATS_TYPE_FE: obj_type = "Frontend"; break;
621 case STATS_TYPE_BE: obj_type = "Backend"; break;
622 case STATS_TYPE_SO: obj_type = "Listener"; break;
623 case STATS_TYPE_SV: obj_type = "Server"; break;
624 default: obj_type = "Unknown"; break;
625 }
626
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200627 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100628 chunk_appendf(out,
629 "{"
630 "\"objType\":\"%s\","
631 "\"proxyId\":%d,"
632 "\"id\":%d,"
633 "\"field\":{\"pos\":%d,\"name\":\"%s\"},"
634 "\"processNum\":%u,",
635 obj_type, stats[ST_F_IID].u.u32,
636 stats[ST_F_SID].u.u32, field,
637 stat_field_names[field], stats[ST_F_PID].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200638 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100639 goto err;
640
641 if (!stats_emit_json_field_tags(out, &stats[field]))
642 goto err;
643
644 if (!stats_emit_json_data_field(out, &stats[field]))
645 goto err;
646
647 if (!chunk_strcat(out, "}"))
648 goto err;
649 }
650
651 if (!chunk_strcat(out, "]"))
652 goto err;
653
654 return 1;
655
656err:
657 chunk_reset(out);
658 if (!first_stat)
659 chunk_strcat(out, ",");
660 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
661 return 0;
662}
663
William Lallemand74c24fb2016-11-21 17:18:36 +0100664/* Dump all fields from <stats> into <out> using the HTML format. A column is
665 * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info
666 * are provided if ST_SHLGNDS is present in <flags>.
667 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200668static int stats_dump_fields_html(struct buffer *out,
669 const struct field *stats,
670 unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100671{
Willy Tarreau83061a82018-07-13 11:56:34 +0200672 struct buffer src;
William Lallemand74c24fb2016-11-21 17:18:36 +0100673
674 if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) {
675 chunk_appendf(out,
676 /* name, queue */
677 "<tr class=\"frontend\">");
678
679 if (flags & ST_SHOWADMIN) {
680 /* Column sub-heading for Enable or Disable server */
681 chunk_appendf(out, "<td></td>");
682 }
683
684 chunk_appendf(out,
685 "<td class=ac>"
686 "<a name=\"%s/Frontend\"></a>"
687 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
688 "<td colspan=3></td>"
689 "",
690 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
691
692 chunk_appendf(out,
693 /* sessions rate : current */
694 "<td><u>%s<div class=tips><table class=det>"
695 "<tr><th>Current connection rate:</th><td>%s/s</td></tr>"
696 "<tr><th>Current session rate:</th><td>%s/s</td></tr>"
697 "",
698 U2H(stats[ST_F_RATE].u.u32),
699 U2H(stats[ST_F_CONN_RATE].u.u32),
700 U2H(stats[ST_F_RATE].u.u32));
701
702 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
703 chunk_appendf(out,
704 "<tr><th>Current request rate:</th><td>%s/s</td></tr>",
705 U2H(stats[ST_F_REQ_RATE].u.u32));
706
707 chunk_appendf(out,
708 "</table></div></u></td>"
709 /* sessions rate : max */
710 "<td><u>%s<div class=tips><table class=det>"
711 "<tr><th>Max connection rate:</th><td>%s/s</td></tr>"
712 "<tr><th>Max session rate:</th><td>%s/s</td></tr>"
713 "",
714 U2H(stats[ST_F_RATE_MAX].u.u32),
715 U2H(stats[ST_F_CONN_RATE_MAX].u.u32),
716 U2H(stats[ST_F_RATE_MAX].u.u32));
717
718 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
719 chunk_appendf(out,
720 "<tr><th>Max request rate:</th><td>%s/s</td></tr>",
721 U2H(stats[ST_F_REQ_RATE_MAX].u.u32));
722
723 chunk_appendf(out,
724 "</table></div></u></td>"
725 /* sessions rate : limit */
726 "<td>%s</td>",
727 LIM2A(stats[ST_F_RATE_LIM].u.u32, "-"));
728
729 chunk_appendf(out,
730 /* sessions: current, max, limit, total */
731 "<td>%s</td><td>%s</td><td>%s</td>"
732 "<td><u>%s<div class=tips><table class=det>"
733 "<tr><th>Cum. connections:</th><td>%s</td></tr>"
734 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
735 "",
736 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
737 U2H(stats[ST_F_STOT].u.u64),
738 U2H(stats[ST_F_CONN_TOT].u.u64),
739 U2H(stats[ST_F_STOT].u.u64));
740
741 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
742 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
743 chunk_appendf(out,
744 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
745 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
746 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
747 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
748 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
749 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
750 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
751 "<tr><th>- other responses:</th><td>%s</td></tr>"
752 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
Willy Tarreaua1214a52018-12-14 14:00:25 +0100753 "<tr><th>Cache lookups:</th><td>%s</td></tr>"
754 "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200755 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100756 "",
757 U2H(stats[ST_F_REQ_TOT].u.u64),
758 U2H(stats[ST_F_HRSP_1XX].u.u64),
759 U2H(stats[ST_F_HRSP_2XX].u.u64),
760 U2H(stats[ST_F_COMP_RSP].u.u64),
761 stats[ST_F_HRSP_2XX].u.u64 ?
762 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
763 U2H(stats[ST_F_HRSP_3XX].u.u64),
764 U2H(stats[ST_F_HRSP_4XX].u.u64),
765 U2H(stats[ST_F_HRSP_5XX].u.u64),
766 U2H(stats[ST_F_HRSP_OTHER].u.u64),
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200767 U2H(stats[ST_F_INTERCEPTED].u.u64),
Willy Tarreaua1214a52018-12-14 14:00:25 +0100768 U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
769 U2H(stats[ST_F_CACHE_HITS].u.u64),
770 stats[ST_F_CACHE_LOOKUPS].u.u64 ?
771 (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200772 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +0100773 }
774
775 chunk_appendf(out,
776 "</table></div></u></td>"
777 /* sessions: lbtot, lastsess */
778 "<td></td><td></td>"
779 /* bytes : in */
780 "<td>%s</td>"
781 "",
782 U2H(stats[ST_F_BIN].u.u64));
783
784 chunk_appendf(out,
785 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
786 "<td>%s%s<div class=tips><table class=det>"
787 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
788 "<tr><th>Compression in:</th><td>%s</td></tr>"
789 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
790 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
791 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
792 "</table></div>%s</td>",
793 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
794 U2H(stats[ST_F_BOUT].u.u64),
795 U2H(stats[ST_F_BOUT].u.u64),
796 U2H(stats[ST_F_COMP_IN].u.u64),
797 U2H(stats[ST_F_COMP_OUT].u.u64),
798 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
799 U2H(stats[ST_F_COMP_BYP].u.u64),
800 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
801 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,
802 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
803
804 chunk_appendf(out,
805 /* denied: req, resp */
806 "<td>%s</td><td>%s</td>"
807 /* errors : request, connect, response */
808 "<td>%s</td><td></td><td></td>"
809 /* warnings: retries, redispatches */
810 "<td></td><td></td>"
811 /* server status : reflect frontend status */
812 "<td class=ac>%s</td>"
813 /* rest of server: nothing */
814 "<td class=ac colspan=8></td></tr>"
815 "",
816 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
817 U2H(stats[ST_F_EREQ].u.u64),
818 field_str(stats, ST_F_STATUS));
819 }
820 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) {
821 chunk_appendf(out, "<tr class=socket>");
822 if (flags & ST_SHOWADMIN) {
823 /* Column sub-heading for Enable or Disable server */
824 chunk_appendf(out, "<td></td>");
825 }
826
827 chunk_appendf(out,
828 /* frontend name, listener name */
829 "<td class=ac><a name=\"%s/+%s\"></a>%s"
830 "<a class=lfsb href=\"#%s/+%s\">%s</a>"
831 "",
832 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
833 (flags & ST_SHLGNDS)?"<u>":"",
834 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
835
836 if (flags & ST_SHLGNDS) {
837 chunk_appendf(out, "<div class=tips>");
838
839 if (isdigit(*field_str(stats, ST_F_ADDR)))
840 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
841 else if (*field_str(stats, ST_F_ADDR) == '[')
842 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
843 else if (*field_str(stats, ST_F_ADDR))
844 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
845
846 /* id */
847 chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32);
848 }
849
850 chunk_appendf(out,
851 /* queue */
852 "%s</td><td colspan=3></td>"
853 /* sessions rate: current, max, limit */
854 "<td colspan=3>&nbsp;</td>"
855 /* sessions: current, max, limit, total, lbtot, lastsess */
856 "<td>%s</td><td>%s</td><td>%s</td>"
857 "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
858 /* bytes: in, out */
859 "<td>%s</td><td>%s</td>"
860 "",
861 (flags & ST_SHLGNDS)?"</u>":"",
862 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
863 U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64));
864
865 chunk_appendf(out,
866 /* denied: req, resp */
867 "<td>%s</td><td>%s</td>"
868 /* errors: request, connect, response */
869 "<td>%s</td><td></td><td></td>"
870 /* warnings: retries, redispatches */
871 "<td></td><td></td>"
872 /* server status: reflect listener status */
873 "<td class=ac>%s</td>"
874 /* rest of server: nothing */
875 "<td class=ac colspan=8></td></tr>"
876 "",
877 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
878 U2H(stats[ST_F_EREQ].u.u64),
879 field_str(stats, ST_F_STATUS));
880 }
881 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) {
882 const char *style;
883
884 /* determine the style to use depending on the server's state,
885 * its health and weight. There isn't a 1-to-1 mapping between
886 * state and styles for the cases where the server is (still)
887 * up. The reason is that we don't want to report nolb and
888 * drain with the same color.
889 */
890
891 if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 ||
892 strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) {
893 style = "down";
894 }
895 else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) {
896 style = "going_up";
897 }
898 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) {
899 style = "going_down";
900 }
901 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) {
902 style = "nolb";
903 }
904 else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) {
905 style = "no_check";
906 }
907 else if (!stats[ST_F_CHKFAIL].type ||
908 stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) {
909 /* no check or max health = UP */
910 if (stats[ST_F_WEIGHT].u.u32)
911 style = "up";
912 else
913 style = "draining";
914 }
915 else {
916 style = "going_down";
917 }
918
919 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0)
920 chunk_appendf(out, "<tr class=\"maintain\">");
921 else
922 chunk_appendf(out,
923 "<tr class=\"%s_%s\">",
924 (stats[ST_F_BCK].u.u32) ? "backup" : "active", style);
925
926
927 if (flags & ST_SHOWADMIN)
928 chunk_appendf(out,
David Harrigand3db35a2016-12-30 12:12:49 +0000929 "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
930 field_str(stats, ST_F_PXNAME),
William Lallemand74c24fb2016-11-21 17:18:36 +0100931 field_str(stats, ST_F_SVNAME));
932
933 chunk_appendf(out,
934 "<td class=ac><a name=\"%s/%s\"></a>%s"
935 "<a class=lfsb href=\"#%s/%s\">%s</a>"
936 "",
937 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
938 (flags & ST_SHLGNDS) ? "<u>" : "",
939 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
940
941 if (flags & ST_SHLGNDS) {
942 chunk_appendf(out, "<div class=tips>");
943
944 if (isdigit(*field_str(stats, ST_F_ADDR)))
945 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
946 else if (*field_str(stats, ST_F_ADDR) == '[')
947 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
948 else if (*field_str(stats, ST_F_ADDR))
949 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
950
951 /* id */
952 chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32);
953
954 /* cookie */
955 if (stats[ST_F_COOKIE].type) {
956 chunk_appendf(out, ", cookie: '");
957 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
958 chunk_htmlencode(out, &src);
959 chunk_appendf(out, "'");
960 }
961
962 chunk_appendf(out, "</div>");
963 }
964
965 chunk_appendf(out,
966 /* queue : current, max, limit */
967 "%s</td><td>%s</td><td>%s</td><td>%s</td>"
968 /* sessions rate : current, max, limit */
969 "<td>%s</td><td>%s</td><td></td>"
970 "",
971 (flags & ST_SHLGNDS) ? "</u>" : "",
972 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"),
973 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
974
975 chunk_appendf(out,
976 /* sessions: current, max, limit, total */
977 "<td>%s</td><td>%s</td><td>%s</td>"
978 "<td><u>%s<div class=tips><table class=det>"
979 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
980 "",
981 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"),
982 U2H(stats[ST_F_STOT].u.u64),
983 U2H(stats[ST_F_STOT].u.u64));
984
985 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
986 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
987 unsigned long long tot;
988
989 tot = stats[ST_F_HRSP_OTHER].u.u64;
990 tot += stats[ST_F_HRSP_1XX].u.u64;
991 tot += stats[ST_F_HRSP_2XX].u.u64;
992 tot += stats[ST_F_HRSP_3XX].u.u64;
993 tot += stats[ST_F_HRSP_4XX].u.u64;
994 tot += stats[ST_F_HRSP_5XX].u.u64;
995
996 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +0100997 "<tr><th>New connections:</th><td>%s</td></tr>"
998 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100999 "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
1000 "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1001 "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1002 "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1003 "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1004 "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
1005 "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001006 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001007 "",
Willy Tarreauf1573842018-12-14 11:35:36 +01001008 U2H(stats[ST_F_CONNECT].u.u64),
1009 U2H(stats[ST_F_REUSE].u.u64),
1010 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
1011 (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 +01001012 U2H(tot),
1013 U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0,
1014 U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0,
1015 U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0,
1016 U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0,
1017 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 +02001018 U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0,
1019 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +01001020 }
1021
1022 chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>");
1023 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
1024 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
1025 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
1026 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
1027 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
1028
1029 chunk_appendf(out,
1030 "</table></div></u></td>"
1031 /* sessions: lbtot, last */
1032 "<td>%s</td><td>%s</td>",
1033 U2H(stats[ST_F_LBTOT].u.u64),
1034 human_time(stats[ST_F_LASTSESS].u.s32, 1));
1035
1036 chunk_appendf(out,
1037 /* bytes : in, out */
1038 "<td>%s</td><td>%s</td>"
1039 /* denied: req, resp */
1040 "<td></td><td>%s</td>"
1041 /* errors : request, connect */
1042 "<td></td><td>%s</td>"
1043 /* errors : response */
1044 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1045 /* warnings: retries, redispatches */
1046 "<td>%lld</td><td>%lld</td>"
1047 "",
1048 U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64),
1049 U2H(stats[ST_F_DRESP].u.u64),
1050 U2H(stats[ST_F_ECON].u.u64),
1051 U2H(stats[ST_F_ERESP].u.u64),
1052 (long long)stats[ST_F_CLI_ABRT].u.u64,
1053 (long long)stats[ST_F_SRV_ABRT].u.u64,
1054 (long long)stats[ST_F_WRETR].u.u64,
1055 (long long)stats[ST_F_WREDIS].u.u64);
1056
1057 /* status, last change */
1058 chunk_appendf(out, "<td class=ac>");
1059
1060 /* FIXME!!!!
1061 * LASTCHG should contain the last change for *this* server and must be computed
1062 * properly above, as was done below, ie: this server if maint, otherwise ref server
1063 * if tracking. Note that ref is either local or remote depending on tracking.
1064 */
1065
1066
1067 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) {
1068 chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1));
1069 }
1070 else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) {
1071 chunk_strcat(out, "<i>no check</i>");
1072 }
1073 else {
1074 chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS));
1075 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) {
1076 if (stats[ST_F_CHECK_HEALTH].u.u32)
1077 chunk_strcat(out, " &uarr;");
1078 }
1079 else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1)
1080 chunk_strcat(out, " &darr;");
1081 }
1082
1083 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 &&
1084 stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) {
1085 chunk_appendf(out,
1086 "</td><td class=ac><u> %s",
1087 field_str(stats, ST_F_AGENT_STATUS));
1088
1089 if (stats[ST_F_AGENT_CODE].type)
1090 chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32);
1091
1092 if (stats[ST_F_AGENT_DURATION].type)
1093 chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64);
1094
1095 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC));
1096
1097 if (*field_str(stats, ST_F_LAST_AGT)) {
1098 chunk_appendf(out, ": ");
1099 chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT));
1100 chunk_htmlencode(out, &src);
1101 }
1102 chunk_appendf(out, "</div></u>");
1103 }
1104 else if (stats[ST_F_CHECK_STATUS].type) {
1105 chunk_appendf(out,
1106 "</td><td class=ac><u> %s",
1107 field_str(stats, ST_F_CHECK_STATUS));
1108
1109 if (stats[ST_F_CHECK_CODE].type)
1110 chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32);
1111
1112 if (stats[ST_F_CHECK_DURATION].type)
1113 chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64);
1114
1115 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC));
1116
1117 if (*field_str(stats, ST_F_LAST_CHK)) {
1118 chunk_appendf(out, ": ");
1119 chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK));
1120 chunk_htmlencode(out, &src);
1121 }
1122 chunk_appendf(out, "</div></u>");
1123 }
1124 else
1125 chunk_appendf(out, "</td><td>");
1126
1127 chunk_appendf(out,
1128 /* weight */
1129 "</td><td class=ac>%d</td>"
1130 /* act, bck */
1131 "<td class=ac>%s</td><td class=ac>%s</td>"
1132 "",
1133 stats[ST_F_WEIGHT].u.u32,
1134 stats[ST_F_BCK].u.u32 ? "-" : "Y",
1135 stats[ST_F_BCK].u.u32 ? "Y" : "-");
1136
1137 /* check failures: unique, fatal, down time */
1138 if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) {
1139 chunk_appendf(out, "<td class=ac colspan=3>resolution</td>");
1140 }
1141 else if (stats[ST_F_CHKFAIL].type) {
1142 chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64);
1143
1144 if (stats[ST_F_HANAFAIL].type)
1145 chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64);
1146
1147 chunk_appendf(out,
1148 "<div class=tips>Failed Health Checks%s</div></u></td>"
1149 "<td>%lld</td><td>%s</td>"
1150 "",
1151 stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "",
1152 (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1));
1153 }
1154 else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) {
1155 /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */
1156 chunk_appendf(out,
1157 "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>",
1158 field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED));
1159 }
1160 else
1161 chunk_appendf(out, "<td colspan=3></td>");
1162
1163 /* throttle */
1164 if (stats[ST_F_THROTTLE].type)
1165 chunk_appendf(out, "<td class=ac>%d %%</td></tr>\n", stats[ST_F_THROTTLE].u.u32);
1166 else
1167 chunk_appendf(out, "<td class=ac>-</td></tr>\n");
1168 }
1169 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) {
1170 chunk_appendf(out, "<tr class=\"backend\">");
1171 if (flags & ST_SHOWADMIN) {
1172 /* Column sub-heading for Enable or Disable server */
1173 chunk_appendf(out, "<td></td>");
1174 }
1175 chunk_appendf(out,
1176 "<td class=ac>"
1177 /* name */
1178 "%s<a name=\"%s/Backend\"></a>"
1179 "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
1180 "",
1181 (flags & ST_SHLGNDS)?"<u>":"",
1182 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
1183
1184 if (flags & ST_SHLGNDS) {
1185 /* balancing */
1186 chunk_appendf(out, "<div class=tips>balancing: %s",
1187 field_str(stats, ST_F_ALGO));
1188
1189 /* cookie */
1190 if (stats[ST_F_COOKIE].type) {
1191 chunk_appendf(out, ", cookie: '");
1192 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
1193 chunk_htmlencode(out, &src);
1194 chunk_appendf(out, "'");
1195 }
1196 chunk_appendf(out, "</div>");
1197 }
1198
1199 chunk_appendf(out,
1200 "%s</td>"
1201 /* queue : current, max */
1202 "<td>%s</td><td>%s</td><td></td>"
1203 /* sessions rate : current, max, limit */
1204 "<td>%s</td><td>%s</td><td></td>"
1205 "",
1206 (flags & ST_SHLGNDS)?"</u>":"",
1207 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32),
1208 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
1209
1210 chunk_appendf(out,
1211 /* sessions: current, max, limit, total */
1212 "<td>%s</td><td>%s</td><td>%s</td>"
1213 "<td><u>%s<div class=tips><table class=det>"
1214 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
1215 "",
Willy Tarreau8e0f1752016-12-12 15:07:29 +01001216 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 +01001217 U2H(stats[ST_F_STOT].u.u64),
1218 U2H(stats[ST_F_STOT].u.u64));
1219
1220 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1221 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
1222 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +01001223 "<tr><th>New connections:</th><td>%s</td></tr>"
1224 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001225 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
1226 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
1227 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
1228 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
1229 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
1230 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
1231 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
1232 "<tr><th>- other responses:</th><td>%s</td></tr>"
Willy Tarreaua1214a52018-12-14 14:00:25 +01001233 "<tr><th>Cache lookups:</th><td>%s</td></tr>"
1234 "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001235 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001236 "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
1237 "",
Willy Tarreauf1573842018-12-14 11:35:36 +01001238 U2H(stats[ST_F_CONNECT].u.u64),
1239 U2H(stats[ST_F_REUSE].u.u64),
1240 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
1241 (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 +01001242 U2H(stats[ST_F_REQ_TOT].u.u64),
1243 U2H(stats[ST_F_HRSP_1XX].u.u64),
1244 U2H(stats[ST_F_HRSP_2XX].u.u64),
1245 U2H(stats[ST_F_COMP_RSP].u.u64),
1246 stats[ST_F_HRSP_2XX].u.u64 ?
1247 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
1248 U2H(stats[ST_F_HRSP_3XX].u.u64),
1249 U2H(stats[ST_F_HRSP_4XX].u.u64),
1250 U2H(stats[ST_F_HRSP_5XX].u.u64),
Willy Tarreaufeead3a2018-12-14 13:48:44 +01001251 U2H(stats[ST_F_HRSP_OTHER].u.u64),
Willy Tarreaua1214a52018-12-14 14:00:25 +01001252 U2H(stats[ST_F_CACHE_LOOKUPS].u.u64),
1253 U2H(stats[ST_F_CACHE_HITS].u.u64),
1254 stats[ST_F_CACHE_LOOKUPS].u.u64 ?
1255 (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0,
Willy Tarreaufeead3a2018-12-14 13:48:44 +01001256 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +01001257 }
1258
1259 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
1260 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
1261 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
1262 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
1263 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
1264
1265 chunk_appendf(out,
1266 "</table></div></u></td>"
1267 /* sessions: lbtot, last */
1268 "<td>%s</td><td>%s</td>"
1269 /* bytes: in */
1270 "<td>%s</td>"
1271 "",
1272 U2H(stats[ST_F_LBTOT].u.u64),
1273 human_time(stats[ST_F_LASTSESS].u.s32, 1),
1274 U2H(stats[ST_F_BIN].u.u64));
1275
1276 chunk_appendf(out,
1277 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
1278 "<td>%s%s<div class=tips><table class=det>"
1279 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
1280 "<tr><th>Compression in:</th><td>%s</td></tr>"
1281 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
1282 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
1283 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
1284 "</table></div>%s</td>",
1285 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
1286 U2H(stats[ST_F_BOUT].u.u64),
1287 U2H(stats[ST_F_BOUT].u.u64),
1288 U2H(stats[ST_F_COMP_IN].u.u64),
1289 U2H(stats[ST_F_COMP_OUT].u.u64),
1290 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
1291 U2H(stats[ST_F_COMP_BYP].u.u64),
1292 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
1293 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,
1294 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
1295
1296 chunk_appendf(out,
1297 /* denied: req, resp */
1298 "<td>%s</td><td>%s</td>"
1299 /* errors : request, connect */
1300 "<td></td><td>%s</td>"
1301 /* errors : response */
1302 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1303 /* warnings: retries, redispatches */
1304 "<td>%lld</td><td>%lld</td>"
1305 /* backend status: reflect backend status (up/down): we display UP
1306 * if the backend has known working servers or if it has no server at
1307 * all (eg: for stats). Then we display the total weight, number of
1308 * active and backups. */
1309 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
1310 "<td class=ac>%d</td><td class=ac>%d</td>"
1311 "",
1312 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
1313 U2H(stats[ST_F_ECON].u.u64),
1314 U2H(stats[ST_F_ERESP].u.u64),
1315 (long long)stats[ST_F_CLI_ABRT].u.u64,
1316 (long long)stats[ST_F_SRV_ABRT].u.u64,
1317 (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64,
1318 human_time(stats[ST_F_LASTCHG].u.u32, 1),
1319 strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>",
1320 stats[ST_F_WEIGHT].u.u32,
1321 stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32);
1322
1323 chunk_appendf(out,
1324 /* rest of backend: nothing, down transitions, total downtime, throttle */
1325 "<td class=ac>&nbsp;</td><td>%d</td>"
1326 "<td>%s</td>"
1327 "<td></td>"
1328 "</tr>",
1329 stats[ST_F_CHKDOWN].u.u32,
1330 stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : "&nbsp;");
1331 }
1332 return 1;
1333}
1334
1335int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx)
1336{
Simon Horman05ee2132017-01-04 09:37:25 +01001337 int ret;
1338
William Lallemand74c24fb2016-11-21 17:18:36 +01001339 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN))
1340 flags |= ST_SHOWADMIN;
1341
1342 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Simon Horman05ee2132017-01-04 09:37:25 +01001343 ret = stats_dump_fields_html(&trash, stats, flags);
William Lallemand74c24fb2016-11-21 17:18:36 +01001344 else if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
Simon Horman05ee2132017-01-04 09:37:25 +01001345 ret = stats_dump_fields_typed(&trash, stats);
1346 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
1347 ret = stats_dump_fields_json(&trash, stats,
1348 !(appctx->ctx.stats.flags &
1349 STAT_STARTED));
William Lallemand74c24fb2016-11-21 17:18:36 +01001350 else
Simon Horman05ee2132017-01-04 09:37:25 +01001351 ret = stats_dump_fields_csv(&trash, stats);
1352
1353 if (ret)
1354 appctx->ctx.stats.flags |= STAT_STARTED;
1355
1356 return ret;
William Lallemand74c24fb2016-11-21 17:18:36 +01001357}
1358
1359/* Fill <stats> with the frontend statistics. <stats> is
1360 * preallocated array of length <len>. The length of the array
1361 * must be at least ST_F_TOTAL_FIELDS. If this length is less then
1362 * this value, the function returns 0, otherwise, it returns 1.
1363 */
1364int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len)
1365{
1366 if (len < ST_F_TOTAL_FIELDS)
1367 return 0;
1368
1369 memset(stats, 0, sizeof(*stats) * len);
1370
1371 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1372 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND");
1373 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1374 stats[ST_F_SCUR] = mkf_u32(0, px->feconn);
1375 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1376 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1377 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1378 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1379 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1380 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1381 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1382 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1383 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1384 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1385 stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP");
1386 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1387 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1388 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1389 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE);
1390 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec));
1391 stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1392 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001393 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001394
1395 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1396 if (px->mode == PR_MODE_HTTP) {
1397 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1398 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1399 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1400 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1401 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1402 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1403 stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
Willy Tarreaua1214a52018-12-14 14:00:25 +01001404 stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1405 stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
William Lallemand74c24fb2016-11-21 17:18:36 +01001406 }
1407
1408 /* requests : req_rate, req_rate_max, req_tot, */
1409 stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec));
1410 stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1411 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1412
1413 /* compression: in, out, bypassed, responses */
1414 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1415 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1416 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1417 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1418
1419 /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */
1420 stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec));
1421 stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1422 stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1423
1424 return 1;
1425}
1426
1427/* Dumps a frontend's line to the trash for the current proxy <px> and uses
1428 * the state from stream interface <si>. The caller is responsible for clearing
1429 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
1430 */
1431static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
1432{
1433 struct appctx *appctx = __objt_appctx(si->end);
1434
1435 if (!(px->cap & PR_CAP_FE))
1436 return 0;
1437
1438 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE)))
1439 return 0;
1440
1441 if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS))
1442 return 0;
1443
1444 return stats_dump_one_line(stats, 0, px, appctx);
1445}
1446
1447/* Fill <stats> with the listener statistics. <stats> is
1448 * preallocated array of length <len>. The length of the array
1449 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1450 * then this value, the function returns 0, otherwise, it
1451 * returns 1. <flags> can take the value ST_SHLGNDS.
1452 */
1453int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
1454 struct field *stats, int len)
1455{
Willy Tarreau83061a82018-07-13 11:56:34 +02001456 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001457
1458 if (len < ST_F_TOTAL_FIELDS)
1459 return 0;
1460
1461 if (!l->counters)
1462 return 0;
1463
1464 chunk_reset(out);
1465 memset(stats, 0, sizeof(*stats) * len);
1466
1467 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1468 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name);
1469 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1470 stats[ST_F_SCUR] = mkf_u32(0, l->nbconn);
1471 stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max);
1472 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn);
1473 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn);
1474 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in);
1475 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out);
1476 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req);
1477 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp);
1478 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req);
1479 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn);
1480 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess);
Willy Tarreaua8cf66b2019-02-27 16:49:00 +01001481 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 +01001482 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1483 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1484 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid);
1485 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001486 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, l->counters->failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001487
1488 if (flags & ST_SHLGNDS) {
1489 char str[INET6_ADDRSTRLEN];
1490 int port;
1491
1492 port = get_host_port(&l->addr);
1493 switch (addr_to_str(&l->addr, str, sizeof(str))) {
1494 case AF_INET:
1495 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1496 chunk_appendf(out, "%s:%d", str, port);
1497 break;
1498 case AF_INET6:
1499 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1500 chunk_appendf(out, "[%s]:%d", str, port);
1501 break;
1502 case AF_UNIX:
1503 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1504 break;
1505 case -1:
1506 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1507 chunk_strcat(out, strerror(errno));
1508 break;
1509 default: /* address family not supported */
1510 break;
1511 }
1512 }
1513
1514 return 1;
1515}
1516
1517/* Dumps a line for listener <l> and proxy <px> to the trash and uses the state
1518 * from stream interface <si>, and stats flags <flags>. The caller is responsible
1519 * for clearing the trash if needed. Returns non-zero if it emits anything, zero
1520 * otherwise.
1521 */
1522static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags)
1523{
1524 struct appctx *appctx = __objt_appctx(si->end);
1525
1526 if (!stats_fill_li_stats(px, l, flags, stats, ST_F_TOTAL_FIELDS))
1527 return 0;
1528
1529 return stats_dump_one_line(stats, flags, px, appctx);
1530}
1531
1532enum srv_stats_state {
1533 SRV_STATS_STATE_DOWN = 0,
1534 SRV_STATS_STATE_DOWN_AGENT,
1535 SRV_STATS_STATE_GOING_UP,
1536 SRV_STATS_STATE_UP_GOING_DOWN,
1537 SRV_STATS_STATE_UP,
1538 SRV_STATS_STATE_NOLB_GOING_DOWN,
1539 SRV_STATS_STATE_NOLB,
1540 SRV_STATS_STATE_DRAIN_GOING_DOWN,
1541 SRV_STATS_STATE_DRAIN,
1542 SRV_STATS_STATE_DRAIN_AGENT,
1543 SRV_STATS_STATE_NO_CHECK,
1544
1545 SRV_STATS_STATE_COUNT, /* Must be last */
1546};
1547
1548static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
1549 [SRV_STATS_STATE_DOWN] = "DOWN",
1550 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)",
1551 [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d",
1552 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d",
1553 [SRV_STATS_STATE_UP] = "UP",
1554 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d",
1555 [SRV_STATS_STATE_NOLB] = "NOLB",
1556 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d",
1557 [SRV_STATS_STATE_DRAIN] = "DRAIN",
1558 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
1559 [SRV_STATS_STATE_NO_CHECK] = "no check"
1560};
1561
1562/* Fill <stats> with the server statistics. <stats> is
1563 * preallocated array of length <len>. The length of the array
1564 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1565 * then this value, the function returns 0, otherwise, it
1566 * returns 1. <flags> can take the value ST_SHLGNDS.
1567 */
1568int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
1569 struct field *stats, int len)
1570{
1571 struct server *via, *ref;
1572 char str[INET6_ADDRSTRLEN];
Willy Tarreau83061a82018-07-13 11:56:34 +02001573 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001574 enum srv_stats_state state;
1575 char *fld_status;
1576
1577 if (len < ST_F_TOTAL_FIELDS)
1578 return 0;
1579
1580 memset(stats, 0, sizeof(*stats) * len);
1581
1582 /* we have "via" which is the tracked server as described in the configuration,
1583 * and "ref" which is the checked server and the end of the chain.
1584 */
1585 via = sv->track ? sv->track : sv;
1586 ref = via;
1587 while (ref->track)
1588 ref = ref->track;
1589
Emeric Brun52a91d32017-08-31 14:41:55 +02001590 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001591 if ((ref->check.state & CHK_ST_ENABLED) &&
1592 (ref->check.health < ref->check.rise + ref->check.fall - 1)) {
1593 state = SRV_STATS_STATE_UP_GOING_DOWN;
1594 } else {
1595 state = SRV_STATS_STATE_UP;
1596 }
1597
Emeric Brun52a91d32017-08-31 14:41:55 +02001598 if (sv->cur_admin & SRV_ADMF_DRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001599 if (ref->agent.state & CHK_ST_ENABLED)
1600 state = SRV_STATS_STATE_DRAIN_AGENT;
1601 else if (state == SRV_STATS_STATE_UP_GOING_DOWN)
1602 state = SRV_STATS_STATE_DRAIN_GOING_DOWN;
1603 else
1604 state = SRV_STATS_STATE_DRAIN;
1605 }
1606
1607 if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) {
1608 state = SRV_STATS_STATE_NO_CHECK;
1609 }
1610 }
Emeric Brun52a91d32017-08-31 14:41:55 +02001611 else if (sv->cur_state == SRV_ST_STOPPING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001612 if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) ||
1613 (ref->check.health == ref->check.rise + ref->check.fall - 1)) {
1614 state = SRV_STATS_STATE_NOLB;
1615 } else {
1616 state = SRV_STATS_STATE_NOLB_GOING_DOWN;
1617 }
1618 }
1619 else { /* stopped */
1620 if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) {
1621 state = SRV_STATS_STATE_DOWN_AGENT;
1622 } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) {
1623 state = SRV_STATS_STATE_DOWN; /* DOWN */
1624 } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) {
1625 state = SRV_STATS_STATE_GOING_UP;
1626 } else {
1627 state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */
1628 }
1629 }
1630
1631 chunk_reset(out);
1632
1633 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1634 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id);
1635 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1636 stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend);
1637 stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1638 stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess);
1639 stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1640
1641 if (sv->maxconn)
1642 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1643
1644 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1645 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1646 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1647 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu);
1648 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1649 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1650 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries);
1651 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001652 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001653 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, sv->counters.connect);
1654 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, sv->counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001655
1656 /* status */
1657 fld_status = chunk_newstr(out);
Emeric Brun52a91d32017-08-31 14:41:55 +02001658 if (sv->cur_admin & SRV_ADMF_RMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001659 chunk_appendf(out, "MAINT (resolution)");
Emeric Brun52a91d32017-08-31 14:41:55 +02001660 else if (sv->cur_admin & SRV_ADMF_IMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001661 chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id);
Emeric Brun52a91d32017-08-31 14:41:55 +02001662 else if (sv->cur_admin & SRV_ADMF_MAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001663 chunk_appendf(out, "MAINT");
1664 else
1665 chunk_appendf(out,
1666 srv_hlt_st[state],
Emeric Brun52a91d32017-08-31 14:41:55 +02001667 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
1668 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
William Lallemand74c24fb2016-11-21 17:18:36 +01001669
1670 stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status);
1671 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
Emeric Brun52a91d32017-08-31 14:41:55 +02001672 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 +01001673 stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1);
1674 stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0);
1675
1676 /* check failures: unique, fatal; last change, total downtime */
1677 if (sv->check.state & CHK_ST_ENABLED) {
1678 stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1679 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1680 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv));
1681 }
1682
1683 if (sv->maxqueue)
1684 stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1685
1686 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1687 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1688 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid);
1689
Emeric Brun52a91d32017-08-31 14:41:55 +02001690 if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv))
William Lallemand74c24fb2016-11-21 17:18:36 +01001691 stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv));
1692
1693 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1694
1695 if (sv->track) {
1696 char *fld_track = chunk_newstr(out);
1697
1698 chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id);
1699 stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track);
1700 }
1701
1702 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV);
1703 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec));
1704 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max);
1705
1706 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1707 const char *fld_chksts;
1708
1709 fld_chksts = chunk_newstr(out);
1710 chunk_strcat(out, "* "); // for check in progress
1711 chunk_strcat(out, get_check_status_info(sv->check.status));
1712 if (!(sv->check.state & CHK_ST_INPROGRESS))
1713 fld_chksts += 2; // skip "* "
1714 stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1715
1716 if (sv->check.status >= HCHK_STATUS_L57DATA)
1717 stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code);
1718
1719 if (sv->check.status >= HCHK_STATUS_CHECKED)
1720 stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration);
1721
1722 stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status));
1723 stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc);
1724 stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise);
1725 stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall);
1726 stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health);
1727 }
1728
1729 if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1730 const char *fld_chksts;
1731
1732 fld_chksts = chunk_newstr(out);
1733 chunk_strcat(out, "* "); // for check in progress
1734 chunk_strcat(out, get_check_status_info(sv->agent.status));
1735 if (!(sv->agent.state & CHK_ST_INPROGRESS))
1736 fld_chksts += 2; // skip "* "
1737 stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1738
1739 if (sv->agent.status >= HCHK_STATUS_L57DATA)
1740 stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code);
1741
1742 if (sv->agent.status >= HCHK_STATUS_CHECKED)
1743 stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration);
1744
1745 stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status));
1746 stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc);
1747 stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise);
1748 stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall);
1749 stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health);
1750 }
1751
1752 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1753 if (px->mode == PR_MODE_HTTP) {
1754 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1755 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1756 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1757 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1758 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
1759 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
1760 }
1761
1762 if (ref->observe)
1763 stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana);
1764
1765 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1766 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1767 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv));
1768
1769 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES));
1770 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES));
1771 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
1772 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
1773
1774 if (flags & ST_SHLGNDS) {
1775 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
1776 case AF_INET:
1777 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001778 chunk_appendf(out, "%s:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001779 break;
1780 case AF_INET6:
1781 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001782 chunk_appendf(out, "[%s]:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001783 break;
1784 case AF_UNIX:
1785 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1786 break;
1787 case -1:
1788 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1789 chunk_strcat(out, strerror(errno));
1790 break;
1791 default: /* address family not supported */
1792 break;
1793 }
1794
1795 if (sv->cookie)
1796 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie);
1797 }
1798
1799 return 1;
1800}
1801
1802/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
1803 * from stream interface <si>, stats flags <flags>, and server state <state>.
1804 * The caller is responsible for clearing the trash if needed. Returns non-zero
1805 * if it emits anything, zero otherwise.
1806 */
1807static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv)
1808{
1809 struct appctx *appctx = __objt_appctx(si->end);
1810
1811 if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS))
1812 return 0;
1813
1814 return stats_dump_one_line(stats, flags, px, appctx);
1815}
1816
1817/* Fill <stats> with the backend statistics. <stats> is
1818 * preallocated array of length <len>. The length of the array
1819 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1820 * then this value, the function returns 0, otherwise, it
1821 * returns 1. <flags> can take the value ST_SHLGNDS.
1822 */
1823int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len)
1824{
1825 if (len < ST_F_TOTAL_FIELDS)
1826 return 0;
1827
1828 memset(stats, 0, sizeof(*stats) * len);
1829
1830 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1831 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND");
1832 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1833 stats[ST_F_QCUR] = mkf_u32(0, px->nbpend);
1834 stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
Thierry FOURNIER0ff98a42016-12-19 16:50:42 +01001835 stats[ST_F_SCUR] = mkf_u32(0, px->beconn);
William Lallemand74c24fb2016-11-21 17:18:36 +01001836 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max);
1837 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1838 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1839 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1840 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1841 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1842 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1843 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1844 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1845 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries);
1846 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001847 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001848 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, px->be_counters.connect);
1849 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, px->be_counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001850 stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN");
1851 stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv);
1852 stats[ST_F_ACT] = mkf_u32(0, px->srv_act);
1853 stats[ST_F_BCK] = mkf_u32(0, px->srv_bck);
1854 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans);
1855 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1856 if (px->srv)
1857 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px));
1858
1859 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1860 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1861 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1862 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1863 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE);
1864 stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec));
1865 stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max);
1866
1867 if (flags & ST_SHLGNDS) {
1868 if (px->cookie_name)
1869 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name);
1870 stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
1871 }
1872
1873 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1874 if (px->mode == PR_MODE_HTTP) {
1875 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1876 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1877 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1878 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1879 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1880 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1881 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
Willy Tarreaua1214a52018-12-14 14:00:25 +01001882 stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1883 stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
William Lallemand74c24fb2016-11-21 17:18:36 +01001884 }
1885
1886 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1887 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1888
1889 /* compression: in, out, bypassed, responses */
1890 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1891 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1892 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1893 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1894 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px));
1895
1896 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES));
1897 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES));
1898 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES));
1899 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
1900
1901 return 1;
1902}
1903
1904/* Dumps a line for backend <px> to the trash for and uses the state from stream
1905 * interface <si> and stats flags <flags>. The caller is responsible for clearing
1906 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
1907 */
1908static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags)
1909{
1910 struct appctx *appctx = __objt_appctx(si->end);
1911
1912 if (!(px->cap & PR_CAP_BE))
1913 return 0;
1914
1915 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
1916 return 0;
1917
1918 if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS))
1919 return 0;
1920
1921 return stats_dump_one_line(stats, flags, px, appctx);
1922}
1923
1924/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from
1925 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
1926 * for clearing the trash if needed.
1927 */
1928static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
1929{
1930 struct appctx *appctx = __objt_appctx(si->end);
1931 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
1932
1933 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
1934 /* A form to enable/disable this proxy servers */
1935
1936 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
1937 scope_txt[0] = 0;
1938 if (appctx->ctx.stats.scope_len) {
Christopher Fauleted7a0662019-01-14 11:07:34 +01001939 const char *scope_ptr = stats_scope_ptr(appctx, si);
1940
William Lallemand74c24fb2016-11-21 17:18:36 +01001941 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01001942 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01001943 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
1944 }
1945
1946 chunk_appendf(&trash,
1947 "<form method=\"post\">");
1948 }
1949
1950 /* print a new table */
1951 chunk_appendf(&trash,
1952 "<table class=\"tbl\" width=\"100%%\">\n"
1953 "<tr class=\"titre\">"
1954 "<th class=\"pxname\" width=\"10%%\">");
1955
1956 chunk_appendf(&trash,
1957 "<a name=\"%s\"></a>%s"
1958 "<a class=px href=\"#%s\">%s</a>",
1959 px->id,
1960 (uri->flags & ST_SHLGNDS) ? "<u>":"",
1961 px->id, px->id);
1962
1963 if (uri->flags & ST_SHLGNDS) {
1964 /* cap, mode, id */
1965 chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
1966 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
1967 px->uuid);
1968 chunk_appendf(&trash, "</div>");
1969 }
1970
1971 chunk_appendf(&trash,
1972 "%s</th>"
1973 "<th class=\"%s\" width=\"90%%\">%s</th>"
1974 "</tr>\n"
1975 "</table>\n"
1976 "<table class=\"tbl\" width=\"100%%\">\n"
1977 "<tr class=\"titre\">",
1978 (uri->flags & ST_SHLGNDS) ? "</u>":"",
1979 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
1980
1981 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
1982 /* Column heading for Enable or Disable server */
David Harrigand3db35a2016-12-30 12:12:49 +00001983 chunk_appendf(&trash,
1984 "<th rowspan=2 width=1><input type=\"checkbox\" \
1985 onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) \
1986 document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>",
1987 px->id,
1988 px->id);
William Lallemand74c24fb2016-11-21 17:18:36 +01001989 }
1990
1991 chunk_appendf(&trash,
1992 "<th rowspan=2></th>"
1993 "<th colspan=3>Queue</th>"
1994 "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
1995 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
1996 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
1997 "<th colspan=9>Server</th>"
1998 "</tr>\n"
1999 "<tr class=\"titre\">"
2000 "<th>Cur</th><th>Max</th><th>Limit</th>"
2001 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
2002 "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>"
2003 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
2004 "<th>Resp</th><th>Retr</th><th>Redis</th>"
2005 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
2006 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
2007 "<th>Thrtle</th>\n"
2008 "</tr>");
2009}
2010
2011/* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from
2012 * stream interface <si>. The caller is responsible for clearing the trash if needed.
2013 */
2014static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px)
2015{
2016 struct appctx *appctx = __objt_appctx(si->end);
2017 chunk_appendf(&trash, "</table>");
2018
2019 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
2020 /* close the form used to enable/disable this proxy servers */
2021 chunk_appendf(&trash,
2022 "Choose the action to perform on the checked servers : "
2023 "<select name=action>"
2024 "<option value=\"\"></option>"
2025 "<option value=\"ready\">Set state to READY</option>"
2026 "<option value=\"drain\">Set state to DRAIN</option>"
2027 "<option value=\"maint\">Set state to MAINT</option>"
2028 "<option value=\"dhlth\">Health: disable checks</option>"
2029 "<option value=\"ehlth\">Health: enable checks</option>"
2030 "<option value=\"hrunn\">Health: force UP</option>"
2031 "<option value=\"hnolb\">Health: force NOLB</option>"
2032 "<option value=\"hdown\">Health: force DOWN</option>"
2033 "<option value=\"dagent\">Agent: disable checks</option>"
2034 "<option value=\"eagent\">Agent: enable checks</option>"
2035 "<option value=\"arunn\">Agent: force UP</option>"
2036 "<option value=\"adown\">Agent: force DOWN</option>"
2037 "<option value=\"shutdown\">Kill Sessions</option>"
2038 "</select>"
2039 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
2040 "&nbsp;<input type=\"submit\" value=\"Apply\">"
2041 "</form>",
2042 px->uuid);
2043 }
2044
2045 chunk_appendf(&trash, "<p>\n");
2046}
2047
2048/*
2049 * Dumps statistics for a proxy. The output is sent to the stream interface's
2050 * input buffer. Returns 0 if it had to stop dumping data because of lack of
2051 * buffer space, or non-zero if everything completed. This function is used
2052 * both by the CLI and the HTTP entry points, and is able to dump the output
2053 * in HTML or CSV formats. If the later, <uri> must be NULL.
2054 */
Christopher Fauletef779222018-10-31 08:47:01 +01002055int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
2056 struct proxy *px, struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002057{
2058 struct appctx *appctx = __objt_appctx(si->end);
2059 struct stream *s = si_strm(si);
2060 struct channel *rep = si_ic(si);
2061 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
2062 struct listener *l;
2063 unsigned int flags;
2064
2065 if (uri)
2066 flags = uri->flags;
William Lallemand07a62f72017-05-24 00:57:40 +02002067 else if ((strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER)
William Lallemand74c24fb2016-11-21 17:18:36 +01002068 flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC;
2069 else
2070 flags = ST_SHNODE | ST_SHDESC;
2071
2072 chunk_reset(&trash);
2073
2074 switch (appctx->ctx.stats.px_st) {
2075 case STAT_PX_ST_INIT:
2076 /* we are on a new proxy */
2077 if (uri && uri->scope) {
2078 /* we have a limited scope, we have to check the proxy name */
2079 struct stat_scope *scope;
2080 int len;
2081
2082 len = strlen(px->id);
2083 scope = uri->scope;
2084
2085 while (scope) {
2086 /* match exact proxy name */
2087 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2088 break;
2089
2090 /* match '.' which means 'self' proxy */
2091 if (!strcmp(scope->px_id, ".") && px == s->be)
2092 break;
2093 scope = scope->next;
2094 }
2095
2096 /* proxy name not found : don't dump anything */
2097 if (scope == NULL)
2098 return 1;
2099 }
2100
2101 /* if the user has requested a limited output and the proxy
2102 * name does not match, skip it.
2103 */
Christopher Fauleted7a0662019-01-14 11:07:34 +01002104 if (appctx->ctx.stats.scope_len) {
2105 const char *scope_ptr = stats_scope_ptr(appctx, si);
2106
2107 if (strnistr(px->id, strlen(px->id), scope_ptr, appctx->ctx.stats.scope_len) == NULL)
2108 return 1;
2109 }
William Lallemand74c24fb2016-11-21 17:18:36 +01002110
2111 if ((appctx->ctx.stats.flags & STAT_BOUND) &&
2112 (appctx->ctx.stats.iid != -1) &&
2113 (px->uuid != appctx->ctx.stats.iid))
2114 return 1;
2115
2116 appctx->ctx.stats.px_st = STAT_PX_ST_TH;
2117 /* fall through */
2118
2119 case STAT_PX_ST_TH:
2120 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2121 stats_dump_html_px_hdr(si, px, uri);
Christopher Fauletef779222018-10-31 08:47:01 +01002122 if (!stats_putchk(rep, htx, &trash))
2123 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002124 }
2125
2126 appctx->ctx.stats.px_st = STAT_PX_ST_FE;
2127 /* fall through */
2128
2129 case STAT_PX_ST_FE:
2130 /* print the frontend */
2131 if (stats_dump_fe_stats(si, px)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002132 if (!stats_putchk(rep, htx, &trash))
2133 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002134 }
2135
2136 appctx->ctx.stats.l = px->conf.listeners.n;
2137 appctx->ctx.stats.px_st = STAT_PX_ST_LI;
2138 /* fall through */
2139
2140 case STAT_PX_ST_LI:
2141 /* stats.l has been initialized above */
2142 for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) {
Christopher Fauletef779222018-10-31 08:47:01 +01002143 if (htx) {
2144 if (htx_almost_full(htx))
2145 goto full;
2146 }
2147 else {
2148 if (buffer_almost_full(&rep->buf))
2149 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002150 }
2151
2152 l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe);
2153 if (!l->counters)
2154 continue;
2155
2156 if (appctx->ctx.stats.flags & STAT_BOUND) {
2157 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO)))
2158 break;
2159
2160 if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid)
2161 continue;
2162 }
2163
2164 /* print the frontend */
2165 if (stats_dump_li_stats(si, px, l, flags)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002166 if (!stats_putchk(rep, htx, &trash))
2167 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002168 }
2169 }
2170
2171 appctx->ctx.stats.sv = px->srv; /* may be NULL */
2172 appctx->ctx.stats.px_st = STAT_PX_ST_SV;
2173 /* fall through */
2174
2175 case STAT_PX_ST_SV:
2176 /* stats.sv has been initialized above */
2177 for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) {
Christopher Fauletef779222018-10-31 08:47:01 +01002178 if (htx) {
2179 if (htx_almost_full(htx))
2180 goto full;
2181 }
2182 else {
2183 if (buffer_almost_full(&rep->buf))
2184 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002185 }
2186
2187 sv = appctx->ctx.stats.sv;
2188
2189 if (appctx->ctx.stats.flags & STAT_BOUND) {
2190 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV)))
2191 break;
2192
2193 if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid)
2194 continue;
2195 }
2196
2197 svs = sv;
2198 while (svs->track)
2199 svs = svs->track;
2200
2201 /* do not report servers which are DOWN and not changing state */
2202 if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) &&
Emeric Brun52a91d32017-08-31 14:41:55 +02002203 ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */
2204 (sv->cur_state == SRV_ST_STOPPED && /* server is down */
William Lallemand74c24fb2016-11-21 17:18:36 +01002205 (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) ||
2206 ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) ||
2207 ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) {
2208 continue;
2209 }
2210
2211 if (stats_dump_sv_stats(si, px, flags, sv)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002212 if (!stats_putchk(rep, htx, &trash))
2213 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002214 }
2215 } /* for sv */
2216
2217 appctx->ctx.stats.px_st = STAT_PX_ST_BE;
2218 /* fall through */
2219
2220 case STAT_PX_ST_BE:
2221 /* print the backend */
2222 if (stats_dump_be_stats(si, px, flags)) {
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
2227 appctx->ctx.stats.px_st = STAT_PX_ST_END;
2228 /* fall through */
2229
2230 case STAT_PX_ST_END:
2231 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2232 stats_dump_html_px_end(si, px);
Christopher Fauletef779222018-10-31 08:47:01 +01002233 if (!stats_putchk(rep, htx, &trash))
2234 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002235 }
2236
2237 appctx->ctx.stats.px_st = STAT_PX_ST_FIN;
2238 /* fall through */
2239
2240 case STAT_PX_ST_FIN:
2241 return 1;
2242
2243 default:
2244 /* unknown state, we should put an abort() here ! */
2245 return 1;
2246 }
Christopher Fauletef779222018-10-31 08:47:01 +01002247
2248 full:
2249 si_rx_room_blk(si);
2250 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01002251}
2252
2253/* Dumps the HTTP stats head block to the trash for and uses the per-uri
2254 * parameters <uri>. The caller is responsible for clearing the trash if needed.
2255 */
2256static void stats_dump_html_head(struct uri_auth *uri)
2257{
2258 /* WARNING! This must fit in the first buffer !!! */
2259 chunk_appendf(&trash,
2260 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
2261 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
2262 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
2263 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
2264 "<style type=\"text/css\"><!--\n"
2265 "body {"
2266 " font-family: arial, helvetica, sans-serif;"
2267 " font-size: 12px;"
2268 " font-weight: normal;"
2269 " color: black;"
2270 " background: white;"
2271 "}\n"
2272 "th,td {"
2273 " font-size: 10px;"
2274 "}\n"
2275 "h1 {"
2276 " font-size: x-large;"
2277 " margin-bottom: 0.5em;"
2278 "}\n"
2279 "h2 {"
2280 " font-family: helvetica, arial;"
2281 " font-size: x-large;"
2282 " font-weight: bold;"
2283 " font-style: italic;"
2284 " color: #6020a0;"
2285 " margin-top: 0em;"
2286 " margin-bottom: 0em;"
2287 "}\n"
2288 "h3 {"
2289 " font-family: helvetica, arial;"
2290 " font-size: 16px;"
2291 " font-weight: bold;"
2292 " color: #b00040;"
2293 " background: #e8e8d0;"
2294 " margin-top: 0em;"
2295 " margin-bottom: 0em;"
2296 "}\n"
2297 "li {"
2298 " margin-top: 0.25em;"
2299 " margin-right: 2em;"
2300 "}\n"
2301 ".hr {margin-top: 0.25em;"
2302 " border-color: black;"
2303 " border-bottom-style: solid;"
2304 "}\n"
2305 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
2306 ".total {background: #20D0D0;color: #ffff80;}\n"
2307 ".frontend {background: #e8e8d0;}\n"
2308 ".socket {background: #d0d0d0;}\n"
2309 ".backend {background: #e8e8d0;}\n"
2310 ".active_down {background: #ff9090;}\n"
2311 ".active_going_up {background: #ffd020;}\n"
2312 ".active_going_down {background: #ffffa0;}\n"
2313 ".active_up {background: #c0ffc0;}\n"
2314 ".active_nolb {background: #20a0ff;}\n"
2315 ".active_draining {background: #20a0FF;}\n"
2316 ".active_no_check {background: #e0e0e0;}\n"
2317 ".backup_down {background: #ff9090;}\n"
2318 ".backup_going_up {background: #ff80ff;}\n"
2319 ".backup_going_down {background: #c060ff;}\n"
2320 ".backup_up {background: #b0d0ff;}\n"
2321 ".backup_nolb {background: #90b0e0;}\n"
2322 ".backup_draining {background: #cc9900;}\n"
2323 ".backup_no_check {background: #e0e0e0;}\n"
2324 ".maintain {background: #c07820;}\n"
2325 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
2326 "\n"
2327 "a.px:link {color: #ffff40; text-decoration: none;}"
2328 "a.px:visited {color: #ffff40; text-decoration: none;}"
2329 "a.px:hover {color: #ffffff; text-decoration: none;}"
2330 "a.lfsb:link {color: #000000; text-decoration: none;}"
2331 "a.lfsb:visited {color: #000000; text-decoration: none;}"
2332 "a.lfsb:hover {color: #505050; text-decoration: none;}"
2333 "\n"
2334 "table.tbl { border-collapse: collapse; border-style: none;}\n"
2335 "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"
2336 "table.tbl td.ac { text-align: center;}\n"
2337 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
2338 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
2339 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
2340 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
2341 "\n"
2342 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
2343 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
2344 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
2345 "table.det { border-collapse: collapse; border-style: none; }\n"
2346 "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"
2347 "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"
2348 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
2349 "div.tips {\n"
2350 " display:block;\n"
2351 " visibility:hidden;\n"
2352 " z-index:2147483647;\n"
2353 " position:absolute;\n"
2354 " padding:2px 4px 3px;\n"
2355 " background:#f0f060; color:#000000;\n"
2356 " border:1px solid #7040c0;\n"
2357 " white-space:nowrap;\n"
2358 " font-style:normal;font-size:11px;font-weight:normal;\n"
2359 " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n"
2360 " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n"
2361 "}\n"
2362 "u:hover div.tips {visibility:visible;}\n"
2363 "-->\n"
2364 "</style></head>\n",
2365 (uri->flags & ST_SHNODE) ? " on " : "",
2366 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
2367 );
2368}
2369
2370/* Dumps the HTML stats information block to the trash for and uses the state from
2371 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
2372 * for clearing the trash if needed.
2373 */
2374static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri)
2375{
2376 struct appctx *appctx = __objt_appctx(si->end);
2377 unsigned int up = (now.tv_sec - start_date.tv_sec);
2378 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
Christopher Fauleted7a0662019-01-14 11:07:34 +01002379 const char *scope_ptr = stats_scope_ptr(appctx, si);
Willy Tarreau1713c032019-05-23 12:23:55 +02002380 unsigned long long bps = (unsigned long long)read_freq_ctr(&global.out_32bps) * 32;
2381
2382 /* Turn the bytes per second to bits per second and take care of the
2383 * usual ethernet overhead in order to help figure how far we are from
2384 * interface saturation since it's the only case which usually matters.
2385 * For this we count the total size of an Ethernet frame on the wire
2386 * including preamble and IFG (1538) for the largest TCP segment it
2387 * transports (1448 with TCP timestamps). This is not valid for smaller
2388 * packets (under-estimated), but it gives a reasonably accurate
2389 * estimation of how far we are from uplink saturation.
2390 */
2391 bps = bps * 8 * 1538 / 1448;
William Lallemand74c24fb2016-11-21 17:18:36 +01002392
2393 /* WARNING! this has to fit the first packet too.
2394 * We are around 3.5 kB, add adding entries will
2395 * become tricky if we want to support 4kB buffers !
2396 */
2397 chunk_appendf(&trash,
2398 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
2399 PRODUCT_NAME "%s</a></h1>\n"
2400 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
2401 "<hr width=\"100%%\" class=\"hr\">\n"
2402 "<h3>&gt; General process information</h3>\n"
2403 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Yves Lafon95317282018-02-26 11:10:37 +01002404 "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n"
William Lallemand74c24fb2016-11-21 17:18:36 +01002405 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
2406 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
2407 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
Willy Tarreau1713c032019-05-23 12:23:55 +02002408 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec; bit rate = %.3f %cbps<br>\n"
William Lallemand74c24fb2016-11-21 17:18:36 +01002409 "Running tasks: %d/%d; idle = %d %%<br>\n"
2410 "</td><td align=\"center\" nowrap>\n"
2411 "<table class=\"lgd\"><tr>\n"
2412 "<td class=\"active_up\">&nbsp;</td><td class=\"noborder\">active UP </td>"
2413 "<td class=\"backup_up\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
2414 "</tr><tr>\n"
2415 "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>"
2416 "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>"
2417 "</tr><tr>\n"
2418 "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>"
2419 "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>"
2420 "</tr><tr>\n"
2421 "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
2422 "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>"
2423 "</tr><tr>\n"
2424 "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) &nbsp;</td>"
2425 "</tr><tr>\n"
2426 "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance &nbsp;</td>"
2427 "</tr></table>\n"
2428 "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled."
2429 "</td>"
2430 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2431 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
2432 "",
Willy Tarreau909b9d82019-01-04 18:20:32 +01002433 (uri->flags & ST_HIDEVER) ? "" : (stats_version_string),
William Lallemand74c24fb2016-11-21 17:18:36 +01002434 pid, (uri->flags & ST_SHNODE) ? " on " : "",
2435 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
2436 (uri->flags & ST_SHDESC) ? ": " : "",
2437 (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
Yves Lafon95317282018-02-26 11:10:37 +01002438 pid, relative_pid, global.nbproc, global.nbthread,
William Lallemand74c24fb2016-11-21 17:18:36 +01002439 up / 86400, (up % 86400) / 3600,
2440 (up % 3600) / 60, (up % 60),
2441 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
2442 global.rlimit_memmax ? " MB" : "",
2443 global.rlimit_nofile,
2444 global.maxsock, global.maxconn, global.maxpipes,
2445 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Willy Tarreau1713c032019-05-23 12:23:55 +02002446 bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0),
2447 bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k',
Willy Tarreau81036f22019-05-20 19:24:50 +02002448 tasks_run_queue_cur, nb_tasks_cur, ti->idle_pct
William Lallemand74c24fb2016-11-21 17:18:36 +01002449 );
2450
2451 /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Christopher Fauleted7a0662019-01-14 11:07:34 +01002452 memcpy(scope_txt, scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002453 scope_txt[appctx->ctx.stats.scope_len] = '\0';
2454
2455 chunk_appendf(&trash,
2456 "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n",
2457 (appctx->ctx.stats.scope_len > 0) ? scope_txt : "",
2458 STAT_SCOPE_TXT_MAXLEN);
2459
2460 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
2461 scope_txt[0] = 0;
2462 if (appctx->ctx.stats.scope_len) {
2463 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01002464 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002465 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
2466 }
2467
2468 if (appctx->ctx.stats.flags & STAT_HIDE_DOWN)
2469 chunk_appendf(&trash,
2470 "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n",
2471 uri->uri_prefix,
2472 "",
2473 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2474 scope_txt);
2475 else
2476 chunk_appendf(&trash,
2477 "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n",
2478 uri->uri_prefix,
2479 ";up",
2480 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2481 scope_txt);
2482
2483 if (uri->refresh > 0) {
2484 if (appctx->ctx.stats.flags & STAT_NO_REFRESH)
2485 chunk_appendf(&trash,
2486 "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n",
2487 uri->uri_prefix,
2488 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2489 "",
2490 scope_txt);
2491 else
2492 chunk_appendf(&trash,
2493 "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n",
2494 uri->uri_prefix,
2495 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2496 ";norefresh",
2497 scope_txt);
2498 }
2499
2500 chunk_appendf(&trash,
2501 "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n",
2502 uri->uri_prefix,
2503 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2504 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2505 scope_txt);
2506
2507 chunk_appendf(&trash,
2508 "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n",
2509 uri->uri_prefix,
2510 (uri->refresh > 0) ? ";norefresh" : "",
2511 scope_txt);
2512
2513 chunk_appendf(&trash,
2514 "</ul></td>"
2515 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2516 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
2517 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2518 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2519 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2520 "</ul>"
2521 "</td>"
2522 "</tr></table>\n"
2523 ""
2524 );
2525
2526 if (appctx->ctx.stats.st_code) {
2527 switch (appctx->ctx.stats.st_code) {
2528 case STAT_STATUS_DONE:
2529 chunk_appendf(&trash,
2530 "<p><div class=active_up>"
2531 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2532 "Action processed successfully."
2533 "</div>\n", uri->uri_prefix,
2534 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2535 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2536 scope_txt);
2537 break;
2538 case STAT_STATUS_NONE:
2539 chunk_appendf(&trash,
2540 "<p><div class=active_going_down>"
2541 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2542 "Nothing has changed."
2543 "</div>\n", uri->uri_prefix,
2544 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2545 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2546 scope_txt);
2547 break;
2548 case STAT_STATUS_PART:
2549 chunk_appendf(&trash,
2550 "<p><div class=active_going_down>"
2551 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2552 "Action partially processed.<br>"
2553 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2554 "</div>\n", uri->uri_prefix,
2555 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2556 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2557 scope_txt);
2558 break;
2559 case STAT_STATUS_ERRP:
2560 chunk_appendf(&trash,
2561 "<p><div class=active_down>"
2562 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2563 "Action not processed because of invalid parameters."
2564 "<ul>"
2565 "<li>The action is maybe unknown.</li>"
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002566 "<li>Invalid key parameter (empty or too long).</li>"
William Lallemand74c24fb2016-11-21 17:18:36 +01002567 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2568 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2569 "</ul>"
2570 "</div>\n", uri->uri_prefix,
2571 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2572 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2573 scope_txt);
2574 break;
2575 case STAT_STATUS_EXCD:
2576 chunk_appendf(&trash,
2577 "<p><div class=active_down>"
2578 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2579 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2580 "You should retry with less servers at a time.</b>"
2581 "</div>\n", uri->uri_prefix,
2582 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2583 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2584 scope_txt);
2585 break;
2586 case STAT_STATUS_DENY:
2587 chunk_appendf(&trash,
2588 "<p><div class=active_down>"
2589 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2590 "<b>Action denied.</b>"
2591 "</div>\n", uri->uri_prefix,
2592 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2593 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2594 scope_txt);
2595 break;
Christopher Faulet3c2ecf72019-02-27 16:41:27 +01002596 case STAT_STATUS_IVAL:
2597 chunk_appendf(&trash,
2598 "<p><div class=active_down>"
2599 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2600 "<b>Invalid requests (unsupported method or chunked encoded request).</b>"
2601 "</div>\n", uri->uri_prefix,
2602 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2603 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2604 scope_txt);
2605 break;
William Lallemand74c24fb2016-11-21 17:18:36 +01002606 default:
2607 chunk_appendf(&trash,
2608 "<p><div class=active_no_check>"
2609 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2610 "Unexpected result."
2611 "</div>\n", uri->uri_prefix,
2612 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2613 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2614 scope_txt);
2615 }
2616 chunk_appendf(&trash, "<p>\n");
2617 }
2618}
2619
2620/* Dumps the HTML stats trailer block to the trash. The caller is responsible
2621 * for clearing the trash if needed.
2622 */
2623static void stats_dump_html_end()
2624{
2625 chunk_appendf(&trash, "</body></html>\n");
2626}
2627
Simon Horman05ee2132017-01-04 09:37:25 +01002628/* Dumps the stats JSON header to the trash buffer which. The caller is responsible
2629 * for clearing it if needed.
2630 */
2631static void stats_dump_json_header()
2632{
2633 chunk_strcat(&trash, "[");
2634}
2635
2636
2637/* Dumps the JSON stats trailer block to the trash. The caller is responsible
2638 * for clearing the trash if needed.
2639 */
2640static void stats_dump_json_end()
2641{
2642 chunk_strcat(&trash, "]");
2643}
2644
William Lallemand74c24fb2016-11-21 17:18:36 +01002645/* This function dumps statistics onto the stream interface's read buffer in
2646 * either CSV or HTML format. <uri> contains some HTML-specific parameters that
2647 * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if
2648 * it had to stop writing data and an I/O is needed, 1 if the dump is finished
2649 * and the stream must be closed, or -1 in case of any error. This function is
2650 * used by both the CLI and the HTTP handlers.
2651 */
Christopher Fauletef779222018-10-31 08:47:01 +01002652static int stats_dump_stat_to_buffer(struct stream_interface *si, struct htx *htx,
2653 struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002654{
2655 struct appctx *appctx = __objt_appctx(si->end);
2656 struct channel *rep = si_ic(si);
2657 struct proxy *px;
2658
2659 chunk_reset(&trash);
2660
2661 switch (appctx->st2) {
2662 case STAT_ST_INIT:
2663 appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
2664 /* fall through */
2665
2666 case STAT_ST_HEAD:
2667 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
2668 stats_dump_html_head(uri);
Simon Horman05ee2132017-01-04 09:37:25 +01002669 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreau9d7fb632017-04-11 07:53:04 +02002670 stats_dump_json_header();
William Lallemand74c24fb2016-11-21 17:18:36 +01002671 else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED))
2672 stats_dump_csv_header();
2673
Christopher Fauletef779222018-10-31 08:47:01 +01002674 if (!stats_putchk(rep, htx, &trash))
2675 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002676
2677 appctx->st2 = STAT_ST_INFO;
2678 /* fall through */
2679
2680 case STAT_ST_INFO:
2681 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2682 stats_dump_html_info(si, uri);
Christopher Fauletef779222018-10-31 08:47:01 +01002683 if (!stats_putchk(rep, htx, &trash))
2684 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002685 }
2686
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002687 appctx->ctx.stats.px = proxies_list;
William Lallemand74c24fb2016-11-21 17:18:36 +01002688 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2689 appctx->st2 = STAT_ST_LIST;
2690 /* fall through */
2691
2692 case STAT_ST_LIST:
2693 /* dump proxies */
2694 while (appctx->ctx.stats.px) {
Christopher Fauletef779222018-10-31 08:47:01 +01002695 if (htx) {
2696 if (htx_almost_full(htx))
2697 goto full;
2698 }
2699 else {
2700 if (buffer_almost_full(&rep->buf))
2701 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002702 }
2703
2704 px = appctx->ctx.stats.px;
2705 /* skip the disabled proxies, global frontend and non-networked ones */
2706 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Christopher Fauletef779222018-10-31 08:47:01 +01002707 if (stats_dump_proxy_to_buffer(si, htx, px, uri) == 0)
William Lallemand74c24fb2016-11-21 17:18:36 +01002708 return 0;
2709
2710 appctx->ctx.stats.px = px->next;
2711 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2712 }
2713 /* here, we just have reached the last proxy */
2714
2715 appctx->st2 = STAT_ST_END;
2716 /* fall through */
2717
2718 case STAT_ST_END:
Simon Horman05ee2132017-01-04 09:37:25 +01002719 if (appctx->ctx.stats.flags & (STAT_FMT_HTML|STAT_FMT_JSON)) {
2720 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
2721 stats_dump_html_end();
2722 else
2723 stats_dump_json_end();
Christopher Fauletef779222018-10-31 08:47:01 +01002724 if (!stats_putchk(rep, htx, &trash))
2725 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002726 }
2727
2728 appctx->st2 = STAT_ST_FIN;
2729 /* fall through */
2730
2731 case STAT_ST_FIN:
2732 return 1;
2733
2734 default:
2735 /* unknown state ! */
2736 appctx->st2 = STAT_ST_FIN;
2737 return -1;
2738 }
Christopher Fauletef779222018-10-31 08:47:01 +01002739
2740 full:
2741 si_rx_room_blk(si);
2742 return 0;
2743
William Lallemand74c24fb2016-11-21 17:18:36 +01002744}
2745
2746/* We reached the stats page through a POST request. The appctx is
2747 * expected to have already been allocated by the caller.
2748 * Parse the posted data and enable/disable servers if necessary.
2749 * Returns 1 if request was parsed or zero if it needs more data.
2750 */
2751static int stats_process_http_post(struct stream_interface *si)
2752{
2753 struct stream *s = si_strm(si);
2754 struct appctx *appctx = objt_appctx(si->end);
2755
2756 struct proxy *px = NULL;
2757 struct server *sv = NULL;
2758
2759 char key[LINESIZE];
2760 int action = ST_ADM_ACTION_NONE;
2761 int reprocess = 0;
2762
2763 int total_servers = 0;
2764 int altered_servers = 0;
2765
2766 char *first_param, *cur_param, *next_param, *end_params;
2767 char *st_cur_param = NULL;
2768 char *st_next_param = NULL;
2769
Christopher Fauleta3618372018-12-13 21:59:56 +01002770 struct buffer *temp = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01002771
Christopher Fauletb7f88902019-07-15 21:56:43 +02002772 struct htx *htx = htxbuf(&s->req.buf);
2773 struct htx_blk *blk;
Christopher Fauleta3618372018-12-13 21:59:56 +01002774
Christopher Fauletb7f88902019-07-15 21:56:43 +02002775 /* we need more data */
2776 if (s->txn->req.msg_state < HTTP_MSG_DONE) {
2777 /* check if we can receive more */
2778 if (htx_free_data_space(htx) <= global.tune.maxrewrite) {
2779 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2780 goto out;
Christopher Fauleta3618372018-12-13 21:59:56 +01002781 }
Christopher Fauletb7f88902019-07-15 21:56:43 +02002782 goto wait;
2783 }
Christopher Fauleta3618372018-12-13 21:59:56 +01002784
Christopher Fauletb7f88902019-07-15 21:56:43 +02002785 /* The request was fully received. Copy data */
2786 blk = htx_get_head_blk(htx);
2787 while (blk) {
2788 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauleta3618372018-12-13 21:59:56 +01002789
Christopher Fauletb7f88902019-07-15 21:56:43 +02002790 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
2791 break;
2792 if (type == HTX_BLK_DATA) {
2793 struct ist v = htx_get_blk_value(htx, blk);
Christopher Fauleta3618372018-12-13 21:59:56 +01002794
Christopher Fauletb7f88902019-07-15 21:56:43 +02002795 if (!chunk_memcat(temp, v.ptr, v.len)) {
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002796 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2797 goto out;
2798 }
Christopher Fauleta3618372018-12-13 21:59:56 +01002799 }
Christopher Fauletb7f88902019-07-15 21:56:43 +02002800 blk = htx_get_next_blk(htx, blk);
William Lallemand74c24fb2016-11-21 17:18:36 +01002801 }
2802
Willy Tarreau843b7cb2018-07-13 10:54:26 +02002803 first_param = temp->area;
Christopher Fauleta3618372018-12-13 21:59:56 +01002804 end_params = temp->area + temp->data;
William Lallemand74c24fb2016-11-21 17:18:36 +01002805 cur_param = next_param = end_params;
2806 *end_params = '\0';
2807
2808 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
2809
2810 /*
2811 * Parse the parameters in reverse order to only store the last value.
2812 * From the html form, the backend and the action are at the end.
2813 */
2814 while (cur_param > first_param) {
2815 char *value;
2816 int poffset, plen;
2817
2818 cur_param--;
2819
2820 if ((*cur_param == '&') || (cur_param == first_param)) {
2821 reprocess_servers:
2822 /* Parse the key */
2823 poffset = (cur_param != first_param ? 1 : 0);
2824 plen = next_param - cur_param + (cur_param == first_param ? 1 : 0);
2825 if ((plen > 0) && (plen <= sizeof(key))) {
2826 strncpy(key, cur_param + poffset, plen);
2827 key[plen - 1] = '\0';
2828 } else {
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01002829 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
William Lallemand74c24fb2016-11-21 17:18:36 +01002830 goto out;
2831 }
2832
2833 /* Parse the value */
2834 value = key;
2835 while (*value != '\0' && *value != '=') {
2836 value++;
2837 }
2838 if (*value == '=') {
2839 /* Ok, a value is found, we can mark the end of the key */
2840 *value++ = '\0';
2841 }
2842 if (url_decode(key) < 0 || url_decode(value) < 0)
2843 break;
2844
2845 /* Now we can check the key to see what to do */
2846 if (!px && (strcmp(key, "b") == 0)) {
2847 if ((px = proxy_be_by_name(value)) == NULL) {
2848 /* the backend name is unknown or ambiguous (duplicate names) */
2849 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2850 goto out;
2851 }
2852 }
2853 else if (!action && (strcmp(key, "action") == 0)) {
2854 if (strcmp(value, "ready") == 0) {
2855 action = ST_ADM_ACTION_READY;
2856 }
2857 else if (strcmp(value, "drain") == 0) {
2858 action = ST_ADM_ACTION_DRAIN;
2859 }
2860 else if (strcmp(value, "maint") == 0) {
2861 action = ST_ADM_ACTION_MAINT;
2862 }
2863 else if (strcmp(value, "shutdown") == 0) {
2864 action = ST_ADM_ACTION_SHUTDOWN;
2865 }
2866 else if (strcmp(value, "dhlth") == 0) {
2867 action = ST_ADM_ACTION_DHLTH;
2868 }
2869 else if (strcmp(value, "ehlth") == 0) {
2870 action = ST_ADM_ACTION_EHLTH;
2871 }
2872 else if (strcmp(value, "hrunn") == 0) {
2873 action = ST_ADM_ACTION_HRUNN;
2874 }
2875 else if (strcmp(value, "hnolb") == 0) {
2876 action = ST_ADM_ACTION_HNOLB;
2877 }
2878 else if (strcmp(value, "hdown") == 0) {
2879 action = ST_ADM_ACTION_HDOWN;
2880 }
2881 else if (strcmp(value, "dagent") == 0) {
2882 action = ST_ADM_ACTION_DAGENT;
2883 }
2884 else if (strcmp(value, "eagent") == 0) {
2885 action = ST_ADM_ACTION_EAGENT;
2886 }
2887 else if (strcmp(value, "arunn") == 0) {
2888 action = ST_ADM_ACTION_ARUNN;
2889 }
2890 else if (strcmp(value, "adown") == 0) {
2891 action = ST_ADM_ACTION_ADOWN;
2892 }
2893 /* else these are the old supported methods */
2894 else if (strcmp(value, "disable") == 0) {
2895 action = ST_ADM_ACTION_DISABLE;
2896 }
2897 else if (strcmp(value, "enable") == 0) {
2898 action = ST_ADM_ACTION_ENABLE;
2899 }
2900 else if (strcmp(value, "stop") == 0) {
2901 action = ST_ADM_ACTION_STOP;
2902 }
2903 else if (strcmp(value, "start") == 0) {
2904 action = ST_ADM_ACTION_START;
2905 }
2906 else {
2907 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2908 goto out;
2909 }
2910 }
2911 else if (strcmp(key, "s") == 0) {
2912 if (!(px && action)) {
2913 /*
2914 * Indicates that we'll need to reprocess the parameters
2915 * as soon as backend and action are known
2916 */
2917 if (!reprocess) {
2918 st_cur_param = cur_param;
2919 st_next_param = next_param;
2920 }
2921 reprocess = 1;
2922 }
2923 else if ((sv = findserver(px, value)) != NULL) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002924 HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01002925 switch (action) {
2926 case ST_ADM_ACTION_DISABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002927 if (!(sv->cur_admin & SRV_ADMF_FMAINT)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002928 altered_servers++;
2929 total_servers++;
2930 srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page");
2931 }
2932 break;
2933 case ST_ADM_ACTION_ENABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002934 if (sv->cur_admin & SRV_ADMF_FMAINT) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002935 altered_servers++;
2936 total_servers++;
2937 srv_clr_admin_flag(sv, SRV_ADMF_FMAINT);
2938 }
2939 break;
2940 case ST_ADM_ACTION_STOP:
Emeric Brun52a91d32017-08-31 14:41:55 +02002941 if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002942 srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page");
2943 altered_servers++;
2944 total_servers++;
2945 }
2946 break;
2947 case ST_ADM_ACTION_START:
Emeric Brun52a91d32017-08-31 14:41:55 +02002948 if (sv->cur_admin & SRV_ADMF_FDRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002949 srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN);
2950 altered_servers++;
2951 total_servers++;
2952 }
2953 break;
2954 case ST_ADM_ACTION_DHLTH:
2955 if (sv->check.state & CHK_ST_CONFIGURED) {
2956 sv->check.state &= ~CHK_ST_ENABLED;
2957 altered_servers++;
2958 total_servers++;
2959 }
2960 break;
2961 case ST_ADM_ACTION_EHLTH:
2962 if (sv->check.state & CHK_ST_CONFIGURED) {
2963 sv->check.state |= CHK_ST_ENABLED;
2964 altered_servers++;
2965 total_servers++;
2966 }
2967 break;
2968 case ST_ADM_ACTION_HRUNN:
2969 if (!(sv->track)) {
2970 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02002971 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002972 altered_servers++;
2973 total_servers++;
2974 }
2975 break;
2976 case ST_ADM_ACTION_HNOLB:
2977 if (!(sv->track)) {
2978 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02002979 srv_set_stopping(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002980 altered_servers++;
2981 total_servers++;
2982 }
2983 break;
2984 case ST_ADM_ACTION_HDOWN:
2985 if (!(sv->track)) {
2986 sv->check.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02002987 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002988 altered_servers++;
2989 total_servers++;
2990 }
2991 break;
2992 case ST_ADM_ACTION_DAGENT:
2993 if (sv->agent.state & CHK_ST_CONFIGURED) {
2994 sv->agent.state &= ~CHK_ST_ENABLED;
2995 altered_servers++;
2996 total_servers++;
2997 }
2998 break;
2999 case ST_ADM_ACTION_EAGENT:
3000 if (sv->agent.state & CHK_ST_CONFIGURED) {
3001 sv->agent.state |= CHK_ST_ENABLED;
3002 altered_servers++;
3003 total_servers++;
3004 }
3005 break;
3006 case ST_ADM_ACTION_ARUNN:
3007 if (sv->agent.state & CHK_ST_ENABLED) {
3008 sv->agent.health = sv->agent.rise + sv->agent.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02003009 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003010 altered_servers++;
3011 total_servers++;
3012 }
3013 break;
3014 case ST_ADM_ACTION_ADOWN:
3015 if (sv->agent.state & CHK_ST_ENABLED) {
3016 sv->agent.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02003017 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01003018 altered_servers++;
3019 total_servers++;
3020 }
3021 break;
3022 case ST_ADM_ACTION_READY:
3023 srv_adm_set_ready(sv);
3024 altered_servers++;
3025 total_servers++;
3026 break;
3027 case ST_ADM_ACTION_DRAIN:
3028 srv_adm_set_drain(sv);
3029 altered_servers++;
3030 total_servers++;
3031 break;
3032 case ST_ADM_ACTION_MAINT:
3033 srv_adm_set_maint(sv);
3034 altered_servers++;
3035 total_servers++;
3036 break;
3037 case ST_ADM_ACTION_SHUTDOWN:
3038 if (px->state != PR_STSTOPPED) {
3039 struct stream *sess, *sess_bck;
3040
3041 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
3042 if (sess->srv_conn == sv)
3043 stream_shutdown(sess, SF_ERR_KILLED);
3044
3045 altered_servers++;
3046 total_servers++;
3047 }
3048 break;
3049 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01003050 HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01003051 } else {
3052 /* the server name is unknown or ambiguous (duplicate names) */
3053 total_servers++;
3054 }
3055 }
3056 if (reprocess && px && action) {
3057 /* Now, we know the backend and the action chosen by the user.
3058 * We can safely restart from the first server parameter
3059 * to reprocess them
3060 */
3061 cur_param = st_cur_param;
3062 next_param = st_next_param;
3063 reprocess = 0;
3064 goto reprocess_servers;
3065 }
3066
3067 next_param = cur_param;
3068 }
3069 }
3070
3071 if (total_servers == 0) {
3072 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
3073 }
3074 else if (altered_servers == 0) {
3075 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
3076 }
3077 else if (altered_servers == total_servers) {
3078 appctx->ctx.stats.st_code = STAT_STATUS_DONE;
3079 }
3080 else {
3081 appctx->ctx.stats.st_code = STAT_STATUS_PART;
3082 }
3083 out:
3084 return 1;
Christopher Faulet2f9a41d2019-02-27 15:30:57 +01003085 wait:
3086 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
3087 return 0;
Christopher Fauletef779222018-10-31 08:47:01 +01003088}
3089
3090
Christopher Fauletb7f88902019-07-15 21:56:43 +02003091static int stats_send_http_headers(struct stream_interface *si, struct htx *htx)
Christopher Fauletef779222018-10-31 08:47:01 +01003092{
3093 struct stream *s = si_strm(si);
3094 struct uri_auth *uri = s->be->uri_auth;
3095 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003096 struct htx_sl *sl;
3097 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003098
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003099 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);
3100 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
3101 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003102 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003103 sl->info.res.status = 200;
Christopher Fauletef779222018-10-31 08:47:01 +01003104
Christopher Fauletb829f4c2019-03-29 16:13:55 +01003105 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")))
Christopher Fauletef779222018-10-31 08:47:01 +01003106 goto full;
3107 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
3108 if (!htx_add_header(htx, ist("Content-Type"), ist("text/html")))
3109 goto full;
3110 }
3111 else {
3112 if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain")))
3113 goto full;
3114 }
3115
3116 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) {
3117 const char *refresh = U2A(uri->refresh);
3118 if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh))))
3119 goto full;
3120 }
3121
3122 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
3123 if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")))
3124 goto full;
3125 }
3126
3127 if (!htx_add_endof(htx, HTX_BLK_EOH))
3128 goto full;
3129
Christopher Faulet1e2d6362019-02-27 16:28:48 +01003130 channel_add_input(&s->res, htx->data);
Christopher Fauletef779222018-10-31 08:47:01 +01003131 return 1;
3132
3133 full:
3134 htx_reset(htx);
3135 si_rx_room_blk(si);
3136 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01003137}
3138
Christopher Fauletef779222018-10-31 08:47:01 +01003139
Christopher Fauletb7f88902019-07-15 21:56:43 +02003140static int stats_send_http_redirect(struct stream_interface *si, struct htx *htx)
Christopher Fauletef779222018-10-31 08:47:01 +01003141{
3142 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
3143 struct stream *s = si_strm(si);
3144 struct uri_auth *uri = s->be->uri_auth;
3145 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003146 struct htx_sl *sl;
3147 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003148
3149 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
3150 scope_txt[0] = 0;
3151 if (appctx->ctx.stats.scope_len) {
Christopher Fauleted7a0662019-01-14 11:07:34 +01003152 const char *scope_ptr = stats_scope_ptr(appctx, si);
3153
Christopher Fauletef779222018-10-31 08:47:01 +01003154 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Christopher Fauleted7a0662019-01-14 11:07:34 +01003155 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len);
Christopher Fauletef779222018-10-31 08:47:01 +01003156 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
3157 }
3158
3159 /* We don't want to land on the posted stats page because a refresh will
3160 * repost the data. We don't want this to happen on accident so we redirect
3161 * the browse to the stats page with a GET.
3162 */
3163 chunk_printf(&trash, "%s;st=%s%s%s%s",
3164 uri->uri_prefix,
3165 ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) &&
3166 (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) &&
3167 stat_status_codes[appctx->ctx.stats.st_code]) ?
3168 stat_status_codes[appctx->ctx.stats.st_code] :
3169 stat_status_codes[STAT_STATUS_UNKN],
3170 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3171 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
3172 scope_txt);
3173
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003174 flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK);
3175 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other"));
3176 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003177 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003178 sl->info.res.status = 303;
Christopher Fauletef779222018-10-31 08:47:01 +01003179
3180 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
Christopher Fauletef779222018-10-31 08:47:01 +01003181 !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) ||
3182 !htx_add_header(htx, ist("Content-Length"), ist("0")) ||
3183 !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data)))
3184 goto full;
3185
3186 if (!htx_add_endof(htx, HTX_BLK_EOH))
3187 goto full;
3188
Christopher Faulet1e2d6362019-02-27 16:28:48 +01003189 channel_add_input(&s->res, htx->data);
Christopher Fauletef779222018-10-31 08:47:01 +01003190 return 1;
3191
3192full:
3193 htx_reset(htx);
3194 si_rx_room_blk(si);
3195 return 0;
3196}
William Lallemand74c24fb2016-11-21 17:18:36 +01003197
Simon Horman05ee2132017-01-04 09:37:25 +01003198
William Lallemand74c24fb2016-11-21 17:18:36 +01003199/* This I/O handler runs as an applet embedded in a stream interface. It is
3200 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
3201 * appctx->st0 contains the operation in progress (dump, done). The handler
3202 * automatically unregisters itself once transfer is complete.
3203 */
Christopher Fauletb7f88902019-07-15 21:56:43 +02003204static void http_stats_io_handler(struct appctx *appctx)
Christopher Fauletef779222018-10-31 08:47:01 +01003205{
3206 struct stream_interface *si = appctx->owner;
3207 struct stream *s = si_strm(si);
3208 struct channel *req = si_oc(si);
3209 struct channel *res = si_ic(si);
3210 struct htx *req_htx, *res_htx;
3211
3212 res_htx = htx_from_buf(&res->buf);
3213
3214 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
3215 goto out;
3216
3217 /* Check if the input buffer is avalaible. */
3218 if (!b_size(&res->buf)) {
3219 si_rx_room_blk(si);
3220 goto out;
3221 }
3222
3223 /* check that the output is not closed */
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003224 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_SHUTR))
3225 appctx->st0 = STAT_HTTP_END;
Christopher Fauletef779222018-10-31 08:47:01 +01003226
3227 /* all states are processed in sequence */
3228 if (appctx->st0 == STAT_HTTP_HEAD) {
Christopher Fauletb7f88902019-07-15 21:56:43 +02003229 if (stats_send_http_headers(si, res_htx)) {
Christopher Fauletef779222018-10-31 08:47:01 +01003230 if (s->txn->meth == HTTP_METH_HEAD)
3231 appctx->st0 = STAT_HTTP_DONE;
3232 else
3233 appctx->st0 = STAT_HTTP_DUMP;
3234 }
3235 }
3236
3237 if (appctx->st0 == STAT_HTTP_DUMP) {
3238 if (stats_dump_stat_to_buffer(si, res_htx, s->be->uri_auth))
3239 appctx->st0 = STAT_HTTP_DONE;
3240 }
3241
3242 if (appctx->st0 == STAT_HTTP_POST) {
3243 if (stats_process_http_post(si))
3244 appctx->st0 = STAT_HTTP_LAST;
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003245 else if (req->flags & CF_SHUTR)
Christopher Fauletef779222018-10-31 08:47:01 +01003246 appctx->st0 = STAT_HTTP_DONE;
3247 }
3248
3249 if (appctx->st0 == STAT_HTTP_LAST) {
Christopher Fauletb7f88902019-07-15 21:56:43 +02003250 if (stats_send_http_redirect(si, res_htx))
Christopher Fauletef779222018-10-31 08:47:01 +01003251 appctx->st0 = STAT_HTTP_DONE;
3252 }
3253
3254 if (appctx->st0 == STAT_HTTP_DONE) {
Christopher Faulet54b5e212019-06-04 10:08:28 +02003255 /* Don't add TLR because mux-h1 will take care of it */
Christopher Fauletef779222018-10-31 08:47:01 +01003256 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
3257 si_rx_room_blk(si);
3258 goto out;
3259 }
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003260 channel_add_input(&s->res, 1);
3261 appctx->st0 = STAT_HTTP_END;
Christopher Fauletef779222018-10-31 08:47:01 +01003262 }
3263
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003264 if (appctx->st0 == STAT_HTTP_END) {
3265 if (!(res->flags & CF_SHUTR)) {
Christopher Fauletef779222018-10-31 08:47:01 +01003266 res->flags |= CF_READ_NULL;
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003267 si_shutr(si);
3268 }
3269
3270 /* eat the whole request */
3271 if (co_data(req)) {
3272 req_htx = htx_from_buf(&req->buf);
3273 co_htx_skip(req, req_htx, co_data(req));
3274 htx_to_buf(req_htx, &req->buf);
Christopher Fauletef779222018-10-31 08:47:01 +01003275 }
3276 }
Christopher Faulet3a78aa62019-02-27 16:19:48 +01003277
Christopher Fauletef779222018-10-31 08:47:01 +01003278 out:
3279 /* we have left the request in the buffer for the case where we
3280 * process a POST, and this automatically re-enables activity on
3281 * read. It's better to indicate that we want to stop reading when
3282 * we're sending, so that we know there's at most one direction
3283 * deciding to wake the applet up. It saves it from looping when
3284 * emitting large blocks into small TCP windows.
3285 */
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01003286 htx_to_buf(res_htx, &res->buf);
3287 if (!channel_is_empty(res))
Christopher Fauletef779222018-10-31 08:47:01 +01003288 si_stop_get(si);
Christopher Fauletef779222018-10-31 08:47:01 +01003289}
3290
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003291/* Dump all fields from <info> into <out> using the "show info" format (name: value) */
Willy Tarreau83061a82018-07-13 11:56:34 +02003292static int stats_dump_info_fields(struct buffer *out,
3293 const struct field *info)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003294{
3295 int field;
3296
3297 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3298 if (!field_format(info, field))
3299 continue;
3300
3301 if (!chunk_appendf(out, "%s: ", info_field_names[field]))
3302 return 0;
3303 if (!stats_emit_raw_data_field(out, &info[field]))
3304 return 0;
3305 if (!chunk_strcat(out, "\n"))
3306 return 0;
3307 }
3308 return 1;
3309}
3310
3311/* Dump all fields from <info> into <out> using the "show info typed" format */
Willy Tarreau83061a82018-07-13 11:56:34 +02003312static int stats_dump_typed_info_fields(struct buffer *out,
3313 const struct field *info)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003314{
3315 int field;
3316
3317 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3318 if (!field_format(info, field))
3319 continue;
3320
3321 if (!chunk_appendf(out, "%d.%s.%u:", field, info_field_names[field], info[INF_PROCESS_NUM].u.u32))
3322 return 0;
3323 if (!stats_emit_field_tags(out, &info[field], ':'))
3324 return 0;
3325 if (!stats_emit_typed_data_field(out, &info[field]))
3326 return 0;
3327 if (!chunk_strcat(out, "\n"))
3328 return 0;
3329 }
3330 return 1;
3331}
3332
3333/* Fill <info> with HAProxy global info. <info> is preallocated
3334 * array of length <len>. The length of the aray must be
3335 * INF_TOTAL_FIELDS. If this length is less then this value, the
3336 * function returns 0, otherwise, it returns 1.
3337 */
3338int stats_fill_info(struct field *info, int len)
3339{
3340 unsigned int up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau83061a82018-07-13 11:56:34 +02003341 struct buffer *out = get_trash_chunk();
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003342
3343#ifdef USE_OPENSSL
3344 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
3345 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
3346 int ssl_reuse = 0;
3347
3348 if (ssl_key_rate < ssl_sess_rate) {
3349 /* count the ssl reuse ratio and avoid overflows in both directions */
3350 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
3351 }
3352#endif
3353
3354 if (len < INF_TOTAL_FIELDS)
3355 return 0;
3356
3357 chunk_reset(out);
3358 memset(info, 0, sizeof(*info) * len);
3359
3360 info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME);
Willy Tarreau909b9d82019-01-04 18:20:32 +01003361 info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version);
3362 info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_date);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003363
Yves Lafon95317282018-02-26 11:10:37 +01003364 info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003365 info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
3366 info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid);
3367 info[INF_PID] = mkf_u32(FO_STATUS, pid);
3368
3369 info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out));
3370 chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
3371
3372 info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up);
3373 info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
3374 info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L));
3375 info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L));
3376 info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures());
3377 info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
3378 info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
3379 info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
3380 info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
3381 info[INF_CURR_CONN] = mkf_u32(0, actconn);
3382 info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn);
3383 info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count);
3384#ifdef USE_OPENSSL
3385 info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn);
3386 info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns);
3387 info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns);
3388#endif
3389 info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
3390 info[INF_PIPES_USED] = mkf_u32(0, pipes_used);
3391 info[INF_PIPES_FREE] = mkf_u32(0, pipes_free);
3392 info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
3393 info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
3394 info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max);
3395 info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
3396 info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
3397 info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max);
3398
3399#ifdef USE_OPENSSL
3400 info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate);
3401 info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
3402 info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max);
3403 info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate);
3404 info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
3405 info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse);
3406 info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
3407 info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max);
3408 info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups);
3409 info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses);
3410#endif
3411 info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
3412 info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
3413 info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
3414#ifdef USE_ZLIB
3415 info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory);
3416 info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
3417#endif
3418 info[INF_TASKS] = mkf_u32(0, nb_tasks_cur);
Christopher Faulet34c5cc92016-12-06 09:15:30 +01003419 info[INF_RUN_QUEUE] = mkf_u32(0, tasks_run_queue_cur);
Willy Tarreau81036f22019-05-20 19:24:50 +02003420 info[INF_IDLE_PCT] = mkf_u32(FN_AVG, ti->idle_pct);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003421 info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node);
3422 if (global.desc)
3423 info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003424 info[INF_STOPPING] = mkf_u32(0, stopping);
3425 info[INF_JOBS] = mkf_u32(0, jobs);
William Lallemanda7199262018-11-16 16:57:20 +01003426 info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003427 info[INF_LISTENERS] = mkf_u32(0, listeners);
Willy Tarreau199ad242018-11-05 16:31:22 +01003428 info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers);
Willy Tarreau2d372c22018-11-05 17:12:27 +01003429 info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers);
Willy Tarreau13ef7732018-11-12 07:25:28 +01003430 info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs);
Willy Tarreaubeb859a2018-11-22 18:07:59 +01003431 info[INF_BUSY_POLLING] = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
Baptiste Assmann333939c2019-01-21 08:34:50 +01003432 info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, dns_failed_resolutions);
Willy Tarreau7cf0e452019-05-23 11:39:14 +02003433 info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, global.out_bytes);
3434 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 +01003435
3436 return 1;
3437}
3438
3439/* This function dumps information onto the stream interface's read buffer.
3440 * It returns 0 as long as it does not complete, non-zero upon completion.
3441 * No state is used.
3442 */
3443static int stats_dump_info_to_buffer(struct stream_interface *si)
3444{
3445 struct appctx *appctx = __objt_appctx(si->end);
3446
3447 if (!stats_fill_info(info, INF_TOTAL_FIELDS))
3448 return 0;
3449
3450 chunk_reset(&trash);
3451
3452 if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
3453 stats_dump_typed_info_fields(&trash, info);
Simon Horman05ee2132017-01-04 09:37:25 +01003454 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
3455 stats_dump_json_info_fields(&trash, info);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003456 else
3457 stats_dump_info_fields(&trash, info);
3458
Willy Tarreau06d80a92017-10-19 14:32:15 +02003459 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003460 si_rx_room_blk(si);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003461 return 0;
3462 }
3463
3464 return 1;
3465}
3466
Simon Horman6f6bb382017-01-04 09:37:26 +01003467/* This function dumps the schema onto the stream interface's read buffer.
3468 * It returns 0 as long as it does not complete, non-zero upon completion.
3469 * No state is used.
3470 *
3471 * Integer values bouned to the range [-(2**53)+1, (2**53)-1] as
3472 * per the recommendation for interoperable integers in section 6 of RFC 7159.
3473 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003474static void stats_dump_json_schema(struct buffer *out)
Simon Horman6f6bb382017-01-04 09:37:26 +01003475{
3476
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003477 int old_len = out->data;
Simon Horman6f6bb382017-01-04 09:37:26 +01003478
3479 chunk_strcat(out,
3480 "{"
3481 "\"$schema\":\"http://json-schema.org/draft-04/schema#\","
3482 "\"oneOf\":["
3483 "{"
3484 "\"title\":\"Info\","
3485 "\"type\":\"array\","
3486 "\"items\":{"
3487 "\"properties\":{"
3488 "\"title\":\"InfoItem\","
3489 "\"type\":\"object\","
3490 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3491 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3492 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3493 "\"value\":{\"$ref\":\"#/definitions/typedValue\"}"
3494 "},"
3495 "\"required\":[\"field\",\"processNum\",\"tags\","
3496 "\"value\"]"
3497 "}"
3498 "},"
3499 "{"
3500 "\"title\":\"Stat\","
3501 "\"type\":\"array\","
3502 "\"items\":{"
3503 "\"title\":\"InfoItem\","
3504 "\"type\":\"object\","
3505 "\"properties\":{"
3506 "\"objType\":{"
3507 "\"enum\":[\"Frontend\",\"Backend\",\"Listener\","
3508 "\"Server\",\"Unknown\"]"
3509 "},"
3510 "\"proxyId\":{"
3511 "\"type\":\"integer\","
3512 "\"minimum\":0"
3513 "},"
3514 "\"id\":{"
3515 "\"type\":\"integer\","
3516 "\"minimum\":0"
3517 "},"
3518 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3519 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3520 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3521 "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}"
3522 "},"
3523 "\"required\":[\"objType\",\"proxyId\",\"id\","
3524 "\"field\",\"processNum\",\"tags\","
3525 "\"value\"]"
3526 "}"
3527 "},"
3528 "{"
3529 "\"title\":\"Error\","
3530 "\"type\":\"object\","
3531 "\"properties\":{"
3532 "\"errorStr\":{"
3533 "\"type\":\"string\""
3534 "},"
3535 "\"required\":[\"errorStr\"]"
3536 "}"
3537 "}"
3538 "],"
3539 "\"definitions\":{"
3540 "\"field\":{"
3541 "\"type\":\"object\","
3542 "\"pos\":{"
3543 "\"type\":\"integer\","
3544 "\"minimum\":0"
3545 "},"
3546 "\"name\":{"
3547 "\"type\":\"string\""
3548 "},"
3549 "\"required\":[\"pos\",\"name\"]"
3550 "},"
3551 "\"processNum\":{"
3552 "\"type\":\"integer\","
3553 "\"minimum\":1"
3554 "},"
3555 "\"tags\":{"
3556 "\"type\":\"object\","
3557 "\"origin\":{"
3558 "\"type\":\"string\","
3559 "\"enum\":[\"Metric\",\"Status\",\"Key\","
3560 "\"Config\",\"Product\",\"Unknown\"]"
3561 "},"
3562 "\"nature\":{"
3563 "\"type\":\"string\","
3564 "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\","
3565 "\"Rate\",\"Counter\",\"Duration\","
3566 "\"Age\",\"Time\",\"Name\",\"Output\","
3567 "\"Avg\", \"Unknown\"]"
3568 "},"
3569 "\"scope\":{"
3570 "\"type\":\"string\","
3571 "\"enum\":[\"Cluster\",\"Process\",\"Service\","
3572 "\"System\",\"Unknown\"]"
3573 "},"
3574 "\"required\":[\"origin\",\"nature\",\"scope\"]"
3575 "},"
3576 "\"typedValue\":{"
3577 "\"type\":\"object\","
3578 "\"oneOf\":["
3579 "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"},"
3580 "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"},"
3581 "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"},"
3582 "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"},"
3583 "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}"
3584 "],"
3585 "\"definitions\":{"
3586 "\"s32Value\":{"
3587 "\"properties\":{"
3588 "\"type\":{"
3589 "\"type\":\"string\","
3590 "\"enum\":[\"s32\"]"
3591 "},"
3592 "\"value\":{"
3593 "\"type\":\"integer\","
3594 "\"minimum\":-2147483648,"
3595 "\"maximum\":2147483647"
3596 "}"
3597 "},"
3598 "\"required\":[\"type\",\"value\"]"
3599 "},"
3600 "\"s64Value\":{"
3601 "\"properties\":{"
3602 "\"type\":{"
3603 "\"type\":\"string\","
3604 "\"enum\":[\"s64\"]"
3605 "},"
3606 "\"value\":{"
3607 "\"type\":\"integer\","
3608 "\"minimum\":-9007199254740991,"
3609 "\"maximum\":9007199254740991"
3610 "}"
3611 "},"
3612 "\"required\":[\"type\",\"value\"]"
3613 "},"
3614 "\"u32Value\":{"
3615 "\"properties\":{"
3616 "\"type\":{"
3617 "\"type\":\"string\","
3618 "\"enum\":[\"u32\"]"
3619 "},"
3620 "\"value\":{"
3621 "\"type\":\"integer\","
3622 "\"minimum\":0,"
3623 "\"maximum\":4294967295"
3624 "}"
3625 "},"
3626 "\"required\":[\"type\",\"value\"]"
3627 "},"
3628 "\"u64Value\":{"
3629 "\"properties\":{"
3630 "\"type\":{"
3631 "\"type\":\"string\","
3632 "\"enum\":[\"u64\"]"
3633 "},"
3634 "\"value\":{"
3635 "\"type\":\"integer\","
3636 "\"minimum\":0,"
3637 "\"maximum\":9007199254740991"
3638 "}"
3639 "},"
3640 "\"required\":[\"type\",\"value\"]"
3641 "},"
3642 "\"strValue\":{"
3643 "\"properties\":{"
3644 "\"type\":{"
3645 "\"type\":\"string\","
3646 "\"enum\":[\"str\"]"
3647 "},"
3648 "\"value\":{\"type\":\"string\"}"
3649 "},"
3650 "\"required\":[\"type\",\"value\"]"
3651 "},"
3652 "\"unknownValue\":{"
3653 "\"properties\":{"
3654 "\"type\":{"
3655 "\"type\":\"integer\","
3656 "\"minimum\":0"
3657 "},"
3658 "\"value\":{"
3659 "\"type\":\"string\","
3660 "\"enum\":[\"unknown\"]"
3661 "}"
3662 "},"
3663 "\"required\":[\"type\",\"value\"]"
3664 "}"
3665 "}"
3666 "}"
3667 "}"
3668 "}");
3669
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003670 if (old_len == out->data) {
Simon Horman6f6bb382017-01-04 09:37:26 +01003671 chunk_reset(out);
3672 chunk_appendf(out,
3673 "{\"errorStr\":\"output buffer too short\"}");
3674 }
3675}
3676
3677/* This function dumps the schema onto the stream interface's read buffer.
3678 * It returns 0 as long as it does not complete, non-zero upon completion.
3679 * No state is used.
3680 */
3681static int stats_dump_json_schema_to_buffer(struct stream_interface *si)
3682{
3683 chunk_reset(&trash);
3684
3685 stats_dump_json_schema(&trash);
3686
Willy Tarreau06d80a92017-10-19 14:32:15 +02003687 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003688 si_rx_room_blk(si);
Simon Horman6f6bb382017-01-04 09:37:26 +01003689 return 0;
3690 }
3691
3692 return 1;
3693}
3694
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003695static int cli_parse_clear_counters(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau89d467c2016-11-23 11:02:40 +01003696{
3697 struct proxy *px;
3698 struct server *sv;
3699 struct listener *li;
3700 int clrall = 0;
3701
3702 if (strcmp(args[2], "all") == 0)
3703 clrall = 1;
3704
3705 /* check permissions */
3706 if (!cli_has_level(appctx, ACCESS_LVL_OPER) ||
3707 (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN)))
3708 return 1;
3709
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003710 for (px = proxies_list; px; px = px->next) {
Willy Tarreau89d467c2016-11-23 11:02:40 +01003711 if (clrall) {
3712 memset(&px->be_counters, 0, sizeof(px->be_counters));
3713 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
3714 }
3715 else {
3716 px->be_counters.conn_max = 0;
3717 px->be_counters.p.http.rps_max = 0;
3718 px->be_counters.sps_max = 0;
3719 px->be_counters.cps_max = 0;
3720 px->be_counters.nbpend_max = 0;
3721
3722 px->fe_counters.conn_max = 0;
3723 px->fe_counters.p.http.rps_max = 0;
3724 px->fe_counters.sps_max = 0;
3725 px->fe_counters.cps_max = 0;
Willy Tarreau89d467c2016-11-23 11:02:40 +01003726 }
3727
3728 for (sv = px->srv; sv; sv = sv->next)
3729 if (clrall)
3730 memset(&sv->counters, 0, sizeof(sv->counters));
3731 else {
3732 sv->counters.cur_sess_max = 0;
3733 sv->counters.nbpend_max = 0;
3734 sv->counters.sps_max = 0;
3735 }
3736
3737 list_for_each_entry(li, &px->conf.listeners, by_fe)
3738 if (li->counters) {
3739 if (clrall)
3740 memset(li->counters, 0, sizeof(*li->counters));
3741 else
3742 li->counters->conn_max = 0;
3743 }
3744 }
3745
3746 global.cps_max = 0;
3747 global.sps_max = 0;
Olivier Houchard00bc3cb2017-10-17 19:23:25 +02003748 global.ssl_max = 0;
3749 global.ssl_fe_keys_max = 0;
3750 global.ssl_be_keys_max = 0;
Willy Tarreaud80cb4e2018-01-20 19:30:13 +01003751
3752 memset(activity, 0, sizeof(activity));
Willy Tarreau89d467c2016-11-23 11:02:40 +01003753 return 1;
3754}
3755
3756
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003757static int cli_parse_show_info(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003758{
Willy Tarreaud25fc792016-12-16 12:33:47 +01003759 appctx->ctx.stats.scope_str = 0;
3760 appctx->ctx.stats.scope_len = 0;
3761 appctx->ctx.stats.flags = 0;
3762
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003763 if (strcmp(args[2], "typed") == 0)
3764 appctx->ctx.stats.flags |= STAT_FMT_TYPED;
Simon Horman05ee2132017-01-04 09:37:25 +01003765 else if (strcmp(args[2], "json") == 0)
3766 appctx->ctx.stats.flags |= STAT_FMT_JSON;
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003767 return 0;
3768}
3769
3770
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003771static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau2b812e22016-11-22 16:18:05 +01003772{
Willy Tarreaud25fc792016-12-16 12:33:47 +01003773 appctx->ctx.stats.scope_str = 0;
3774 appctx->ctx.stats.scope_len = 0;
3775 appctx->ctx.stats.flags = 0;
3776
Willy Tarreau2b812e22016-11-22 16:18:05 +01003777 if (*args[2] && *args[3] && *args[4]) {
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003778 struct proxy *px;
3779
3780 px = proxy_find_by_name(args[2], 0, 0);
3781 if (px)
3782 appctx->ctx.stats.iid = px->uuid;
3783 else
3784 appctx->ctx.stats.iid = atoi(args[2]);
3785
Willy Tarreau9d008692019-08-09 11:21:01 +02003786 if (!appctx->ctx.stats.iid)
3787 return cli_err(appctx, "No such proxy.\n");
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003788
Willy Tarreau2b812e22016-11-22 16:18:05 +01003789 appctx->ctx.stats.flags |= STAT_BOUND;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003790 appctx->ctx.stats.type = atoi(args[3]);
3791 appctx->ctx.stats.sid = atoi(args[4]);
3792 if (strcmp(args[5], "typed") == 0)
3793 appctx->ctx.stats.flags |= STAT_FMT_TYPED;
Simon Horman05ee2132017-01-04 09:37:25 +01003794 else if (strcmp(args[5], "json") == 0)
3795 appctx->ctx.stats.flags |= STAT_FMT_JSON;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003796 }
3797 else if (strcmp(args[2], "typed") == 0)
3798 appctx->ctx.stats.flags |= STAT_FMT_TYPED;
Simon Horman05ee2132017-01-04 09:37:25 +01003799 else if (strcmp(args[2], "json") == 0)
3800 appctx->ctx.stats.flags |= STAT_FMT_JSON;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003801
Willy Tarreau2b812e22016-11-22 16:18:05 +01003802 return 0;
3803}
3804
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003805static int cli_io_handler_dump_info(struct appctx *appctx)
3806{
3807 return stats_dump_info_to_buffer(appctx->owner);
3808}
3809
Willy Tarreau2b812e22016-11-22 16:18:05 +01003810/* This I/O handler runs as an applet embedded in a stream interface. It is
3811 * used to send raw stats over a socket.
3812 */
3813static int cli_io_handler_dump_stat(struct appctx *appctx)
3814{
Christopher Fauletef779222018-10-31 08:47:01 +01003815 return stats_dump_stat_to_buffer(appctx->owner, NULL, NULL);
Willy Tarreau2b812e22016-11-22 16:18:05 +01003816}
3817
Simon Horman6f6bb382017-01-04 09:37:26 +01003818static int cli_io_handler_dump_json_schema(struct appctx *appctx)
3819{
3820 return stats_dump_json_schema_to_buffer(appctx->owner);
3821}
3822
Willy Tarreau2b812e22016-11-22 16:18:05 +01003823/* register cli keywords */
3824static struct cli_kw_list cli_kws = {{ },{
Willy Tarreau89d467c2016-11-23 11:02:40 +01003825 { { "clear", "counters", NULL }, "clear counters : clear max statistics counters (add 'all' for all counters)", cli_parse_clear_counters, NULL, NULL },
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003826 { { "show", "info", NULL }, "show info : report information about the running process", cli_parse_show_info, cli_io_handler_dump_info, NULL },
Willy Tarreau2b812e22016-11-22 16:18:05 +01003827 { { "show", "stat", NULL }, "show stat : report counters for each proxy and server", cli_parse_show_stat, cli_io_handler_dump_stat, NULL },
Simon Horman6f6bb382017-01-04 09:37:26 +01003828 { { "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 +01003829 {{},}
3830}};
3831
Willy Tarreau0108d902018-11-25 19:14:37 +01003832INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
3833
William Lallemand74c24fb2016-11-21 17:18:36 +01003834struct applet http_stats_applet = {
3835 .obj_type = OBJ_TYPE_APPLET,
3836 .name = "<STATS>", /* used for logging */
3837 .fct = http_stats_io_handler,
3838 .release = NULL,
3839};
3840
William Lallemand74c24fb2016-11-21 17:18:36 +01003841/*
3842 * Local variables:
3843 * c-indent-level: 8
3844 * c-basic-offset: 8
3845 * End:
3846 */