blob: 0fb3477d79ec97bda8c7f1f237e479b99ca0071c [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 Tarreau39f7e6d2008-03-17 21:38:24 +010032#define STAT_HIDE_DOWN 0x00000008 /* hide 'down' servers in the stats page */
33#define STAT_NO_REFRESH 0x00000010 /* do not automatically refresh the stats page */
Cyril Bonté474be412010-10-12 00:14:36 +020034#define STAT_ADMIN 0x00000020 /* indicate a stats admin level */
Willy Tarreauaf3cf702014-04-22 22:19:53 +020035#define STAT_CHUNKED 0x00000040 /* use chunked encoding (HTTP/1.1) */
Willy Tarreau39f7e6d2008-03-17 21:38:24 +010036#define STAT_BOUND 0x00800000 /* bound statistics to selected proxies/types/services */
Willy Tarreau55bb8452007-10-17 18:44:57 +020037
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010038#define STATS_TYPE_FE 0
39#define STATS_TYPE_BE 1
40#define STATS_TYPE_SV 2
Krzysztof Piotr Oledzkiaeebf9b2009-10-04 15:43:17 +020041#define STATS_TYPE_SO 3
Krzysztof Piotr Oledzki2c6962c2008-03-02 02:42:14 +010042
Willy Tarreau96d44912013-11-22 12:25:24 +010043/* HTTP stats : applet.st0 */
44enum {
45 STAT_HTTP_DONE = 0, /* finished */
Willy Tarreau347a35d2013-11-22 17:51:09 +010046 STAT_HTTP_HEAD, /* send headers before dump */
Willy Tarreau96d44912013-11-22 12:25:24 +010047 STAT_HTTP_DUMP, /* dumping stats */
Willy Tarreau347a35d2013-11-22 17:51:09 +010048 STAT_HTTP_POST, /* waiting post data */
49 STAT_HTTP_LAST, /* sending last chunk of response */
Willy Tarreau96d44912013-11-22 12:25:24 +010050};
51
de Lafond Guillaume88c278f2013-04-15 19:27:10 +020052/* HTML form to limit output scope */
53#define STAT_SCOPE_TXT_MAXLEN 20 /* max len for scope substring */
54#define STAT_SCOPE_INPUT_NAME "scope" /* pattern form scope name <input> in html form */
55#define STAT_SCOPE_PATTERN "?" STAT_SCOPE_INPUT_NAME "="
56
Willy Tarreau8e62c052016-01-04 17:23:25 +010057/* This level of detail is needed to let the stats consumer know how to
58 * aggregate them (eg: between processes or cluster nodes). Only a few
59 * combinations are actually in use, though the mechanism tends to make
60 * this easy to extend to future uses.
61 *
62 * Each reported stats element is typed based on 4 dimensions :
63 * - the field format : it indicates the validity range of the reported value,
64 * its limits and how to parse it. 6 types are currently supported :
65 * empty, signed 32-bit integer, unsigned 32-bit integer, signed 64-bit
66 * integer, unsigned 64-bit integer, string
67 *
68 * - the field origin : how was the value retrieved and what it depends on.
69 * 5 origins are currently defined : product (eg: haproxy version or
70 * release date), configuration (eg: a configured limit), key (identifier
71 * used to group values at a certain level), metric (a measure of something),
72 * status (something discrete which by definition cannot be averaged nor
73 * aggregated, such as "listening" versus "full").
74 *
75 * - the field nature : what does the data represent, implying how to aggregate
76 * it. At least 9 different natures are expected : counter (an increasing
77 * positive counter that may wrap when its type is overflown such as a byte
78 * counter), gauge (a measure at any instant that may vary, such as a
79 * concurrent connection count), a limit (eg: maximum acceptable concurrent
80 * connections), a minimum (eg: minimum free memory over a period), a
81 * maximum (eg: highest queue length over a period), an event rate (eg:
82 * incoming connections per second), a duration that is often aggregated by
83 * taking the max (eg: service uptime), an age that generally reports the
84 * last time an event appeared and which generally is aggregated by taking
85 * the most recent event hence the smallest one, the time which reports a
86 * discrete instant and cannot obviously be averaged either, a name which
87 * will generally be the name of an entity (such as a server name or cookie
88 * name), an output which is mostly used for various unsafe strings that are
89 * retrieved (eg: last check output, product name, description, etc), and an
90 * average which indicates that the value is relative and meant to be averaged
91 * between all nodes (eg: response time, throttling, etc).
92 *
93 * - the field scope : if the value is shared with other elements, which ones
94 * are expected to report the same value. The first scope with the least
95 * share is the process (most common one) where all data are only relevant
96 * to the process being consulted. The next one is the service, which is
97 * valid for all processes launched together (eg: shared SSL cache usage
98 * among processes). The next one is the system (such as the OS version)
99 * and which will report the same information for all instances running on
100 * the same node. The next one is the cluster, which indicates that the
101 * information are shared with other nodes being part of a same cluster.
102 * Stick-tables may carry such cluster-wide information. Larger scopes may
103 * be added in the future such as datacenter, country, continent, planet,
104 * galaxy, universe, etc.
105 *
106 * All these information will be encoded in the field as a bit field so that
107 * it is easy to pass composite values by simply ORing elements above, and
108 * to ease the definition of a few field types for the most common field
109 * combinations.
110 *
111 * The enums try to be arranged so that most likely characteristics are
112 * assigned the value zero, making it easier to add new fields.
113 *
114 * Field format has precedence over the other parts of the type. Please avoid
115 * declaring extra formats unless absolutely needed. The first one, FF_EMPTY,
116 * must absolutely have value zero so that it is what is returned after a
117 * memset(0). Furthermore, the producer is responsible for ensuring that when
118 * this format is set, all other bits of the type as well as the values in the
119 * union only contain zeroes. This makes it easier for the consumer to use the
120 * values as the expected type.
121 */
122
123enum field_format {
124 FF_EMPTY = 0x00000000,
125 FF_S32 = 0x00000001,
126 FF_U32 = 0x00000002,
127 FF_S64 = 0x00000003,
128 FF_U64 = 0x00000004,
129 FF_STR = 0x00000005,
130 FF_MASK = 0x000000FF,
131};
132
133enum field_origin {
134 FO_METRIC = 0x00000000,
135 FO_STATUS = 0x00000100,
136 FO_KEY = 0x00000200,
137 FO_CONFIG = 0x00000300,
138 FO_PRODUCT = 0x00000400,
139 FO_MASK = 0x0000FF00,
140};
141
142enum field_nature {
143 FN_GAUGE = 0x00000000,
144 FN_LIMIT = 0x00010000,
145 FN_MIN = 0x00020000,
146 FN_MAX = 0x00030000,
147 FN_RATE = 0x00040000,
148 FN_COUNTER = 0x00050000,
149 FN_DURATION = 0x00060000,
150 FN_AGE = 0x00070000,
151 FN_TIME = 0x00080000,
152 FN_NAME = 0x00090000,
153 FN_OUTPUT = 0x000A0000,
154 FN_AVG = 0x000B0000,
155 FN_MASK = 0x00FF0000,
156};
157
158enum field_scope {
159 FS_PROCESS = 0x00000000,
160 FS_SERVICE = 0x01000000,
161 FS_SYSTEM = 0x02000000,
162 FS_CLUSTER = 0x03000000,
163 FS_MASK = 0xFF000000,
164};
165
166struct field {
167 uint32_t type;
168 union {
169 int32_t s32; /* FF_S32 */
170 uint32_t u32; /* FF_U32 */
171 int64_t s64; /* FF_S64 */
172 uint64_t u64; /* FF_U64 */
173 const char *str; /* FF_STR */
174 } u;
175};
176
177static inline enum field_format field_format(const struct field *f, int e)
178{
179 return f[e].type & FF_MASK;
180}
181
182static inline enum field_origin field_origin(const struct field *f, int e)
183{
184 return f[e].type & FO_MASK;
185}
186
187static inline enum field_scope field_scope(const struct field *f, int e)
188{
189 return f[e].type & FS_MASK;
190}
191
192static inline enum field_nature field_nature(const struct field *f, int e)
193{
194 return f[e].type & FN_MASK;
195}
196
197static inline const char *field_str(const struct field *f, int e)
198{
199 return (field_format(f, e) == FF_STR) ? f[e].u.str : "";
200}
201
202static inline struct field mkf_s32(uint32_t type, int32_t value)
203{
204 struct field f = { .type = FF_S32 | type, .u.s32 = value };
205 return f;
206}
207
208static inline struct field mkf_u32(uint32_t type, uint32_t value)
209{
210 struct field f = { .type = FF_U32 | type, .u.u32 = value };
211 return f;
212}
213
214static inline struct field mkf_s64(uint32_t type, int64_t value)
215{
216 struct field f = { .type = FF_S64 | type, .u.s64 = value };
217 return f;
218}
219
220static inline struct field mkf_u64(uint32_t type, uint64_t value)
221{
222 struct field f = { .type = FF_U64 | type, .u.u64 = value };
223 return f;
224}
225
226static inline struct field mkf_str(uint32_t type, const char *value)
227{
228 struct field f = { .type = FF_STR | type, .u.str = value };
229 return f;
230}
231
Willy Tarreau30576452015-04-13 13:50:30 +0200232extern struct applet http_stats_applet;
Willy Tarreaub1356cf2008-12-07 16:06:43 +0100233
Willy Tarreau9a42c0d2009-09-22 19:31:03 +0200234void stats_io_handler(struct stream_interface *si);
Willy Tarreau91861262007-10-17 17:06:05 +0200235
236
237#endif /* _PROTO_DUMPSTATS_H */
238
239/*
240 * Local variables:
241 * c-indent-level: 8
242 * c-basic-offset: 8
243 * End:
244 */