blob: db60bab83bcdee91fba9363d679684177e258d58 [file] [log] [blame]
Willy Tarreau91861262007-10-17 17:06:05 +02001/*
Willy Tarreaueb472682010-05-28 18:46:57 +02002 * include/proto/dumpstats.h
3 * This file contains definitions of some primitives to dedicated to
4 * statistics output.
5 *
Willy Tarreaub24281b2011-02-13 13:16:36 +01006 * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
Willy Tarreaueb472682010-05-28 18:46:57 +02007 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
Willy Tarreau91861262007-10-17 17:06:05 +020022
23#ifndef _PROTO_DUMPSTATS_H
24#define _PROTO_DUMPSTATS_H
25
26#include <common/config.h>
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020027#include <types/applet.h>
Willy Tarreauc7e42382012-08-24 19:22:53 +020028#include <types/stream_interface.h>
Willy Tarreau91861262007-10-17 17:06:05 +020029
Willy Tarreau295a8372011-03-10 11:25:07 +010030/* Flags for applet.ctx.stats.flags */
Willy Tarreau354898b2012-12-23 18:15:23 +010031#define STAT_FMT_HTML 0x00000001 /* dump the stats in HTML format */
Willy Tarreaucb809122016-01-11 20:08:42 +010032#define STAT_FMT_TYPED 0x00000002 /* use the typed output format */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +010033#define STAT_HIDE_DOWN 0x00000008 /* hide 'down' servers in the stats page */
34#define STAT_NO_REFRESH 0x00000010 /* do not automatically refresh the stats page */
Cyril Bonté474be412010-10-12 00:14:36 +020035#define STAT_ADMIN 0x00000020 /* indicate a stats admin level */
Willy Tarreauaf3cf702014-04-22 22:19:53 +020036#define STAT_CHUNKED 0x00000040 /* use chunked encoding (HTTP/1.1) */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +010037#define STAT_BOUND 0x00800000 /* bound statistics to selected proxies/types/services */
Willy Tarreau55bb8452007-10-17 18:44:57 +020038
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010039#define STATS_TYPE_FE 0
40#define STATS_TYPE_BE 1
41#define STATS_TYPE_SV 2
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +020042#define STATS_TYPE_SO 3
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010043
Willy Tarreau96d44912013-11-22 12:25:24 +010044/* HTTP stats : applet.st0 */
45enum {
46 STAT_HTTP_DONE = 0, /* finished */
Willy Tarreau347a35d2013-11-22 17:51:09 +010047 STAT_HTTP_HEAD, /* send headers before dump */
Willy Tarreau96d44912013-11-22 12:25:24 +010048 STAT_HTTP_DUMP, /* dumping stats */
Willy Tarreau347a35d2013-11-22 17:51:09 +010049 STAT_HTTP_POST, /* waiting post data */
50 STAT_HTTP_LAST, /* sending last chunk of response */
Willy Tarreau96d44912013-11-22 12:25:24 +010051};
52
de Lafond Guillaume88c278f2013-04-15 19:27:10 +020053/* HTML form to limit output scope */
54#define STAT_SCOPE_TXT_MAXLEN 20 /* max len for scope substring */
55#define STAT_SCOPE_INPUT_NAME "scope" /* pattern form scope name <input> in html form */
56#define STAT_SCOPE_PATTERN "?" STAT_SCOPE_INPUT_NAME "="
57
Thierry Fournier31e64ca2016-03-23 16:25:49 +010058/* Show Info fields for CLI output. For any field added here, please add the text
59 * representation in the info_field_names array below. Please only append at the end,
60 * before the INF_TOTAL_FIELDS entry, and never insert anything in the middle
61 * nor at the beginning.
62 */
63enum info_field {
64 INF_NAME,
65 INF_VERSION,
66 INF_RELEASE_DATE,
67 INF_NBPROC,
68 INF_PROCESS_NUM,
69 INF_PID,
70 INF_UPTIME,
71 INF_UPTIME_SEC,
72 INF_MEMMAX_MB,
73 INF_POOL_ALLOC_MB,
74 INF_POOL_USED_MB,
75 INF_POOL_FAILED,
76 INF_ULIMIT_N,
77 INF_MAXSOCK,
78 INF_MAXCONN,
79 INF_HARD_MAXCONN,
80 INF_CURR_CONN,
81 INF_CUM_CONN,
82 INF_CUM_REQ,
83 INF_MAX_SSL_CONNS,
84 INF_CURR_SSL_CONNS,
85 INF_CUM_SSL_CONNS,
86 INF_MAXPIPES,
87 INF_PIPES_USED,
88 INF_PIPES_FREE,
89 INF_CONN_RATE,
90 INF_CONN_RATE_LIMIT,
91 INF_MAX_CONN_RATE,
92 INF_SESS_RATE,
93 INF_SESS_RATE_LIMIT,
94 INF_MAX_SESS_RATE,
95 INF_SSL_RATE,
96 INF_SSL_RATE_LIMIT,
97 INF_MAX_SSL_RATE,
98 INF_SSL_FRONTEND_KEY_RATE,
99 INF_SSL_FRONTEND_MAX_KEY_RATE,
100 INF_SSL_FRONTEND_SESSION_REUSE_PCT,
101 INF_SSL_BACKEND_KEY_RATE,
102 INF_SSL_BACKEND_MAX_KEY_RATE,
103 INF_SSL_CACHE_LOOKUPS,
104 INF_SSL_CACHE_MISSES,
105 INF_COMPRESS_BPS_IN,
106 INF_COMPRESS_BPS_OUT,
107 INF_COMPRESS_BPS_RATE_LIM,
108 INF_ZLIB_MEM_USAGE,
109 INF_MAX_ZLIB_MEM_USAGE,
110 INF_TASKS,
111 INF_RUN_QUEUE,
112 INF_IDLE_PCT,
113 INF_NODE,
114 INF_DESCRIPTION,
115
116 /* must always be the last one */
117 INF_TOTAL_FIELDS
118};
119
120/* Stats fields for CSV output. For any field added here, please add the text
121 * representation in the stat_field_names array below. Please only append at the end,
122 * before the ST_F_TOTAL_FIELDS entry, and never insert anything in the middle
123 * nor at the beginning.
124 */
125enum stat_field {
126 ST_F_PXNAME,
127 ST_F_SVNAME,
128 ST_F_QCUR,
129 ST_F_QMAX,
130 ST_F_SCUR,
131 ST_F_SMAX,
132 ST_F_SLIM,
133 ST_F_STOT,
134 ST_F_BIN ,
135 ST_F_BOUT,
136 ST_F_DREQ,
137 ST_F_DRESP,
138 ST_F_EREQ,
139 ST_F_ECON,
140 ST_F_ERESP,
141 ST_F_WRETR,
142 ST_F_WREDIS,
143 ST_F_STATUS,
144 ST_F_WEIGHT,
145 ST_F_ACT,
146 ST_F_BCK,
147 ST_F_CHKFAIL,
148 ST_F_CHKDOWN,
149 ST_F_LASTCHG,
150 ST_F_DOWNTIME,
151 ST_F_QLIMIT,
152 ST_F_PID,
153 ST_F_IID,
154 ST_F_SID,
155 ST_F_THROTTLE,
156 ST_F_LBTOT,
157 ST_F_TRACKED,
158 ST_F_TYPE,
159 ST_F_RATE,
160 ST_F_RATE_LIM,
161 ST_F_RATE_MAX,
162 ST_F_CHECK_STATUS,
163 ST_F_CHECK_CODE,
164 ST_F_CHECK_DURATION,
165 ST_F_HRSP_1XX,
166 ST_F_HRSP_2XX,
167 ST_F_HRSP_3XX,
168 ST_F_HRSP_4XX,
169 ST_F_HRSP_5XX,
170 ST_F_HRSP_OTHER,
171 ST_F_HANAFAIL,
172 ST_F_REQ_RATE,
173 ST_F_REQ_RATE_MAX,
174 ST_F_REQ_TOT,
175 ST_F_CLI_ABRT,
176 ST_F_SRV_ABRT,
177 ST_F_COMP_IN,
178 ST_F_COMP_OUT,
179 ST_F_COMP_BYP,
180 ST_F_COMP_RSP,
181 ST_F_LASTSESS,
182 ST_F_LAST_CHK,
183 ST_F_LAST_AGT,
184 ST_F_QTIME,
185 ST_F_CTIME,
186 ST_F_RTIME,
187 ST_F_TTIME,
188 ST_F_AGENT_STATUS,
189 ST_F_AGENT_CODE,
190 ST_F_AGENT_DURATION,
191 ST_F_CHECK_DESC,
192 ST_F_AGENT_DESC,
193 ST_F_CHECK_RISE,
194 ST_F_CHECK_FALL,
195 ST_F_CHECK_HEALTH,
196 ST_F_AGENT_RISE,
197 ST_F_AGENT_FALL,
198 ST_F_AGENT_HEALTH,
199 ST_F_ADDR,
200 ST_F_COOKIE,
201 ST_F_MODE,
202 ST_F_ALGO,
203 ST_F_CONN_RATE,
204 ST_F_CONN_RATE_MAX,
205 ST_F_CONN_TOT,
206 ST_F_INTERCEPTED,
Willy Tarreau8a90b8e2016-10-21 18:15:32 +0200207 ST_F_DCON,
Willy Tarreaua5bc36b2016-10-21 18:16:27 +0200208 ST_F_DSES,
Thierry Fournier31e64ca2016-03-23 16:25:49 +0100209
210 /* must always be the last one */
211 ST_F_TOTAL_FIELDS
212};
213
Willy Tarreau8e62c052016-01-04 17:23:25 +0100214/* This level of detail is needed to let the stats consumer know how to
215 * aggregate them (eg: between processes or cluster nodes). Only a few
216 * combinations are actually in use, though the mechanism tends to make
217 * this easy to extend to future uses.
218 *
219 * Each reported stats element is typed based on 4 dimensions :
220 * - the field format : it indicates the validity range of the reported value,
221 * its limits and how to parse it. 6 types are currently supported :
222 * empty, signed 32-bit integer, unsigned 32-bit integer, signed 64-bit
223 * integer, unsigned 64-bit integer, string
224 *
225 * - the field origin : how was the value retrieved and what it depends on.
226 * 5 origins are currently defined : product (eg: haproxy version or
227 * release date), configuration (eg: a configured limit), key (identifier
228 * used to group values at a certain level), metric (a measure of something),
229 * status (something discrete which by definition cannot be averaged nor
230 * aggregated, such as "listening" versus "full").
231 *
232 * - the field nature : what does the data represent, implying how to aggregate
233 * it. At least 9 different natures are expected : counter (an increasing
234 * positive counter that may wrap when its type is overflown such as a byte
235 * counter), gauge (a measure at any instant that may vary, such as a
236 * concurrent connection count), a limit (eg: maximum acceptable concurrent
237 * connections), a minimum (eg: minimum free memory over a period), a
238 * maximum (eg: highest queue length over a period), an event rate (eg:
239 * incoming connections per second), a duration that is often aggregated by
240 * taking the max (eg: service uptime), an age that generally reports the
241 * last time an event appeared and which generally is aggregated by taking
242 * the most recent event hence the smallest one, the time which reports a
243 * discrete instant and cannot obviously be averaged either, a name which
244 * will generally be the name of an entity (such as a server name or cookie
245 * name), an output which is mostly used for various unsafe strings that are
246 * retrieved (eg: last check output, product name, description, etc), and an
247 * average which indicates that the value is relative and meant to be averaged
248 * between all nodes (eg: response time, throttling, etc).
249 *
250 * - the field scope : if the value is shared with other elements, which ones
251 * are expected to report the same value. The first scope with the least
252 * share is the process (most common one) where all data are only relevant
253 * to the process being consulted. The next one is the service, which is
254 * valid for all processes launched together (eg: shared SSL cache usage
255 * among processes). The next one is the system (such as the OS version)
256 * and which will report the same information for all instances running on
257 * the same node. The next one is the cluster, which indicates that the
258 * information are shared with other nodes being part of a same cluster.
259 * Stick-tables may carry such cluster-wide information. Larger scopes may
260 * be added in the future such as datacenter, country, continent, planet,
261 * galaxy, universe, etc.
262 *
263 * All these information will be encoded in the field as a bit field so that
264 * it is easy to pass composite values by simply ORing elements above, and
265 * to ease the definition of a few field types for the most common field
266 * combinations.
267 *
268 * The enums try to be arranged so that most likely characteristics are
269 * assigned the value zero, making it easier to add new fields.
270 *
271 * Field format has precedence over the other parts of the type. Please avoid
272 * declaring extra formats unless absolutely needed. The first one, FF_EMPTY,
273 * must absolutely have value zero so that it is what is returned after a
274 * memset(0). Furthermore, the producer is responsible for ensuring that when
275 * this format is set, all other bits of the type as well as the values in the
276 * union only contain zeroes. This makes it easier for the consumer to use the
277 * values as the expected type.
278 */
279
280enum field_format {
281 FF_EMPTY = 0x00000000,
282 FF_S32 = 0x00000001,
283 FF_U32 = 0x00000002,
284 FF_S64 = 0x00000003,
285 FF_U64 = 0x00000004,
286 FF_STR = 0x00000005,
287 FF_MASK = 0x000000FF,
288};
289
290enum field_origin {
291 FO_METRIC = 0x00000000,
292 FO_STATUS = 0x00000100,
293 FO_KEY = 0x00000200,
294 FO_CONFIG = 0x00000300,
295 FO_PRODUCT = 0x00000400,
296 FO_MASK = 0x0000FF00,
297};
298
299enum field_nature {
300 FN_GAUGE = 0x00000000,
301 FN_LIMIT = 0x00010000,
302 FN_MIN = 0x00020000,
303 FN_MAX = 0x00030000,
304 FN_RATE = 0x00040000,
305 FN_COUNTER = 0x00050000,
306 FN_DURATION = 0x00060000,
307 FN_AGE = 0x00070000,
308 FN_TIME = 0x00080000,
309 FN_NAME = 0x00090000,
310 FN_OUTPUT = 0x000A0000,
311 FN_AVG = 0x000B0000,
312 FN_MASK = 0x00FF0000,
313};
314
315enum field_scope {
316 FS_PROCESS = 0x00000000,
317 FS_SERVICE = 0x01000000,
318 FS_SYSTEM = 0x02000000,
319 FS_CLUSTER = 0x03000000,
320 FS_MASK = 0xFF000000,
321};
322
323struct field {
324 uint32_t type;
325 union {
326 int32_t s32; /* FF_S32 */
327 uint32_t u32; /* FF_U32 */
328 int64_t s64; /* FF_S64 */
329 uint64_t u64; /* FF_U64 */
330 const char *str; /* FF_STR */
331 } u;
332};
333
334static inline enum field_format field_format(const struct field *f, int e)
335{
336 return f[e].type & FF_MASK;
337}
338
339static inline enum field_origin field_origin(const struct field *f, int e)
340{
341 return f[e].type & FO_MASK;
342}
343
344static inline enum field_scope field_scope(const struct field *f, int e)
345{
346 return f[e].type & FS_MASK;
347}
348
349static inline enum field_nature field_nature(const struct field *f, int e)
350{
351 return f[e].type & FN_MASK;
352}
353
354static inline const char *field_str(const struct field *f, int e)
355{
356 return (field_format(f, e) == FF_STR) ? f[e].u.str : "";
357}
358
359static inline struct field mkf_s32(uint32_t type, int32_t value)
360{
361 struct field f = { .type = FF_S32 | type, .u.s32 = value };
362 return f;
363}
364
365static inline struct field mkf_u32(uint32_t type, uint32_t value)
366{
367 struct field f = { .type = FF_U32 | type, .u.u32 = value };
368 return f;
369}
370
371static inline struct field mkf_s64(uint32_t type, int64_t value)
372{
373 struct field f = { .type = FF_S64 | type, .u.s64 = value };
374 return f;
375}
376
377static inline struct field mkf_u64(uint32_t type, uint64_t value)
378{
379 struct field f = { .type = FF_U64 | type, .u.u64 = value };
380 return f;
381}
382
383static inline struct field mkf_str(uint32_t type, const char *value)
384{
385 struct field f = { .type = FF_STR | type, .u.str = value };
386 return f;
387}
388
Thierry Fournier31e64ca2016-03-23 16:25:49 +0100389/* These two structs contains all field names according with
390 * the the number of entries in "enum stat_field" and
391 * "enum info_field"
392 */
393extern const char *info_field_names[];
394extern const char *stat_field_names[];
395
Thierry Fourniercb2c7672016-03-25 08:19:23 +0100396int stats_fill_info(struct field *info, int len);
Thierry Fournier23d2d642016-03-25 08:20:11 +0100397int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len);
Thierry Fournierc4456852016-03-25 08:20:49 +0100398int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
399 struct field *stats, int len);
Thierry Fournier61fe6c02016-03-25 08:21:21 +0100400int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
401 struct field *stats, int len);
Thierry Fournierd0a56c22016-03-25 08:21:51 +0100402int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len);
Thierry Fourniercb2c7672016-03-25 08:19:23 +0100403
Willy Tarreau30576452015-04-13 13:50:30 +0200404extern struct applet http_stats_applet;
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100405
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200406void stats_io_handler(struct stream_interface *si);
Willy Tarreaub47785f2016-02-24 23:28:31 +0100407int stats_emit_raw_data_field(struct chunk *out, const struct field *f);
408int stats_emit_typed_data_field(struct chunk *out, const struct field *f);
409int stats_emit_field_tags(struct chunk *out, const struct field *f, char delim);
Willy Tarreau91861262007-10-17 17:06:05 +0200410
411
William Lallemand1e08cd82016-10-13 17:57:55 +0200412struct cli_kw {
413 const char *str_kw[5]; /* keywords ended by NULL, limited to 5
414 separated keywords combination */
415 const char *usage; /* usage message */
416 int (*parse)(char **args, struct appctx *appctx);
417 int (*io_handler)(struct appctx *appctx);
418};
419
420struct cli_kw_list {
421 struct list list;
422 struct cli_kw kw[VAR_ARRAY];
423};
424
425struct cli_kw* cli_find_kw(char **args);
426void cli_register_kw(struct cli_kw_list *kw_list);
427
428/* stats socket states */
429enum {
430 STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */
431 STAT_CLI_END, /* final state, let's close */
432 STAT_CLI_GETREQ, /* wait for a request */
433 STAT_CLI_OUTPUT, /* all states after this one are responses */
434 STAT_CLI_PROMPT, /* display the prompt (first output, same code) */
435 STAT_CLI_PRINT, /* display message in cli->msg */
436 STAT_CLI_PRINT_FREE, /* display message in cli->msg. After the display, free the pointer */
437 STAT_CLI_O_INFO, /* dump info */
438 STAT_CLI_O_SESS, /* dump streams */
439 STAT_CLI_O_ERR, /* dump errors */
440 STAT_CLI_O_TAB, /* dump tables */
441 STAT_CLI_O_CLR, /* clear tables */
442 STAT_CLI_O_SET, /* set entries in tables */
443 STAT_CLI_O_STAT, /* dump stats */
444 STAT_CLI_O_PATS, /* list all pattern reference available */
445 STAT_CLI_O_PAT, /* list all entries of a pattern */
446 STAT_CLI_O_MLOOK, /* lookup a map entry */
447 STAT_CLI_O_POOLS, /* dump memory pools */
448 STAT_CLI_O_TLSK, /* list all TLS ticket keys references */
449 STAT_CLI_O_TLSK_ENT, /* list all TLS ticket keys entries for a reference */
450 STAT_CLI_O_RESOLVERS,/* dump a resolver's section nameservers counters */
451 STAT_CLI_O_SERVERS_STATE, /* dump server state and changing information */
452 STAT_CLI_O_BACKEND, /* dump backend list */
453 STAT_CLI_O_ENV, /* dump environment */
454 STAT_CLI_O_CUSTOM, /* custom callback pointer */
455};
456
457/* Actions available for the stats admin forms */
458enum {
459 ST_ADM_ACTION_NONE = 0,
460
461 /* enable/disable health checks */
462 ST_ADM_ACTION_DHLTH,
463 ST_ADM_ACTION_EHLTH,
464
465 /* force health check status */
466 ST_ADM_ACTION_HRUNN,
467 ST_ADM_ACTION_HNOLB,
468 ST_ADM_ACTION_HDOWN,
469
470 /* enable/disable agent checks */
471 ST_ADM_ACTION_DAGENT,
472 ST_ADM_ACTION_EAGENT,
473
474 /* force agent check status */
475 ST_ADM_ACTION_ARUNN,
476 ST_ADM_ACTION_ADOWN,
477
478 /* set admin state */
479 ST_ADM_ACTION_READY,
480 ST_ADM_ACTION_DRAIN,
481 ST_ADM_ACTION_MAINT,
482 ST_ADM_ACTION_SHUTDOWN,
483 /* these are the ancient actions, still available for compatibility */
484 ST_ADM_ACTION_DISABLE,
485 ST_ADM_ACTION_ENABLE,
486 ST_ADM_ACTION_STOP,
487 ST_ADM_ACTION_START,
488};
489
490
491/* data transmission states for the stats responses */
492enum {
493 STAT_ST_INIT = 0,
494 STAT_ST_HEAD,
495 STAT_ST_INFO,
496 STAT_ST_LIST,
497 STAT_ST_END,
498 STAT_ST_FIN,
499};
500
501/* data transmission states for the stats responses inside a proxy */
502enum {
503 STAT_PX_ST_INIT = 0,
504 STAT_PX_ST_TH,
505 STAT_PX_ST_FE,
506 STAT_PX_ST_LI,
507 STAT_PX_ST_SV,
508 STAT_PX_ST_BE,
509 STAT_PX_ST_END,
510 STAT_PX_ST_FIN,
511};
512
513
Willy Tarreau91861262007-10-17 17:06:05 +0200514#endif /* _PROTO_DUMPSTATS_H */
515
516/*
517 * Local variables:
518 * c-indent-level: 8
519 * c-basic-offset: 8
520 * End:
521 */