blob: ef2543447eb83d9d97319811c68bdf08458596b0 [file] [log] [blame]
Christopher Fauletf959d082019-02-07 15:38:42 +01001/*
2 * Promex is a Prometheus exporter for HAProxy
3 *
4 * It is highly inspired by the official Prometheus exporter.
5 * See: https://github.com/prometheus/haproxy_exporter
6 *
7 * Copyright 2019 Christopher Faulet <cfaulet@haproxy.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16#include <common/cfgparse.h>
17#include <common/config.h>
18#include <common/buffer.h>
19#include <common/htx.h>
20#include <common/initcall.h>
21#include <common/memory.h>
22#include <common/mini-clist.h>
23
24#include <types/global.h>
25
26#include <proto/action.h>
27#include <proto/applet.h>
28#include <proto/backend.h>
29#include <proto/compression.h>
30#include <proto/frontend.h>
31#include <proto/listener.h>
32#include <proto/http_htx.h>
33#include <proto/pipe.h>
34#include <proto/proxy.h>
35#include <proto/sample.h>
36#include <proto/server.h>
37#include <proto/ssl_sock.h>
38#include <proto/stats.h>
39#include <proto/stream.h>
40#include <proto/stream_interface.h>
41#include <proto/task.h>
42
43/* Prometheus exporter applet states (appctx->st0) */
44enum {
45 PROMEX_ST_INIT = 0, /* initialized */
46 PROMEX_ST_HEAD, /* send headers before dump */
47 PROMEX_ST_DUMP, /* dumping stats */
48 PROMEX_ST_DONE, /* finished */
Christopher Faulet9744f7c2019-03-27 15:48:53 +010049 PROMEX_ST_END, /* treatment terminated */
Christopher Fauletf959d082019-02-07 15:38:42 +010050};
51
52/* Prometheus exporter dumper states (appctx->st1) */
53enum {
54 PROMEX_DUMPER_INIT = 0, /* initialized */
55 PROMEX_DUMPER_GLOBAL, /* dump metrics of globals */
56 PROMEX_DUMPER_FRONT, /* dump metrics of frontend proxies */
57 PROMEX_DUMPER_BACK, /* dump metrics of backend proxies */
58 PROMEX_DUMPER_LI, /* dump metrics of listeners */
59 PROMEX_DUMPER_SRV, /* dump metrics of servers */
60 PROMEX_DUMPER_DONE, /* finished */
61};
62
63/* Prometheus exporter flags (appctx->ctx.stats.flags) */
64#define PROMEX_FL_METRIC_HDR 0x00000001
65#define PROMEX_FL_INFO_METRIC 0x00000002
66#define PROMEX_FL_STATS_METRIC 0x00000004
Christopher Faulet32d634f2019-11-18 14:47:08 +010067#define PROMEX_FL_SCOPE_GLOBAL 0x00000008
68#define PROMEX_FL_SCOPE_FRONT 0x00000010
69#define PROMEX_FL_SCOPE_BACK 0x00000020
70#define PROMEX_FL_SCOPE_SERVER 0x00000040
71
72#define PROMEX_FL_SCOPE_ALL (PROMEX_FL_SCOPE_GLOBAL|PROMEX_FL_SCOPE_FRONT|PROMEX_FL_SCOPE_BACK|PROMEX_FL_SCOPE_SERVER)
Christopher Fauletf959d082019-02-07 15:38:42 +010073
74/* The max length for metrics name. It is a hard limit but it should be
75 * enougth.
76 */
77#define PROMEX_MAX_NAME_LEN 128
78
79/* The expected max length for a metric dump, including its header lines. It is
80 * just a soft limit to avoid extra work. We don't try to dump a metric if less
81 * than this size is available in the HTX.
82 */
83#define PROMEX_MAX_METRIC_LENGTH 512
84
85/* Matrix used to dump global metrics. Each metric points to the next one to be
86 * processed or 0 to stop the dump. */
87const int promex_global_metrics[INF_TOTAL_FIELDS] = {
88 [INF_NAME] = INF_NBTHREAD,
89 [INF_VERSION] = 0,
90 [INF_RELEASE_DATE] = 0,
91 [INF_NBTHREAD] = INF_NBPROC,
92 [INF_NBPROC] = INF_PROCESS_NUM,
93 [INF_PROCESS_NUM] = INF_UPTIME_SEC,
94 [INF_PID] = 0,
95 [INF_UPTIME] = 0,
96 [INF_UPTIME_SEC] = INF_MEMMAX_MB,
97 [INF_MEMMAX_MB] = INF_POOL_ALLOC_MB,
98 [INF_POOL_ALLOC_MB] = INF_POOL_USED_MB,
99 [INF_POOL_USED_MB] = INF_POOL_FAILED,
100 [INF_POOL_FAILED] = INF_ULIMIT_N,
101 [INF_ULIMIT_N] = INF_MAXSOCK,
102 [INF_MAXSOCK] = INF_MAXCONN,
103 [INF_MAXCONN] = INF_HARD_MAXCONN,
104 [INF_HARD_MAXCONN] = INF_CURR_CONN,
105 [INF_CURR_CONN] = INF_CUM_CONN,
106 [INF_CUM_CONN] = INF_CUM_REQ,
107 [INF_CUM_REQ] = INF_MAX_SSL_CONNS,
108 [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS,
109 [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS,
110 [INF_CUM_SSL_CONNS] = INF_MAXPIPES,
111 [INF_MAXPIPES] = INF_PIPES_USED,
112 [INF_PIPES_USED] = INF_PIPES_FREE,
113 [INF_PIPES_FREE] = INF_CONN_RATE,
114 [INF_CONN_RATE] = INF_CONN_RATE_LIMIT,
115 [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE,
116 [INF_MAX_CONN_RATE] = INF_SESS_RATE,
117 [INF_SESS_RATE] = INF_SESS_RATE_LIMIT,
118 [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE,
119 [INF_MAX_SESS_RATE] = INF_SSL_RATE,
120 [INF_SSL_RATE] = INF_SSL_RATE_LIMIT,
121 [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE,
122 [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE,
123 [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE,
124 [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT,
125 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE,
126 [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE,
127 [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS,
128 [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES,
129 [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN,
130 [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT,
131 [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM,
132 [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE,
133 [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE,
134 [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS,
135 [INF_TASKS] = INF_RUN_QUEUE,
136 [INF_RUN_QUEUE] = INF_IDLE_PCT,
137 [INF_IDLE_PCT] = INF_STOPPING,
138 [INF_NODE] = 0,
139 [INF_DESCRIPTION] = 0,
140 [INF_STOPPING] = INF_JOBS,
141 [INF_JOBS] = INF_UNSTOPPABLE_JOBS,
142 [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS,
143 [INF_LISTENERS] = INF_ACTIVE_PEERS,
144 [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS,
145 [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS,
146 [INF_DROPPED_LOGS] = INF_BUSY_POLLING,
147 [INF_BUSY_POLLING] = 0,
148};
149
150/* Matrix used to dump frontend metrics. Each metric points to the next one to be
151 * processed or 0 to stop the dump. */
152const int promex_front_metrics[ST_F_TOTAL_FIELDS] = {
153 [ST_F_PXNAME] = ST_F_STATUS,
154 [ST_F_SVNAME] = 0,
155 [ST_F_QCUR] = 0,
156 [ST_F_QMAX] = 0,
157 [ST_F_SCUR] = ST_F_SMAX,
158 [ST_F_SMAX] = ST_F_SLIM,
159 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200160 [ST_F_STOT] = ST_F_RATE_LIM,
Christopher Fauletf959d082019-02-07 15:38:42 +0100161 [ST_F_BIN] = ST_F_BOUT,
162 [ST_F_BOUT] = ST_F_DREQ,
163 [ST_F_DREQ] = ST_F_DRESP,
164 [ST_F_DRESP] = ST_F_EREQ,
165 [ST_F_EREQ] = ST_F_DCON,
166 [ST_F_ECON] = 0,
167 [ST_F_ERESP] = 0,
168 [ST_F_WRETR] = 0,
169 [ST_F_WREDIS] = 0,
170 [ST_F_STATUS] = ST_F_SCUR,
171 [ST_F_WEIGHT] = 0,
172 [ST_F_ACT] = 0,
173 [ST_F_BCK] = 0,
174 [ST_F_CHKFAIL] = 0,
175 [ST_F_CHKDOWN] = 0,
176 [ST_F_LASTCHG] = 0,
177 [ST_F_DOWNTIME] = 0,
178 [ST_F_QLIMIT] = 0,
179 [ST_F_PID] = 0,
180 [ST_F_IID] = 0,
181 [ST_F_SID] = 0,
182 [ST_F_THROTTLE] = 0,
183 [ST_F_LBTOT] = 0,
184 [ST_F_TRACKED] = 0,
185 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200186 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100187 [ST_F_RATE_LIM] = ST_F_RATE_MAX,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200188 [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100189 [ST_F_CHECK_STATUS] = 0,
190 [ST_F_CHECK_CODE] = 0,
191 [ST_F_CHECK_DURATION] = 0,
192 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
193 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
194 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
195 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
196 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
197 [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED,
198 [ST_F_HANAFAIL] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200199 [ST_F_REQ_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100200 [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT,
201 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
202 [ST_F_CLI_ABRT] = 0,
203 [ST_F_SRV_ABRT] = 0,
204 [ST_F_COMP_IN] = ST_F_COMP_OUT,
205 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
206 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
207 [ST_F_COMP_RSP] = 0,
208 [ST_F_LASTSESS] = 0,
209 [ST_F_LAST_CHK] = 0,
210 [ST_F_LAST_AGT] = 0,
211 [ST_F_QTIME] = 0,
212 [ST_F_CTIME] = 0,
213 [ST_F_RTIME] = 0,
214 [ST_F_TTIME] = 0,
215 [ST_F_AGENT_STATUS] = 0,
216 [ST_F_AGENT_CODE] = 0,
217 [ST_F_AGENT_DURATION] = 0,
218 [ST_F_CHECK_DESC] = 0,
219 [ST_F_AGENT_DESC] = 0,
220 [ST_F_CHECK_RISE] = 0,
221 [ST_F_CHECK_FALL] = 0,
222 [ST_F_CHECK_HEALTH] = 0,
223 [ST_F_AGENT_RISE] = 0,
224 [ST_F_AGENT_FALL] = 0,
225 [ST_F_AGENT_HEALTH] = 0,
226 [ST_F_ADDR] = 0,
227 [ST_F_COOKIE] = 0,
228 [ST_F_MODE] = 0,
229 [ST_F_ALGO] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200230 [ST_F_CONN_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100231 [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT,
232 [ST_F_CONN_TOT] = ST_F_BIN,
233 [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS,
234 [ST_F_DCON] = ST_F_DSES,
235 [ST_F_DSES] = ST_F_WREW,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200236 [ST_F_WREW] = ST_F_REQ_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100237 [ST_F_CONNECT] = 0,
238 [ST_F_REUSE] = 0,
239 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
240 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100241 [ST_F_SRV_ICUR] = 0,
242 [ST_F_SRV_ILIM] = 0,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100243 [ST_F_QT_MAX] = 0,
244 [ST_F_CT_MAX] = 0,
245 [ST_F_RT_MAX] = 0,
246 [ST_F_TT_MAX] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100247};
248
249/* Matrix used to dump backend metrics. Each metric points to the next one to be
250 * processed or 0 to stop the dump. */
251const int promex_back_metrics[ST_F_TOTAL_FIELDS] = {
252 [ST_F_PXNAME] = ST_F_STATUS,
253 [ST_F_SVNAME] = 0,
254 [ST_F_QCUR] = ST_F_QMAX,
255 [ST_F_QMAX] = ST_F_CONNECT,
256 [ST_F_SCUR] = ST_F_SMAX,
257 [ST_F_SMAX] = ST_F_SLIM,
258 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200259 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100260 [ST_F_BIN] = ST_F_BOUT,
261 [ST_F_BOUT] = ST_F_QTIME,
262 [ST_F_DREQ] = ST_F_DRESP,
263 [ST_F_DRESP] = ST_F_ECON,
264 [ST_F_EREQ] = 0,
265 [ST_F_ECON] = ST_F_ERESP,
266 [ST_F_ERESP] = ST_F_WRETR,
267 [ST_F_WRETR] = ST_F_WREDIS,
268 [ST_F_WREDIS] = ST_F_WREW,
269 [ST_F_STATUS] = ST_F_SCUR,
270 [ST_F_WEIGHT] = ST_F_ACT,
271 [ST_F_ACT] = ST_F_BCK,
272 [ST_F_BCK] = ST_F_CHKDOWN,
273 [ST_F_CHKFAIL] = 0,
274 [ST_F_CHKDOWN] = ST_F_LASTCHG,
275 [ST_F_LASTCHG] = ST_F_DOWNTIME,
276 [ST_F_DOWNTIME] = ST_F_LBTOT,
277 [ST_F_QLIMIT] = 0,
278 [ST_F_PID] = 0,
279 [ST_F_IID] = 0,
280 [ST_F_SID] = 0,
281 [ST_F_THROTTLE] = 0,
282 [ST_F_LBTOT] = ST_F_REQ_TOT,
283 [ST_F_TRACKED] = 9,
284 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200285 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100286 [ST_F_RATE_LIM] = 0,
287 [ST_F_RATE_MAX] = ST_F_LASTSESS,
288 [ST_F_CHECK_STATUS] = 0,
289 [ST_F_CHECK_CODE] = 0,
290 [ST_F_CHECK_DURATION] = 0,
291 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
292 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
293 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
294 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
295 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
296 [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS,
297 [ST_F_HANAFAIL] = 0,
298 [ST_F_REQ_RATE] = 0,
299 [ST_F_REQ_RATE_MAX] = 0,
300 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
301 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
302 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
303 [ST_F_COMP_IN] = ST_F_COMP_OUT,
304 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
305 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
306 [ST_F_COMP_RSP] = 0,
307 [ST_F_LASTSESS] = ST_F_QCUR,
308 [ST_F_LAST_CHK] = 0,
309 [ST_F_LAST_AGT] = 0,
310 [ST_F_QTIME] = ST_F_CTIME,
311 [ST_F_CTIME] = ST_F_RTIME,
312 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100313 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100314 [ST_F_AGENT_STATUS] = 0,
315 [ST_F_AGENT_CODE] = 0,
316 [ST_F_AGENT_DURATION] = 0,
317 [ST_F_CHECK_DESC] = 0,
318 [ST_F_AGENT_DESC] = 0,
319 [ST_F_CHECK_RISE] = 0,
320 [ST_F_CHECK_FALL] = 0,
321 [ST_F_CHECK_HEALTH] = 0,
322 [ST_F_AGENT_RISE] = 0,
323 [ST_F_AGENT_FALL] = 0,
324 [ST_F_AGENT_HEALTH] = 0,
325 [ST_F_ADDR] = 0,
326 [ST_F_COOKIE] = 0,
327 [ST_F_MODE] = 0,
328 [ST_F_ALGO] = 0,
329 [ST_F_CONN_RATE] = 0,
330 [ST_F_CONN_RATE_MAX] = 0,
331 [ST_F_CONN_TOT] = 0,
332 [ST_F_INTERCEPTED] = 0,
333 [ST_F_DCON] = 0,
334 [ST_F_DSES] = 0,
335 [ST_F_WREW] = ST_F_CLI_ABRT,
336 [ST_F_CONNECT] = ST_F_REUSE,
337 [ST_F_REUSE] = ST_F_BIN,
338 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
339 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100340 [ST_F_SRV_ICUR] = 0,
341 [ST_F_SRV_ILIM] = 0,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100342 [ST_F_QT_MAX] = ST_F_CT_MAX,
343 [ST_F_CT_MAX] = ST_F_RT_MAX,
344 [ST_F_RT_MAX] = ST_F_TT_MAX,
345 [ST_F_TT_MAX] = ST_F_DREQ,
Christopher Fauletf959d082019-02-07 15:38:42 +0100346};
347
348/* Matrix used to dump server metrics. Each metric points to the next one to be
349 * processed or 0 to stop the dump. */
350const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = {
351 [ST_F_PXNAME] = ST_F_STATUS,
352 [ST_F_SVNAME] = 0,
353 [ST_F_QCUR] = ST_F_QMAX,
354 [ST_F_QMAX] = ST_F_QLIMIT,
355 [ST_F_SCUR] = ST_F_SMAX,
356 [ST_F_SMAX] = ST_F_SLIM,
357 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200358 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100359 [ST_F_BIN] = ST_F_BOUT,
360 [ST_F_BOUT] = ST_F_QTIME,
361 [ST_F_DREQ] = 0,
362 [ST_F_DRESP] = ST_F_ECON,
363 [ST_F_EREQ] = 0,
364 [ST_F_ECON] = ST_F_ERESP,
365 [ST_F_ERESP] = ST_F_WRETR,
366 [ST_F_WRETR] = ST_F_WREDIS,
367 [ST_F_WREDIS] = ST_F_WREW,
368 [ST_F_STATUS] = ST_F_SCUR,
369 [ST_F_WEIGHT] = ST_F_CHKFAIL,
370 [ST_F_ACT] = 0,
371 [ST_F_BCK] = 0,
372 [ST_F_CHKFAIL] = ST_F_CHKDOWN,
373 [ST_F_CHKDOWN] = ST_F_DOWNTIME,
374 [ST_F_LASTCHG] = ST_F_THROTTLE,
375 [ST_F_DOWNTIME] = ST_F_LASTCHG,
376 [ST_F_QLIMIT] = ST_F_BIN,
377 [ST_F_PID] = 0,
378 [ST_F_IID] = 0,
379 [ST_F_SID] = 0,
380 [ST_F_THROTTLE] = ST_F_LBTOT,
381 [ST_F_LBTOT] = ST_F_HRSP_1XX,
382 [ST_F_TRACKED] = 0,
383 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200384 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100385 [ST_F_RATE_LIM] = 0,
386 [ST_F_RATE_MAX] = ST_F_LASTSESS,
387 [ST_F_CHECK_STATUS] = 0,
388 [ST_F_CHECK_CODE] = 0,
389 [ST_F_CHECK_DURATION] = 0,
390 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
391 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
392 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
393 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
394 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100395 [ST_F_HRSP_OTHER] = ST_F_SRV_ICUR,
Christopher Fauletf959d082019-02-07 15:38:42 +0100396 [ST_F_HANAFAIL] = 0,
397 [ST_F_REQ_RATE] = 0,
398 [ST_F_REQ_RATE_MAX] = 0,
399 [ST_F_REQ_TOT] = 0,
400 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
401 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
402 [ST_F_COMP_IN] = 0,
403 [ST_F_COMP_OUT] = 0,
404 [ST_F_COMP_BYP] = 0,
405 [ST_F_COMP_RSP] = 0,
406 [ST_F_LASTSESS] = ST_F_QCUR,
407 [ST_F_LAST_CHK] = 0,
408 [ST_F_LAST_AGT] = 0,
409 [ST_F_QTIME] = ST_F_CTIME,
410 [ST_F_CTIME] = ST_F_RTIME,
411 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100412 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100413 [ST_F_AGENT_STATUS] = 0,
414 [ST_F_AGENT_CODE] = 0,
415 [ST_F_AGENT_DURATION] = 0,
416 [ST_F_CHECK_DESC] = 0,
417 [ST_F_AGENT_DESC] = 0,
418 [ST_F_CHECK_RISE] = 0,
419 [ST_F_CHECK_FALL] = 0,
420 [ST_F_CHECK_HEALTH] = 0,
421 [ST_F_AGENT_RISE] = 0,
422 [ST_F_AGENT_FALL] = 0,
423 [ST_F_AGENT_HEALTH] = 0,
424 [ST_F_ADDR] = 0,
425 [ST_F_COOKIE] = 0,
426 [ST_F_MODE] = 0,
427 [ST_F_ALGO] = 0,
428 [ST_F_CONN_RATE] = 0,
429 [ST_F_CONN_RATE_MAX] = 0,
430 [ST_F_CONN_TOT] = 0,
431 [ST_F_INTERCEPTED] = 0,
432 [ST_F_DCON] = 0,
433 [ST_F_DSES] = 0,
434 [ST_F_WREW] = ST_F_CLI_ABRT,
435 [ST_F_CONNECT] = ST_F_REUSE,
436 [ST_F_REUSE] = ST_F_DRESP,
437 [ST_F_CACHE_LOOKUPS] = 0,
438 [ST_F_CACHE_HITS] = 0,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100439 [ST_F_SRV_ICUR] = ST_F_SRV_ILIM,
440 [ST_F_SRV_ILIM] = 0,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100441 [ST_F_QT_MAX] = ST_F_CT_MAX,
442 [ST_F_CT_MAX] = ST_F_RT_MAX,
443 [ST_F_RT_MAX] = ST_F_TT_MAX,
444 [ST_F_TT_MAX] = ST_F_CONNECT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100445};
446
447/* Name of all info fields */
448const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
449 [INF_NAME] = IST("name"),
450 [INF_VERSION] = IST("version"),
451 [INF_RELEASE_DATE] = IST("release_date"),
452 [INF_NBTHREAD] = IST("nbthread"),
453 [INF_NBPROC] = IST("nbproc"),
454 [INF_PROCESS_NUM] = IST("relative_process_id"),
455 [INF_PID] = IST("pid"),
456 [INF_UPTIME] = IST("uptime"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200457 [INF_UPTIME_SEC] = IST("start_time_seconds"),
458 [INF_MEMMAX_MB] = IST("max_memory_bytes"),
459 [INF_POOL_ALLOC_MB] = IST("pool_allocated_bytes"),
460 [INF_POOL_USED_MB] = IST("pool_used_bytes"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100461 [INF_POOL_FAILED] = IST("pool_failures_total"),
462 [INF_ULIMIT_N] = IST("max_fds"),
463 [INF_MAXSOCK] = IST("max_sockets"),
464 [INF_MAXCONN] = IST("max_connections"),
465 [INF_HARD_MAXCONN] = IST("hard_max_connections"),
466 [INF_CURR_CONN] = IST("current_connections"),
467 [INF_CUM_CONN] = IST("connections_total"),
468 [INF_CUM_REQ] = IST("requests_total"),
469 [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"),
470 [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"),
471 [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"),
472 [INF_MAXPIPES] = IST("max_pipes"),
473 [INF_PIPES_USED] = IST("pipes_used_total"),
474 [INF_PIPES_FREE] = IST("pipes_free_total"),
475 [INF_CONN_RATE] = IST("current_connection_rate"),
476 [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"),
477 [INF_MAX_CONN_RATE] = IST("max_connection_rate"),
478 [INF_SESS_RATE] = IST("current_session_rate"),
479 [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"),
480 [INF_MAX_SESS_RATE] = IST("max_session_rate"),
481 [INF_SSL_RATE] = IST("current_ssl_rate"),
482 [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"),
483 [INF_MAX_SSL_RATE] = IST("max_ssl_rate"),
484 [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"),
485 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"),
486 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontent_ssl_reuse"),
487 [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"),
488 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200489 [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"),
490 [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100491 [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"),
492 [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"),
493 [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"),
494 [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"),
495 [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"),
496 [INF_TASKS] = IST("current_tasks"),
497 [INF_RUN_QUEUE] = IST("current_run_queue"),
498 [INF_IDLE_PCT] = IST("idle_time_percent"),
499 [INF_NODE] = IST("node"),
500 [INF_DESCRIPTION] = IST("description"),
501 [INF_STOPPING] = IST("stopping"),
502 [INF_JOBS] = IST("jobs"),
503 [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"),
504 [INF_LISTENERS] = IST("listeners"),
505 [INF_ACTIVE_PEERS] = IST("active_peers"),
506 [INF_CONNECTED_PEERS] = IST("connected_peers"),
507 [INF_DROPPED_LOGS] = IST("dropped_logs_total"),
508 [INF_BUSY_POLLING] = IST("busy_polling_enabled"),
509};
510
511/* Name of all stats fields */
512const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = {
513 [ST_F_PXNAME] = IST("proxy_name"),
514 [ST_F_SVNAME] = IST("service_name"),
515 [ST_F_QCUR] = IST("current_queue"),
516 [ST_F_QMAX] = IST("max_queue"),
517 [ST_F_SCUR] = IST("current_sessions"),
518 [ST_F_SMAX] = IST("max_sessions"),
519 [ST_F_SLIM] = IST("limit_sessions"),
520 [ST_F_STOT] = IST("sessions_total"),
521 [ST_F_BIN] = IST("bytes_in_total"),
522 [ST_F_BOUT] = IST("bytes_out_total"),
523 [ST_F_DREQ] = IST("requests_denied_total"),
524 [ST_F_DRESP] = IST("responses_denied_total"),
525 [ST_F_EREQ] = IST("request_errors_total"),
526 [ST_F_ECON] = IST("connection_errors_total"),
527 [ST_F_ERESP] = IST("response_errors_total"),
528 [ST_F_WRETR] = IST("retry_warnings_total"),
529 [ST_F_WREDIS] = IST("redispatch_warnings_total"),
530 [ST_F_STATUS] = IST("status"),
531 [ST_F_WEIGHT] = IST("weight"),
532 [ST_F_ACT] = IST("active_servers"),
533 [ST_F_BCK] = IST("backup_servers"),
534 [ST_F_CHKFAIL] = IST("check_failures_total"),
535 [ST_F_CHKDOWN] = IST("check_up_down_total"),
536 [ST_F_LASTCHG] = IST("check_last_change_seconds"),
537 [ST_F_DOWNTIME] = IST("downtime_seconds_total"),
538 [ST_F_QLIMIT] = IST("queue_limit"),
539 [ST_F_PID] = IST("pid"),
540 [ST_F_IID] = IST("proxy_id"),
541 [ST_F_SID] = IST("server_id"),
542 [ST_F_THROTTLE] = IST("current_throttle"),
543 [ST_F_LBTOT] = IST("loadbalanced_total"),
544 [ST_F_TRACKED] = IST("tracked"),
545 [ST_F_TYPE] = IST("type"),
546 [ST_F_RATE] = IST("current_session_rate"),
547 [ST_F_RATE_LIM] = IST("limit_session_rate"),
548 [ST_F_RATE_MAX] = IST("max_session_rate"),
549 [ST_F_CHECK_STATUS] = IST("check_status"),
550 [ST_F_CHECK_CODE] = IST("check_code"),
551 [ST_F_CHECK_DURATION] = IST("check_duration_milliseconds"),
552 [ST_F_HRSP_1XX] = IST("http_responses_total"),
553 [ST_F_HRSP_2XX] = IST("http_responses_total"),
554 [ST_F_HRSP_3XX] = IST("http_responses_total"),
555 [ST_F_HRSP_4XX] = IST("http_responses_total"),
556 [ST_F_HRSP_5XX] = IST("http_responses_total"),
557 [ST_F_HRSP_OTHER] = IST("http_responses_total"),
558 [ST_F_HANAFAIL] = IST("check_analyses_failures_total"),
559 [ST_F_REQ_RATE] = IST("http_requests_rate_current"),
560 [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"),
561 [ST_F_REQ_TOT] = IST("http_requests_total"),
562 [ST_F_CLI_ABRT] = IST("client_aborts_total"),
563 [ST_F_SRV_ABRT] = IST("server_aborts_total"),
564 [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"),
565 [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"),
566 [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"),
567 [ST_F_COMP_RSP] = IST("http_comp_responses_total"),
568 [ST_F_LASTSESS] = IST("last_session_seconds"),
569 [ST_F_LAST_CHK] = IST("check_last_content"),
570 [ST_F_LAST_AGT] = IST("agentcheck_last_content"),
Christopher Faulet3388fd22019-11-08 15:12:29 +0100571 [ST_F_QTIME] = IST("queue_time_average_seconds"),
572 [ST_F_CTIME] = IST("connect_time_average_seconds"),
573 [ST_F_RTIME] = IST("response_time_average_seconds"),
574 [ST_F_TTIME] = IST("total_time_average_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100575 [ST_F_AGENT_STATUS] = IST("agentcheck_status"),
576 [ST_F_AGENT_CODE] = IST("agentcheck_code"),
577 [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"),
578 [ST_F_CHECK_DESC] = IST("check_description"),
579 [ST_F_AGENT_DESC] = IST("agentcheck_description"),
580 [ST_F_CHECK_RISE] = IST("check_rise"),
581 [ST_F_CHECK_FALL] = IST("check_fall"),
582 [ST_F_CHECK_HEALTH] = IST("check_value"),
583 [ST_F_AGENT_RISE] = IST("agentcheck_rise"),
584 [ST_F_AGENT_FALL] = IST("agentcheck_fall"),
585 [ST_F_AGENT_HEALTH] = IST("agentcheck_value"),
586 [ST_F_ADDR] = IST("address"),
587 [ST_F_COOKIE] = IST("cookie"),
588 [ST_F_MODE] = IST("mode"),
589 [ST_F_ALGO] = IST("loadbalance_algorithm"),
590 [ST_F_CONN_RATE] = IST("connections_rate_current"),
591 [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"),
592 [ST_F_CONN_TOT] = IST("connections_total"),
593 [ST_F_INTERCEPTED] = IST("intercepted_requests_total"),
594 [ST_F_DCON] = IST("denied_connections_total"),
595 [ST_F_DSES] = IST("denied_sessions_total"),
596 [ST_F_WREW] = IST("failed_header_rewriting_total"),
597 [ST_F_CONNECT] = IST("connection_attempts_total"),
598 [ST_F_REUSE] = IST("connection_reuses_total"),
599 [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"),
600 [ST_F_CACHE_HITS] = IST("http_cache_hits_total"),
Christopher Fauletbd767f72019-11-08 15:24:32 +0100601 [ST_F_SRV_ICUR] = IST("server_idle_connections_current"),
602 [ST_F_SRV_ILIM] = IST("server_idle_connections_limit"),
Christopher Faulet5df597a2019-11-08 15:05:31 +0100603 [ST_F_QT_MAX] = IST("max_queue_time_seconds"),
604 [ST_F_CT_MAX] = IST("max_connect_time_seconds"),
605 [ST_F_RT_MAX] = IST("max_response_time_seconds"),
606 [ST_F_TT_MAX] = IST("max_total_time_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100607};
608
609/* Description of all info fields */
610const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
611 [INF_NAME] = IST("Product name."),
612 [INF_VERSION] = IST("HAProxy version."),
613 [INF_RELEASE_DATE] = IST("HAProxy realease date."),
614 [INF_NBTHREAD] = IST("Configured number of threads."),
615 [INF_NBPROC] = IST("Configured number of processes."),
616 [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
617 [INF_PID] = IST("HAProxy PID."),
618 [INF_UPTIME] = IST("Uptime in a human readable format."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200619 [INF_UPTIME_SEC] = IST("Start time in seconds."),
620 [INF_MEMMAX_MB] = IST("Per-process memory limit (in bytes); 0=unset."),
621 [INF_POOL_ALLOC_MB] = IST("Total amount of memory allocated in pools (in bytes)."),
622 [INF_POOL_USED_MB] = IST("Total amount of memory used in pools (in bytes)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100623 [INF_POOL_FAILED] = IST("Total number of failed pool allocations."),
624 [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."),
625 [INF_MAXSOCK] = IST("Maximum numer of open sockets."),
626 [INF_MAXCONN] = IST("Maximum number of concurrent connections."),
627 [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."),
628 [INF_CURR_CONN] = IST("Number of active sessions."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200629 [INF_CUM_CONN] = IST("Total number of created sessions."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100630 [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."),
631 [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."),
632 [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."),
633 [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."),
634 [INF_MAXPIPES] = IST("Configured maximum number of pipes."),
635 [INF_PIPES_USED] = IST("Number of pipes in used."),
636 [INF_PIPES_FREE] = IST("Number of pipes unused."),
637 [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."),
638 [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."),
639 [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."),
640 [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."),
641 [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."),
642 [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."),
643 [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."),
644 [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."),
645 [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."),
646 [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."),
647 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."),
648 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."),
649 [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."),
650 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."),
651 [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."),
652 [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."),
653 [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."),
654 [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."),
655 [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."),
656 [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."),
657 [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."),
658 [INF_TASKS] = IST("Current number of tasks."),
659 [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."),
660 [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."),
661 [INF_NODE] = IST("Node name."),
662 [INF_DESCRIPTION] = IST("Node description."),
663 [INF_STOPPING] = IST("Non zero means stopping in progress."),
664 [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."),
665 [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."),
666 [INF_LISTENERS] = IST("Current number of active listeners."),
667 [INF_ACTIVE_PEERS] = IST("Current number of active peers."),
668 [INF_CONNECTED_PEERS] = IST("Current number of connected peers."),
669 [INF_DROPPED_LOGS] = IST("Total number of dropped logs."),
670 [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."),
671};
672
673/* Description of all stats fields */
674const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
675 [ST_F_PXNAME] = IST("The proxy name."),
676 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
677 [ST_F_QCUR] = IST("Current number of queued requests."),
678 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
679 [ST_F_SCUR] = IST("Current number of active sessions."),
680 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
681 [ST_F_SLIM] = IST("Configured session limit."),
682 [ST_F_STOT] = IST("Total number of sessions."),
683 [ST_F_BIN] = IST("Current total of incoming bytes."),
684 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
685 [ST_F_DREQ] = IST("Total number of denied requests."),
686 [ST_F_DRESP] = IST("Total number of denied responses."),
687 [ST_F_EREQ] = IST("Total number of request errors."),
688 [ST_F_ECON] = IST("Total number of connection errors."),
689 [ST_F_ERESP] = IST("Total number of response errors."),
690 [ST_F_WRETR] = IST("Total number of retry warnings."),
691 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Christopher Faulet8e40fa22019-09-06 16:10:19 +0200692 [ST_F_STATUS] = IST("Current status of the service (frontend: 0=STOP, 1=UP, 2=FULL - backend: 0=DOWN, 1=UP - server: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100693 [ST_F_WEIGHT] = IST("Service weight."),
694 [ST_F_ACT] = IST("Current number of active servers."),
695 [ST_F_BCK] = IST("Current number of backup servers."),
696 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
697 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
698 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
699 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
700 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
701 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
702 [ST_F_IID] = IST("Unique proxy id."),
703 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
704 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
705 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
706 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
707 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
708 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
709 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
710 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
711 [ST_F_CHECK_STATUS] = IST("Status of last health check (If a check is running, the status will be reported, prefixed with '* ')."),
712 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
713 [ST_F_CHECK_DURATION] = IST("Time in ms took to finish last health check."),
714 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
715 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
716 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
717 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
718 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
719 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
720 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
721 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
722 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
723 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
724 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
725 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
726 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
727 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
728 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
729 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
730 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
731 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
732 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
733 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
734 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
735 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
736 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
737 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
738 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
739 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
740 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
741 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
742 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
743 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
744 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
745 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
746 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
747 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
748 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
749 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
750 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
751 [ST_F_ALGO] = IST("Load balancing algorithm."),
752 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
753 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
754 [ST_F_CONN_TOT] = IST("Total number of connections."),
755 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
756 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
757 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
758 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
759 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
760 [ST_F_REUSE] = IST("Total number of connection reuses."),
761 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
762 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Fauletbd767f72019-11-08 15:24:32 +0100763 [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"),
764 [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"),
Christopher Faulet5df597a2019-11-08 15:05:31 +0100765 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
766 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
767 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
768 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100769};
770
771/* Specific labels for all info fields. Empty by default. */
772const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
773 [INF_NAME] = IST(""),
774 [INF_VERSION] = IST(""),
775 [INF_RELEASE_DATE] = IST(""),
776 [INF_NBTHREAD] = IST(""),
777 [INF_NBPROC] = IST(""),
778 [INF_PROCESS_NUM] = IST(""),
779 [INF_PID] = IST(""),
780 [INF_UPTIME] = IST(""),
781 [INF_UPTIME_SEC] = IST(""),
782 [INF_MEMMAX_MB] = IST(""),
783 [INF_POOL_ALLOC_MB] = IST(""),
784 [INF_POOL_USED_MB] = IST(""),
785 [INF_POOL_FAILED] = IST(""),
786 [INF_ULIMIT_N] = IST(""),
787 [INF_MAXSOCK] = IST(""),
788 [INF_MAXCONN] = IST(""),
789 [INF_HARD_MAXCONN] = IST(""),
790 [INF_CURR_CONN] = IST(""),
791 [INF_CUM_CONN] = IST(""),
792 [INF_CUM_REQ] = IST(""),
793 [INF_MAX_SSL_CONNS] = IST(""),
794 [INF_CURR_SSL_CONNS] = IST(""),
795 [INF_CUM_SSL_CONNS] = IST(""),
796 [INF_MAXPIPES] = IST(""),
797 [INF_PIPES_USED] = IST(""),
798 [INF_PIPES_FREE] = IST(""),
799 [INF_CONN_RATE] = IST(""),
800 [INF_CONN_RATE_LIMIT] = IST(""),
801 [INF_MAX_CONN_RATE] = IST(""),
802 [INF_SESS_RATE] = IST(""),
803 [INF_SESS_RATE_LIMIT] = IST(""),
804 [INF_MAX_SESS_RATE] = IST(""),
805 [INF_SSL_RATE] = IST(""),
806 [INF_SSL_RATE_LIMIT] = IST(""),
807 [INF_MAX_SSL_RATE] = IST(""),
808 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
809 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
810 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
811 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
812 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
813 [INF_SSL_CACHE_LOOKUPS] = IST(""),
814 [INF_SSL_CACHE_MISSES] = IST(""),
815 [INF_COMPRESS_BPS_IN] = IST(""),
816 [INF_COMPRESS_BPS_OUT] = IST(""),
817 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
818 [INF_ZLIB_MEM_USAGE] = IST(""),
819 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
820 [INF_TASKS] = IST(""),
821 [INF_RUN_QUEUE] = IST(""),
822 [INF_IDLE_PCT] = IST(""),
823 [INF_NODE] = IST(""),
824 [INF_DESCRIPTION] = IST(""),
825 [INF_STOPPING] = IST(""),
826 [INF_JOBS] = IST(""),
827 [INF_UNSTOPPABLE_JOBS] = IST(""),
828 [INF_LISTENERS] = IST(""),
829 [INF_ACTIVE_PEERS] = IST(""),
830 [INF_CONNECTED_PEERS] = IST(""),
831 [INF_DROPPED_LOGS] = IST(""),
832 [INF_BUSY_POLLING] = IST(""),
833};
834
835/* Specific labels for all stats fields. Empty by default. */
836const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
837 [ST_F_PXNAME] = IST(""),
838 [ST_F_SVNAME] = IST(""),
839 [ST_F_QCUR] = IST(""),
840 [ST_F_QMAX] = IST(""),
841 [ST_F_SCUR] = IST(""),
842 [ST_F_SMAX] = IST(""),
843 [ST_F_SLIM] = IST(""),
844 [ST_F_STOT] = IST(""),
845 [ST_F_BIN] = IST(""),
846 [ST_F_BOUT] = IST(""),
847 [ST_F_DREQ] = IST(""),
848 [ST_F_DRESP] = IST(""),
849 [ST_F_EREQ] = IST(""),
850 [ST_F_ECON] = IST(""),
851 [ST_F_ERESP] = IST(""),
852 [ST_F_WRETR] = IST(""),
853 [ST_F_WREDIS] = IST(""),
854 [ST_F_STATUS] = IST(""),
855 [ST_F_WEIGHT] = IST(""),
856 [ST_F_ACT] = IST(""),
857 [ST_F_BCK] = IST(""),
858 [ST_F_CHKFAIL] = IST(""),
859 [ST_F_CHKDOWN] = IST(""),
860 [ST_F_LASTCHG] = IST(""),
861 [ST_F_DOWNTIME] = IST(""),
862 [ST_F_QLIMIT] = IST(""),
863 [ST_F_PID] = IST(""),
864 [ST_F_IID] = IST(""),
865 [ST_F_SID] = IST(""),
866 [ST_F_THROTTLE] = IST(""),
867 [ST_F_LBTOT] = IST(""),
868 [ST_F_TRACKED] = IST(""),
869 [ST_F_TYPE] = IST(""),
870 [ST_F_RATE] = IST(""),
871 [ST_F_RATE_LIM] = IST(""),
872 [ST_F_RATE_MAX] = IST(""),
873 [ST_F_CHECK_STATUS] = IST(""),
874 [ST_F_CHECK_CODE] = IST(""),
875 [ST_F_CHECK_DURATION] = IST(""),
876 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
877 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
878 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
879 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
880 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
881 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
882 [ST_F_HANAFAIL] = IST(""),
883 [ST_F_REQ_RATE] = IST(""),
884 [ST_F_REQ_RATE_MAX] = IST(""),
885 [ST_F_REQ_TOT] = IST(""),
886 [ST_F_CLI_ABRT] = IST(""),
887 [ST_F_SRV_ABRT] = IST(""),
888 [ST_F_COMP_IN] = IST(""),
889 [ST_F_COMP_OUT] = IST(""),
890 [ST_F_COMP_BYP] = IST(""),
891 [ST_F_COMP_RSP] = IST(""),
892 [ST_F_LASTSESS] = IST(""),
893 [ST_F_LAST_CHK] = IST(""),
894 [ST_F_LAST_AGT] = IST(""),
895 [ST_F_QTIME] = IST(""),
896 [ST_F_CTIME] = IST(""),
897 [ST_F_RTIME] = IST(""),
898 [ST_F_TTIME] = IST(""),
899 [ST_F_AGENT_STATUS] = IST(""),
900 [ST_F_AGENT_CODE] = IST(""),
901 [ST_F_AGENT_DURATION] = IST(""),
902 [ST_F_CHECK_DESC] = IST(""),
903 [ST_F_AGENT_DESC] = IST(""),
904 [ST_F_CHECK_RISE] = IST(""),
905 [ST_F_CHECK_FALL] = IST(""),
906 [ST_F_CHECK_HEALTH] = IST(""),
907 [ST_F_AGENT_RISE] = IST(""),
908 [ST_F_AGENT_FALL] = IST(""),
909 [ST_F_AGENT_HEALTH] = IST(""),
910 [ST_F_ADDR] = IST(""),
911 [ST_F_COOKIE] = IST(""),
912 [ST_F_MODE] = IST(""),
913 [ST_F_ALGO] = IST(""),
914 [ST_F_CONN_RATE] = IST(""),
915 [ST_F_CONN_RATE_MAX] = IST(""),
916 [ST_F_CONN_TOT] = IST(""),
917 [ST_F_INTERCEPTED] = IST(""),
918 [ST_F_DCON] = IST(""),
919 [ST_F_DSES] = IST(""),
920 [ST_F_WREW] = IST(""),
921 [ST_F_CONNECT] = IST(""),
922 [ST_F_REUSE] = IST(""),
923 [ST_F_CACHE_LOOKUPS] = IST(""),
924 [ST_F_CACHE_HITS] = IST(""),
925};
926
927/* Type for all info fields. "untyped" is used for unsupported field. */
928const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
929 [INF_NAME] = IST("untyped"),
930 [INF_VERSION] = IST("untyped"),
931 [INF_RELEASE_DATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200932 [INF_NBTHREAD] = IST("gauge"),
933 [INF_NBPROC] = IST("gauge"),
934 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100935 [INF_PID] = IST("untyped"),
936 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200937 [INF_UPTIME_SEC] = IST("gauge"),
938 [INF_MEMMAX_MB] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100939 [INF_POOL_ALLOC_MB] = IST("gauge"),
940 [INF_POOL_USED_MB] = IST("gauge"),
941 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200942 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100943 [INF_MAXSOCK] = IST("gauge"),
944 [INF_MAXCONN] = IST("gauge"),
945 [INF_HARD_MAXCONN] = IST("gauge"),
946 [INF_CURR_CONN] = IST("gauge"),
947 [INF_CUM_CONN] = IST("counter"),
948 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200949 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100950 [INF_CURR_SSL_CONNS] = IST("gauge"),
951 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200952 [INF_MAXPIPES] = IST("gauge"),
953 [INF_PIPES_USED] = IST("counter"),
954 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100955 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200956 [INF_CONN_RATE_LIMIT] = IST("gauge"),
957 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100958 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200959 [INF_SESS_RATE_LIMIT] = IST("gauge"),
960 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100961 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200962 [INF_SSL_RATE_LIMIT] = IST("gauge"),
963 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100964 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200965 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100966 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
967 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200968 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100969 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
970 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200971 [INF_COMPRESS_BPS_IN] = IST("counter"),
972 [INF_COMPRESS_BPS_OUT] = IST("counter"),
973 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100974 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200975 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100976 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +0200977 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100978 [INF_IDLE_PCT] = IST("gauge"),
979 [INF_NODE] = IST("untyped"),
980 [INF_DESCRIPTION] = IST("untyped"),
981 [INF_STOPPING] = IST("gauge"),
982 [INF_JOBS] = IST("gauge"),
983 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
984 [INF_LISTENERS] = IST("gauge"),
985 [INF_ACTIVE_PEERS] = IST("gauge"),
986 [INF_CONNECTED_PEERS] = IST("gauge"),
987 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200988 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100989};
990
991/* Type for all stats fields. "untyped" is used for unsupported field. */
992const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
993 [ST_F_PXNAME] = IST("untyped"),
994 [ST_F_SVNAME] = IST("untyped"),
995 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200996 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100997 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200998 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100999 [ST_F_SLIM] = IST("gauge"),
1000 [ST_F_STOT] = IST("counter"),
1001 [ST_F_BIN] = IST("counter"),
1002 [ST_F_BOUT] = IST("counter"),
1003 [ST_F_DREQ] = IST("counter"),
1004 [ST_F_DRESP] = IST("counter"),
1005 [ST_F_EREQ] = IST("counter"),
1006 [ST_F_ECON] = IST("counter"),
1007 [ST_F_ERESP] = IST("counter"),
1008 [ST_F_WRETR] = IST("counter"),
1009 [ST_F_WREDIS] = IST("counter"),
1010 [ST_F_STATUS] = IST("gauge"),
1011 [ST_F_WEIGHT] = IST("gauge"),
1012 [ST_F_ACT] = IST("gauge"),
1013 [ST_F_BCK] = IST("gauge"),
1014 [ST_F_CHKFAIL] = IST("counter"),
1015 [ST_F_CHKDOWN] = IST("counter"),
1016 [ST_F_LASTCHG] = IST("gauge"),
1017 [ST_F_DOWNTIME] = IST("counter"),
1018 [ST_F_QLIMIT] = IST("gauge"),
1019 [ST_F_PID] = IST("untyped"),
1020 [ST_F_IID] = IST("untyped"),
1021 [ST_F_SID] = IST("untyped"),
1022 [ST_F_THROTTLE] = IST("gauge"),
1023 [ST_F_LBTOT] = IST("counter"),
1024 [ST_F_TRACKED] = IST("untyped"),
1025 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001026 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001027 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001028 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001029 [ST_F_CHECK_STATUS] = IST("untyped"),
1030 [ST_F_CHECK_CODE] = IST("untyped"),
1031 [ST_F_CHECK_DURATION] = IST("gauge"),
1032 [ST_F_HRSP_1XX] = IST("counter"),
1033 [ST_F_HRSP_2XX] = IST("counter"),
1034 [ST_F_HRSP_3XX] = IST("counter"),
1035 [ST_F_HRSP_4XX] = IST("counter"),
1036 [ST_F_HRSP_5XX] = IST("counter"),
1037 [ST_F_HRSP_OTHER] = IST("counter"),
1038 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001039 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001040 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001041 [ST_F_REQ_TOT] = IST("counter"),
1042 [ST_F_CLI_ABRT] = IST("counter"),
1043 [ST_F_SRV_ABRT] = IST("counter"),
1044 [ST_F_COMP_IN] = IST("counter"),
1045 [ST_F_COMP_OUT] = IST("counter"),
1046 [ST_F_COMP_BYP] = IST("counter"),
1047 [ST_F_COMP_RSP] = IST("counter"),
1048 [ST_F_LASTSESS] = IST("gauge"),
1049 [ST_F_LAST_CHK] = IST("untyped"),
1050 [ST_F_LAST_AGT] = IST("untyped"),
1051 [ST_F_QTIME] = IST("gauge"),
1052 [ST_F_CTIME] = IST("gauge"),
1053 [ST_F_RTIME] = IST("gauge"),
1054 [ST_F_TTIME] = IST("gauge"),
1055 [ST_F_AGENT_STATUS] = IST("untyped"),
1056 [ST_F_AGENT_CODE] = IST("untyped"),
1057 [ST_F_AGENT_DURATION] = IST("gauge"),
1058 [ST_F_CHECK_DESC] = IST("untyped"),
1059 [ST_F_AGENT_DESC] = IST("untyped"),
1060 [ST_F_CHECK_RISE] = IST("gauge"),
1061 [ST_F_CHECK_FALL] = IST("gauge"),
1062 [ST_F_CHECK_HEALTH] = IST("gauge"),
1063 [ST_F_AGENT_RISE] = IST("gauge"),
1064 [ST_F_AGENT_FALL] = IST("gauge"),
1065 [ST_F_AGENT_HEALTH] = IST("gauge"),
1066 [ST_F_ADDR] = IST("untyped"),
1067 [ST_F_COOKIE] = IST("untyped"),
1068 [ST_F_MODE] = IST("untyped"),
1069 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001070 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001071 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001072 [ST_F_CONN_TOT] = IST("counter"),
1073 [ST_F_INTERCEPTED] = IST("counter"),
1074 [ST_F_DCON] = IST("counter"),
1075 [ST_F_DSES] = IST("counter"),
1076 [ST_F_WREW] = IST("counter"),
1077 [ST_F_CONNECT] = IST("counter"),
1078 [ST_F_REUSE] = IST("counter"),
1079 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1080 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Fauletbd767f72019-11-08 15:24:32 +01001081 [ST_F_SRV_ICUR] = IST("gauge"),
1082 [ST_F_SRV_ILIM] = IST("gauge"),
Christopher Faulet5df597a2019-11-08 15:05:31 +01001083 [ST_F_QT_MAX] = IST("gauge"),
1084 [ST_F_CT_MAX] = IST("gauge"),
1085 [ST_F_RT_MAX] = IST("gauge"),
1086 [ST_F_TT_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001087};
1088
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001089/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001090static int promex_srv_status(struct server *sv)
1091{
Christopher Fauletf959d082019-02-07 15:38:42 +01001092 int state = 0;
1093
Christopher Fauletf959d082019-02-07 15:38:42 +01001094 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1095 state = 1;
1096 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001097 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001098 }
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001099 else if (sv->cur_state == SRV_ST_STOPPING)
1100 state = 4;
1101
1102 if (sv->cur_admin & SRV_ADMF_MAINT)
1103 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001104
1105 return state;
1106}
1107
1108/* Convert a field to its string representation and write it in <out>, followed
1109 * by a newline, if there is enough space. non-numeric value are converted in
1110 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1111 * to process this kind of value). It returns 1 on success. Otherwise, it
1112 * returns 0. The buffer's length must not exceed <max> value.
1113 */
1114static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1115{
1116 int ret = 0;
1117
1118 switch (field_format(f, 0)) {
1119 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1120 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1121 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1122 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1123 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Faulete86bf652019-09-24 16:35:19 +02001124 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001125 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1126 default: ret = chunk_strcat(out, "Nan\n"); break;
1127 }
1128 if (!ret || out->data > max)
1129 return 0;
1130 return 1;
1131}
1132
1133/* Concatenate the <prefix> with the field name using the array
1134 * <promex_st_metric_names> and store it in <name>. The field type is in
1135 * <appctx->st2>. This function never fails but relies on
1136 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enougth to be copied in
1137 * <name>
1138 */
1139static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1140{
1141 const struct ist *names;
1142
1143 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1144 ? promex_inf_metric_names
1145 : promex_st_metric_names);
1146
1147 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1148 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1149}
1150
1151/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1152 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1153 */
1154static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1155 const struct ist name, struct ist *out, size_t max)
1156{
1157 const struct ist *desc, *types;
1158
1159 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1160 desc = promex_inf_metric_desc;
1161 types = promex_inf_metric_types;
1162 }
1163 else {
1164 desc = promex_st_metric_desc;
1165 types = promex_st_metric_types;
1166 }
1167
Anthonin Bonnefoydd4e4ef2019-08-07 17:45:25 +02001168 if (istcat(out, ist("# HELP "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001169 istcat(out, name, max) == -1 ||
1170 istcat(out, ist(" "), max) == -1 ||
1171 istcat(out, desc[appctx->st2], max) == -1 ||
Anthonin Bonnefoydd4e4ef2019-08-07 17:45:25 +02001172 istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001173 istcat(out, name, max) == -1 ||
1174 istcat(out, ist(" "), max) == -1 ||
1175 istcat(out, types[appctx->st2], max) == -1 ||
1176 istcat(out, ist("\n"), max) == -1)
1177 goto full;
1178
1179 return 1;
1180
1181 full:
1182 return 0;
1183}
1184
1185/* Dump the line for <metric>. It starts by the metric name followed by its
1186 * labels (proxy name, server name...) between braces and finally its value. If
1187 * not already done, the header lines are dumped first. It returns 1 on
1188 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1189 */
1190static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1191 const struct ist prefix, struct field *metric,
1192 struct ist *out, size_t max)
1193{
1194 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1195 size_t len = out->len;
1196
1197 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1198 return 0;
1199
1200 promex_metric_name(appctx, &name, prefix);
1201 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1202 !promex_dump_metric_header(appctx, htx, name, out, max))
1203 goto full;
1204
1205 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1206 const struct ist label = promex_inf_metric_labels[appctx->st2];
1207
1208 if (istcat(out, name, max) == -1 ||
1209 (label.len && istcat(out, ist("{"), max) == -1) ||
1210 (label.len && istcat(out, label, max) == -1) ||
1211 (label.len && istcat(out, ist("}"), max) == -1) ||
1212 istcat(out, ist(" "), max) == -1)
1213 goto full;
1214 }
1215 else {
1216 struct proxy *px = appctx->ctx.stats.px;
1217 struct server *srv = appctx->ctx.stats.sv;
1218 const struct ist label = promex_st_metric_labels[appctx->st2];
1219
1220 if (istcat(out, name, max) == -1 ||
1221 istcat(out, ist("{proxy=\""), max) == -1 ||
1222 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1223 istcat(out, ist("\""), max) == -1 ||
1224 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1225 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1226 (srv && istcat(out, ist("\""), max) == -1) ||
1227 (label.len && istcat(out, ist(","), max) == -1) ||
1228 (label.len && istcat(out, label, max) == -1) ||
1229 istcat(out, ist("} "), max) == -1)
1230 goto full;
1231 }
1232
1233 trash.data = out->len;
1234 if (!promex_metric_to_str(&trash, metric, max))
1235 goto full;
1236 out->len = trash.data;
1237
1238 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1239 return 1;
1240 full:
1241 // Restore previous length
1242 out->len = len;
1243 return 0;
1244
1245}
1246
1247
1248/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on sucess,
1249 * 0 if <htx> is full and -1 in case of any error. */
1250static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1251{
1252 static struct ist prefix = IST("haproxy_process_");
1253 struct field metric;
1254 struct channel *chn = si_ic(appctx->owner);
1255 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001256 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001257 int ret = 1;
1258
1259#ifdef USE_OPENSSL
1260 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
1261 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
1262 int ssl_reuse = 0;
1263
1264 if (ssl_key_rate < ssl_sess_rate) {
1265 /* count the ssl reuse ratio and avoid overflows in both directions */
1266 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
1267 }
1268#endif
Christopher Fauletf959d082019-02-07 15:38:42 +01001269 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1270 switch (appctx->st2) {
1271 case INF_NBTHREAD:
1272 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
1273 break;
1274 case INF_NBPROC:
1275 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
1276 break;
1277 case INF_PROCESS_NUM:
1278 metric = mkf_u32(FO_KEY, relative_pid);
1279 break;
1280 case INF_UPTIME_SEC:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001281 metric = mkf_u32(FN_DURATION, start_date.tv_sec);
Christopher Fauletf959d082019-02-07 15:38:42 +01001282 break;
1283 case INF_MEMMAX_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001284 metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
Christopher Fauletf959d082019-02-07 15:38:42 +01001285 break;
1286 case INF_POOL_ALLOC_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001287 metric = mkf_u64(0, pool_total_allocated());
Christopher Fauletf959d082019-02-07 15:38:42 +01001288 break;
1289 case INF_POOL_USED_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001290 metric = mkf_u64(0, pool_total_used());
Christopher Fauletf959d082019-02-07 15:38:42 +01001291 break;
1292 case INF_POOL_FAILED:
1293 metric = mkf_u32(FN_COUNTER, pool_total_failures());
1294 break;
1295 case INF_ULIMIT_N:
1296 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
1297 break;
1298 case INF_MAXSOCK:
1299 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
1300 break;
1301 case INF_MAXCONN:
1302 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
1303 break;
1304 case INF_HARD_MAXCONN:
1305 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
1306 break;
1307 case INF_CURR_CONN:
1308 metric = mkf_u32(0, actconn);
1309 break;
1310 case INF_CUM_CONN:
1311 metric = mkf_u32(FN_COUNTER, totalconn);
1312 break;
1313 case INF_CUM_REQ:
1314 metric = mkf_u32(FN_COUNTER, global.req_count);
1315 break;
1316#ifdef USE_OPENSSL
1317 case INF_MAX_SSL_CONNS:
1318 metric = mkf_u32(FN_MAX, global.maxsslconn);
1319 break;
1320 case INF_CURR_SSL_CONNS:
1321 metric = mkf_u32(0, sslconns);
1322 break;
1323 case INF_CUM_SSL_CONNS:
1324 metric = mkf_u32(FN_COUNTER, totalsslconns);
1325 break;
1326#endif
1327 case INF_MAXPIPES:
1328 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
1329 break;
1330 case INF_PIPES_USED:
1331 metric = mkf_u32(0, pipes_used);
1332 break;
1333 case INF_PIPES_FREE:
1334 metric = mkf_u32(0, pipes_free);
1335 break;
1336 case INF_CONN_RATE:
1337 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
1338 break;
1339 case INF_CONN_RATE_LIMIT:
1340 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
1341 break;
1342 case INF_MAX_CONN_RATE:
1343 metric = mkf_u32(FN_MAX, global.cps_max);
1344 break;
1345 case INF_SESS_RATE:
1346 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
1347 break;
1348 case INF_SESS_RATE_LIMIT:
1349 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
1350 break;
1351 case INF_MAX_SESS_RATE:
1352 metric = mkf_u32(FN_RATE, global.sps_max);
1353 break;
1354#ifdef USE_OPENSSL
1355 case INF_SSL_RATE:
1356 metric = mkf_u32(FN_RATE, ssl_sess_rate);
1357 break;
1358 case INF_SSL_RATE_LIMIT:
1359 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
1360 break;
1361 case INF_MAX_SSL_RATE:
1362 metric = mkf_u32(FN_MAX, global.ssl_max);
1363 break;
1364 case INF_SSL_FRONTEND_KEY_RATE:
1365 metric = mkf_u32(0, ssl_key_rate);
1366 break;
1367 case INF_SSL_FRONTEND_MAX_KEY_RATE:
1368 metric = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
1369 break;
1370 case INF_SSL_FRONTEND_SESSION_REUSE_PCT:
1371 metric = mkf_u32(0, ssl_reuse);
1372 break;
1373 case INF_SSL_BACKEND_KEY_RATE:
1374 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
1375 break;
1376 case INF_SSL_BACKEND_MAX_KEY_RATE:
1377 metric = mkf_u32(FN_MAX, global.ssl_be_keys_max);
1378 break;
1379 case INF_SSL_CACHE_LOOKUPS:
1380 metric = mkf_u32(FN_COUNTER, global.shctx_lookups);
1381 break;
1382 case INF_SSL_CACHE_MISSES:
1383 metric = mkf_u32(FN_COUNTER, global.shctx_misses);
1384 break;
1385#endif
1386 case INF_COMPRESS_BPS_IN:
1387 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
1388 break;
1389 case INF_COMPRESS_BPS_OUT:
1390 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
1391 break;
1392 case INF_COMPRESS_BPS_RATE_LIM:
1393 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
1394 break;
1395#ifdef USE_ZLIB
1396 case INF_ZLIB_MEM_USAGE:
1397 metric = mkf_u32(0, zlib_used_memory);
1398 break;
1399 case INF_MAX_ZLIB_MEM_USAGE:
1400 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
1401 break;
1402#endif
1403 case INF_TASKS:
1404 metric = mkf_u32(0, nb_tasks_cur);
1405 break;
1406 case INF_RUN_QUEUE:
1407 metric = mkf_u32(0, tasks_run_queue_cur);
1408 break;
1409 case INF_IDLE_PCT:
Willy Tarreau76824a82019-06-02 10:38:48 +02001410 metric = mkf_u32(FN_AVG, ti->idle_pct);
Christopher Fauletf959d082019-02-07 15:38:42 +01001411 break;
1412 case INF_STOPPING:
1413 metric = mkf_u32(0, stopping);
1414 break;
1415 case INF_JOBS:
1416 metric = mkf_u32(0, jobs);
1417 break;
1418 case INF_UNSTOPPABLE_JOBS:
1419 metric = mkf_u32(0, unstoppable_jobs);
1420 break;
1421 case INF_LISTENERS:
1422 metric = mkf_u32(0, listeners);
1423 break;
1424 case INF_ACTIVE_PEERS:
1425 metric = mkf_u32(0, active_peers);
1426 break;
1427 case INF_CONNECTED_PEERS:
1428 metric = mkf_u32(0, connected_peers);
1429 break;
1430 case INF_DROPPED_LOGS:
1431 metric = mkf_u32(0, dropped_logs);
1432 break;
1433 case INF_BUSY_POLLING:
1434 metric = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
1435 break;
1436
1437 default:
1438 goto next_metric;
1439 }
1440
1441 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1442 goto full;
1443
1444 next_metric:
1445 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1446 appctx->st2 = promex_global_metrics[appctx->st2];
1447 }
1448
1449 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001450 if (out.len) {
1451 if (!htx_add_data_atonce(htx, out))
1452 return -1; /* Unexpected and unrecoverable error */
1453 channel_add_input(chn, out.len);
1454 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001455 return ret;
1456 full:
1457 ret = 0;
1458 goto end;
1459}
1460
1461/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on sucess,
1462 * 0 if <htx> is full and -1 in case of any error. */
1463static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1464{
1465 static struct ist prefix = IST("haproxy_frontend_");
1466 struct proxy *px;
1467 struct field metric;
1468 struct channel *chn = si_ic(appctx->owner);
1469 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001470 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001471 int ret = 1;
1472
1473 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1474 while (appctx->ctx.stats.px) {
1475 px = appctx->ctx.stats.px;
1476
1477 /* skip the disabled proxies, global frontend and non-networked ones */
1478 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
1479 goto next_px;
1480
1481 switch (appctx->st2) {
1482 case ST_F_STATUS:
1483 metric = mkf_u32(FO_STATUS, px->state == PR_STREADY ? 1 : px->state == PR_STFULL ? 2 : 0);
1484 break;
1485 case ST_F_SCUR:
1486 metric = mkf_u32(0, px->feconn);
1487 break;
1488 case ST_F_SMAX:
1489 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1490 break;
1491 case ST_F_SLIM:
1492 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1493 break;
1494 case ST_F_STOT:
1495 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1496 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001497 case ST_F_RATE_LIM:
1498 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1499 break;
1500 case ST_F_RATE_MAX:
1501 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1502 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001503 case ST_F_CONN_RATE_MAX:
1504 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1505 break;
1506 case ST_F_CONN_TOT:
1507 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1508 break;
1509 case ST_F_BIN:
1510 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1511 break;
1512 case ST_F_BOUT:
1513 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1514 break;
1515 case ST_F_DREQ:
1516 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1517 break;
1518 case ST_F_DRESP:
1519 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1520 break;
1521 case ST_F_EREQ:
1522 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1523 break;
1524 case ST_F_DCON:
1525 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1526 break;
1527 case ST_F_DSES:
1528 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1529 break;
1530 case ST_F_WREW:
1531 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1532 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001533 case ST_F_REQ_RATE_MAX:
1534 if (px->mode != PR_MODE_HTTP)
1535 goto next_px;
1536 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1537 break;
1538 case ST_F_REQ_TOT:
1539 if (px->mode != PR_MODE_HTTP)
1540 goto next_px;
1541 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1542 break;
1543 case ST_F_HRSP_1XX:
1544 if (px->mode != PR_MODE_HTTP)
1545 goto next_px;
1546 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1547 break;
1548 case ST_F_HRSP_2XX:
1549 if (px->mode != PR_MODE_HTTP)
1550 goto next_px;
1551 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1552 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1553 break;
1554 case ST_F_HRSP_3XX:
1555 if (px->mode != PR_MODE_HTTP)
1556 goto next_px;
1557 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1558 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1559 break;
1560 case ST_F_HRSP_4XX:
1561 if (px->mode != PR_MODE_HTTP)
1562 goto next_px;
1563 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1564 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1565 break;
1566 case ST_F_HRSP_5XX:
1567 if (px->mode != PR_MODE_HTTP)
1568 goto next_px;
1569 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1570 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1571 break;
1572 case ST_F_HRSP_OTHER:
1573 if (px->mode != PR_MODE_HTTP)
1574 goto next_px;
1575 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1576 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1577 break;
1578 case ST_F_INTERCEPTED:
1579 if (px->mode != PR_MODE_HTTP)
1580 goto next_px;
1581 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1582 break;
1583 case ST_F_CACHE_LOOKUPS:
1584 if (px->mode != PR_MODE_HTTP)
1585 goto next_px;
1586 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1587 break;
1588 case ST_F_CACHE_HITS:
1589 if (px->mode != PR_MODE_HTTP)
1590 goto next_px;
1591 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1592 break;
1593 case ST_F_COMP_IN:
1594 if (px->mode != PR_MODE_HTTP)
1595 goto next_px;
1596 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1597 break;
1598 case ST_F_COMP_OUT:
1599 if (px->mode != PR_MODE_HTTP)
1600 goto next_px;
1601 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1602 break;
1603 case ST_F_COMP_BYP:
1604 if (px->mode != PR_MODE_HTTP)
1605 goto next_px;
1606 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1607 break;
1608 case ST_F_COMP_RSP:
1609 if (px->mode != PR_MODE_HTTP)
1610 goto next_px;
1611 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1612 break;
1613
1614 default:
1615 goto next_metric;
1616 }
1617
1618 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1619 goto full;
1620 next_px:
1621 appctx->ctx.stats.px = px->next;
1622 }
1623 next_metric:
1624 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1625 appctx->ctx.stats.px = proxies_list;
1626 appctx->st2 = promex_front_metrics[appctx->st2];
1627 }
1628
1629 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001630 if (out.len) {
1631 if (!htx_add_data_atonce(htx, out))
1632 return -1; /* Unexpected and unrecoverable error */
1633 channel_add_input(chn, out.len);
1634 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001635 return ret;
1636 full:
1637 ret = 0;
1638 goto end;
1639}
1640
1641/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on sucess,
1642 * 0 if <htx> is full and -1 in case of any error. */
1643static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1644{
1645 static struct ist prefix = IST("haproxy_backend_");
1646 struct proxy *px;
1647 struct field metric;
1648 struct channel *chn = si_ic(appctx->owner);
1649 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001650 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001651 int ret = 1;
1652 uint32_t weight;
Christopher Faulete86bf652019-09-24 16:35:19 +02001653 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001654
1655 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1656 while (appctx->ctx.stats.px) {
1657 px = appctx->ctx.stats.px;
1658
1659 /* skip the disabled proxies, global frontend and non-networked ones */
1660 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1661 goto next_px;
1662
1663 switch (appctx->st2) {
1664 case ST_F_STATUS:
1665 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1666 break;
1667 case ST_F_SCUR:
1668 metric = mkf_u32(0, px->beconn);
1669 break;
1670 case ST_F_SMAX:
1671 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1672 break;
1673 case ST_F_SLIM:
1674 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1675 break;
1676 case ST_F_STOT:
1677 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1678 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001679 case ST_F_RATE_MAX:
1680 metric = mkf_u32(0, px->be_counters.sps_max);
1681 break;
1682 case ST_F_LASTSESS:
1683 metric = mkf_s32(FN_AGE, be_lastsession(px));
1684 break;
1685 case ST_F_QCUR:
1686 metric = mkf_u32(0, px->nbpend);
1687 break;
1688 case ST_F_QMAX:
1689 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1690 break;
1691 case ST_F_CONNECT:
1692 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1693 break;
1694 case ST_F_REUSE:
1695 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1696 break;
1697 case ST_F_BIN:
1698 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1699 break;
1700 case ST_F_BOUT:
1701 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1702 break;
1703 case ST_F_QTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001704 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1705 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001706 break;
1707 case ST_F_CTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001708 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1709 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001710 break;
1711 case ST_F_RTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001712 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1713 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001714 break;
1715 case ST_F_TTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001716 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1717 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001718 break;
Christopher Faulet5df597a2019-11-08 15:05:31 +01001719 case ST_F_QT_MAX:
1720 secs = (double)px->be_counters.qtime_max / 1000.0;
1721 metric = mkf_flt(FN_MAX, secs);
1722 break;
1723 case ST_F_CT_MAX:
1724 secs = (double)px->be_counters.ctime_max / 1000.0;
1725 metric = mkf_flt(FN_MAX, secs);
1726 break;
1727 case ST_F_RT_MAX:
1728 secs = (double)px->be_counters.dtime_max / 1000.0;
1729 metric = mkf_flt(FN_MAX, secs);
1730 break;
1731 case ST_F_TT_MAX:
1732 secs = (double)px->be_counters.ttime_max / 1000.0;
1733 metric = mkf_flt(FN_MAX, secs);
1734 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001735 case ST_F_DREQ:
1736 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1737 break;
1738 case ST_F_DRESP:
1739 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1740 break;
1741 case ST_F_ECON:
1742 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1743 break;
1744 case ST_F_ERESP:
1745 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1746 break;
1747 case ST_F_WRETR:
1748 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1749 break;
1750 case ST_F_WREDIS:
1751 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1752 break;
1753 case ST_F_WREW:
1754 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1755 break;
1756 case ST_F_CLI_ABRT:
1757 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1758 break;
1759 case ST_F_SRV_ABRT:
1760 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1761 break;
1762 case ST_F_WEIGHT:
1763 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1764 metric = mkf_u32(FN_AVG, weight);
1765 break;
1766 case ST_F_ACT:
1767 metric = mkf_u32(0, px->srv_act);
1768 break;
1769 case ST_F_BCK:
1770 metric = mkf_u32(0, px->srv_bck);
1771 break;
1772 case ST_F_CHKDOWN:
1773 metric = mkf_u64(FN_COUNTER, px->down_trans);
1774 break;
1775 case ST_F_LASTCHG:
1776 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1777 break;
1778 case ST_F_DOWNTIME:
1779 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1780 break;
1781 case ST_F_LBTOT:
1782 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1783 break;
1784 case ST_F_REQ_TOT:
1785 if (px->mode != PR_MODE_HTTP)
1786 goto next_px;
1787 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1788 break;
1789 case ST_F_HRSP_1XX:
1790 if (px->mode != PR_MODE_HTTP)
1791 goto next_px;
1792 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1793 break;
1794 case ST_F_HRSP_2XX:
1795 if (px->mode != PR_MODE_HTTP)
1796 goto next_px;
1797 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1798 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1799 break;
1800 case ST_F_HRSP_3XX:
1801 if (px->mode != PR_MODE_HTTP)
1802 goto next_px;
1803 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1804 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1805 break;
1806 case ST_F_HRSP_4XX:
1807 if (px->mode != PR_MODE_HTTP)
1808 goto next_px;
1809 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1810 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1811 break;
1812 case ST_F_HRSP_5XX:
1813 if (px->mode != PR_MODE_HTTP)
1814 goto next_px;
1815 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1816 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1817 break;
1818 case ST_F_HRSP_OTHER:
1819 if (px->mode != PR_MODE_HTTP)
1820 goto next_px;
1821 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1822 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1823 break;
1824 case ST_F_CACHE_LOOKUPS:
1825 if (px->mode != PR_MODE_HTTP)
1826 goto next_px;
1827 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1828 break;
1829 case ST_F_CACHE_HITS:
1830 if (px->mode != PR_MODE_HTTP)
1831 goto next_px;
1832 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1833 break;
1834 case ST_F_COMP_IN:
1835 if (px->mode != PR_MODE_HTTP)
1836 goto next_px;
1837 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1838 break;
1839 case ST_F_COMP_OUT:
1840 if (px->mode != PR_MODE_HTTP)
1841 goto next_px;
1842 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1843 break;
1844 case ST_F_COMP_BYP:
1845 if (px->mode != PR_MODE_HTTP)
1846 goto next_px;
1847 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1848 break;
1849 case ST_F_COMP_RSP:
1850 if (px->mode != PR_MODE_HTTP)
1851 goto next_px;
1852 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1853 break;
1854
1855 default:
1856 goto next_metric;
1857 }
1858
1859 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1860 goto full;
1861 next_px:
1862 appctx->ctx.stats.px = px->next;
1863 }
1864 next_metric:
1865 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1866 appctx->ctx.stats.px = proxies_list;
1867 appctx->st2 = promex_back_metrics[appctx->st2];
1868 }
1869
1870 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001871 if (out.len) {
1872 if (!htx_add_data_atonce(htx, out))
1873 return -1; /* Unexpected and unrecoverable error */
1874 channel_add_input(chn, out.len);
1875 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001876 return ret;
1877 full:
1878 ret = 0;
1879 goto end;
1880}
1881
1882/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on sucess,
1883 * 0 if <htx> is full and -1 in case of any error. */
1884static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1885{
1886 static struct ist prefix = IST("haproxy_server_");
1887 struct proxy *px;
1888 struct server *sv;
1889 struct field metric;
1890 struct channel *chn = si_ic(appctx->owner);
1891 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001892 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001893 int ret = 1;
1894 uint32_t weight;
Christopher Faulete86bf652019-09-24 16:35:19 +02001895 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001896
1897 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1898 while (appctx->ctx.stats.px) {
1899 px = appctx->ctx.stats.px;
1900
1901 /* skip the disabled proxies, global frontend and non-networked ones */
1902 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1903 goto next_px;
1904
1905 while (appctx->ctx.stats.sv) {
1906 sv = appctx->ctx.stats.sv;
1907
1908 switch (appctx->st2) {
1909 case ST_F_STATUS:
1910 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1911 break;
1912 case ST_F_SCUR:
1913 metric = mkf_u32(0, sv->cur_sess);
1914 break;
1915 case ST_F_SMAX:
1916 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1917 break;
1918 case ST_F_SLIM:
1919 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1920 break;
1921 case ST_F_STOT:
1922 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1923 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001924 case ST_F_RATE_MAX:
1925 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1926 break;
1927 case ST_F_LASTSESS:
1928 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1929 break;
1930 case ST_F_QCUR:
1931 metric = mkf_u32(0, sv->nbpend);
1932 break;
1933 case ST_F_QMAX:
1934 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1935 break;
1936 case ST_F_QLIMIT:
1937 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1938 break;
1939 case ST_F_BIN:
1940 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1941 break;
1942 case ST_F_BOUT:
1943 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1944 break;
1945 case ST_F_QTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001946 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1947 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001948 break;
1949 case ST_F_CTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001950 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1951 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001952 break;
1953 case ST_F_RTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001954 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1955 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001956 break;
1957 case ST_F_TTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001958 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1959 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001960 break;
Christopher Faulet5df597a2019-11-08 15:05:31 +01001961 case ST_F_QT_MAX:
1962 secs = (double)sv->counters.qtime_max / 1000.0;
1963 metric = mkf_flt(FN_MAX, secs);
1964 break;
1965 case ST_F_CT_MAX:
1966 secs = (double)sv->counters.ctime_max / 1000.0;
1967 metric = mkf_flt(FN_MAX, secs);
1968 break;
1969 case ST_F_RT_MAX:
1970 secs = (double)sv->counters.dtime_max / 1000.0;
1971 metric = mkf_flt(FN_MAX, secs);
1972 break;
1973 case ST_F_TT_MAX:
1974 secs = (double)sv->counters.ttime_max / 1000.0;
1975 metric = mkf_flt(FN_MAX, secs);
1976 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001977 case ST_F_CONNECT:
1978 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1979 break;
1980 case ST_F_REUSE:
1981 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1982 break;
1983 case ST_F_DRESP:
1984 metric = mkf_u64(FN_COUNTER, sv->counters.failed_secu);
1985 break;
1986 case ST_F_ECON:
1987 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1988 break;
1989 case ST_F_ERESP:
1990 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1991 break;
1992 case ST_F_WRETR:
1993 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
1994 break;
1995 case ST_F_WREDIS:
1996 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
1997 break;
1998 case ST_F_WREW:
1999 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
2000 break;
2001 case ST_F_CLI_ABRT:
2002 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
2003 break;
2004 case ST_F_SRV_ABRT:
2005 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
2006 break;
2007 case ST_F_WEIGHT:
2008 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
2009 metric = mkf_u32(FN_AVG, weight);
2010 break;
2011 case ST_F_CHKFAIL:
2012 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
2013 break;
2014 case ST_F_CHKDOWN:
2015 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
2016 break;
2017 case ST_F_DOWNTIME:
2018 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
2019 break;
2020 case ST_F_LASTCHG:
2021 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
2022 break;
2023 case ST_F_THROTTLE:
2024 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
2025 break;
2026 case ST_F_LBTOT:
2027 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
2028 break;
2029 case ST_F_HRSP_1XX:
2030 if (px->mode != PR_MODE_HTTP)
2031 goto next_px;
2032 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
2033 break;
2034 case ST_F_HRSP_2XX:
2035 if (px->mode != PR_MODE_HTTP)
2036 goto next_px;
2037 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2038 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
2039 break;
2040 case ST_F_HRSP_3XX:
2041 if (px->mode != PR_MODE_HTTP)
2042 goto next_px;
2043 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2044 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
2045 break;
2046 case ST_F_HRSP_4XX:
2047 if (px->mode != PR_MODE_HTTP)
2048 goto next_px;
2049 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2050 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
2051 break;
2052 case ST_F_HRSP_5XX:
2053 if (px->mode != PR_MODE_HTTP)
2054 goto next_px;
2055 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2056 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
2057 break;
2058 case ST_F_HRSP_OTHER:
2059 if (px->mode != PR_MODE_HTTP)
2060 goto next_px;
2061 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2062 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
2063 break;
Christopher Fauletbd767f72019-11-08 15:24:32 +01002064 case ST_F_SRV_ICUR:
2065 metric = mkf_u32(0, sv->curr_idle_conns);
2066 break;
2067 case ST_F_SRV_ILIM:
2068 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2069 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002070
2071 default:
2072 goto next_metric;
2073 }
2074
2075 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2076 goto full;
2077
2078 appctx->ctx.stats.sv = sv->next;
2079 }
2080
2081 next_px:
2082 appctx->ctx.stats.px = px->next;
2083 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2084 }
2085 next_metric:
2086 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
2087 appctx->ctx.stats.px = proxies_list;
2088 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2089 appctx->st2 = promex_srv_metrics[appctx->st2];
2090 }
2091
2092
2093 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02002094 if (out.len) {
2095 if (!htx_add_data_atonce(htx, out))
2096 return -1; /* Unexpected and unrecoverable error */
2097 channel_add_input(chn, out.len);
2098 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002099 return ret;
2100 full:
2101 ret = 0;
2102 goto end;
2103}
2104
2105/* Dump all metrics (global, frontends, backends and servers) depending on the
2106 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
2107 * -1 in case of any error. */
2108static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2109{
2110 int ret;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002111 int flags = appctx->ctx.stats.flags;
Christopher Fauletf959d082019-02-07 15:38:42 +01002112
2113 switch (appctx->st1) {
2114 case PROMEX_DUMPER_INIT:
2115 appctx->ctx.stats.px = NULL;
2116 appctx->ctx.stats.sv = NULL;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002117 appctx->ctx.stats.flags = (flags|PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002118 appctx->st2 = promex_global_metrics[INF_NAME];
2119 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2120 /* fall through */
2121
2122 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002123 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2124 ret = promex_dump_global_metrics(appctx, htx);
2125 if (ret <= 0) {
2126 if (ret == -1)
2127 goto error;
2128 goto full;
2129 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002130 }
2131
2132 appctx->ctx.stats.px = proxies_list;
2133 appctx->ctx.stats.sv = NULL;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002134 appctx->ctx.stats.flags = (flags|PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002135 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2136 appctx->st1 = PROMEX_DUMPER_FRONT;
2137 /* fall through */
2138
2139 case PROMEX_DUMPER_FRONT:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002140 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2141 ret = promex_dump_front_metrics(appctx, htx);
2142 if (ret <= 0) {
2143 if (ret == -1)
2144 goto error;
2145 goto full;
2146 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002147 }
2148
2149 appctx->ctx.stats.px = proxies_list;
2150 appctx->ctx.stats.sv = NULL;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002151 appctx->ctx.stats.flags = (flags|PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002152 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2153 appctx->st1 = PROMEX_DUMPER_BACK;
2154 /* fall through */
2155
2156 case PROMEX_DUMPER_BACK:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002157 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2158 ret = promex_dump_back_metrics(appctx, htx);
2159 if (ret <= 0) {
2160 if (ret == -1)
2161 goto error;
2162 goto full;
2163 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002164 }
2165
2166 appctx->ctx.stats.px = proxies_list;
2167 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
Christopher Faulet32d634f2019-11-18 14:47:08 +01002168 appctx->ctx.stats.flags = (flags|PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002169 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2170 appctx->st1 = PROMEX_DUMPER_SRV;
2171 /* fall through */
2172
2173 case PROMEX_DUMPER_SRV:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002174 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2175 ret = promex_dump_srv_metrics(appctx, htx);
2176 if (ret <= 0) {
2177 if (ret == -1)
2178 goto error;
2179 goto full;
2180 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002181 }
2182
2183 appctx->ctx.stats.px = NULL;
2184 appctx->ctx.stats.sv = NULL;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002185 appctx->ctx.stats.flags = flags;
Christopher Fauletf959d082019-02-07 15:38:42 +01002186 appctx->st2 = 0;
2187 appctx->st1 = PROMEX_DUMPER_DONE;
2188 /* fall through */
2189
2190 case PROMEX_DUMPER_DONE:
2191 default:
2192 break;
2193 }
2194
2195 return 1;
2196
2197 full:
2198 si_rx_room_blk(si);
2199 return 0;
2200 error:
2201 /* unrecoverable error */
2202 appctx->ctx.stats.px = NULL;
2203 appctx->ctx.stats.sv = NULL;
2204 appctx->ctx.stats.flags = 0;
2205 appctx->st2 = 0;
2206 appctx->st1 = PROMEX_DUMPER_DONE;
2207 return -1;
2208}
2209
Christopher Faulet32d634f2019-11-18 14:47:08 +01002210/* Parse the query stirng of request URI to filter the metrics. It returns 1 on
2211 * success and -1 on error. */
2212static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2213{
2214 struct channel *req = si_oc(si);
2215 struct channel *res = si_ic(si);
2216 struct htx *req_htx, *res_htx;
2217 struct htx_sl *sl;
2218 const char *p, *end;
2219 struct buffer *err;
2220 int default_scopes = PROMEX_FL_SCOPE_ALL;
2221 int len;
2222
2223 /* Get the query-string */
2224 req_htx = htxbuf(&req->buf);
2225 sl = http_get_stline(req_htx);
2226 if (!sl)
2227 goto error;
2228 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2229 if (!p)
2230 goto end;
2231 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
2232 len = end-p;
2233
2234 /* Decode the query-string */
2235 chunk_reset(&trash);
2236 memcpy(trash.area, p, len);
2237 trash.area[len] = 0;
2238 len = url_decode(trash.area);
2239 if (len == -1)
2240 goto error;
2241 p = trash.area;
2242 end = p + len;
2243
2244 /* Parse the query-string */
2245 while (p < end) {
2246 if (*p == '&')
2247 ++p;
2248 else if (*p == 's' && (end-p) >= 6 && !memcmp(p, "scope=", 6)) {
2249 default_scopes = 0; /* at least a scope defined, unset default scopes */
2250 p += 6; /* now p point on the parameter value */
2251 len = 0; /* len is the value length */
2252 while ((p+len) < end && *(p+len) != '&')
2253 ++len;
2254
2255 if (len == 0)
2256 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
2257 else if (len == 1 && *p == '*')
2258 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
2259 else if (len == 6) {
2260 if (!memcmp(p, "global", len))
2261 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
2262 else if (!memcmp(p, "server", len))
2263 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
2264 }
2265 else if (len == 7 && !memcmp(p, "backend", len))
2266 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
2267 else if (len == 8 && !memcmp(p, "frontend", len))
2268 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2269 else
2270 goto error;
2271
2272 p += len;
2273 }
2274 else {
2275 /* ignore all other params for now */
2276 while (p < end && *p != '&')
2277 p++;
2278 }
2279 }
2280
2281 end:
2282 appctx->ctx.stats.flags |= default_scopes;
2283 return 1;
2284
2285 error:
2286 err = &http_err_chunks[HTTP_ERR_400];
2287 channel_erase(res);
2288 res->buf.data = b_data(err);
2289 memcpy(res->buf.area, b_head(err), b_data(err));
2290 res_htx = htx_from_buf(&res->buf);
2291 channel_add_input(res, res_htx->data);
2292 appctx->st0 = PROMEX_ST_END;
2293 return -1;
2294}
2295
Christopher Fauletf959d082019-02-07 15:38:42 +01002296/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2297 * full. */
2298static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2299{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002300 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002301 struct htx_sl *sl;
2302 unsigned int flags;
2303
2304 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);
2305 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2306 if (!sl)
2307 goto full;
2308 sl->info.res.status = 200;
2309 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
2310 !htx_add_header(htx, ist("Connection"), ist("close")) ||
2311 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2312 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2313 !htx_add_endof(htx, HTX_BLK_EOH))
2314 goto full;
2315
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002316 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002317 return 1;
2318 full:
2319 htx_reset(htx);
2320 si_rx_room_blk(si);
2321 return 0;
2322}
2323
2324/* The function returns 1 if the initialisation is complete, 0 if
2325 * an errors occurs and -1 if more data are required for initializing
2326 * the applet.
2327 */
2328static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2329{
2330 appctx->st0 = PROMEX_ST_INIT;
2331 return 1;
2332}
2333
2334/* The main I/O handler for the promex applet. */
2335static void promex_appctx_handle_io(struct appctx *appctx)
2336{
2337 struct stream_interface *si = appctx->owner;
2338 struct stream *s = si_strm(si);
2339 struct channel *req = si_oc(si);
2340 struct channel *res = si_ic(si);
2341 struct htx *req_htx, *res_htx;
2342 int ret;
2343
2344 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002345 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2346 goto out;
2347
2348 /* Check if the input buffer is avalaible. */
2349 if (!b_size(&res->buf)) {
2350 si_rx_room_blk(si);
2351 goto out;
2352 }
2353
2354 switch (appctx->st0) {
2355 case PROMEX_ST_INIT:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002356 ret = promex_parse_uri(appctx, si);
2357 if (ret <= 0) {
2358 if (ret == -1)
2359 goto error;
2360 goto out;
2361 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002362 appctx->st0 = PROMEX_ST_HEAD;
2363 appctx->st1 = PROMEX_DUMPER_INIT;
2364 /* fall through */
2365
2366 case PROMEX_ST_HEAD:
2367 if (!promex_send_headers(appctx, si, res_htx))
2368 goto out;
2369 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2370 /* fall through */
2371
2372 case PROMEX_ST_DUMP:
2373 ret = promex_dump_metrics(appctx, si, res_htx);
2374 if (ret <= 0) {
2375 if (ret == -1)
2376 goto error;
2377 goto out;
2378 }
2379 appctx->st0 = PROMEX_ST_DONE;
2380 /* fall through */
2381
2382 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002383 /* Don't add TLR because mux-h1 will take care of it */
Christopher Fauletf959d082019-02-07 15:38:42 +01002384 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2385 si_rx_room_blk(si);
2386 goto out;
2387 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002388 channel_add_input(res, 1);
2389 appctx->st0 = PROMEX_ST_END;
2390 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002391
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002392 case PROMEX_ST_END:
2393 if (!(res->flags & CF_SHUTR)) {
2394 res->flags |= CF_READ_NULL;
2395 si_shutr(si);
2396 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002397 }
2398
Christopher Fauletf959d082019-02-07 15:38:42 +01002399 out:
2400 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002401
2402 /* eat the whole request */
2403 if (co_data(req)) {
2404 req_htx = htx_from_buf(&req->buf);
2405 co_htx_skip(req, req_htx, co_data(req));
2406 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002407 return;
2408
2409 error:
2410 res->flags |= CF_READ_NULL;
2411 si_shutr(si);
2412 si_shutw(si);
2413}
2414
2415struct applet promex_applet = {
2416 .obj_type = OBJ_TYPE_APPLET,
2417 .name = "<PROMEX>", /* used for logging */
2418 .init = promex_appctx_init,
2419 .fct = promex_appctx_handle_io,
2420};
2421
2422static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2423 struct act_rule *rule, char **err)
2424{
2425 /* Prometheus exporter service is only available on "http-request" rulesets */
2426 if (rule->from != ACT_F_HTTP_REQ) {
2427 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2428 return ACT_RET_PRS_ERR;
2429 }
2430 if (!(px->options2 & PR_O2_USE_HTX)) {
2431 memprintf(err, "Prometheus exporter service only available for HTX proxies");
2432 return ACT_RET_PRS_ERR;
2433 }
2434
2435 /* Add applet pointer in the rule. */
2436 rule->applet = promex_applet;
2437
2438 return ACT_RET_PRS_OK;
2439}
2440static void promex_register_build_options(void)
2441{
2442 char *ptr = NULL;
2443
2444 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2445 hap_register_build_opts(ptr, 1);
2446}
2447
2448
2449static struct action_kw_list service_actions = { ILH, {
2450 { "prometheus-exporter", service_parse_prometheus_exporter },
2451 { /* END */ }
2452}};
2453
2454INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2455INITCALL0(STG_REGISTER, promex_register_build_options);