blob: 823502ff36f502a02c096e69c4bdd83c0a8ac69c [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>
William Lallemand9ed62032016-11-21 17:49:11 +010054#include <proto/stats.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010055#include <proto/fd.h>
56#include <proto/freq_ctr.h>
57#include <proto/frontend.h>
58#include <proto/log.h>
59#include <proto/pattern.h>
60#include <proto/pipe.h>
61#include <proto/listener.h>
62#include <proto/map.h>
Christopher Fauletef779222018-10-31 08:47:01 +010063#include <proto/proto_http.h>
William Lallemand74c24fb2016-11-21 17:18:36 +010064#include <proto/proxy.h>
65#include <proto/sample.h>
66#include <proto/session.h>
67#include <proto/stream.h>
68#include <proto/server.h>
69#include <proto/raw_sock.h>
70#include <proto/stream_interface.h>
71#include <proto/task.h>
72
73#ifdef USE_OPENSSL
74#include <proto/ssl_sock.h>
75#include <types/ssl_sock.h>
76#endif
77
78
Willy Tarreau0baac8c2016-11-22 16:36:53 +010079/* These are the field names for each INF_* field position. Please pay attention
80 * to always use the exact same name except that the strings for new names must
81 * be lower case or CamelCase while the enum entries must be upper case.
82 */
83const char *info_field_names[INF_TOTAL_FIELDS] = {
84 [INF_NAME] = "Name",
85 [INF_VERSION] = "Version",
86 [INF_RELEASE_DATE] = "Release_date",
Yves Lafon95317282018-02-26 11:10:37 +010087 [INF_NBTHREAD] = "Nbthread",
Willy Tarreau0baac8c2016-11-22 16:36:53 +010088 [INF_NBPROC] = "Nbproc",
89 [INF_PROCESS_NUM] = "Process_num",
90 [INF_PID] = "Pid",
91 [INF_UPTIME] = "Uptime",
92 [INF_UPTIME_SEC] = "Uptime_sec",
93 [INF_MEMMAX_MB] = "Memmax_MB",
94 [INF_POOL_ALLOC_MB] = "PoolAlloc_MB",
95 [INF_POOL_USED_MB] = "PoolUsed_MB",
96 [INF_POOL_FAILED] = "PoolFailed",
97 [INF_ULIMIT_N] = "Ulimit-n",
98 [INF_MAXSOCK] = "Maxsock",
99 [INF_MAXCONN] = "Maxconn",
100 [INF_HARD_MAXCONN] = "Hard_maxconn",
101 [INF_CURR_CONN] = "CurrConns",
102 [INF_CUM_CONN] = "CumConns",
103 [INF_CUM_REQ] = "CumReq",
104 [INF_MAX_SSL_CONNS] = "MaxSslConns",
105 [INF_CURR_SSL_CONNS] = "CurrSslConns",
106 [INF_CUM_SSL_CONNS] = "CumSslConns",
107 [INF_MAXPIPES] = "Maxpipes",
108 [INF_PIPES_USED] = "PipesUsed",
109 [INF_PIPES_FREE] = "PipesFree",
110 [INF_CONN_RATE] = "ConnRate",
111 [INF_CONN_RATE_LIMIT] = "ConnRateLimit",
112 [INF_MAX_CONN_RATE] = "MaxConnRate",
113 [INF_SESS_RATE] = "SessRate",
114 [INF_SESS_RATE_LIMIT] = "SessRateLimit",
115 [INF_MAX_SESS_RATE] = "MaxSessRate",
116 [INF_SSL_RATE] = "SslRate",
117 [INF_SSL_RATE_LIMIT] = "SslRateLimit",
118 [INF_MAX_SSL_RATE] = "MaxSslRate",
119 [INF_SSL_FRONTEND_KEY_RATE] = "SslFrontendKeyRate",
120 [INF_SSL_FRONTEND_MAX_KEY_RATE] = "SslFrontendMaxKeyRate",
121 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = "SslFrontendSessionReuse_pct",
122 [INF_SSL_BACKEND_KEY_RATE] = "SslBackendKeyRate",
123 [INF_SSL_BACKEND_MAX_KEY_RATE] = "SslBackendMaxKeyRate",
124 [INF_SSL_CACHE_LOOKUPS] = "SslCacheLookups",
125 [INF_SSL_CACHE_MISSES] = "SslCacheMisses",
126 [INF_COMPRESS_BPS_IN] = "CompressBpsIn",
127 [INF_COMPRESS_BPS_OUT] = "CompressBpsOut",
128 [INF_COMPRESS_BPS_RATE_LIM] = "CompressBpsRateLim",
129 [INF_ZLIB_MEM_USAGE] = "ZlibMemUsage",
130 [INF_MAX_ZLIB_MEM_USAGE] = "MaxZlibMemUsage",
131 [INF_TASKS] = "Tasks",
132 [INF_RUN_QUEUE] = "Run_queue",
133 [INF_IDLE_PCT] = "Idle_pct",
134 [INF_NODE] = "node",
135 [INF_DESCRIPTION] = "description",
Willy Tarreau00098ea2018-11-05 14:38:13 +0100136 [INF_STOPPING] = "Stopping",
137 [INF_JOBS] = "Jobs",
William Lallemanda7199262018-11-16 16:57:20 +0100138 [INF_UNSTOPPABLE_JOBS] = "Unstoppable Jobs",
Willy Tarreau00098ea2018-11-05 14:38:13 +0100139 [INF_LISTENERS] = "Listeners",
Willy Tarreau199ad242018-11-05 16:31:22 +0100140 [INF_ACTIVE_PEERS] = "ActivePeers",
Willy Tarreau2d372c22018-11-05 17:12:27 +0100141 [INF_CONNECTED_PEERS] = "ConnectedPeers",
Willy Tarreau13ef7732018-11-12 07:25:28 +0100142 [INF_DROPPED_LOGS] = "DroppedLogs",
Willy Tarreaubeb859a2018-11-22 18:07:59 +0100143 [INF_BUSY_POLLING] = "BusyPolling",
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100144};
145
William Lallemand74c24fb2016-11-21 17:18:36 +0100146const char *stat_field_names[ST_F_TOTAL_FIELDS] = {
147 [ST_F_PXNAME] = "pxname",
148 [ST_F_SVNAME] = "svname",
149 [ST_F_QCUR] = "qcur",
150 [ST_F_QMAX] = "qmax",
151 [ST_F_SCUR] = "scur",
152 [ST_F_SMAX] = "smax",
153 [ST_F_SLIM] = "slim",
154 [ST_F_STOT] = "stot",
155 [ST_F_BIN] = "bin",
156 [ST_F_BOUT] = "bout",
157 [ST_F_DREQ] = "dreq",
158 [ST_F_DRESP] = "dresp",
159 [ST_F_EREQ] = "ereq",
160 [ST_F_ECON] = "econ",
161 [ST_F_ERESP] = "eresp",
162 [ST_F_WRETR] = "wretr",
163 [ST_F_WREDIS] = "wredis",
164 [ST_F_STATUS] = "status",
165 [ST_F_WEIGHT] = "weight",
166 [ST_F_ACT] = "act",
167 [ST_F_BCK] = "bck",
168 [ST_F_CHKFAIL] = "chkfail",
169 [ST_F_CHKDOWN] = "chkdown",
170 [ST_F_LASTCHG] = "lastchg",
171 [ST_F_DOWNTIME] = "downtime",
172 [ST_F_QLIMIT] = "qlimit",
173 [ST_F_PID] = "pid",
174 [ST_F_IID] = "iid",
175 [ST_F_SID] = "sid",
176 [ST_F_THROTTLE] = "throttle",
177 [ST_F_LBTOT] = "lbtot",
178 [ST_F_TRACKED] = "tracked",
179 [ST_F_TYPE] = "type",
180 [ST_F_RATE] = "rate",
181 [ST_F_RATE_LIM] = "rate_lim",
182 [ST_F_RATE_MAX] = "rate_max",
183 [ST_F_CHECK_STATUS] = "check_status",
184 [ST_F_CHECK_CODE] = "check_code",
185 [ST_F_CHECK_DURATION] = "check_duration",
186 [ST_F_HRSP_1XX] = "hrsp_1xx",
187 [ST_F_HRSP_2XX] = "hrsp_2xx",
188 [ST_F_HRSP_3XX] = "hrsp_3xx",
189 [ST_F_HRSP_4XX] = "hrsp_4xx",
190 [ST_F_HRSP_5XX] = "hrsp_5xx",
191 [ST_F_HRSP_OTHER] = "hrsp_other",
192 [ST_F_HANAFAIL] = "hanafail",
193 [ST_F_REQ_RATE] = "req_rate",
194 [ST_F_REQ_RATE_MAX] = "req_rate_max",
195 [ST_F_REQ_TOT] = "req_tot",
196 [ST_F_CLI_ABRT] = "cli_abrt",
197 [ST_F_SRV_ABRT] = "srv_abrt",
198 [ST_F_COMP_IN] = "comp_in",
199 [ST_F_COMP_OUT] = "comp_out",
200 [ST_F_COMP_BYP] = "comp_byp",
201 [ST_F_COMP_RSP] = "comp_rsp",
202 [ST_F_LASTSESS] = "lastsess",
203 [ST_F_LAST_CHK] = "last_chk",
204 [ST_F_LAST_AGT] = "last_agt",
205 [ST_F_QTIME] = "qtime",
206 [ST_F_CTIME] = "ctime",
207 [ST_F_RTIME] = "rtime",
208 [ST_F_TTIME] = "ttime",
209 [ST_F_AGENT_STATUS] = "agent_status",
210 [ST_F_AGENT_CODE] = "agent_code",
211 [ST_F_AGENT_DURATION] = "agent_duration",
212 [ST_F_CHECK_DESC] = "check_desc",
213 [ST_F_AGENT_DESC] = "agent_desc",
214 [ST_F_CHECK_RISE] = "check_rise",
215 [ST_F_CHECK_FALL] = "check_fall",
216 [ST_F_CHECK_HEALTH] = "check_health",
217 [ST_F_AGENT_RISE] = "agent_rise",
218 [ST_F_AGENT_FALL] = "agent_fall",
219 [ST_F_AGENT_HEALTH] = "agent_health",
220 [ST_F_ADDR] = "addr",
221 [ST_F_COOKIE] = "cookie",
222 [ST_F_MODE] = "mode",
223 [ST_F_ALGO] = "algo",
224 [ST_F_CONN_RATE] = "conn_rate",
225 [ST_F_CONN_RATE_MAX] = "conn_rate_max",
226 [ST_F_CONN_TOT] = "conn_tot",
227 [ST_F_INTERCEPTED] = "intercepted",
228 [ST_F_DCON] = "dcon",
229 [ST_F_DSES] = "dses",
Tim Duesterhus3fd19732018-05-27 20:35:08 +0200230 [ST_F_WREW] = "wrew",
Willy Tarreauf1573842018-12-14 11:35:36 +0100231 [ST_F_CONNECT] = "connect",
232 [ST_F_REUSE] = "reuse",
William Lallemand74c24fb2016-11-21 17:18:36 +0100233};
234
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100235/* one line of info */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100236static THREAD_LOCAL struct field info[INF_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100237/* one line of stats */
Christopher Faulet1bc04c72017-10-29 20:14:08 +0100238static THREAD_LOCAL struct field stats[ST_F_TOTAL_FIELDS];
William Lallemand74c24fb2016-11-21 17:18:36 +0100239
240
Christopher Fauletef779222018-10-31 08:47:01 +0100241static int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk)
242{
243 if (htx) {
244 if (!htx_add_data(htx, ist2(chk->area, chk->data)))
245 return 0;
246 chn->total += chk->data;
247 chk->data = 0;
248 /* notify that some data was read from the SI into the buffer */
249 chn->flags |= CF_READ_PARTIAL;
250 }
251 else {
252 if (ci_putchk(chn, chk) == -1)
253 return 0;
254 }
255 return 1;
256}
Willy Tarreau0baac8c2016-11-22 16:36:53 +0100257
William Lallemand74c24fb2016-11-21 17:18:36 +0100258/*
259 * http_stats_io_handler()
260 * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML
261 * -> stats_dump_csv_header() // emits the CSV headers (same as above)
Simon Horman05ee2132017-01-04 09:37:25 +0100262 * -> stats_dump_json_header() // emits the JSON headers (same as above)
William Lallemand74c24fb2016-11-21 17:18:36 +0100263 * -> stats_dump_html_head() // emits the HTML headers
264 * -> stats_dump_html_info() // emits the equivalent of "show info" at the top
265 * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML
266 * -> stats_dump_html_px_hdr()
267 * -> stats_dump_fe_stats()
268 * -> stats_dump_li_stats()
269 * -> stats_dump_sv_stats()
270 * -> stats_dump_be_stats()
271 * -> stats_dump_html_px_end()
272 * -> stats_dump_html_end() // emits HTML trailer
Simon Horman05ee2132017-01-04 09:37:25 +0100273 * -> stats_dump_json_end() // emits JSON trailer
William Lallemand74c24fb2016-11-21 17:18:36 +0100274 */
275
276
277extern const char *stat_status_codes[];
278
279/* Dumps the stats CSV header to the trash buffer which. The caller is responsible
280 * for clearing it if needed.
281 * NOTE: Some tools happen to rely on the field position instead of its name,
282 * so please only append new fields at the end, never in the middle.
283 */
284static void stats_dump_csv_header()
285{
286 int field;
287
288 chunk_appendf(&trash, "# ");
289 for (field = 0; field < ST_F_TOTAL_FIELDS; field++)
290 chunk_appendf(&trash, "%s,", stat_field_names[field]);
291
292 chunk_appendf(&trash, "\n");
293}
294
295
296/* Emits a stats field without any surrounding element and properly encoded to
297 * resist CSV output. Returns non-zero on success, 0 if the buffer is full.
298 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200299int stats_emit_raw_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100300{
301 switch (field_format(f, 0)) {
302 case FF_EMPTY: return 1;
303 case FF_S32: return chunk_appendf(out, "%d", f->u.s32);
304 case FF_U32: return chunk_appendf(out, "%u", f->u.u32);
305 case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64);
306 case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64);
307 case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL;
308 default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type);
309 }
310}
311
312/* Emits a stats field prefixed with its type. No CSV encoding is prepared, the
313 * output is supposed to be used on its own line. Returns non-zero on success, 0
314 * if the buffer is full.
315 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200316int stats_emit_typed_data_field(struct buffer *out, const struct field *f)
William Lallemand74c24fb2016-11-21 17:18:36 +0100317{
318 switch (field_format(f, 0)) {
319 case FF_EMPTY: return 1;
320 case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32);
321 case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32);
322 case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64);
323 case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64);
324 case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0));
325 default: return chunk_appendf(out, "%08x:?", f->type);
326 }
327}
328
Simon Horman05ee2132017-01-04 09:37:25 +0100329/* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per
330 * the recommendation for interoperable integers in section 6 of RFC 7159.
331 */
332#define JSON_INT_MAX ((1ULL << 53) - 1)
333#define JSON_INT_MIN (0 - JSON_INT_MAX)
334
335/* Emits a stats field value and its type in JSON.
336 * Returns non-zero on success, 0 on error.
337 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200338int stats_emit_json_data_field(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100339{
340 int old_len;
341 char buf[20];
342 const char *type, *value = buf, *quote = "";
343
344 switch (field_format(f, 0)) {
345 case FF_EMPTY: return 1;
346 case FF_S32: type = "\"s32\"";
347 snprintf(buf, sizeof(buf), "%d", f->u.s32);
348 break;
349 case FF_U32: type = "\"u32\"";
350 snprintf(buf, sizeof(buf), "%u", f->u.u32);
351 break;
352 case FF_S64: type = "\"s64\"";
353 if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX)
354 return 0;
355 type = "\"s64\"";
356 snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64);
357 break;
358 case FF_U64: if (f->u.u64 > JSON_INT_MAX)
359 return 0;
360 type = "\"u64\"";
361 snprintf(buf, sizeof(buf), "%llu",
362 (unsigned long long) f->u.u64);
363 break;
364 case FF_STR: type = "\"str\"";
365 value = field_str(f, 0);
366 quote = "\"";
367 break;
368 default: snprintf(buf, sizeof(buf), "%u", f->type);
369 type = buf;
370 value = "unknown";
371 quote = "\"";
372 break;
373 }
374
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200375 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100376 chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}",
377 type, quote, value, quote);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200378 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100379}
380
William Lallemand74c24fb2016-11-21 17:18:36 +0100381/* Emits an encoding of the field type on 3 characters followed by a delimiter.
382 * Returns non-zero on success, 0 if the buffer is full.
383 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200384int stats_emit_field_tags(struct buffer *out, const struct field *f,
385 char delim)
William Lallemand74c24fb2016-11-21 17:18:36 +0100386{
387 char origin, nature, scope;
388
389 switch (field_origin(f, 0)) {
390 case FO_METRIC: origin = 'M'; break;
391 case FO_STATUS: origin = 'S'; break;
392 case FO_KEY: origin = 'K'; break;
393 case FO_CONFIG: origin = 'C'; break;
394 case FO_PRODUCT: origin = 'P'; break;
395 default: origin = '?'; break;
396 }
397
398 switch (field_nature(f, 0)) {
399 case FN_GAUGE: nature = 'G'; break;
400 case FN_LIMIT: nature = 'L'; break;
401 case FN_MIN: nature = 'm'; break;
402 case FN_MAX: nature = 'M'; break;
403 case FN_RATE: nature = 'R'; break;
404 case FN_COUNTER: nature = 'C'; break;
405 case FN_DURATION: nature = 'D'; break;
406 case FN_AGE: nature = 'A'; break;
407 case FN_TIME: nature = 'T'; break;
408 case FN_NAME: nature = 'N'; break;
409 case FN_OUTPUT: nature = 'O'; break;
410 case FN_AVG: nature = 'a'; break;
411 default: nature = '?'; break;
412 }
413
414 switch (field_scope(f, 0)) {
415 case FS_PROCESS: scope = 'P'; break;
416 case FS_SERVICE: scope = 'S'; break;
417 case FS_SYSTEM: scope = 's'; break;
418 case FS_CLUSTER: scope = 'C'; break;
419 default: scope = '?'; break;
420 }
421
422 return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim);
423}
424
Simon Horman05ee2132017-01-04 09:37:25 +0100425/* Emits an encoding of the field type as JSON.
426 * Returns non-zero on success, 0 if the buffer is full.
427 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200428int stats_emit_json_field_tags(struct buffer *out, const struct field *f)
Simon Horman05ee2132017-01-04 09:37:25 +0100429{
430 const char *origin, *nature, *scope;
431 int old_len;
432
433 switch (field_origin(f, 0)) {
434 case FO_METRIC: origin = "Metric"; break;
435 case FO_STATUS: origin = "Status"; break;
436 case FO_KEY: origin = "Key"; break;
437 case FO_CONFIG: origin = "Config"; break;
438 case FO_PRODUCT: origin = "Product"; break;
439 default: origin = "Unknown"; break;
440 }
441
442 switch (field_nature(f, 0)) {
443 case FN_GAUGE: nature = "Gauge"; break;
444 case FN_LIMIT: nature = "Limit"; break;
445 case FN_MIN: nature = "Min"; break;
446 case FN_MAX: nature = "Max"; break;
447 case FN_RATE: nature = "Rate"; break;
448 case FN_COUNTER: nature = "Counter"; break;
449 case FN_DURATION: nature = "Duration"; break;
450 case FN_AGE: nature = "Age"; break;
451 case FN_TIME: nature = "Time"; break;
452 case FN_NAME: nature = "Name"; break;
453 case FN_OUTPUT: nature = "Output"; break;
454 case FN_AVG: nature = "Avg"; break;
455 default: nature = "Unknown"; break;
456 }
457
458 switch (field_scope(f, 0)) {
459 case FS_PROCESS: scope = "Process"; break;
460 case FS_SERVICE: scope = "Service"; break;
461 case FS_SYSTEM: scope = "System"; break;
462 case FS_CLUSTER: scope = "Cluster"; break;
463 default: scope = "Unknown"; break;
464 }
465
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200466 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100467 chunk_appendf(out, "\"tags\":{"
468 "\"origin\":\"%s\","
469 "\"nature\":\"%s\","
470 "\"scope\":\"%s\""
471 "}", origin, nature, scope);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200472 return !(old_len == out->data);
Simon Horman05ee2132017-01-04 09:37:25 +0100473}
William Lallemand74c24fb2016-11-21 17:18:36 +0100474
475/* Dump all fields from <stats> into <out> using CSV format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200476static int stats_dump_fields_csv(struct buffer *out,
477 const struct field *stats)
William Lallemand74c24fb2016-11-21 17:18:36 +0100478{
479 int field;
480
481 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
482 if (!stats_emit_raw_data_field(out, &stats[field]))
483 return 0;
484 if (!chunk_strcat(out, ","))
485 return 0;
486 }
487 chunk_strcat(out, "\n");
488 return 1;
489}
490
491/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200492static int stats_dump_fields_typed(struct buffer *out,
493 const struct field *stats)
William Lallemand74c24fb2016-11-21 17:18:36 +0100494{
495 int field;
496
497 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
498 if (!stats[field].type)
499 continue;
500
501 chunk_appendf(out, "%c.%u.%u.%d.%s.%u:",
502 stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' :
503 stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' :
504 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' :
505 stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' :
506 '?',
507 stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32,
508 field, stat_field_names[field], stats[ST_F_PID].u.u32);
509
510 if (!stats_emit_field_tags(out, &stats[field], ':'))
511 return 0;
512 if (!stats_emit_typed_data_field(out, &stats[field]))
513 return 0;
514 if (!chunk_strcat(out, "\n"))
515 return 0;
516 }
517 return 1;
518}
519
Simon Horman05ee2132017-01-04 09:37:25 +0100520/* Dump all fields from <stats> into <out> using the "show info json" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200521static int stats_dump_json_info_fields(struct buffer *out,
Simon Horman05ee2132017-01-04 09:37:25 +0100522 const struct field *info)
523{
524 int field;
525 int started = 0;
526
527 if (!chunk_strcat(out, "["))
528 return 0;
529
530 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
531 int old_len;
532
533 if (!field_format(info, field))
534 continue;
535
536 if (started && !chunk_strcat(out, ","))
537 goto err;
538 started = 1;
539
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200540 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100541 chunk_appendf(out,
542 "{\"field\":{\"pos\":%d,\"name\":\"%s\"},"
543 "\"processNum\":%u,",
544 field, info_field_names[field],
545 info[INF_PROCESS_NUM].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200546 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100547 goto err;
548
549 if (!stats_emit_json_field_tags(out, &info[field]))
550 goto err;
551
552 if (!stats_emit_json_data_field(out, &info[field]))
553 goto err;
554
555 if (!chunk_strcat(out, "}"))
556 goto err;
557 }
558
559 if (!chunk_strcat(out, "]"))
560 goto err;
561 return 1;
562
563err:
564 chunk_reset(out);
565 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
566 return 0;
567}
568
569/* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */
Willy Tarreau83061a82018-07-13 11:56:34 +0200570static int stats_dump_fields_json(struct buffer *out,
571 const struct field *stats,
Simon Horman05ee2132017-01-04 09:37:25 +0100572 int first_stat)
573{
574 int field;
575 int started = 0;
576
577 if (!first_stat && !chunk_strcat(out, ","))
578 return 0;
579 if (!chunk_strcat(out, "["))
580 return 0;
581
582 for (field = 0; field < ST_F_TOTAL_FIELDS; field++) {
583 const char *obj_type;
584 int old_len;
585
586 if (!stats[field].type)
587 continue;
588
589 if (started && !chunk_strcat(out, ","))
590 goto err;
591 started = 1;
592
593 switch (stats[ST_F_TYPE].u.u32) {
594 case STATS_TYPE_FE: obj_type = "Frontend"; break;
595 case STATS_TYPE_BE: obj_type = "Backend"; break;
596 case STATS_TYPE_SO: obj_type = "Listener"; break;
597 case STATS_TYPE_SV: obj_type = "Server"; break;
598 default: obj_type = "Unknown"; break;
599 }
600
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200601 old_len = out->data;
Simon Horman05ee2132017-01-04 09:37:25 +0100602 chunk_appendf(out,
603 "{"
604 "\"objType\":\"%s\","
605 "\"proxyId\":%d,"
606 "\"id\":%d,"
607 "\"field\":{\"pos\":%d,\"name\":\"%s\"},"
608 "\"processNum\":%u,",
609 obj_type, stats[ST_F_IID].u.u32,
610 stats[ST_F_SID].u.u32, field,
611 stat_field_names[field], stats[ST_F_PID].u.u32);
Willy Tarreau843b7cb2018-07-13 10:54:26 +0200612 if (old_len == out->data)
Simon Horman05ee2132017-01-04 09:37:25 +0100613 goto err;
614
615 if (!stats_emit_json_field_tags(out, &stats[field]))
616 goto err;
617
618 if (!stats_emit_json_data_field(out, &stats[field]))
619 goto err;
620
621 if (!chunk_strcat(out, "}"))
622 goto err;
623 }
624
625 if (!chunk_strcat(out, "]"))
626 goto err;
627
628 return 1;
629
630err:
631 chunk_reset(out);
632 if (!first_stat)
633 chunk_strcat(out, ",");
634 chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}");
635 return 0;
636}
637
William Lallemand74c24fb2016-11-21 17:18:36 +0100638/* Dump all fields from <stats> into <out> using the HTML format. A column is
639 * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info
640 * are provided if ST_SHLGNDS is present in <flags>.
641 */
Willy Tarreau83061a82018-07-13 11:56:34 +0200642static int stats_dump_fields_html(struct buffer *out,
643 const struct field *stats,
644 unsigned int flags)
William Lallemand74c24fb2016-11-21 17:18:36 +0100645{
Willy Tarreau83061a82018-07-13 11:56:34 +0200646 struct buffer src;
William Lallemand74c24fb2016-11-21 17:18:36 +0100647
648 if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) {
649 chunk_appendf(out,
650 /* name, queue */
651 "<tr class=\"frontend\">");
652
653 if (flags & ST_SHOWADMIN) {
654 /* Column sub-heading for Enable or Disable server */
655 chunk_appendf(out, "<td></td>");
656 }
657
658 chunk_appendf(out,
659 "<td class=ac>"
660 "<a name=\"%s/Frontend\"></a>"
661 "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>"
662 "<td colspan=3></td>"
663 "",
664 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
665
666 chunk_appendf(out,
667 /* sessions rate : current */
668 "<td><u>%s<div class=tips><table class=det>"
669 "<tr><th>Current connection rate:</th><td>%s/s</td></tr>"
670 "<tr><th>Current session rate:</th><td>%s/s</td></tr>"
671 "",
672 U2H(stats[ST_F_RATE].u.u32),
673 U2H(stats[ST_F_CONN_RATE].u.u32),
674 U2H(stats[ST_F_RATE].u.u32));
675
676 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
677 chunk_appendf(out,
678 "<tr><th>Current request rate:</th><td>%s/s</td></tr>",
679 U2H(stats[ST_F_REQ_RATE].u.u32));
680
681 chunk_appendf(out,
682 "</table></div></u></td>"
683 /* sessions rate : max */
684 "<td><u>%s<div class=tips><table class=det>"
685 "<tr><th>Max connection rate:</th><td>%s/s</td></tr>"
686 "<tr><th>Max session rate:</th><td>%s/s</td></tr>"
687 "",
688 U2H(stats[ST_F_RATE_MAX].u.u32),
689 U2H(stats[ST_F_CONN_RATE_MAX].u.u32),
690 U2H(stats[ST_F_RATE_MAX].u.u32));
691
692 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
693 chunk_appendf(out,
694 "<tr><th>Max request rate:</th><td>%s/s</td></tr>",
695 U2H(stats[ST_F_REQ_RATE_MAX].u.u32));
696
697 chunk_appendf(out,
698 "</table></div></u></td>"
699 /* sessions rate : limit */
700 "<td>%s</td>",
701 LIM2A(stats[ST_F_RATE_LIM].u.u32, "-"));
702
703 chunk_appendf(out,
704 /* sessions: current, max, limit, total */
705 "<td>%s</td><td>%s</td><td>%s</td>"
706 "<td><u>%s<div class=tips><table class=det>"
707 "<tr><th>Cum. connections:</th><td>%s</td></tr>"
708 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
709 "",
710 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
711 U2H(stats[ST_F_STOT].u.u64),
712 U2H(stats[ST_F_CONN_TOT].u.u64),
713 U2H(stats[ST_F_STOT].u.u64));
714
715 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
716 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
717 chunk_appendf(out,
718 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
719 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
720 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
721 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
722 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
723 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
724 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
725 "<tr><th>- other responses:</th><td>%s</td></tr>"
726 "<tr><th>Intercepted requests:</th><td>%s</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200727 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100728 "",
729 U2H(stats[ST_F_REQ_TOT].u.u64),
730 U2H(stats[ST_F_HRSP_1XX].u.u64),
731 U2H(stats[ST_F_HRSP_2XX].u.u64),
732 U2H(stats[ST_F_COMP_RSP].u.u64),
733 stats[ST_F_HRSP_2XX].u.u64 ?
734 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
735 U2H(stats[ST_F_HRSP_3XX].u.u64),
736 U2H(stats[ST_F_HRSP_4XX].u.u64),
737 U2H(stats[ST_F_HRSP_5XX].u.u64),
738 U2H(stats[ST_F_HRSP_OTHER].u.u64),
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200739 U2H(stats[ST_F_INTERCEPTED].u.u64),
740 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +0100741 }
742
743 chunk_appendf(out,
744 "</table></div></u></td>"
745 /* sessions: lbtot, lastsess */
746 "<td></td><td></td>"
747 /* bytes : in */
748 "<td>%s</td>"
749 "",
750 U2H(stats[ST_F_BIN].u.u64));
751
752 chunk_appendf(out,
753 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
754 "<td>%s%s<div class=tips><table class=det>"
755 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
756 "<tr><th>Compression in:</th><td>%s</td></tr>"
757 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
758 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
759 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
760 "</table></div>%s</td>",
761 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
762 U2H(stats[ST_F_BOUT].u.u64),
763 U2H(stats[ST_F_BOUT].u.u64),
764 U2H(stats[ST_F_COMP_IN].u.u64),
765 U2H(stats[ST_F_COMP_OUT].u.u64),
766 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
767 U2H(stats[ST_F_COMP_BYP].u.u64),
768 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
769 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,
770 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
771
772 chunk_appendf(out,
773 /* denied: req, resp */
774 "<td>%s</td><td>%s</td>"
775 /* errors : request, connect, response */
776 "<td>%s</td><td></td><td></td>"
777 /* warnings: retries, redispatches */
778 "<td></td><td></td>"
779 /* server status : reflect frontend status */
780 "<td class=ac>%s</td>"
781 /* rest of server: nothing */
782 "<td class=ac colspan=8></td></tr>"
783 "",
784 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
785 U2H(stats[ST_F_EREQ].u.u64),
786 field_str(stats, ST_F_STATUS));
787 }
788 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) {
789 chunk_appendf(out, "<tr class=socket>");
790 if (flags & ST_SHOWADMIN) {
791 /* Column sub-heading for Enable or Disable server */
792 chunk_appendf(out, "<td></td>");
793 }
794
795 chunk_appendf(out,
796 /* frontend name, listener name */
797 "<td class=ac><a name=\"%s/+%s\"></a>%s"
798 "<a class=lfsb href=\"#%s/+%s\">%s</a>"
799 "",
800 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
801 (flags & ST_SHLGNDS)?"<u>":"",
802 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
803
804 if (flags & ST_SHLGNDS) {
805 chunk_appendf(out, "<div class=tips>");
806
807 if (isdigit(*field_str(stats, ST_F_ADDR)))
808 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
809 else if (*field_str(stats, ST_F_ADDR) == '[')
810 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
811 else if (*field_str(stats, ST_F_ADDR))
812 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
813
814 /* id */
815 chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32);
816 }
817
818 chunk_appendf(out,
819 /* queue */
820 "%s</td><td colspan=3></td>"
821 /* sessions rate: current, max, limit */
822 "<td colspan=3>&nbsp;</td>"
823 /* sessions: current, max, limit, total, lbtot, lastsess */
824 "<td>%s</td><td>%s</td><td>%s</td>"
825 "<td>%s</td><td>&nbsp;</td><td>&nbsp;</td>"
826 /* bytes: in, out */
827 "<td>%s</td><td>%s</td>"
828 "",
829 (flags & ST_SHLGNDS)?"</u>":"",
830 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32),
831 U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64));
832
833 chunk_appendf(out,
834 /* denied: req, resp */
835 "<td>%s</td><td>%s</td>"
836 /* errors: request, connect, response */
837 "<td>%s</td><td></td><td></td>"
838 /* warnings: retries, redispatches */
839 "<td></td><td></td>"
840 /* server status: reflect listener status */
841 "<td class=ac>%s</td>"
842 /* rest of server: nothing */
843 "<td class=ac colspan=8></td></tr>"
844 "",
845 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
846 U2H(stats[ST_F_EREQ].u.u64),
847 field_str(stats, ST_F_STATUS));
848 }
849 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) {
850 const char *style;
851
852 /* determine the style to use depending on the server's state,
853 * its health and weight. There isn't a 1-to-1 mapping between
854 * state and styles for the cases where the server is (still)
855 * up. The reason is that we don't want to report nolb and
856 * drain with the same color.
857 */
858
859 if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 ||
860 strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) {
861 style = "down";
862 }
863 else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) {
864 style = "going_up";
865 }
866 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) {
867 style = "going_down";
868 }
869 else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) {
870 style = "nolb";
871 }
872 else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) {
873 style = "no_check";
874 }
875 else if (!stats[ST_F_CHKFAIL].type ||
876 stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) {
877 /* no check or max health = UP */
878 if (stats[ST_F_WEIGHT].u.u32)
879 style = "up";
880 else
881 style = "draining";
882 }
883 else {
884 style = "going_down";
885 }
886
887 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0)
888 chunk_appendf(out, "<tr class=\"maintain\">");
889 else
890 chunk_appendf(out,
891 "<tr class=\"%s_%s\">",
892 (stats[ST_F_BCK].u.u32) ? "backup" : "active", style);
893
894
895 if (flags & ST_SHOWADMIN)
896 chunk_appendf(out,
David Harrigand3db35a2016-12-30 12:12:49 +0000897 "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>",
898 field_str(stats, ST_F_PXNAME),
William Lallemand74c24fb2016-11-21 17:18:36 +0100899 field_str(stats, ST_F_SVNAME));
900
901 chunk_appendf(out,
902 "<td class=ac><a name=\"%s/%s\"></a>%s"
903 "<a class=lfsb href=\"#%s/%s\">%s</a>"
904 "",
905 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME),
906 (flags & ST_SHLGNDS) ? "<u>" : "",
907 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME));
908
909 if (flags & ST_SHLGNDS) {
910 chunk_appendf(out, "<div class=tips>");
911
912 if (isdigit(*field_str(stats, ST_F_ADDR)))
913 chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR));
914 else if (*field_str(stats, ST_F_ADDR) == '[')
915 chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR));
916 else if (*field_str(stats, ST_F_ADDR))
917 chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR));
918
919 /* id */
920 chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32);
921
922 /* cookie */
923 if (stats[ST_F_COOKIE].type) {
924 chunk_appendf(out, ", cookie: '");
925 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
926 chunk_htmlencode(out, &src);
927 chunk_appendf(out, "'");
928 }
929
930 chunk_appendf(out, "</div>");
931 }
932
933 chunk_appendf(out,
934 /* queue : current, max, limit */
935 "%s</td><td>%s</td><td>%s</td><td>%s</td>"
936 /* sessions rate : current, max, limit */
937 "<td>%s</td><td>%s</td><td></td>"
938 "",
939 (flags & ST_SHLGNDS) ? "</u>" : "",
940 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"),
941 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
942
943 chunk_appendf(out,
944 /* sessions: current, max, limit, total */
945 "<td>%s</td><td>%s</td><td>%s</td>"
946 "<td><u>%s<div class=tips><table class=det>"
947 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
948 "",
949 U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"),
950 U2H(stats[ST_F_STOT].u.u64),
951 U2H(stats[ST_F_STOT].u.u64));
952
953 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
954 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
955 unsigned long long tot;
956
957 tot = stats[ST_F_HRSP_OTHER].u.u64;
958 tot += stats[ST_F_HRSP_1XX].u.u64;
959 tot += stats[ST_F_HRSP_2XX].u.u64;
960 tot += stats[ST_F_HRSP_3XX].u.u64;
961 tot += stats[ST_F_HRSP_4XX].u.u64;
962 tot += stats[ST_F_HRSP_5XX].u.u64;
963
964 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +0100965 "<tr><th>New connections:</th><td>%s</td></tr>"
966 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100967 "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>"
968 "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
969 "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
970 "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
971 "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
972 "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>"
973 "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +0200974 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +0100975 "",
Willy Tarreauf1573842018-12-14 11:35:36 +0100976 U2H(stats[ST_F_CONNECT].u.u64),
977 U2H(stats[ST_F_REUSE].u.u64),
978 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
979 (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 +0100980 U2H(tot),
981 U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0,
982 U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0,
983 U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0,
984 U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0,
985 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 +0200986 U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0,
987 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +0100988 }
989
990 chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>");
991 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
992 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
993 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
994 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
995 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
996
997 chunk_appendf(out,
998 "</table></div></u></td>"
999 /* sessions: lbtot, last */
1000 "<td>%s</td><td>%s</td>",
1001 U2H(stats[ST_F_LBTOT].u.u64),
1002 human_time(stats[ST_F_LASTSESS].u.s32, 1));
1003
1004 chunk_appendf(out,
1005 /* bytes : in, out */
1006 "<td>%s</td><td>%s</td>"
1007 /* denied: req, resp */
1008 "<td></td><td>%s</td>"
1009 /* errors : request, connect */
1010 "<td></td><td>%s</td>"
1011 /* errors : response */
1012 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1013 /* warnings: retries, redispatches */
1014 "<td>%lld</td><td>%lld</td>"
1015 "",
1016 U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64),
1017 U2H(stats[ST_F_DRESP].u.u64),
1018 U2H(stats[ST_F_ECON].u.u64),
1019 U2H(stats[ST_F_ERESP].u.u64),
1020 (long long)stats[ST_F_CLI_ABRT].u.u64,
1021 (long long)stats[ST_F_SRV_ABRT].u.u64,
1022 (long long)stats[ST_F_WRETR].u.u64,
1023 (long long)stats[ST_F_WREDIS].u.u64);
1024
1025 /* status, last change */
1026 chunk_appendf(out, "<td class=ac>");
1027
1028 /* FIXME!!!!
1029 * LASTCHG should contain the last change for *this* server and must be computed
1030 * properly above, as was done below, ie: this server if maint, otherwise ref server
1031 * if tracking. Note that ref is either local or remote depending on tracking.
1032 */
1033
1034
1035 if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) {
1036 chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1));
1037 }
1038 else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) {
1039 chunk_strcat(out, "<i>no check</i>");
1040 }
1041 else {
1042 chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS));
1043 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) {
1044 if (stats[ST_F_CHECK_HEALTH].u.u32)
1045 chunk_strcat(out, " &uarr;");
1046 }
1047 else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1)
1048 chunk_strcat(out, " &darr;");
1049 }
1050
1051 if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 &&
1052 stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) {
1053 chunk_appendf(out,
1054 "</td><td class=ac><u> %s",
1055 field_str(stats, ST_F_AGENT_STATUS));
1056
1057 if (stats[ST_F_AGENT_CODE].type)
1058 chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32);
1059
1060 if (stats[ST_F_AGENT_DURATION].type)
1061 chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64);
1062
1063 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC));
1064
1065 if (*field_str(stats, ST_F_LAST_AGT)) {
1066 chunk_appendf(out, ": ");
1067 chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT));
1068 chunk_htmlencode(out, &src);
1069 }
1070 chunk_appendf(out, "</div></u>");
1071 }
1072 else if (stats[ST_F_CHECK_STATUS].type) {
1073 chunk_appendf(out,
1074 "</td><td class=ac><u> %s",
1075 field_str(stats, ST_F_CHECK_STATUS));
1076
1077 if (stats[ST_F_CHECK_CODE].type)
1078 chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32);
1079
1080 if (stats[ST_F_CHECK_DURATION].type)
1081 chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64);
1082
1083 chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC));
1084
1085 if (*field_str(stats, ST_F_LAST_CHK)) {
1086 chunk_appendf(out, ": ");
1087 chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK));
1088 chunk_htmlencode(out, &src);
1089 }
1090 chunk_appendf(out, "</div></u>");
1091 }
1092 else
1093 chunk_appendf(out, "</td><td>");
1094
1095 chunk_appendf(out,
1096 /* weight */
1097 "</td><td class=ac>%d</td>"
1098 /* act, bck */
1099 "<td class=ac>%s</td><td class=ac>%s</td>"
1100 "",
1101 stats[ST_F_WEIGHT].u.u32,
1102 stats[ST_F_BCK].u.u32 ? "-" : "Y",
1103 stats[ST_F_BCK].u.u32 ? "Y" : "-");
1104
1105 /* check failures: unique, fatal, down time */
1106 if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) {
1107 chunk_appendf(out, "<td class=ac colspan=3>resolution</td>");
1108 }
1109 else if (stats[ST_F_CHKFAIL].type) {
1110 chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64);
1111
1112 if (stats[ST_F_HANAFAIL].type)
1113 chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64);
1114
1115 chunk_appendf(out,
1116 "<div class=tips>Failed Health Checks%s</div></u></td>"
1117 "<td>%lld</td><td>%s</td>"
1118 "",
1119 stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "",
1120 (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1));
1121 }
1122 else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) {
1123 /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */
1124 chunk_appendf(out,
1125 "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>",
1126 field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED));
1127 }
1128 else
1129 chunk_appendf(out, "<td colspan=3></td>");
1130
1131 /* throttle */
1132 if (stats[ST_F_THROTTLE].type)
1133 chunk_appendf(out, "<td class=ac>%d %%</td></tr>\n", stats[ST_F_THROTTLE].u.u32);
1134 else
1135 chunk_appendf(out, "<td class=ac>-</td></tr>\n");
1136 }
1137 else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) {
1138 chunk_appendf(out, "<tr class=\"backend\">");
1139 if (flags & ST_SHOWADMIN) {
1140 /* Column sub-heading for Enable or Disable server */
1141 chunk_appendf(out, "<td></td>");
1142 }
1143 chunk_appendf(out,
1144 "<td class=ac>"
1145 /* name */
1146 "%s<a name=\"%s/Backend\"></a>"
1147 "<a class=lfsb href=\"#%s/Backend\">Backend</a>"
1148 "",
1149 (flags & ST_SHLGNDS)?"<u>":"",
1150 field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME));
1151
1152 if (flags & ST_SHLGNDS) {
1153 /* balancing */
1154 chunk_appendf(out, "<div class=tips>balancing: %s",
1155 field_str(stats, ST_F_ALGO));
1156
1157 /* cookie */
1158 if (stats[ST_F_COOKIE].type) {
1159 chunk_appendf(out, ", cookie: '");
1160 chunk_initstr(&src, field_str(stats, ST_F_COOKIE));
1161 chunk_htmlencode(out, &src);
1162 chunk_appendf(out, "'");
1163 }
1164 chunk_appendf(out, "</div>");
1165 }
1166
1167 chunk_appendf(out,
1168 "%s</td>"
1169 /* queue : current, max */
1170 "<td>%s</td><td>%s</td><td></td>"
1171 /* sessions rate : current, max, limit */
1172 "<td>%s</td><td>%s</td><td></td>"
1173 "",
1174 (flags & ST_SHLGNDS)?"</u>":"",
1175 U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32),
1176 U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32));
1177
1178 chunk_appendf(out,
1179 /* sessions: current, max, limit, total */
1180 "<td>%s</td><td>%s</td><td>%s</td>"
1181 "<td><u>%s<div class=tips><table class=det>"
1182 "<tr><th>Cum. sessions:</th><td>%s</td></tr>"
1183 "",
Willy Tarreau8e0f1752016-12-12 15:07:29 +01001184 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 +01001185 U2H(stats[ST_F_STOT].u.u64),
1186 U2H(stats[ST_F_STOT].u.u64));
1187
1188 /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */
1189 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) {
1190 chunk_appendf(out,
Willy Tarreauf1573842018-12-14 11:35:36 +01001191 "<tr><th>New connections:</th><td>%s</td></tr>"
1192 "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001193 "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>"
1194 "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>"
1195 "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>"
1196 "<tr><th>&nbsp;&nbsp;Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>"
1197 "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>"
1198 "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>"
1199 "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>"
1200 "<tr><th>- other responses:</th><td>%s</td></tr>"
Willy Tarreau1b0f85e2018-05-28 15:12:40 +02001201 "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>"
William Lallemand74c24fb2016-11-21 17:18:36 +01001202 "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"
1203 "",
Willy Tarreauf1573842018-12-14 11:35:36 +01001204 U2H(stats[ST_F_CONNECT].u.u64),
1205 U2H(stats[ST_F_REUSE].u.u64),
1206 (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ?
1207 (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 +01001208 U2H(stats[ST_F_REQ_TOT].u.u64),
1209 U2H(stats[ST_F_HRSP_1XX].u.u64),
1210 U2H(stats[ST_F_HRSP_2XX].u.u64),
1211 U2H(stats[ST_F_COMP_RSP].u.u64),
1212 stats[ST_F_HRSP_2XX].u.u64 ?
1213 (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0,
1214 U2H(stats[ST_F_HRSP_3XX].u.u64),
1215 U2H(stats[ST_F_HRSP_4XX].u.u64),
1216 U2H(stats[ST_F_HRSP_5XX].u.u64),
Willy Tarreaufeead3a2018-12-14 13:48:44 +01001217 U2H(stats[ST_F_HRSP_OTHER].u.u64),
1218 U2H(stats[ST_F_WREW].u.u64));
William Lallemand74c24fb2016-11-21 17:18:36 +01001219 }
1220
1221 chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32));
1222 chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32));
1223 if (strcmp(field_str(stats, ST_F_MODE), "http") == 0)
1224 chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32));
1225 chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32));
1226
1227 chunk_appendf(out,
1228 "</table></div></u></td>"
1229 /* sessions: lbtot, last */
1230 "<td>%s</td><td>%s</td>"
1231 /* bytes: in */
1232 "<td>%s</td>"
1233 "",
1234 U2H(stats[ST_F_LBTOT].u.u64),
1235 human_time(stats[ST_F_LASTSESS].u.s32, 1),
1236 U2H(stats[ST_F_BIN].u.u64));
1237
1238 chunk_appendf(out,
1239 /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */
1240 "<td>%s%s<div class=tips><table class=det>"
1241 "<tr><th>Response bytes in:</th><td>%s</td></tr>"
1242 "<tr><th>Compression in:</th><td>%s</td></tr>"
1243 "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>"
1244 "<tr><th>Compression bypass:</th><td>%s</td></tr>"
1245 "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>"
1246 "</table></div>%s</td>",
1247 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"",
1248 U2H(stats[ST_F_BOUT].u.u64),
1249 U2H(stats[ST_F_BOUT].u.u64),
1250 U2H(stats[ST_F_COMP_IN].u.u64),
1251 U2H(stats[ST_F_COMP_OUT].u.u64),
1252 stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0,
1253 U2H(stats[ST_F_COMP_BYP].u.u64),
1254 U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64),
1255 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,
1256 (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":"");
1257
1258 chunk_appendf(out,
1259 /* denied: req, resp */
1260 "<td>%s</td><td>%s</td>"
1261 /* errors : request, connect */
1262 "<td></td><td>%s</td>"
1263 /* errors : response */
1264 "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>"
1265 /* warnings: retries, redispatches */
1266 "<td>%lld</td><td>%lld</td>"
1267 /* backend status: reflect backend status (up/down): we display UP
1268 * if the backend has known working servers or if it has no server at
1269 * all (eg: for stats). Then we display the total weight, number of
1270 * active and backups. */
1271 "<td class=ac>%s %s</td><td class=ac>&nbsp;</td><td class=ac>%d</td>"
1272 "<td class=ac>%d</td><td class=ac>%d</td>"
1273 "",
1274 U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64),
1275 U2H(stats[ST_F_ECON].u.u64),
1276 U2H(stats[ST_F_ERESP].u.u64),
1277 (long long)stats[ST_F_CLI_ABRT].u.u64,
1278 (long long)stats[ST_F_SRV_ABRT].u.u64,
1279 (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64,
1280 human_time(stats[ST_F_LASTCHG].u.u32, 1),
1281 strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>",
1282 stats[ST_F_WEIGHT].u.u32,
1283 stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32);
1284
1285 chunk_appendf(out,
1286 /* rest of backend: nothing, down transitions, total downtime, throttle */
1287 "<td class=ac>&nbsp;</td><td>%d</td>"
1288 "<td>%s</td>"
1289 "<td></td>"
1290 "</tr>",
1291 stats[ST_F_CHKDOWN].u.u32,
1292 stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : "&nbsp;");
1293 }
1294 return 1;
1295}
1296
1297int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx)
1298{
Simon Horman05ee2132017-01-04 09:37:25 +01001299 int ret;
1300
William Lallemand74c24fb2016-11-21 17:18:36 +01001301 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN))
1302 flags |= ST_SHOWADMIN;
1303
1304 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
Simon Horman05ee2132017-01-04 09:37:25 +01001305 ret = stats_dump_fields_html(&trash, stats, flags);
William Lallemand74c24fb2016-11-21 17:18:36 +01001306 else if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
Simon Horman05ee2132017-01-04 09:37:25 +01001307 ret = stats_dump_fields_typed(&trash, stats);
1308 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
1309 ret = stats_dump_fields_json(&trash, stats,
1310 !(appctx->ctx.stats.flags &
1311 STAT_STARTED));
William Lallemand74c24fb2016-11-21 17:18:36 +01001312 else
Simon Horman05ee2132017-01-04 09:37:25 +01001313 ret = stats_dump_fields_csv(&trash, stats);
1314
1315 if (ret)
1316 appctx->ctx.stats.flags |= STAT_STARTED;
1317
1318 return ret;
William Lallemand74c24fb2016-11-21 17:18:36 +01001319}
1320
1321/* Fill <stats> with the frontend statistics. <stats> is
1322 * preallocated array of length <len>. The length of the array
1323 * must be at least ST_F_TOTAL_FIELDS. If this length is less then
1324 * this value, the function returns 0, otherwise, it returns 1.
1325 */
1326int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len)
1327{
1328 if (len < ST_F_TOTAL_FIELDS)
1329 return 0;
1330
1331 memset(stats, 0, sizeof(*stats) * len);
1332
1333 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1334 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND");
1335 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1336 stats[ST_F_SCUR] = mkf_u32(0, px->feconn);
1337 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1338 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1339 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1340 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1341 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1342 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1343 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1344 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1345 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1346 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1347 stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP");
1348 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1349 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1350 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1351 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE);
1352 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec));
1353 stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1354 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001355 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001356
1357 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1358 if (px->mode == PR_MODE_HTTP) {
1359 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1360 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1361 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1362 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1363 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1364 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1365 stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1366 }
1367
1368 /* requests : req_rate, req_rate_max, req_tot, */
1369 stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec));
1370 stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1371 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1372
1373 /* compression: in, out, bypassed, responses */
1374 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1375 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1376 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1377 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1378
1379 /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */
1380 stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec));
1381 stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1382 stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1383
1384 return 1;
1385}
1386
1387/* Dumps a frontend's line to the trash for the current proxy <px> and uses
1388 * the state from stream interface <si>. The caller is responsible for clearing
1389 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
1390 */
1391static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px)
1392{
1393 struct appctx *appctx = __objt_appctx(si->end);
1394
1395 if (!(px->cap & PR_CAP_FE))
1396 return 0;
1397
1398 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE)))
1399 return 0;
1400
1401 if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS))
1402 return 0;
1403
1404 return stats_dump_one_line(stats, 0, px, appctx);
1405}
1406
1407/* Fill <stats> with the listener statistics. <stats> is
1408 * preallocated array of length <len>. The length of the array
1409 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1410 * then this value, the function returns 0, otherwise, it
1411 * returns 1. <flags> can take the value ST_SHLGNDS.
1412 */
1413int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
1414 struct field *stats, int len)
1415{
Willy Tarreau83061a82018-07-13 11:56:34 +02001416 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001417
1418 if (len < ST_F_TOTAL_FIELDS)
1419 return 0;
1420
1421 if (!l->counters)
1422 return 0;
1423
1424 chunk_reset(out);
1425 memset(stats, 0, sizeof(*stats) * len);
1426
1427 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1428 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name);
1429 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1430 stats[ST_F_SCUR] = mkf_u32(0, l->nbconn);
1431 stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max);
1432 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn);
1433 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn);
1434 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in);
1435 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out);
1436 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req);
1437 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp);
1438 stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req);
1439 stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn);
1440 stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess);
1441 stats[ST_F_STATUS] = mkf_str(FO_STATUS, (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL");
1442 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1443 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1444 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid);
1445 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001446 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, l->counters->failed_rewrites);
William Lallemand74c24fb2016-11-21 17:18:36 +01001447
1448 if (flags & ST_SHLGNDS) {
1449 char str[INET6_ADDRSTRLEN];
1450 int port;
1451
1452 port = get_host_port(&l->addr);
1453 switch (addr_to_str(&l->addr, str, sizeof(str))) {
1454 case AF_INET:
1455 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1456 chunk_appendf(out, "%s:%d", str, port);
1457 break;
1458 case AF_INET6:
1459 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1460 chunk_appendf(out, "[%s]:%d", str, port);
1461 break;
1462 case AF_UNIX:
1463 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1464 break;
1465 case -1:
1466 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1467 chunk_strcat(out, strerror(errno));
1468 break;
1469 default: /* address family not supported */
1470 break;
1471 }
1472 }
1473
1474 return 1;
1475}
1476
1477/* Dumps a line for listener <l> and proxy <px> to the trash and uses the state
1478 * from stream interface <si>, and stats flags <flags>. The caller is responsible
1479 * for clearing the trash if needed. Returns non-zero if it emits anything, zero
1480 * otherwise.
1481 */
1482static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags)
1483{
1484 struct appctx *appctx = __objt_appctx(si->end);
1485
1486 if (!stats_fill_li_stats(px, l, flags, stats, ST_F_TOTAL_FIELDS))
1487 return 0;
1488
1489 return stats_dump_one_line(stats, flags, px, appctx);
1490}
1491
1492enum srv_stats_state {
1493 SRV_STATS_STATE_DOWN = 0,
1494 SRV_STATS_STATE_DOWN_AGENT,
1495 SRV_STATS_STATE_GOING_UP,
1496 SRV_STATS_STATE_UP_GOING_DOWN,
1497 SRV_STATS_STATE_UP,
1498 SRV_STATS_STATE_NOLB_GOING_DOWN,
1499 SRV_STATS_STATE_NOLB,
1500 SRV_STATS_STATE_DRAIN_GOING_DOWN,
1501 SRV_STATS_STATE_DRAIN,
1502 SRV_STATS_STATE_DRAIN_AGENT,
1503 SRV_STATS_STATE_NO_CHECK,
1504
1505 SRV_STATS_STATE_COUNT, /* Must be last */
1506};
1507
1508static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = {
1509 [SRV_STATS_STATE_DOWN] = "DOWN",
1510 [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)",
1511 [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d",
1512 [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d",
1513 [SRV_STATS_STATE_UP] = "UP",
1514 [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d",
1515 [SRV_STATS_STATE_NOLB] = "NOLB",
1516 [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d",
1517 [SRV_STATS_STATE_DRAIN] = "DRAIN",
1518 [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)",
1519 [SRV_STATS_STATE_NO_CHECK] = "no check"
1520};
1521
1522/* Fill <stats> with the server statistics. <stats> is
1523 * preallocated array of length <len>. The length of the array
1524 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1525 * then this value, the function returns 0, otherwise, it
1526 * returns 1. <flags> can take the value ST_SHLGNDS.
1527 */
1528int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
1529 struct field *stats, int len)
1530{
1531 struct server *via, *ref;
1532 char str[INET6_ADDRSTRLEN];
Willy Tarreau83061a82018-07-13 11:56:34 +02001533 struct buffer *out = get_trash_chunk();
William Lallemand74c24fb2016-11-21 17:18:36 +01001534 enum srv_stats_state state;
1535 char *fld_status;
1536
1537 if (len < ST_F_TOTAL_FIELDS)
1538 return 0;
1539
1540 memset(stats, 0, sizeof(*stats) * len);
1541
1542 /* we have "via" which is the tracked server as described in the configuration,
1543 * and "ref" which is the checked server and the end of the chain.
1544 */
1545 via = sv->track ? sv->track : sv;
1546 ref = via;
1547 while (ref->track)
1548 ref = ref->track;
1549
Emeric Brun52a91d32017-08-31 14:41:55 +02001550 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001551 if ((ref->check.state & CHK_ST_ENABLED) &&
1552 (ref->check.health < ref->check.rise + ref->check.fall - 1)) {
1553 state = SRV_STATS_STATE_UP_GOING_DOWN;
1554 } else {
1555 state = SRV_STATS_STATE_UP;
1556 }
1557
Emeric Brun52a91d32017-08-31 14:41:55 +02001558 if (sv->cur_admin & SRV_ADMF_DRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001559 if (ref->agent.state & CHK_ST_ENABLED)
1560 state = SRV_STATS_STATE_DRAIN_AGENT;
1561 else if (state == SRV_STATS_STATE_UP_GOING_DOWN)
1562 state = SRV_STATS_STATE_DRAIN_GOING_DOWN;
1563 else
1564 state = SRV_STATS_STATE_DRAIN;
1565 }
1566
1567 if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) {
1568 state = SRV_STATS_STATE_NO_CHECK;
1569 }
1570 }
Emeric Brun52a91d32017-08-31 14:41:55 +02001571 else if (sv->cur_state == SRV_ST_STOPPING) {
William Lallemand74c24fb2016-11-21 17:18:36 +01001572 if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) ||
1573 (ref->check.health == ref->check.rise + ref->check.fall - 1)) {
1574 state = SRV_STATS_STATE_NOLB;
1575 } else {
1576 state = SRV_STATS_STATE_NOLB_GOING_DOWN;
1577 }
1578 }
1579 else { /* stopped */
1580 if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) {
1581 state = SRV_STATS_STATE_DOWN_AGENT;
1582 } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) {
1583 state = SRV_STATS_STATE_DOWN; /* DOWN */
1584 } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) {
1585 state = SRV_STATS_STATE_GOING_UP;
1586 } else {
1587 state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */
1588 }
1589 }
1590
1591 chunk_reset(out);
1592
1593 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1594 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id);
1595 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1596 stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend);
1597 stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1598 stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess);
1599 stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1600
1601 if (sv->maxconn)
1602 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1603
1604 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1605 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1606 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1607 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu);
1608 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1609 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1610 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries);
1611 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001612 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001613 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, sv->counters.connect);
1614 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, sv->counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001615
1616 /* status */
1617 fld_status = chunk_newstr(out);
Emeric Brun52a91d32017-08-31 14:41:55 +02001618 if (sv->cur_admin & SRV_ADMF_RMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001619 chunk_appendf(out, "MAINT (resolution)");
Emeric Brun52a91d32017-08-31 14:41:55 +02001620 else if (sv->cur_admin & SRV_ADMF_IMAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001621 chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id);
Emeric Brun52a91d32017-08-31 14:41:55 +02001622 else if (sv->cur_admin & SRV_ADMF_MAINT)
William Lallemand74c24fb2016-11-21 17:18:36 +01001623 chunk_appendf(out, "MAINT");
1624 else
1625 chunk_appendf(out,
1626 srv_hlt_st[state],
Emeric Brun52a91d32017-08-31 14:41:55 +02001627 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health),
1628 (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise));
William Lallemand74c24fb2016-11-21 17:18:36 +01001629
1630 stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status);
1631 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
Emeric Brun52a91d32017-08-31 14:41:55 +02001632 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 +01001633 stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1);
1634 stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0);
1635
1636 /* check failures: unique, fatal; last change, total downtime */
1637 if (sv->check.state & CHK_ST_ENABLED) {
1638 stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1639 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1640 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv));
1641 }
1642
1643 if (sv->maxqueue)
1644 stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1645
1646 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1647 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1648 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid);
1649
Emeric Brun52a91d32017-08-31 14:41:55 +02001650 if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv))
William Lallemand74c24fb2016-11-21 17:18:36 +01001651 stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv));
1652
1653 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1654
1655 if (sv->track) {
1656 char *fld_track = chunk_newstr(out);
1657
1658 chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id);
1659 stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track);
1660 }
1661
1662 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV);
1663 stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec));
1664 stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max);
1665
1666 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1667 const char *fld_chksts;
1668
1669 fld_chksts = chunk_newstr(out);
1670 chunk_strcat(out, "* "); // for check in progress
1671 chunk_strcat(out, get_check_status_info(sv->check.status));
1672 if (!(sv->check.state & CHK_ST_INPROGRESS))
1673 fld_chksts += 2; // skip "* "
1674 stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1675
1676 if (sv->check.status >= HCHK_STATUS_L57DATA)
1677 stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code);
1678
1679 if (sv->check.status >= HCHK_STATUS_CHECKED)
1680 stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration);
1681
1682 stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status));
1683 stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc);
1684 stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise);
1685 stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall);
1686 stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health);
1687 }
1688
1689 if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) {
1690 const char *fld_chksts;
1691
1692 fld_chksts = chunk_newstr(out);
1693 chunk_strcat(out, "* "); // for check in progress
1694 chunk_strcat(out, get_check_status_info(sv->agent.status));
1695 if (!(sv->agent.state & CHK_ST_INPROGRESS))
1696 fld_chksts += 2; // skip "* "
1697 stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts);
1698
1699 if (sv->agent.status >= HCHK_STATUS_L57DATA)
1700 stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code);
1701
1702 if (sv->agent.status >= HCHK_STATUS_CHECKED)
1703 stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration);
1704
1705 stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status));
1706 stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc);
1707 stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise);
1708 stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall);
1709 stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health);
1710 }
1711
1712 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1713 if (px->mode == PR_MODE_HTTP) {
1714 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1715 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1716 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1717 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1718 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
1719 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
1720 }
1721
1722 if (ref->observe)
1723 stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana);
1724
1725 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1726 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1727 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv));
1728
1729 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES));
1730 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES));
1731 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES));
1732 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES));
1733
1734 if (flags & ST_SHLGNDS) {
1735 switch (addr_to_str(&sv->addr, str, sizeof(str))) {
1736 case AF_INET:
1737 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001738 chunk_appendf(out, "%s:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001739 break;
1740 case AF_INET6:
1741 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
Willy Tarreau04276f32017-01-06 17:41:29 +01001742 chunk_appendf(out, "[%s]:%d", str, sv->svc_port);
William Lallemand74c24fb2016-11-21 17:18:36 +01001743 break;
1744 case AF_UNIX:
1745 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix");
1746 break;
1747 case -1:
1748 stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out));
1749 chunk_strcat(out, strerror(errno));
1750 break;
1751 default: /* address family not supported */
1752 break;
1753 }
1754
1755 if (sv->cookie)
1756 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie);
1757 }
1758
1759 return 1;
1760}
1761
1762/* Dumps a line for server <sv> and proxy <px> to the trash and uses the state
1763 * from stream interface <si>, stats flags <flags>, and server state <state>.
1764 * The caller is responsible for clearing the trash if needed. Returns non-zero
1765 * if it emits anything, zero otherwise.
1766 */
1767static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv)
1768{
1769 struct appctx *appctx = __objt_appctx(si->end);
1770
1771 if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS))
1772 return 0;
1773
1774 return stats_dump_one_line(stats, flags, px, appctx);
1775}
1776
1777/* Fill <stats> with the backend statistics. <stats> is
1778 * preallocated array of length <len>. The length of the array
1779 * must be at least ST_F_TOTAL_FIELDS. If this length is less
1780 * then this value, the function returns 0, otherwise, it
1781 * returns 1. <flags> can take the value ST_SHLGNDS.
1782 */
1783int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len)
1784{
1785 if (len < ST_F_TOTAL_FIELDS)
1786 return 0;
1787
1788 memset(stats, 0, sizeof(*stats) * len);
1789
1790 stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id);
1791 stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND");
1792 stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode));
1793 stats[ST_F_QCUR] = mkf_u32(0, px->nbpend);
1794 stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
Thierry FOURNIER0ff98a42016-12-19 16:50:42 +01001795 stats[ST_F_SCUR] = mkf_u32(0, px->beconn);
William Lallemand74c24fb2016-11-21 17:18:36 +01001796 stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max);
1797 stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1798 stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1799 stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1800 stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1801 stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1802 stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1803 stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1804 stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1805 stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries);
1806 stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
Tim Duesterhus3fd19732018-05-27 20:35:08 +02001807 stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
Willy Tarreauf1573842018-12-14 11:35:36 +01001808 stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, px->be_counters.connect);
1809 stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, px->be_counters.reuse);
William Lallemand74c24fb2016-11-21 17:18:36 +01001810 stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN");
1811 stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv);
1812 stats[ST_F_ACT] = mkf_u32(0, px->srv_act);
1813 stats[ST_F_BCK] = mkf_u32(0, px->srv_bck);
1814 stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans);
1815 stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1816 if (px->srv)
1817 stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px));
1818
1819 stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid);
1820 stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid);
1821 stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0);
1822 stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1823 stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE);
1824 stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec));
1825 stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max);
1826
1827 if (flags & ST_SHLGNDS) {
1828 if (px->cookie_name)
1829 stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name);
1830 stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO));
1831 }
1832
1833 /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */
1834 if (px->mode == PR_MODE_HTTP) {
1835 stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1836 stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1837 stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1838 stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1839 stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1840 stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1841 stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
William Lallemand74c24fb2016-11-21 17:18:36 +01001842 }
1843
1844 stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1845 stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1846
1847 /* compression: in, out, bypassed, responses */
1848 stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1849 stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1850 stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1851 stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1852 stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px));
1853
1854 stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES));
1855 stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES));
1856 stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES));
1857 stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES));
1858
1859 return 1;
1860}
1861
1862/* Dumps a line for backend <px> to the trash for and uses the state from stream
1863 * interface <si> and stats flags <flags>. The caller is responsible for clearing
1864 * the trash if needed. Returns non-zero if it emits anything, zero otherwise.
1865 */
1866static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags)
1867{
1868 struct appctx *appctx = __objt_appctx(si->end);
1869
1870 if (!(px->cap & PR_CAP_BE))
1871 return 0;
1872
1873 if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE)))
1874 return 0;
1875
1876 if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS))
1877 return 0;
1878
1879 return stats_dump_one_line(stats, flags, px, appctx);
1880}
1881
1882/* Dumps the HTML table header for proxy <px> to the trash for and uses the state from
1883 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
1884 * for clearing the trash if needed.
1885 */
1886static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri)
1887{
1888 struct appctx *appctx = __objt_appctx(si->end);
1889 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
1890
1891 if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
1892 /* A form to enable/disable this proxy servers */
1893
1894 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
1895 scope_txt[0] = 0;
1896 if (appctx->ctx.stats.scope_len) {
1897 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau89faf5d2018-06-07 18:16:48 +02001898 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01001899 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
1900 }
1901
1902 chunk_appendf(&trash,
1903 "<form method=\"post\">");
1904 }
1905
1906 /* print a new table */
1907 chunk_appendf(&trash,
1908 "<table class=\"tbl\" width=\"100%%\">\n"
1909 "<tr class=\"titre\">"
1910 "<th class=\"pxname\" width=\"10%%\">");
1911
1912 chunk_appendf(&trash,
1913 "<a name=\"%s\"></a>%s"
1914 "<a class=px href=\"#%s\">%s</a>",
1915 px->id,
1916 (uri->flags & ST_SHLGNDS) ? "<u>":"",
1917 px->id, px->id);
1918
1919 if (uri->flags & ST_SHLGNDS) {
1920 /* cap, mode, id */
1921 chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d",
1922 proxy_cap_str(px->cap), proxy_mode_str(px->mode),
1923 px->uuid);
1924 chunk_appendf(&trash, "</div>");
1925 }
1926
1927 chunk_appendf(&trash,
1928 "%s</th>"
1929 "<th class=\"%s\" width=\"90%%\">%s</th>"
1930 "</tr>\n"
1931 "</table>\n"
1932 "<table class=\"tbl\" width=\"100%%\">\n"
1933 "<tr class=\"titre\">",
1934 (uri->flags & ST_SHLGNDS) ? "</u>":"",
1935 px->desc ? "desc" : "empty", px->desc ? px->desc : "");
1936
1937 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
1938 /* Column heading for Enable or Disable server */
David Harrigand3db35a2016-12-30 12:12:49 +00001939 chunk_appendf(&trash,
1940 "<th rowspan=2 width=1><input type=\"checkbox\" \
1941 onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) \
1942 document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>",
1943 px->id,
1944 px->id);
William Lallemand74c24fb2016-11-21 17:18:36 +01001945 }
1946
1947 chunk_appendf(&trash,
1948 "<th rowspan=2></th>"
1949 "<th colspan=3>Queue</th>"
1950 "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>"
1951 "<th colspan=2>Bytes</th><th colspan=2>Denied</th>"
1952 "<th colspan=3>Errors</th><th colspan=2>Warnings</th>"
1953 "<th colspan=9>Server</th>"
1954 "</tr>\n"
1955 "<tr class=\"titre\">"
1956 "<th>Cur</th><th>Max</th><th>Limit</th>"
1957 "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>"
1958 "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>"
1959 "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>"
1960 "<th>Resp</th><th>Retr</th><th>Redis</th>"
1961 "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>"
1962 "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>"
1963 "<th>Thrtle</th>\n"
1964 "</tr>");
1965}
1966
1967/* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from
1968 * stream interface <si>. The caller is responsible for clearing the trash if needed.
1969 */
1970static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px)
1971{
1972 struct appctx *appctx = __objt_appctx(si->end);
1973 chunk_appendf(&trash, "</table>");
1974
1975 if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) {
1976 /* close the form used to enable/disable this proxy servers */
1977 chunk_appendf(&trash,
1978 "Choose the action to perform on the checked servers : "
1979 "<select name=action>"
1980 "<option value=\"\"></option>"
1981 "<option value=\"ready\">Set state to READY</option>"
1982 "<option value=\"drain\">Set state to DRAIN</option>"
1983 "<option value=\"maint\">Set state to MAINT</option>"
1984 "<option value=\"dhlth\">Health: disable checks</option>"
1985 "<option value=\"ehlth\">Health: enable checks</option>"
1986 "<option value=\"hrunn\">Health: force UP</option>"
1987 "<option value=\"hnolb\">Health: force NOLB</option>"
1988 "<option value=\"hdown\">Health: force DOWN</option>"
1989 "<option value=\"dagent\">Agent: disable checks</option>"
1990 "<option value=\"eagent\">Agent: enable checks</option>"
1991 "<option value=\"arunn\">Agent: force UP</option>"
1992 "<option value=\"adown\">Agent: force DOWN</option>"
1993 "<option value=\"shutdown\">Kill Sessions</option>"
1994 "</select>"
1995 "<input type=\"hidden\" name=\"b\" value=\"#%d\">"
1996 "&nbsp;<input type=\"submit\" value=\"Apply\">"
1997 "</form>",
1998 px->uuid);
1999 }
2000
2001 chunk_appendf(&trash, "<p>\n");
2002}
2003
2004/*
2005 * Dumps statistics for a proxy. The output is sent to the stream interface's
2006 * input buffer. Returns 0 if it had to stop dumping data because of lack of
2007 * buffer space, or non-zero if everything completed. This function is used
2008 * both by the CLI and the HTTP entry points, and is able to dump the output
2009 * in HTML or CSV formats. If the later, <uri> must be NULL.
2010 */
Christopher Fauletef779222018-10-31 08:47:01 +01002011int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx,
2012 struct proxy *px, struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002013{
2014 struct appctx *appctx = __objt_appctx(si->end);
2015 struct stream *s = si_strm(si);
2016 struct channel *rep = si_ic(si);
2017 struct server *sv, *svs; /* server and server-state, server-state=server or server->track */
2018 struct listener *l;
2019 unsigned int flags;
2020
2021 if (uri)
2022 flags = uri->flags;
William Lallemand07a62f72017-05-24 00:57:40 +02002023 else if ((strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER)
William Lallemand74c24fb2016-11-21 17:18:36 +01002024 flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC;
2025 else
2026 flags = ST_SHNODE | ST_SHDESC;
2027
2028 chunk_reset(&trash);
2029
2030 switch (appctx->ctx.stats.px_st) {
2031 case STAT_PX_ST_INIT:
2032 /* we are on a new proxy */
2033 if (uri && uri->scope) {
2034 /* we have a limited scope, we have to check the proxy name */
2035 struct stat_scope *scope;
2036 int len;
2037
2038 len = strlen(px->id);
2039 scope = uri->scope;
2040
2041 while (scope) {
2042 /* match exact proxy name */
2043 if (scope->px_len == len && !memcmp(px->id, scope->px_id, len))
2044 break;
2045
2046 /* match '.' which means 'self' proxy */
2047 if (!strcmp(scope->px_id, ".") && px == s->be)
2048 break;
2049 scope = scope->next;
2050 }
2051
2052 /* proxy name not found : don't dump anything */
2053 if (scope == NULL)
2054 return 1;
2055 }
2056
2057 /* if the user has requested a limited output and the proxy
2058 * name does not match, skip it.
2059 */
2060 if (appctx->ctx.stats.scope_len &&
Willy Tarreau89faf5d2018-06-07 18:16:48 +02002061 strnistr(px->id, strlen(px->id), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL)
William Lallemand74c24fb2016-11-21 17:18:36 +01002062 return 1;
2063
2064 if ((appctx->ctx.stats.flags & STAT_BOUND) &&
2065 (appctx->ctx.stats.iid != -1) &&
2066 (px->uuid != appctx->ctx.stats.iid))
2067 return 1;
2068
2069 appctx->ctx.stats.px_st = STAT_PX_ST_TH;
2070 /* fall through */
2071
2072 case STAT_PX_ST_TH:
2073 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2074 stats_dump_html_px_hdr(si, px, uri);
Christopher Fauletef779222018-10-31 08:47:01 +01002075 if (!stats_putchk(rep, htx, &trash))
2076 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002077 }
2078
2079 appctx->ctx.stats.px_st = STAT_PX_ST_FE;
2080 /* fall through */
2081
2082 case STAT_PX_ST_FE:
2083 /* print the frontend */
2084 if (stats_dump_fe_stats(si, px)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002085 if (!stats_putchk(rep, htx, &trash))
2086 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002087 }
2088
2089 appctx->ctx.stats.l = px->conf.listeners.n;
2090 appctx->ctx.stats.px_st = STAT_PX_ST_LI;
2091 /* fall through */
2092
2093 case STAT_PX_ST_LI:
2094 /* stats.l has been initialized above */
2095 for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) {
Christopher Fauletef779222018-10-31 08:47:01 +01002096 if (htx) {
2097 if (htx_almost_full(htx))
2098 goto full;
2099 }
2100 else {
2101 if (buffer_almost_full(&rep->buf))
2102 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002103 }
2104
2105 l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe);
2106 if (!l->counters)
2107 continue;
2108
2109 if (appctx->ctx.stats.flags & STAT_BOUND) {
2110 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO)))
2111 break;
2112
2113 if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid)
2114 continue;
2115 }
2116
2117 /* print the frontend */
2118 if (stats_dump_li_stats(si, px, l, flags)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002119 if (!stats_putchk(rep, htx, &trash))
2120 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002121 }
2122 }
2123
2124 appctx->ctx.stats.sv = px->srv; /* may be NULL */
2125 appctx->ctx.stats.px_st = STAT_PX_ST_SV;
2126 /* fall through */
2127
2128 case STAT_PX_ST_SV:
2129 /* stats.sv has been initialized above */
2130 for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) {
Christopher Fauletef779222018-10-31 08:47:01 +01002131 if (htx) {
2132 if (htx_almost_full(htx))
2133 goto full;
2134 }
2135 else {
2136 if (buffer_almost_full(&rep->buf))
2137 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002138 }
2139
2140 sv = appctx->ctx.stats.sv;
2141
2142 if (appctx->ctx.stats.flags & STAT_BOUND) {
2143 if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV)))
2144 break;
2145
2146 if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid)
2147 continue;
2148 }
2149
2150 svs = sv;
2151 while (svs->track)
2152 svs = svs->track;
2153
2154 /* do not report servers which are DOWN and not changing state */
2155 if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) &&
Emeric Brun52a91d32017-08-31 14:41:55 +02002156 ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */
2157 (sv->cur_state == SRV_ST_STOPPED && /* server is down */
William Lallemand74c24fb2016-11-21 17:18:36 +01002158 (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) ||
2159 ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) ||
2160 ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) {
2161 continue;
2162 }
2163
2164 if (stats_dump_sv_stats(si, px, flags, sv)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002165 if (!stats_putchk(rep, htx, &trash))
2166 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002167 }
2168 } /* for sv */
2169
2170 appctx->ctx.stats.px_st = STAT_PX_ST_BE;
2171 /* fall through */
2172
2173 case STAT_PX_ST_BE:
2174 /* print the backend */
2175 if (stats_dump_be_stats(si, px, flags)) {
Christopher Fauletef779222018-10-31 08:47:01 +01002176 if (!stats_putchk(rep, htx, &trash))
2177 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002178 }
2179
2180 appctx->ctx.stats.px_st = STAT_PX_ST_END;
2181 /* fall through */
2182
2183 case STAT_PX_ST_END:
2184 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2185 stats_dump_html_px_end(si, px);
Christopher Fauletef779222018-10-31 08:47:01 +01002186 if (!stats_putchk(rep, htx, &trash))
2187 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002188 }
2189
2190 appctx->ctx.stats.px_st = STAT_PX_ST_FIN;
2191 /* fall through */
2192
2193 case STAT_PX_ST_FIN:
2194 return 1;
2195
2196 default:
2197 /* unknown state, we should put an abort() here ! */
2198 return 1;
2199 }
Christopher Fauletef779222018-10-31 08:47:01 +01002200
2201 full:
2202 si_rx_room_blk(si);
2203 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01002204}
2205
2206/* Dumps the HTTP stats head block to the trash for and uses the per-uri
2207 * parameters <uri>. The caller is responsible for clearing the trash if needed.
2208 */
2209static void stats_dump_html_head(struct uri_auth *uri)
2210{
2211 /* WARNING! This must fit in the first buffer !!! */
2212 chunk_appendf(&trash,
2213 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n"
2214 "\"http://www.w3.org/TR/html4/loose.dtd\">\n"
2215 "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n"
2216 "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n"
2217 "<style type=\"text/css\"><!--\n"
2218 "body {"
2219 " font-family: arial, helvetica, sans-serif;"
2220 " font-size: 12px;"
2221 " font-weight: normal;"
2222 " color: black;"
2223 " background: white;"
2224 "}\n"
2225 "th,td {"
2226 " font-size: 10px;"
2227 "}\n"
2228 "h1 {"
2229 " font-size: x-large;"
2230 " margin-bottom: 0.5em;"
2231 "}\n"
2232 "h2 {"
2233 " font-family: helvetica, arial;"
2234 " font-size: x-large;"
2235 " font-weight: bold;"
2236 " font-style: italic;"
2237 " color: #6020a0;"
2238 " margin-top: 0em;"
2239 " margin-bottom: 0em;"
2240 "}\n"
2241 "h3 {"
2242 " font-family: helvetica, arial;"
2243 " font-size: 16px;"
2244 " font-weight: bold;"
2245 " color: #b00040;"
2246 " background: #e8e8d0;"
2247 " margin-top: 0em;"
2248 " margin-bottom: 0em;"
2249 "}\n"
2250 "li {"
2251 " margin-top: 0.25em;"
2252 " margin-right: 2em;"
2253 "}\n"
2254 ".hr {margin-top: 0.25em;"
2255 " border-color: black;"
2256 " border-bottom-style: solid;"
2257 "}\n"
2258 ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n"
2259 ".total {background: #20D0D0;color: #ffff80;}\n"
2260 ".frontend {background: #e8e8d0;}\n"
2261 ".socket {background: #d0d0d0;}\n"
2262 ".backend {background: #e8e8d0;}\n"
2263 ".active_down {background: #ff9090;}\n"
2264 ".active_going_up {background: #ffd020;}\n"
2265 ".active_going_down {background: #ffffa0;}\n"
2266 ".active_up {background: #c0ffc0;}\n"
2267 ".active_nolb {background: #20a0ff;}\n"
2268 ".active_draining {background: #20a0FF;}\n"
2269 ".active_no_check {background: #e0e0e0;}\n"
2270 ".backup_down {background: #ff9090;}\n"
2271 ".backup_going_up {background: #ff80ff;}\n"
2272 ".backup_going_down {background: #c060ff;}\n"
2273 ".backup_up {background: #b0d0ff;}\n"
2274 ".backup_nolb {background: #90b0e0;}\n"
2275 ".backup_draining {background: #cc9900;}\n"
2276 ".backup_no_check {background: #e0e0e0;}\n"
2277 ".maintain {background: #c07820;}\n"
2278 ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */
2279 "\n"
2280 "a.px:link {color: #ffff40; text-decoration: none;}"
2281 "a.px:visited {color: #ffff40; text-decoration: none;}"
2282 "a.px:hover {color: #ffffff; text-decoration: none;}"
2283 "a.lfsb:link {color: #000000; text-decoration: none;}"
2284 "a.lfsb:visited {color: #000000; text-decoration: none;}"
2285 "a.lfsb:hover {color: #505050; text-decoration: none;}"
2286 "\n"
2287 "table.tbl { border-collapse: collapse; border-style: none;}\n"
2288 "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"
2289 "table.tbl td.ac { text-align: center;}\n"
2290 "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n"
2291 "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n"
2292 "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n"
2293 "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n"
2294 "\n"
2295 "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n"
2296 "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n"
2297 "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n"
2298 "table.det { border-collapse: collapse; border-style: none; }\n"
2299 "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"
2300 "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"
2301 "u {text-decoration:none; border-bottom: 1px dotted black;}\n"
2302 "div.tips {\n"
2303 " display:block;\n"
2304 " visibility:hidden;\n"
2305 " z-index:2147483647;\n"
2306 " position:absolute;\n"
2307 " padding:2px 4px 3px;\n"
2308 " background:#f0f060; color:#000000;\n"
2309 " border:1px solid #7040c0;\n"
2310 " white-space:nowrap;\n"
2311 " font-style:normal;font-size:11px;font-weight:normal;\n"
2312 " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n"
2313 " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n"
2314 "}\n"
2315 "u:hover div.tips {visibility:visible;}\n"
2316 "-->\n"
2317 "</style></head>\n",
2318 (uri->flags & ST_SHNODE) ? " on " : "",
2319 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : ""
2320 );
2321}
2322
2323/* Dumps the HTML stats information block to the trash for and uses the state from
2324 * stream interface <si> and per-uri parameters <uri>. The caller is responsible
2325 * for clearing the trash if needed.
2326 */
2327static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri)
2328{
2329 struct appctx *appctx = __objt_appctx(si->end);
2330 unsigned int up = (now.tv_sec - start_date.tv_sec);
2331 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
2332
2333 /* WARNING! this has to fit the first packet too.
2334 * We are around 3.5 kB, add adding entries will
2335 * become tricky if we want to support 4kB buffers !
2336 */
2337 chunk_appendf(&trash,
2338 "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">"
2339 PRODUCT_NAME "%s</a></h1>\n"
2340 "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n"
2341 "<hr width=\"100%%\" class=\"hr\">\n"
2342 "<h3>&gt; General process information</h3>\n"
2343 "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n"
Yves Lafon95317282018-02-26 11:10:37 +01002344 "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n"
William Lallemand74c24fb2016-11-21 17:18:36 +01002345 "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
2346 "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n"
2347 "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n"
2348 "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n"
2349 "Running tasks: %d/%d; idle = %d %%<br>\n"
2350 "</td><td align=\"center\" nowrap>\n"
2351 "<table class=\"lgd\"><tr>\n"
2352 "<td class=\"active_up\">&nbsp;</td><td class=\"noborder\">active UP </td>"
2353 "<td class=\"backup_up\">&nbsp;</td><td class=\"noborder\">backup UP </td>"
2354 "</tr><tr>\n"
2355 "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>"
2356 "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>"
2357 "</tr><tr>\n"
2358 "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>"
2359 "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>"
2360 "</tr><tr>\n"
2361 "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN &nbsp;</td>"
2362 "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>"
2363 "</tr><tr>\n"
2364 "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) &nbsp;</td>"
2365 "</tr><tr>\n"
2366 "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance &nbsp;</td>"
2367 "</tr></table>\n"
2368 "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled."
2369 "</td>"
2370 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2371 "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
2372 "",
2373 (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING),
2374 pid, (uri->flags & ST_SHNODE) ? " on " : "",
2375 (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "",
2376 (uri->flags & ST_SHDESC) ? ": " : "",
2377 (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "",
Yves Lafon95317282018-02-26 11:10:37 +01002378 pid, relative_pid, global.nbproc, global.nbthread,
William Lallemand74c24fb2016-11-21 17:18:36 +01002379 up / 86400, (up % 86400) / 3600,
2380 (up % 3600) / 60, (up % 60),
2381 global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
2382 global.rlimit_memmax ? " MB" : "",
2383 global.rlimit_nofile,
2384 global.maxsock, global.maxconn, global.maxpipes,
2385 actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec),
Christopher Faulet34c5cc92016-12-06 09:15:30 +01002386 tasks_run_queue_cur, nb_tasks_cur, idle_pct
William Lallemand74c24fb2016-11-21 17:18:36 +01002387 );
2388
2389 /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
Willy Tarreau89faf5d2018-06-07 18:16:48 +02002390 memcpy(scope_txt, co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002391 scope_txt[appctx->ctx.stats.scope_len] = '\0';
2392
2393 chunk_appendf(&trash,
2394 "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n",
2395 (appctx->ctx.stats.scope_len > 0) ? scope_txt : "",
2396 STAT_SCOPE_TXT_MAXLEN);
2397
2398 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
2399 scope_txt[0] = 0;
2400 if (appctx->ctx.stats.scope_len) {
2401 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau89faf5d2018-06-07 18:16:48 +02002402 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01002403 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
2404 }
2405
2406 if (appctx->ctx.stats.flags & STAT_HIDE_DOWN)
2407 chunk_appendf(&trash,
2408 "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n",
2409 uri->uri_prefix,
2410 "",
2411 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2412 scope_txt);
2413 else
2414 chunk_appendf(&trash,
2415 "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n",
2416 uri->uri_prefix,
2417 ";up",
2418 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2419 scope_txt);
2420
2421 if (uri->refresh > 0) {
2422 if (appctx->ctx.stats.flags & STAT_NO_REFRESH)
2423 chunk_appendf(&trash,
2424 "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n",
2425 uri->uri_prefix,
2426 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2427 "",
2428 scope_txt);
2429 else
2430 chunk_appendf(&trash,
2431 "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n",
2432 uri->uri_prefix,
2433 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2434 ";norefresh",
2435 scope_txt);
2436 }
2437
2438 chunk_appendf(&trash,
2439 "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n",
2440 uri->uri_prefix,
2441 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2442 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2443 scope_txt);
2444
2445 chunk_appendf(&trash,
2446 "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n",
2447 uri->uri_prefix,
2448 (uri->refresh > 0) ? ";norefresh" : "",
2449 scope_txt);
2450
2451 chunk_appendf(&trash,
2452 "</ul></td>"
2453 "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">"
2454 "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n"
2455 "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n"
2456 "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n"
2457 "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n"
2458 "</ul>"
2459 "</td>"
2460 "</tr></table>\n"
2461 ""
2462 );
2463
2464 if (appctx->ctx.stats.st_code) {
2465 switch (appctx->ctx.stats.st_code) {
2466 case STAT_STATUS_DONE:
2467 chunk_appendf(&trash,
2468 "<p><div class=active_up>"
2469 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2470 "Action processed successfully."
2471 "</div>\n", uri->uri_prefix,
2472 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2473 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2474 scope_txt);
2475 break;
2476 case STAT_STATUS_NONE:
2477 chunk_appendf(&trash,
2478 "<p><div class=active_going_down>"
2479 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2480 "Nothing has changed."
2481 "</div>\n", uri->uri_prefix,
2482 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2483 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2484 scope_txt);
2485 break;
2486 case STAT_STATUS_PART:
2487 chunk_appendf(&trash,
2488 "<p><div class=active_going_down>"
2489 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2490 "Action partially processed.<br>"
2491 "Some server names are probably unknown or ambiguous (duplicated names in the backend)."
2492 "</div>\n", uri->uri_prefix,
2493 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2494 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2495 scope_txt);
2496 break;
2497 case STAT_STATUS_ERRP:
2498 chunk_appendf(&trash,
2499 "<p><div class=active_down>"
2500 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2501 "Action not processed because of invalid parameters."
2502 "<ul>"
2503 "<li>The action is maybe unknown.</li>"
2504 "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>"
2505 "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>"
2506 "</ul>"
2507 "</div>\n", uri->uri_prefix,
2508 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2509 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2510 scope_txt);
2511 break;
2512 case STAT_STATUS_EXCD:
2513 chunk_appendf(&trash,
2514 "<p><div class=active_down>"
2515 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2516 "<b>Action not processed : the buffer couldn't store all the data.<br>"
2517 "You should retry with less servers at a time.</b>"
2518 "</div>\n", uri->uri_prefix,
2519 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2520 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2521 scope_txt);
2522 break;
2523 case STAT_STATUS_DENY:
2524 chunk_appendf(&trash,
2525 "<p><div class=active_down>"
2526 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2527 "<b>Action denied.</b>"
2528 "</div>\n", uri->uri_prefix,
2529 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2530 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2531 scope_txt);
2532 break;
2533 default:
2534 chunk_appendf(&trash,
2535 "<p><div class=active_no_check>"
2536 "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> "
2537 "Unexpected result."
2538 "</div>\n", uri->uri_prefix,
2539 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
2540 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
2541 scope_txt);
2542 }
2543 chunk_appendf(&trash, "<p>\n");
2544 }
2545}
2546
2547/* Dumps the HTML stats trailer block to the trash. The caller is responsible
2548 * for clearing the trash if needed.
2549 */
2550static void stats_dump_html_end()
2551{
2552 chunk_appendf(&trash, "</body></html>\n");
2553}
2554
Simon Horman05ee2132017-01-04 09:37:25 +01002555/* Dumps the stats JSON header to the trash buffer which. The caller is responsible
2556 * for clearing it if needed.
2557 */
2558static void stats_dump_json_header()
2559{
2560 chunk_strcat(&trash, "[");
2561}
2562
2563
2564/* Dumps the JSON stats trailer block to the trash. The caller is responsible
2565 * for clearing the trash if needed.
2566 */
2567static void stats_dump_json_end()
2568{
2569 chunk_strcat(&trash, "]");
2570}
2571
William Lallemand74c24fb2016-11-21 17:18:36 +01002572/* This function dumps statistics onto the stream interface's read buffer in
2573 * either CSV or HTML format. <uri> contains some HTML-specific parameters that
2574 * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if
2575 * it had to stop writing data and an I/O is needed, 1 if the dump is finished
2576 * and the stream must be closed, or -1 in case of any error. This function is
2577 * used by both the CLI and the HTTP handlers.
2578 */
Christopher Fauletef779222018-10-31 08:47:01 +01002579static int stats_dump_stat_to_buffer(struct stream_interface *si, struct htx *htx,
2580 struct uri_auth *uri)
William Lallemand74c24fb2016-11-21 17:18:36 +01002581{
2582 struct appctx *appctx = __objt_appctx(si->end);
2583 struct channel *rep = si_ic(si);
2584 struct proxy *px;
2585
2586 chunk_reset(&trash);
2587
2588 switch (appctx->st2) {
2589 case STAT_ST_INIT:
2590 appctx->st2 = STAT_ST_HEAD; /* let's start producing data */
2591 /* fall through */
2592
2593 case STAT_ST_HEAD:
2594 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
2595 stats_dump_html_head(uri);
Simon Horman05ee2132017-01-04 09:37:25 +01002596 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
Willy Tarreau9d7fb632017-04-11 07:53:04 +02002597 stats_dump_json_header();
William Lallemand74c24fb2016-11-21 17:18:36 +01002598 else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED))
2599 stats_dump_csv_header();
2600
Christopher Fauletef779222018-10-31 08:47:01 +01002601 if (!stats_putchk(rep, htx, &trash))
2602 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002603
2604 appctx->st2 = STAT_ST_INFO;
2605 /* fall through */
2606
2607 case STAT_ST_INFO:
2608 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
2609 stats_dump_html_info(si, uri);
Christopher Fauletef779222018-10-31 08:47:01 +01002610 if (!stats_putchk(rep, htx, &trash))
2611 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002612 }
2613
Olivier Houchardfbc74e82017-11-24 16:54:05 +01002614 appctx->ctx.stats.px = proxies_list;
William Lallemand74c24fb2016-11-21 17:18:36 +01002615 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2616 appctx->st2 = STAT_ST_LIST;
2617 /* fall through */
2618
2619 case STAT_ST_LIST:
2620 /* dump proxies */
2621 while (appctx->ctx.stats.px) {
Christopher Fauletef779222018-10-31 08:47:01 +01002622 if (htx) {
2623 if (htx_almost_full(htx))
2624 goto full;
2625 }
2626 else {
2627 if (buffer_almost_full(&rep->buf))
2628 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002629 }
2630
2631 px = appctx->ctx.stats.px;
2632 /* skip the disabled proxies, global frontend and non-networked ones */
2633 if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
Christopher Fauletef779222018-10-31 08:47:01 +01002634 if (stats_dump_proxy_to_buffer(si, htx, px, uri) == 0)
William Lallemand74c24fb2016-11-21 17:18:36 +01002635 return 0;
2636
2637 appctx->ctx.stats.px = px->next;
2638 appctx->ctx.stats.px_st = STAT_PX_ST_INIT;
2639 }
2640 /* here, we just have reached the last proxy */
2641
2642 appctx->st2 = STAT_ST_END;
2643 /* fall through */
2644
2645 case STAT_ST_END:
Simon Horman05ee2132017-01-04 09:37:25 +01002646 if (appctx->ctx.stats.flags & (STAT_FMT_HTML|STAT_FMT_JSON)) {
2647 if (appctx->ctx.stats.flags & STAT_FMT_HTML)
2648 stats_dump_html_end();
2649 else
2650 stats_dump_json_end();
Christopher Fauletef779222018-10-31 08:47:01 +01002651 if (!stats_putchk(rep, htx, &trash))
2652 goto full;
William Lallemand74c24fb2016-11-21 17:18:36 +01002653 }
2654
2655 appctx->st2 = STAT_ST_FIN;
2656 /* fall through */
2657
2658 case STAT_ST_FIN:
2659 return 1;
2660
2661 default:
2662 /* unknown state ! */
2663 appctx->st2 = STAT_ST_FIN;
2664 return -1;
2665 }
Christopher Fauletef779222018-10-31 08:47:01 +01002666
2667 full:
2668 si_rx_room_blk(si);
2669 return 0;
2670
William Lallemand74c24fb2016-11-21 17:18:36 +01002671}
2672
2673/* We reached the stats page through a POST request. The appctx is
2674 * expected to have already been allocated by the caller.
2675 * Parse the posted data and enable/disable servers if necessary.
2676 * Returns 1 if request was parsed or zero if it needs more data.
2677 */
2678static int stats_process_http_post(struct stream_interface *si)
2679{
2680 struct stream *s = si_strm(si);
2681 struct appctx *appctx = objt_appctx(si->end);
2682
2683 struct proxy *px = NULL;
2684 struct server *sv = NULL;
2685
2686 char key[LINESIZE];
2687 int action = ST_ADM_ACTION_NONE;
2688 int reprocess = 0;
2689
2690 int total_servers = 0;
2691 int altered_servers = 0;
2692
2693 char *first_param, *cur_param, *next_param, *end_params;
2694 char *st_cur_param = NULL;
2695 char *st_next_param = NULL;
2696
Willy Tarreau83061a82018-07-13 11:56:34 +02002697 struct buffer *temp;
William Lallemand74c24fb2016-11-21 17:18:36 +01002698 int reql;
2699
2700 temp = get_trash_chunk();
2701 if (temp->size < s->txn->req.body_len) {
2702 /* too large request */
2703 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2704 goto out;
2705 }
2706
Willy Tarreau843b7cb2018-07-13 10:54:26 +02002707 reql = co_getblk(si_oc(si), temp->area, s->txn->req.body_len,
2708 s->txn->req.eoh + 2);
William Lallemand74c24fb2016-11-21 17:18:36 +01002709 if (reql <= 0) {
2710 /* we need more data */
2711 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
2712 return 0;
2713 }
2714
Willy Tarreau843b7cb2018-07-13 10:54:26 +02002715 first_param = temp->area;
2716 end_params = temp->area + reql;
William Lallemand74c24fb2016-11-21 17:18:36 +01002717 cur_param = next_param = end_params;
2718 *end_params = '\0';
2719
2720 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
2721
2722 /*
2723 * Parse the parameters in reverse order to only store the last value.
2724 * From the html form, the backend and the action are at the end.
2725 */
2726 while (cur_param > first_param) {
2727 char *value;
2728 int poffset, plen;
2729
2730 cur_param--;
2731
2732 if ((*cur_param == '&') || (cur_param == first_param)) {
2733 reprocess_servers:
2734 /* Parse the key */
2735 poffset = (cur_param != first_param ? 1 : 0);
2736 plen = next_param - cur_param + (cur_param == first_param ? 1 : 0);
2737 if ((plen > 0) && (plen <= sizeof(key))) {
2738 strncpy(key, cur_param + poffset, plen);
2739 key[plen - 1] = '\0';
2740 } else {
2741 appctx->ctx.stats.st_code = STAT_STATUS_EXCD;
2742 goto out;
2743 }
2744
2745 /* Parse the value */
2746 value = key;
2747 while (*value != '\0' && *value != '=') {
2748 value++;
2749 }
2750 if (*value == '=') {
2751 /* Ok, a value is found, we can mark the end of the key */
2752 *value++ = '\0';
2753 }
2754 if (url_decode(key) < 0 || url_decode(value) < 0)
2755 break;
2756
2757 /* Now we can check the key to see what to do */
2758 if (!px && (strcmp(key, "b") == 0)) {
2759 if ((px = proxy_be_by_name(value)) == NULL) {
2760 /* the backend name is unknown or ambiguous (duplicate names) */
2761 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2762 goto out;
2763 }
2764 }
2765 else if (!action && (strcmp(key, "action") == 0)) {
2766 if (strcmp(value, "ready") == 0) {
2767 action = ST_ADM_ACTION_READY;
2768 }
2769 else if (strcmp(value, "drain") == 0) {
2770 action = ST_ADM_ACTION_DRAIN;
2771 }
2772 else if (strcmp(value, "maint") == 0) {
2773 action = ST_ADM_ACTION_MAINT;
2774 }
2775 else if (strcmp(value, "shutdown") == 0) {
2776 action = ST_ADM_ACTION_SHUTDOWN;
2777 }
2778 else if (strcmp(value, "dhlth") == 0) {
2779 action = ST_ADM_ACTION_DHLTH;
2780 }
2781 else if (strcmp(value, "ehlth") == 0) {
2782 action = ST_ADM_ACTION_EHLTH;
2783 }
2784 else if (strcmp(value, "hrunn") == 0) {
2785 action = ST_ADM_ACTION_HRUNN;
2786 }
2787 else if (strcmp(value, "hnolb") == 0) {
2788 action = ST_ADM_ACTION_HNOLB;
2789 }
2790 else if (strcmp(value, "hdown") == 0) {
2791 action = ST_ADM_ACTION_HDOWN;
2792 }
2793 else if (strcmp(value, "dagent") == 0) {
2794 action = ST_ADM_ACTION_DAGENT;
2795 }
2796 else if (strcmp(value, "eagent") == 0) {
2797 action = ST_ADM_ACTION_EAGENT;
2798 }
2799 else if (strcmp(value, "arunn") == 0) {
2800 action = ST_ADM_ACTION_ARUNN;
2801 }
2802 else if (strcmp(value, "adown") == 0) {
2803 action = ST_ADM_ACTION_ADOWN;
2804 }
2805 /* else these are the old supported methods */
2806 else if (strcmp(value, "disable") == 0) {
2807 action = ST_ADM_ACTION_DISABLE;
2808 }
2809 else if (strcmp(value, "enable") == 0) {
2810 action = ST_ADM_ACTION_ENABLE;
2811 }
2812 else if (strcmp(value, "stop") == 0) {
2813 action = ST_ADM_ACTION_STOP;
2814 }
2815 else if (strcmp(value, "start") == 0) {
2816 action = ST_ADM_ACTION_START;
2817 }
2818 else {
2819 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2820 goto out;
2821 }
2822 }
2823 else if (strcmp(key, "s") == 0) {
2824 if (!(px && action)) {
2825 /*
2826 * Indicates that we'll need to reprocess the parameters
2827 * as soon as backend and action are known
2828 */
2829 if (!reprocess) {
2830 st_cur_param = cur_param;
2831 st_next_param = next_param;
2832 }
2833 reprocess = 1;
2834 }
2835 else if ((sv = findserver(px, value)) != NULL) {
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002836 HA_SPIN_LOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01002837 switch (action) {
2838 case ST_ADM_ACTION_DISABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002839 if (!(sv->cur_admin & SRV_ADMF_FMAINT)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002840 altered_servers++;
2841 total_servers++;
2842 srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page");
2843 }
2844 break;
2845 case ST_ADM_ACTION_ENABLE:
Emeric Brun52a91d32017-08-31 14:41:55 +02002846 if (sv->cur_admin & SRV_ADMF_FMAINT) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002847 altered_servers++;
2848 total_servers++;
2849 srv_clr_admin_flag(sv, SRV_ADMF_FMAINT);
2850 }
2851 break;
2852 case ST_ADM_ACTION_STOP:
Emeric Brun52a91d32017-08-31 14:41:55 +02002853 if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002854 srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page");
2855 altered_servers++;
2856 total_servers++;
2857 }
2858 break;
2859 case ST_ADM_ACTION_START:
Emeric Brun52a91d32017-08-31 14:41:55 +02002860 if (sv->cur_admin & SRV_ADMF_FDRAIN) {
William Lallemand74c24fb2016-11-21 17:18:36 +01002861 srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN);
2862 altered_servers++;
2863 total_servers++;
2864 }
2865 break;
2866 case ST_ADM_ACTION_DHLTH:
2867 if (sv->check.state & CHK_ST_CONFIGURED) {
2868 sv->check.state &= ~CHK_ST_ENABLED;
2869 altered_servers++;
2870 total_servers++;
2871 }
2872 break;
2873 case ST_ADM_ACTION_EHLTH:
2874 if (sv->check.state & CHK_ST_CONFIGURED) {
2875 sv->check.state |= CHK_ST_ENABLED;
2876 altered_servers++;
2877 total_servers++;
2878 }
2879 break;
2880 case ST_ADM_ACTION_HRUNN:
2881 if (!(sv->track)) {
2882 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02002883 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002884 altered_servers++;
2885 total_servers++;
2886 }
2887 break;
2888 case ST_ADM_ACTION_HNOLB:
2889 if (!(sv->track)) {
2890 sv->check.health = sv->check.rise + sv->check.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02002891 srv_set_stopping(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002892 altered_servers++;
2893 total_servers++;
2894 }
2895 break;
2896 case ST_ADM_ACTION_HDOWN:
2897 if (!(sv->track)) {
2898 sv->check.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02002899 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002900 altered_servers++;
2901 total_servers++;
2902 }
2903 break;
2904 case ST_ADM_ACTION_DAGENT:
2905 if (sv->agent.state & CHK_ST_CONFIGURED) {
2906 sv->agent.state &= ~CHK_ST_ENABLED;
2907 altered_servers++;
2908 total_servers++;
2909 }
2910 break;
2911 case ST_ADM_ACTION_EAGENT:
2912 if (sv->agent.state & CHK_ST_CONFIGURED) {
2913 sv->agent.state |= CHK_ST_ENABLED;
2914 altered_servers++;
2915 total_servers++;
2916 }
2917 break;
2918 case ST_ADM_ACTION_ARUNN:
2919 if (sv->agent.state & CHK_ST_ENABLED) {
2920 sv->agent.health = sv->agent.rise + sv->agent.fall - 1;
Emeric Brun5a133512017-10-19 14:42:30 +02002921 srv_set_running(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002922 altered_servers++;
2923 total_servers++;
2924 }
2925 break;
2926 case ST_ADM_ACTION_ADOWN:
2927 if (sv->agent.state & CHK_ST_ENABLED) {
2928 sv->agent.health = 0;
Emeric Brun5a133512017-10-19 14:42:30 +02002929 srv_set_stopped(sv, "changed from Web interface", NULL);
William Lallemand74c24fb2016-11-21 17:18:36 +01002930 altered_servers++;
2931 total_servers++;
2932 }
2933 break;
2934 case ST_ADM_ACTION_READY:
2935 srv_adm_set_ready(sv);
2936 altered_servers++;
2937 total_servers++;
2938 break;
2939 case ST_ADM_ACTION_DRAIN:
2940 srv_adm_set_drain(sv);
2941 altered_servers++;
2942 total_servers++;
2943 break;
2944 case ST_ADM_ACTION_MAINT:
2945 srv_adm_set_maint(sv);
2946 altered_servers++;
2947 total_servers++;
2948 break;
2949 case ST_ADM_ACTION_SHUTDOWN:
2950 if (px->state != PR_STSTOPPED) {
2951 struct stream *sess, *sess_bck;
2952
2953 list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv)
2954 if (sess->srv_conn == sv)
2955 stream_shutdown(sess, SF_ERR_KILLED);
2956
2957 altered_servers++;
2958 total_servers++;
2959 }
2960 break;
2961 }
Christopher Faulet2a944ee2017-11-07 10:42:54 +01002962 HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock);
William Lallemand74c24fb2016-11-21 17:18:36 +01002963 } else {
2964 /* the server name is unknown or ambiguous (duplicate names) */
2965 total_servers++;
2966 }
2967 }
2968 if (reprocess && px && action) {
2969 /* Now, we know the backend and the action chosen by the user.
2970 * We can safely restart from the first server parameter
2971 * to reprocess them
2972 */
2973 cur_param = st_cur_param;
2974 next_param = st_next_param;
2975 reprocess = 0;
2976 goto reprocess_servers;
2977 }
2978
2979 next_param = cur_param;
2980 }
2981 }
2982
2983 if (total_servers == 0) {
2984 appctx->ctx.stats.st_code = STAT_STATUS_NONE;
2985 }
2986 else if (altered_servers == 0) {
2987 appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
2988 }
2989 else if (altered_servers == total_servers) {
2990 appctx->ctx.stats.st_code = STAT_STATUS_DONE;
2991 }
2992 else {
2993 appctx->ctx.stats.st_code = STAT_STATUS_PART;
2994 }
2995 out:
2996 return 1;
Christopher Fauletef779222018-10-31 08:47:01 +01002997}
2998
2999
3000static int stats_send_htx_headers(struct stream_interface *si, struct htx *htx)
3001{
3002 struct stream *s = si_strm(si);
3003 struct uri_auth *uri = s->be->uri_auth;
3004 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003005 struct htx_sl *sl;
3006 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003007
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003008 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);
3009 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
3010 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003011 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003012 sl->info.res.status = 200;
Christopher Fauletef779222018-10-31 08:47:01 +01003013
3014 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
3015 !htx_add_header(htx, ist("Connection"), ist("close")))
3016 goto full;
3017 if (appctx->ctx.stats.flags & STAT_FMT_HTML) {
3018 if (!htx_add_header(htx, ist("Content-Type"), ist("text/html")))
3019 goto full;
3020 }
3021 else {
3022 if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain")))
3023 goto full;
3024 }
3025
3026 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) {
3027 const char *refresh = U2A(uri->refresh);
3028 if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh))))
3029 goto full;
3030 }
3031
3032 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
3033 if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")))
3034 goto full;
3035 }
3036
3037 if (!htx_add_endof(htx, HTX_BLK_EOH))
3038 goto full;
3039
3040 return 1;
3041
3042 full:
3043 htx_reset(htx);
3044 si_rx_room_blk(si);
3045 return 0;
William Lallemand74c24fb2016-11-21 17:18:36 +01003046}
3047
Christopher Fauletef779222018-10-31 08:47:01 +01003048
3049static int stats_send_htx_redirect(struct stream_interface *si, struct htx *htx)
3050{
3051 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
3052 struct stream *s = si_strm(si);
3053 struct uri_auth *uri = s->be->uri_auth;
3054 struct appctx *appctx = __objt_appctx(si->end);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003055 struct htx_sl *sl;
3056 unsigned int flags;
Christopher Fauletef779222018-10-31 08:47:01 +01003057
3058 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
3059 scope_txt[0] = 0;
3060 if (appctx->ctx.stats.scope_len) {
3061 strcpy(scope_txt, STAT_SCOPE_PATTERN);
3062 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
3063 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
3064 }
3065
3066 /* We don't want to land on the posted stats page because a refresh will
3067 * repost the data. We don't want this to happen on accident so we redirect
3068 * the browse to the stats page with a GET.
3069 */
3070 chunk_printf(&trash, "%s;st=%s%s%s%s",
3071 uri->uri_prefix,
3072 ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) &&
3073 (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) &&
3074 stat_status_codes[appctx->ctx.stats.st_code]) ?
3075 stat_status_codes[appctx->ctx.stats.st_code] :
3076 stat_status_codes[STAT_STATUS_UNKN],
3077 (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "",
3078 (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "",
3079 scope_txt);
3080
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003081 flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK);
3082 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other"));
3083 if (!sl)
Christopher Fauletef779222018-10-31 08:47:01 +01003084 goto full;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +01003085 sl->info.res.status = 303;
Christopher Fauletef779222018-10-31 08:47:01 +01003086
3087 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
3088 !htx_add_header(htx, ist("Connection"), ist("close")) ||
3089 !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) ||
3090 !htx_add_header(htx, ist("Content-Length"), ist("0")) ||
3091 !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data)))
3092 goto full;
3093
3094 if (!htx_add_endof(htx, HTX_BLK_EOH))
3095 goto full;
3096
3097 return 1;
3098
3099full:
3100 htx_reset(htx);
3101 si_rx_room_blk(si);
3102 return 0;
3103}
William Lallemand74c24fb2016-11-21 17:18:36 +01003104
3105static int stats_send_http_headers(struct stream_interface *si)
3106{
3107 struct stream *s = si_strm(si);
3108 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau21ff2c42018-09-20 11:01:01 +02003109 struct appctx *appctx = __objt_appctx(si->end);
William Lallemand74c24fb2016-11-21 17:18:36 +01003110
3111 chunk_printf(&trash,
3112 "HTTP/1.1 200 OK\r\n"
3113 "Cache-Control: no-cache\r\n"
3114 "Connection: close\r\n"
3115 "Content-Type: %s\r\n",
3116 (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain");
3117
3118 if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH))
3119 chunk_appendf(&trash, "Refresh: %d\r\n",
3120 uri->refresh);
3121
3122 /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */
3123
3124 if (appctx->ctx.stats.flags & STAT_CHUNKED)
3125 chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n");
3126 else
3127 chunk_appendf(&trash, "\r\n");
3128
Willy Tarreau06d80a92017-10-19 14:32:15 +02003129 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003130 si_rx_room_blk(si);
William Lallemand74c24fb2016-11-21 17:18:36 +01003131 return 0;
3132 }
3133
3134 return 1;
3135}
3136
3137static int stats_send_http_redirect(struct stream_interface *si)
3138{
3139 char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN];
3140 struct stream *s = si_strm(si);
3141 struct uri_auth *uri = s->be->uri_auth;
Willy Tarreau21ff2c42018-09-20 11:01:01 +02003142 struct appctx *appctx = __objt_appctx(si->end);
William Lallemand74c24fb2016-11-21 17:18:36 +01003143
3144 /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
3145 scope_txt[0] = 0;
3146 if (appctx->ctx.stats.scope_len) {
3147 strcpy(scope_txt, STAT_SCOPE_PATTERN);
Willy Tarreau89faf5d2018-06-07 18:16:48 +02003148 memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01003149 scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0;
3150 }
3151
3152 /* We don't want to land on the posted stats page because a refresh will
3153 * repost the data. We don't want this to happen on accident so we redirect
3154 * the browse to the stats page with a GET.
3155 */
3156 chunk_printf(&trash,
3157 "HTTP/1.1 303 See Other\r\n"
3158 "Cache-Control: no-cache\r\n"
3159 "Content-Type: text/plain\r\n"
3160 "Connection: close\r\n"
3161 "Location: %s;st=%s%s%s%s\r\n"
3162 "Content-length: 0\r\n"
3163 "\r\n",
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
Willy Tarreau06d80a92017-10-19 14:32:15 +02003174 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003175 si_rx_room_blk(si);
William Lallemand74c24fb2016-11-21 17:18:36 +01003176 return 0;
3177 }
3178
3179 return 1;
3180}
3181
Simon Horman05ee2132017-01-04 09:37:25 +01003182
William Lallemand74c24fb2016-11-21 17:18:36 +01003183/* This I/O handler runs as an applet embedded in a stream interface. It is
3184 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
3185 * appctx->st0 contains the operation in progress (dump, done). The handler
3186 * automatically unregisters itself once transfer is complete.
3187 */
Christopher Fauletef779222018-10-31 08:47:01 +01003188static void htx_stats_io_handler(struct appctx *appctx)
3189{
3190 struct stream_interface *si = appctx->owner;
3191 struct stream *s = si_strm(si);
3192 struct channel *req = si_oc(si);
3193 struct channel *res = si_ic(si);
3194 struct htx *req_htx, *res_htx;
3195
3196 res_htx = htx_from_buf(&res->buf);
3197
3198 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
3199 goto out;
3200
3201 /* Check if the input buffer is avalaible. */
3202 if (!b_size(&res->buf)) {
3203 si_rx_room_blk(si);
3204 goto out;
3205 }
3206
3207 /* check that the output is not closed */
3208 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
3209 appctx->st0 = STAT_HTTP_DONE;
3210
3211 /* all states are processed in sequence */
3212 if (appctx->st0 == STAT_HTTP_HEAD) {
3213 if (stats_send_htx_headers(si, res_htx)) {
3214 if (s->txn->meth == HTTP_METH_HEAD)
3215 appctx->st0 = STAT_HTTP_DONE;
3216 else
3217 appctx->st0 = STAT_HTTP_DUMP;
3218 }
3219 }
3220
3221 if (appctx->st0 == STAT_HTTP_DUMP) {
3222 if (stats_dump_stat_to_buffer(si, res_htx, s->be->uri_auth))
3223 appctx->st0 = STAT_HTTP_DONE;
3224 }
3225
3226 if (appctx->st0 == STAT_HTTP_POST) {
3227 if (stats_process_http_post(si))
3228 appctx->st0 = STAT_HTTP_LAST;
3229 else if (si_oc(si)->flags & CF_SHUTR)
3230 appctx->st0 = STAT_HTTP_DONE;
3231 }
3232
3233 if (appctx->st0 == STAT_HTTP_LAST) {
3234 if (stats_send_htx_redirect(si, res_htx))
3235 appctx->st0 = STAT_HTTP_DONE;
3236 }
3237
3238 if (appctx->st0 == STAT_HTTP_DONE) {
Christopher Fauletb1b08212018-11-21 13:51:07 +01003239 /* Don't add EOD and TLR because mux-h1 will take care of it */
Christopher Fauletef779222018-10-31 08:47:01 +01003240 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
3241 si_rx_room_blk(si);
3242 goto out;
3243 }
3244
3245 /* eat the whole request */
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01003246 req_htx = htxbuf(&req->buf);
3247 htx_reset(req_htx);
3248 htx_to_buf(req_htx, &req->buf);
Christopher Faulet9b95d312018-11-19 21:58:10 +01003249 co_set_data(req, 0);
Christopher Fauletef779222018-10-31 08:47:01 +01003250 res->flags |= CF_READ_NULL;
3251 si_shutr(si);
3252 }
3253
3254 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
3255 si_shutw(si);
3256
3257 if (appctx->st0 == STAT_HTTP_DONE) {
3258 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) {
3259 si_shutr(si);
3260 res->flags |= CF_READ_NULL;
3261 }
3262 }
3263 out:
3264 /* we have left the request in the buffer for the case where we
3265 * process a POST, and this automatically re-enables activity on
3266 * read. It's better to indicate that we want to stop reading when
3267 * we're sending, so that we know there's at most one direction
3268 * deciding to wake the applet up. It saves it from looping when
3269 * emitting large blocks into small TCP windows.
3270 */
Christopher Faulet27ba2dc2018-12-05 11:53:24 +01003271 htx_to_buf(res_htx, &res->buf);
3272 if (!channel_is_empty(res))
Christopher Fauletef779222018-10-31 08:47:01 +01003273 si_stop_get(si);
Christopher Fauletef779222018-10-31 08:47:01 +01003274}
3275
3276
3277/* This I/O handler runs as an applet embedded in a stream interface. It is
3278 * used to send HTTP stats over a TCP socket. The mechanism is very simple.
3279 * appctx->st0 contains the operation in progress (dump, done). The handler
3280 * automatically unregisters itself once transfer is complete.
3281 */
William Lallemand74c24fb2016-11-21 17:18:36 +01003282static void http_stats_io_handler(struct appctx *appctx)
3283{
3284 struct stream_interface *si = appctx->owner;
3285 struct stream *s = si_strm(si);
3286 struct channel *req = si_oc(si);
3287 struct channel *res = si_ic(si);
3288
Christopher Fauletef779222018-10-31 08:47:01 +01003289 if (IS_HTX_STRM(s))
3290 return htx_stats_io_handler(appctx);
3291
William Lallemand74c24fb2016-11-21 17:18:36 +01003292 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
3293 goto out;
3294
Joseph Herlant29023ec2018-11-15 13:39:46 -08003295 /* Check if the input buffer is available. */
Willy Tarreauc9fa0482018-07-10 17:43:27 +02003296 if (res->buf.size == 0) {
Willy Tarreau4b962a42018-11-15 11:03:21 +01003297 /* already subscribed, we'll be called later once the buffer is
3298 * available.
3299 */
Christopher Fauleta73e59b2016-12-09 17:30:18 +01003300 goto out;
3301 }
3302
William Lallemand74c24fb2016-11-21 17:18:36 +01003303 /* check that the output is not closed */
3304 if (res->flags & (CF_SHUTW|CF_SHUTW_NOW))
3305 appctx->st0 = STAT_HTTP_DONE;
3306
3307 /* all states are processed in sequence */
3308 if (appctx->st0 == STAT_HTTP_HEAD) {
3309 if (stats_send_http_headers(si)) {
3310 if (s->txn->meth == HTTP_METH_HEAD)
3311 appctx->st0 = STAT_HTTP_DONE;
3312 else
3313 appctx->st0 = STAT_HTTP_DUMP;
3314 }
3315 }
3316
3317 if (appctx->st0 == STAT_HTTP_DUMP) {
Willy Tarreau97f538b2018-06-15 19:41:31 +02003318 unsigned int prev_len = ci_data(si_ic(si));
William Lallemand74c24fb2016-11-21 17:18:36 +01003319 unsigned int data_len;
3320 unsigned int last_len;
3321 unsigned int last_fwd = 0;
3322
3323 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
3324 /* One difficulty we're facing is that we must prevent
3325 * the input data from being automatically forwarded to
3326 * the output area. For this, we temporarily disable
3327 * forwarding on the channel.
3328 */
3329 last_fwd = si_ic(si)->to_forward;
3330 si_ic(si)->to_forward = 0;
3331 chunk_printf(&trash, "\r\n000000\r\n");
Willy Tarreau06d80a92017-10-19 14:32:15 +02003332 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003333 si_rx_room_blk(si);
William Lallemand74c24fb2016-11-21 17:18:36 +01003334 si_ic(si)->to_forward = last_fwd;
3335 goto out;
3336 }
3337 }
3338
Willy Tarreau97f538b2018-06-15 19:41:31 +02003339 data_len = ci_data(si_ic(si));
Christopher Fauletef779222018-10-31 08:47:01 +01003340 if (stats_dump_stat_to_buffer(si, NULL, s->be->uri_auth))
William Lallemand74c24fb2016-11-21 17:18:36 +01003341 appctx->st0 = STAT_HTTP_DONE;
3342
Willy Tarreau97f538b2018-06-15 19:41:31 +02003343 last_len = ci_data(si_ic(si));
William Lallemand74c24fb2016-11-21 17:18:36 +01003344
3345 /* Now we must either adjust or remove the chunk size. This is
3346 * not easy because the chunk size might wrap at the end of the
3347 * buffer, so we pretend we have nothing in the buffer, we write
3348 * the size, then restore the buffer's contents. Note that we can
3349 * only do that because no forwarding is scheduled on the stats
3350 * applet.
3351 */
3352 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
3353 si_ic(si)->total -= (last_len - prev_len);
Willy Tarreau97f538b2018-06-15 19:41:31 +02003354 b_sub(si_ib(si), (last_len - prev_len));
William Lallemand74c24fb2016-11-21 17:18:36 +01003355
3356 if (last_len != data_len) {
3357 chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len));
Willy Tarreau06d80a92017-10-19 14:32:15 +02003358 if (ci_putchk(si_ic(si), &trash) == -1)
Willy Tarreaudb398432018-11-15 11:08:52 +01003359 si_rx_room_blk(si);
William Lallemand74c24fb2016-11-21 17:18:36 +01003360
3361 si_ic(si)->total += (last_len - data_len);
Willy Tarreau97f538b2018-06-15 19:41:31 +02003362 b_add(si_ib(si), last_len - data_len);
William Lallemand74c24fb2016-11-21 17:18:36 +01003363 }
3364 /* now re-enable forwarding */
3365 channel_forward(si_ic(si), last_fwd);
3366 }
3367 }
3368
3369 if (appctx->st0 == STAT_HTTP_POST) {
3370 if (stats_process_http_post(si))
3371 appctx->st0 = STAT_HTTP_LAST;
3372 else if (si_oc(si)->flags & CF_SHUTR)
3373 appctx->st0 = STAT_HTTP_DONE;
3374 }
3375
3376 if (appctx->st0 == STAT_HTTP_LAST) {
3377 if (stats_send_http_redirect(si))
3378 appctx->st0 = STAT_HTTP_DONE;
3379 }
3380
3381 if (appctx->st0 == STAT_HTTP_DONE) {
3382 if (appctx->ctx.stats.flags & STAT_CHUNKED) {
3383 chunk_printf(&trash, "\r\n0\r\n\r\n");
Willy Tarreau06d80a92017-10-19 14:32:15 +02003384 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003385 si_rx_room_blk(si);
William Lallemand74c24fb2016-11-21 17:18:36 +01003386 goto out;
3387 }
3388 }
3389 /* eat the whole request */
Willy Tarreau97f538b2018-06-15 19:41:31 +02003390 co_skip(si_oc(si), co_data(si_oc(si)));
William Lallemand74c24fb2016-11-21 17:18:36 +01003391 res->flags |= CF_READ_NULL;
3392 si_shutr(si);
3393 }
3394
3395 if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST))
3396 si_shutw(si);
3397
3398 if (appctx->st0 == STAT_HTTP_DONE) {
3399 if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) {
3400 si_shutr(si);
3401 res->flags |= CF_READ_NULL;
3402 }
3403 }
3404 out:
Willy Tarreau055ba4f2018-07-24 17:05:54 +02003405 /* we have left the request in the buffer for the case where we
3406 * process a POST, and this automatically re-enables activity on
3407 * read. It's better to indicate that we want to stop reading when
3408 * we're sending, so that we know there's at most one direction
3409 * deciding to wake the applet up. It saves it from looping when
3410 * emitting large blocks into small TCP windows.
3411 */
3412 if (!channel_is_empty(res))
Willy Tarreau0cd3bd62018-11-06 18:46:37 +01003413 si_stop_get(si);
William Lallemand74c24fb2016-11-21 17:18:36 +01003414}
3415
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003416/* Dump all fields from <info> into <out> using the "show info" format (name: value) */
Willy Tarreau83061a82018-07-13 11:56:34 +02003417static int stats_dump_info_fields(struct buffer *out,
3418 const struct field *info)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003419{
3420 int field;
3421
3422 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3423 if (!field_format(info, field))
3424 continue;
3425
3426 if (!chunk_appendf(out, "%s: ", info_field_names[field]))
3427 return 0;
3428 if (!stats_emit_raw_data_field(out, &info[field]))
3429 return 0;
3430 if (!chunk_strcat(out, "\n"))
3431 return 0;
3432 }
3433 return 1;
3434}
3435
3436/* Dump all fields from <info> into <out> using the "show info typed" format */
Willy Tarreau83061a82018-07-13 11:56:34 +02003437static int stats_dump_typed_info_fields(struct buffer *out,
3438 const struct field *info)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003439{
3440 int field;
3441
3442 for (field = 0; field < INF_TOTAL_FIELDS; field++) {
3443 if (!field_format(info, field))
3444 continue;
3445
3446 if (!chunk_appendf(out, "%d.%s.%u:", field, info_field_names[field], info[INF_PROCESS_NUM].u.u32))
3447 return 0;
3448 if (!stats_emit_field_tags(out, &info[field], ':'))
3449 return 0;
3450 if (!stats_emit_typed_data_field(out, &info[field]))
3451 return 0;
3452 if (!chunk_strcat(out, "\n"))
3453 return 0;
3454 }
3455 return 1;
3456}
3457
3458/* Fill <info> with HAProxy global info. <info> is preallocated
3459 * array of length <len>. The length of the aray must be
3460 * INF_TOTAL_FIELDS. If this length is less then this value, the
3461 * function returns 0, otherwise, it returns 1.
3462 */
3463int stats_fill_info(struct field *info, int len)
3464{
3465 unsigned int up = (now.tv_sec - start_date.tv_sec);
Willy Tarreau83061a82018-07-13 11:56:34 +02003466 struct buffer *out = get_trash_chunk();
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003467
3468#ifdef USE_OPENSSL
3469 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
3470 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
3471 int ssl_reuse = 0;
3472
3473 if (ssl_key_rate < ssl_sess_rate) {
3474 /* count the ssl reuse ratio and avoid overflows in both directions */
3475 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
3476 }
3477#endif
3478
3479 if (len < INF_TOTAL_FIELDS)
3480 return 0;
3481
3482 chunk_reset(out);
3483 memset(info, 0, sizeof(*info) * len);
3484
3485 info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME);
3486 info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION);
3487 info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE);
3488
Yves Lafon95317282018-02-26 11:10:37 +01003489 info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003490 info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
3491 info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid);
3492 info[INF_PID] = mkf_u32(FO_STATUS, pid);
3493
3494 info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out));
3495 chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
3496
3497 info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up);
3498 info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax);
3499 info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L));
3500 info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L));
3501 info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures());
3502 info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
3503 info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
3504 info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
3505 info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
3506 info[INF_CURR_CONN] = mkf_u32(0, actconn);
3507 info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn);
3508 info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count);
3509#ifdef USE_OPENSSL
3510 info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn);
3511 info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns);
3512 info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns);
3513#endif
3514 info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
3515 info[INF_PIPES_USED] = mkf_u32(0, pipes_used);
3516 info[INF_PIPES_FREE] = mkf_u32(0, pipes_free);
3517 info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
3518 info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
3519 info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max);
3520 info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
3521 info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
3522 info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max);
3523
3524#ifdef USE_OPENSSL
3525 info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate);
3526 info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
3527 info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max);
3528 info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate);
3529 info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
3530 info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse);
3531 info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
3532 info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max);
3533 info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups);
3534 info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses);
3535#endif
3536 info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
3537 info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
3538 info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
3539#ifdef USE_ZLIB
3540 info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory);
3541 info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
3542#endif
3543 info[INF_TASKS] = mkf_u32(0, nb_tasks_cur);
Christopher Faulet34c5cc92016-12-06 09:15:30 +01003544 info[INF_RUN_QUEUE] = mkf_u32(0, tasks_run_queue_cur);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003545 info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct);
3546 info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node);
3547 if (global.desc)
3548 info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003549 info[INF_STOPPING] = mkf_u32(0, stopping);
3550 info[INF_JOBS] = mkf_u32(0, jobs);
William Lallemanda7199262018-11-16 16:57:20 +01003551 info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs);
Willy Tarreau00098ea2018-11-05 14:38:13 +01003552 info[INF_LISTENERS] = mkf_u32(0, listeners);
Willy Tarreau199ad242018-11-05 16:31:22 +01003553 info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers);
Willy Tarreau2d372c22018-11-05 17:12:27 +01003554 info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers);
Willy Tarreau13ef7732018-11-12 07:25:28 +01003555 info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs);
Willy Tarreaubeb859a2018-11-22 18:07:59 +01003556 info[INF_BUSY_POLLING] = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003557
3558 return 1;
3559}
3560
3561/* This function dumps information onto the stream interface's read buffer.
3562 * It returns 0 as long as it does not complete, non-zero upon completion.
3563 * No state is used.
3564 */
3565static int stats_dump_info_to_buffer(struct stream_interface *si)
3566{
3567 struct appctx *appctx = __objt_appctx(si->end);
3568
3569 if (!stats_fill_info(info, INF_TOTAL_FIELDS))
3570 return 0;
3571
3572 chunk_reset(&trash);
3573
3574 if (appctx->ctx.stats.flags & STAT_FMT_TYPED)
3575 stats_dump_typed_info_fields(&trash, info);
Simon Horman05ee2132017-01-04 09:37:25 +01003576 else if (appctx->ctx.stats.flags & STAT_FMT_JSON)
3577 stats_dump_json_info_fields(&trash, info);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003578 else
3579 stats_dump_info_fields(&trash, info);
3580
Willy Tarreau06d80a92017-10-19 14:32:15 +02003581 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003582 si_rx_room_blk(si);
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003583 return 0;
3584 }
3585
3586 return 1;
3587}
3588
Simon Horman6f6bb382017-01-04 09:37:26 +01003589/* This function dumps the schema onto the stream interface's read buffer.
3590 * It returns 0 as long as it does not complete, non-zero upon completion.
3591 * No state is used.
3592 *
3593 * Integer values bouned to the range [-(2**53)+1, (2**53)-1] as
3594 * per the recommendation for interoperable integers in section 6 of RFC 7159.
3595 */
Willy Tarreau83061a82018-07-13 11:56:34 +02003596static void stats_dump_json_schema(struct buffer *out)
Simon Horman6f6bb382017-01-04 09:37:26 +01003597{
3598
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003599 int old_len = out->data;
Simon Horman6f6bb382017-01-04 09:37:26 +01003600
3601 chunk_strcat(out,
3602 "{"
3603 "\"$schema\":\"http://json-schema.org/draft-04/schema#\","
3604 "\"oneOf\":["
3605 "{"
3606 "\"title\":\"Info\","
3607 "\"type\":\"array\","
3608 "\"items\":{"
3609 "\"properties\":{"
3610 "\"title\":\"InfoItem\","
3611 "\"type\":\"object\","
3612 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3613 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3614 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3615 "\"value\":{\"$ref\":\"#/definitions/typedValue\"}"
3616 "},"
3617 "\"required\":[\"field\",\"processNum\",\"tags\","
3618 "\"value\"]"
3619 "}"
3620 "},"
3621 "{"
3622 "\"title\":\"Stat\","
3623 "\"type\":\"array\","
3624 "\"items\":{"
3625 "\"title\":\"InfoItem\","
3626 "\"type\":\"object\","
3627 "\"properties\":{"
3628 "\"objType\":{"
3629 "\"enum\":[\"Frontend\",\"Backend\",\"Listener\","
3630 "\"Server\",\"Unknown\"]"
3631 "},"
3632 "\"proxyId\":{"
3633 "\"type\":\"integer\","
3634 "\"minimum\":0"
3635 "},"
3636 "\"id\":{"
3637 "\"type\":\"integer\","
3638 "\"minimum\":0"
3639 "},"
3640 "\"field\":{\"$ref\":\"#/definitions/field\"},"
3641 "\"processNum\":{\"$ref\":\"#/definitions/processNum\"},"
3642 "\"tags\":{\"$ref\":\"#/definitions/tags\"},"
3643 "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}"
3644 "},"
3645 "\"required\":[\"objType\",\"proxyId\",\"id\","
3646 "\"field\",\"processNum\",\"tags\","
3647 "\"value\"]"
3648 "}"
3649 "},"
3650 "{"
3651 "\"title\":\"Error\","
3652 "\"type\":\"object\","
3653 "\"properties\":{"
3654 "\"errorStr\":{"
3655 "\"type\":\"string\""
3656 "},"
3657 "\"required\":[\"errorStr\"]"
3658 "}"
3659 "}"
3660 "],"
3661 "\"definitions\":{"
3662 "\"field\":{"
3663 "\"type\":\"object\","
3664 "\"pos\":{"
3665 "\"type\":\"integer\","
3666 "\"minimum\":0"
3667 "},"
3668 "\"name\":{"
3669 "\"type\":\"string\""
3670 "},"
3671 "\"required\":[\"pos\",\"name\"]"
3672 "},"
3673 "\"processNum\":{"
3674 "\"type\":\"integer\","
3675 "\"minimum\":1"
3676 "},"
3677 "\"tags\":{"
3678 "\"type\":\"object\","
3679 "\"origin\":{"
3680 "\"type\":\"string\","
3681 "\"enum\":[\"Metric\",\"Status\",\"Key\","
3682 "\"Config\",\"Product\",\"Unknown\"]"
3683 "},"
3684 "\"nature\":{"
3685 "\"type\":\"string\","
3686 "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\","
3687 "\"Rate\",\"Counter\",\"Duration\","
3688 "\"Age\",\"Time\",\"Name\",\"Output\","
3689 "\"Avg\", \"Unknown\"]"
3690 "},"
3691 "\"scope\":{"
3692 "\"type\":\"string\","
3693 "\"enum\":[\"Cluster\",\"Process\",\"Service\","
3694 "\"System\",\"Unknown\"]"
3695 "},"
3696 "\"required\":[\"origin\",\"nature\",\"scope\"]"
3697 "},"
3698 "\"typedValue\":{"
3699 "\"type\":\"object\","
3700 "\"oneOf\":["
3701 "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"},"
3702 "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"},"
3703 "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"},"
3704 "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"},"
3705 "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}"
3706 "],"
3707 "\"definitions\":{"
3708 "\"s32Value\":{"
3709 "\"properties\":{"
3710 "\"type\":{"
3711 "\"type\":\"string\","
3712 "\"enum\":[\"s32\"]"
3713 "},"
3714 "\"value\":{"
3715 "\"type\":\"integer\","
3716 "\"minimum\":-2147483648,"
3717 "\"maximum\":2147483647"
3718 "}"
3719 "},"
3720 "\"required\":[\"type\",\"value\"]"
3721 "},"
3722 "\"s64Value\":{"
3723 "\"properties\":{"
3724 "\"type\":{"
3725 "\"type\":\"string\","
3726 "\"enum\":[\"s64\"]"
3727 "},"
3728 "\"value\":{"
3729 "\"type\":\"integer\","
3730 "\"minimum\":-9007199254740991,"
3731 "\"maximum\":9007199254740991"
3732 "}"
3733 "},"
3734 "\"required\":[\"type\",\"value\"]"
3735 "},"
3736 "\"u32Value\":{"
3737 "\"properties\":{"
3738 "\"type\":{"
3739 "\"type\":\"string\","
3740 "\"enum\":[\"u32\"]"
3741 "},"
3742 "\"value\":{"
3743 "\"type\":\"integer\","
3744 "\"minimum\":0,"
3745 "\"maximum\":4294967295"
3746 "}"
3747 "},"
3748 "\"required\":[\"type\",\"value\"]"
3749 "},"
3750 "\"u64Value\":{"
3751 "\"properties\":{"
3752 "\"type\":{"
3753 "\"type\":\"string\","
3754 "\"enum\":[\"u64\"]"
3755 "},"
3756 "\"value\":{"
3757 "\"type\":\"integer\","
3758 "\"minimum\":0,"
3759 "\"maximum\":9007199254740991"
3760 "}"
3761 "},"
3762 "\"required\":[\"type\",\"value\"]"
3763 "},"
3764 "\"strValue\":{"
3765 "\"properties\":{"
3766 "\"type\":{"
3767 "\"type\":\"string\","
3768 "\"enum\":[\"str\"]"
3769 "},"
3770 "\"value\":{\"type\":\"string\"}"
3771 "},"
3772 "\"required\":[\"type\",\"value\"]"
3773 "},"
3774 "\"unknownValue\":{"
3775 "\"properties\":{"
3776 "\"type\":{"
3777 "\"type\":\"integer\","
3778 "\"minimum\":0"
3779 "},"
3780 "\"value\":{"
3781 "\"type\":\"string\","
3782 "\"enum\":[\"unknown\"]"
3783 "}"
3784 "},"
3785 "\"required\":[\"type\",\"value\"]"
3786 "}"
3787 "}"
3788 "}"
3789 "}"
3790 "}");
3791
Willy Tarreau843b7cb2018-07-13 10:54:26 +02003792 if (old_len == out->data) {
Simon Horman6f6bb382017-01-04 09:37:26 +01003793 chunk_reset(out);
3794 chunk_appendf(out,
3795 "{\"errorStr\":\"output buffer too short\"}");
3796 }
3797}
3798
3799/* This function dumps the schema onto the stream interface's read buffer.
3800 * It returns 0 as long as it does not complete, non-zero upon completion.
3801 * No state is used.
3802 */
3803static int stats_dump_json_schema_to_buffer(struct stream_interface *si)
3804{
3805 chunk_reset(&trash);
3806
3807 stats_dump_json_schema(&trash);
3808
Willy Tarreau06d80a92017-10-19 14:32:15 +02003809 if (ci_putchk(si_ic(si), &trash) == -1) {
Willy Tarreaudb398432018-11-15 11:08:52 +01003810 si_rx_room_blk(si);
Simon Horman6f6bb382017-01-04 09:37:26 +01003811 return 0;
3812 }
3813
3814 return 1;
3815}
3816
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003817static int cli_parse_clear_counters(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau89d467c2016-11-23 11:02:40 +01003818{
3819 struct proxy *px;
3820 struct server *sv;
3821 struct listener *li;
3822 int clrall = 0;
3823
3824 if (strcmp(args[2], "all") == 0)
3825 clrall = 1;
3826
3827 /* check permissions */
3828 if (!cli_has_level(appctx, ACCESS_LVL_OPER) ||
3829 (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN)))
3830 return 1;
3831
Olivier Houchardfbc74e82017-11-24 16:54:05 +01003832 for (px = proxies_list; px; px = px->next) {
Willy Tarreau89d467c2016-11-23 11:02:40 +01003833 if (clrall) {
3834 memset(&px->be_counters, 0, sizeof(px->be_counters));
3835 memset(&px->fe_counters, 0, sizeof(px->fe_counters));
3836 }
3837 else {
3838 px->be_counters.conn_max = 0;
3839 px->be_counters.p.http.rps_max = 0;
3840 px->be_counters.sps_max = 0;
3841 px->be_counters.cps_max = 0;
3842 px->be_counters.nbpend_max = 0;
3843
3844 px->fe_counters.conn_max = 0;
3845 px->fe_counters.p.http.rps_max = 0;
3846 px->fe_counters.sps_max = 0;
3847 px->fe_counters.cps_max = 0;
Willy Tarreau89d467c2016-11-23 11:02:40 +01003848 }
3849
3850 for (sv = px->srv; sv; sv = sv->next)
3851 if (clrall)
3852 memset(&sv->counters, 0, sizeof(sv->counters));
3853 else {
3854 sv->counters.cur_sess_max = 0;
3855 sv->counters.nbpend_max = 0;
3856 sv->counters.sps_max = 0;
3857 }
3858
3859 list_for_each_entry(li, &px->conf.listeners, by_fe)
3860 if (li->counters) {
3861 if (clrall)
3862 memset(li->counters, 0, sizeof(*li->counters));
3863 else
3864 li->counters->conn_max = 0;
3865 }
3866 }
3867
3868 global.cps_max = 0;
3869 global.sps_max = 0;
Olivier Houchard00bc3cb2017-10-17 19:23:25 +02003870 global.ssl_max = 0;
3871 global.ssl_fe_keys_max = 0;
3872 global.ssl_be_keys_max = 0;
Willy Tarreaud80cb4e2018-01-20 19:30:13 +01003873
3874 memset(activity, 0, sizeof(activity));
Willy Tarreau89d467c2016-11-23 11:02:40 +01003875 return 1;
3876}
3877
3878
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003879static int cli_parse_show_info(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003880{
Willy Tarreaud25fc792016-12-16 12:33:47 +01003881 appctx->ctx.stats.scope_str = 0;
3882 appctx->ctx.stats.scope_len = 0;
3883 appctx->ctx.stats.flags = 0;
3884
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003885 if (strcmp(args[2], "typed") == 0)
3886 appctx->ctx.stats.flags |= STAT_FMT_TYPED;
Simon Horman05ee2132017-01-04 09:37:25 +01003887 else if (strcmp(args[2], "json") == 0)
3888 appctx->ctx.stats.flags |= STAT_FMT_JSON;
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003889 return 0;
3890}
3891
3892
Aurélien Nephtaliabbf6072018-04-18 13:26:46 +02003893static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx, void *private)
Willy Tarreau2b812e22016-11-22 16:18:05 +01003894{
Willy Tarreaud25fc792016-12-16 12:33:47 +01003895 appctx->ctx.stats.scope_str = 0;
3896 appctx->ctx.stats.scope_len = 0;
3897 appctx->ctx.stats.flags = 0;
3898
Willy Tarreau2b812e22016-11-22 16:18:05 +01003899 if (*args[2] && *args[3] && *args[4]) {
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003900 struct proxy *px;
3901
3902 px = proxy_find_by_name(args[2], 0, 0);
3903 if (px)
3904 appctx->ctx.stats.iid = px->uuid;
3905 else
3906 appctx->ctx.stats.iid = atoi(args[2]);
3907
3908 if (!appctx->ctx.stats.iid) {
Andjelko Iharosc3680ec2017-07-20 16:49:14 +02003909 appctx->ctx.cli.severity = LOG_ERR;
Willy Tarreaua1b1ed52016-11-25 08:50:58 +01003910 appctx->ctx.cli.msg = "No such proxy.\n";
3911 appctx->st0 = CLI_ST_PRINT;
3912 return 1;
3913 }
3914
Willy Tarreau2b812e22016-11-22 16:18:05 +01003915 appctx->ctx.stats.flags |= STAT_BOUND;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003916 appctx->ctx.stats.type = atoi(args[3]);
3917 appctx->ctx.stats.sid = atoi(args[4]);
3918 if (strcmp(args[5], "typed") == 0)
3919 appctx->ctx.stats.flags |= STAT_FMT_TYPED;
Simon Horman05ee2132017-01-04 09:37:25 +01003920 else if (strcmp(args[5], "json") == 0)
3921 appctx->ctx.stats.flags |= STAT_FMT_JSON;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003922 }
3923 else if (strcmp(args[2], "typed") == 0)
3924 appctx->ctx.stats.flags |= STAT_FMT_TYPED;
Simon Horman05ee2132017-01-04 09:37:25 +01003925 else if (strcmp(args[2], "json") == 0)
3926 appctx->ctx.stats.flags |= STAT_FMT_JSON;
Willy Tarreau2b812e22016-11-22 16:18:05 +01003927
Willy Tarreau2b812e22016-11-22 16:18:05 +01003928 return 0;
3929}
3930
Willy Tarreau0baac8c2016-11-22 16:36:53 +01003931static int cli_io_handler_dump_info(struct appctx *appctx)
3932{
3933 return stats_dump_info_to_buffer(appctx->owner);
3934}
3935
Willy Tarreau2b812e22016-11-22 16:18:05 +01003936/* This I/O handler runs as an applet embedded in a stream interface. It is
3937 * used to send raw stats over a socket.
3938 */
3939static int cli_io_handler_dump_stat(struct appctx *appctx)
3940{
Christopher Fauletef779222018-10-31 08:47:01 +01003941 return stats_dump_stat_to_buffer(appctx->owner, NULL, NULL);
Willy Tarreau2b812e22016-11-22 16:18:05 +01003942}
3943
Simon Horman6f6bb382017-01-04 09:37:26 +01003944static int cli_io_handler_dump_json_schema(struct appctx *appctx)
3945{
3946 return stats_dump_json_schema_to_buffer(appctx->owner);
3947}
3948
Willy Tarreau2b812e22016-11-22 16:18:05 +01003949/* register cli keywords */
3950static struct cli_kw_list cli_kws = {{ },{
Willy Tarreau89d467c2016-11-23 11:02:40 +01003951 { { "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 +01003952 { { "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 +01003953 { { "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 +01003954 { { "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 +01003955 {{},}
3956}};
3957
Willy Tarreau0108d902018-11-25 19:14:37 +01003958INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws);
3959
William Lallemand74c24fb2016-11-21 17:18:36 +01003960struct applet http_stats_applet = {
3961 .obj_type = OBJ_TYPE_APPLET,
3962 .name = "<STATS>", /* used for logging */
3963 .fct = http_stats_io_handler,
3964 .release = NULL,
3965};
3966
William Lallemand74c24fb2016-11-21 17:18:36 +01003967/*
3968 * Local variables:
3969 * c-indent-level: 8
3970 * c-basic-offset: 8
3971 * End:
3972 */