blob: c446722f657344671f28142bc185e4f944cc3dd2 [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,
207
208 /* must always be the last one */
209 ST_F_TOTAL_FIELDS
210};
211
Willy Tarreau8e62c052016-01-04 17:23:25 +0100212/* This level of detail is needed to let the stats consumer know how to
213 * aggregate them (eg: between processes or cluster nodes). Only a few
214 * combinations are actually in use, though the mechanism tends to make
215 * this easy to extend to future uses.
216 *
217 * Each reported stats element is typed based on 4 dimensions :
218 * - the field format : it indicates the validity range of the reported value,
219 * its limits and how to parse it. 6 types are currently supported :
220 * empty, signed 32-bit integer, unsigned 32-bit integer, signed 64-bit
221 * integer, unsigned 64-bit integer, string
222 *
223 * - the field origin : how was the value retrieved and what it depends on.
224 * 5 origins are currently defined : product (eg: haproxy version or
225 * release date), configuration (eg: a configured limit), key (identifier
226 * used to group values at a certain level), metric (a measure of something),
227 * status (something discrete which by definition cannot be averaged nor
228 * aggregated, such as "listening" versus "full").
229 *
230 * - the field nature : what does the data represent, implying how to aggregate
231 * it. At least 9 different natures are expected : counter (an increasing
232 * positive counter that may wrap when its type is overflown such as a byte
233 * counter), gauge (a measure at any instant that may vary, such as a
234 * concurrent connection count), a limit (eg: maximum acceptable concurrent
235 * connections), a minimum (eg: minimum free memory over a period), a
236 * maximum (eg: highest queue length over a period), an event rate (eg:
237 * incoming connections per second), a duration that is often aggregated by
238 * taking the max (eg: service uptime), an age that generally reports the
239 * last time an event appeared and which generally is aggregated by taking
240 * the most recent event hence the smallest one, the time which reports a
241 * discrete instant and cannot obviously be averaged either, a name which
242 * will generally be the name of an entity (such as a server name or cookie
243 * name), an output which is mostly used for various unsafe strings that are
244 * retrieved (eg: last check output, product name, description, etc), and an
245 * average which indicates that the value is relative and meant to be averaged
246 * between all nodes (eg: response time, throttling, etc).
247 *
248 * - the field scope : if the value is shared with other elements, which ones
249 * are expected to report the same value. The first scope with the least
250 * share is the process (most common one) where all data are only relevant
251 * to the process being consulted. The next one is the service, which is
252 * valid for all processes launched together (eg: shared SSL cache usage
253 * among processes). The next one is the system (such as the OS version)
254 * and which will report the same information for all instances running on
255 * the same node. The next one is the cluster, which indicates that the
256 * information are shared with other nodes being part of a same cluster.
257 * Stick-tables may carry such cluster-wide information. Larger scopes may
258 * be added in the future such as datacenter, country, continent, planet,
259 * galaxy, universe, etc.
260 *
261 * All these information will be encoded in the field as a bit field so that
262 * it is easy to pass composite values by simply ORing elements above, and
263 * to ease the definition of a few field types for the most common field
264 * combinations.
265 *
266 * The enums try to be arranged so that most likely characteristics are
267 * assigned the value zero, making it easier to add new fields.
268 *
269 * Field format has precedence over the other parts of the type. Please avoid
270 * declaring extra formats unless absolutely needed. The first one, FF_EMPTY,
271 * must absolutely have value zero so that it is what is returned after a
272 * memset(0). Furthermore, the producer is responsible for ensuring that when
273 * this format is set, all other bits of the type as well as the values in the
274 * union only contain zeroes. This makes it easier for the consumer to use the
275 * values as the expected type.
276 */
277
278enum field_format {
279 FF_EMPTY = 0x00000000,
280 FF_S32 = 0x00000001,
281 FF_U32 = 0x00000002,
282 FF_S64 = 0x00000003,
283 FF_U64 = 0x00000004,
284 FF_STR = 0x00000005,
285 FF_MASK = 0x000000FF,
286};
287
288enum field_origin {
289 FO_METRIC = 0x00000000,
290 FO_STATUS = 0x00000100,
291 FO_KEY = 0x00000200,
292 FO_CONFIG = 0x00000300,
293 FO_PRODUCT = 0x00000400,
294 FO_MASK = 0x0000FF00,
295};
296
297enum field_nature {
298 FN_GAUGE = 0x00000000,
299 FN_LIMIT = 0x00010000,
300 FN_MIN = 0x00020000,
301 FN_MAX = 0x00030000,
302 FN_RATE = 0x00040000,
303 FN_COUNTER = 0x00050000,
304 FN_DURATION = 0x00060000,
305 FN_AGE = 0x00070000,
306 FN_TIME = 0x00080000,
307 FN_NAME = 0x00090000,
308 FN_OUTPUT = 0x000A0000,
309 FN_AVG = 0x000B0000,
310 FN_MASK = 0x00FF0000,
311};
312
313enum field_scope {
314 FS_PROCESS = 0x00000000,
315 FS_SERVICE = 0x01000000,
316 FS_SYSTEM = 0x02000000,
317 FS_CLUSTER = 0x03000000,
318 FS_MASK = 0xFF000000,
319};
320
321struct field {
322 uint32_t type;
323 union {
324 int32_t s32; /* FF_S32 */
325 uint32_t u32; /* FF_U32 */
326 int64_t s64; /* FF_S64 */
327 uint64_t u64; /* FF_U64 */
328 const char *str; /* FF_STR */
329 } u;
330};
331
332static inline enum field_format field_format(const struct field *f, int e)
333{
334 return f[e].type & FF_MASK;
335}
336
337static inline enum field_origin field_origin(const struct field *f, int e)
338{
339 return f[e].type & FO_MASK;
340}
341
342static inline enum field_scope field_scope(const struct field *f, int e)
343{
344 return f[e].type & FS_MASK;
345}
346
347static inline enum field_nature field_nature(const struct field *f, int e)
348{
349 return f[e].type & FN_MASK;
350}
351
352static inline const char *field_str(const struct field *f, int e)
353{
354 return (field_format(f, e) == FF_STR) ? f[e].u.str : "";
355}
356
357static inline struct field mkf_s32(uint32_t type, int32_t value)
358{
359 struct field f = { .type = FF_S32 | type, .u.s32 = value };
360 return f;
361}
362
363static inline struct field mkf_u32(uint32_t type, uint32_t value)
364{
365 struct field f = { .type = FF_U32 | type, .u.u32 = value };
366 return f;
367}
368
369static inline struct field mkf_s64(uint32_t type, int64_t value)
370{
371 struct field f = { .type = FF_S64 | type, .u.s64 = value };
372 return f;
373}
374
375static inline struct field mkf_u64(uint32_t type, uint64_t value)
376{
377 struct field f = { .type = FF_U64 | type, .u.u64 = value };
378 return f;
379}
380
381static inline struct field mkf_str(uint32_t type, const char *value)
382{
383 struct field f = { .type = FF_STR | type, .u.str = value };
384 return f;
385}
386
Thierry Fournier31e64ca2016-03-23 16:25:49 +0100387/* These two structs contains all field names according with
388 * the the number of entries in "enum stat_field" and
389 * "enum info_field"
390 */
391extern const char *info_field_names[];
392extern const char *stat_field_names[];
393
Thierry Fourniercb2c7672016-03-25 08:19:23 +0100394int stats_fill_info(struct field *info, int len);
Thierry Fournier23d2d642016-03-25 08:20:11 +0100395int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len);
Thierry Fournierc4456852016-03-25 08:20:49 +0100396int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags,
397 struct field *stats, int len);
Thierry Fournier61fe6c02016-03-25 08:21:21 +0100398int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags,
399 struct field *stats, int len);
Thierry Fournierd0a56c22016-03-25 08:21:51 +0100400int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len);
Thierry Fourniercb2c7672016-03-25 08:19:23 +0100401
Willy Tarreau30576452015-04-13 13:50:30 +0200402extern struct applet http_stats_applet;
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100403
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200404void stats_io_handler(struct stream_interface *si);
Willy Tarreaub47785f2016-02-24 23:28:31 +0100405int stats_emit_raw_data_field(struct chunk *out, const struct field *f);
406int stats_emit_typed_data_field(struct chunk *out, const struct field *f);
407int stats_emit_field_tags(struct chunk *out, const struct field *f, char delim);
Willy Tarreau91861262007-10-17 17:06:05 +0200408
409
410#endif /* _PROTO_DUMPSTATS_H */
411
412/*
413 * Local variables:
414 * c-indent-level: 8
415 * c-basic-offset: 8
416 * End:
417 */