blob: 19918231f8c7dff35bb3078f75c86e40af582214 [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
67
68/* The max length for metrics name. It is a hard limit but it should be
69 * enougth.
70 */
71#define PROMEX_MAX_NAME_LEN 128
72
73/* The expected max length for a metric dump, including its header lines. It is
74 * just a soft limit to avoid extra work. We don't try to dump a metric if less
75 * than this size is available in the HTX.
76 */
77#define PROMEX_MAX_METRIC_LENGTH 512
78
79/* Matrix used to dump global metrics. Each metric points to the next one to be
80 * processed or 0 to stop the dump. */
81const int promex_global_metrics[INF_TOTAL_FIELDS] = {
82 [INF_NAME] = INF_NBTHREAD,
83 [INF_VERSION] = 0,
84 [INF_RELEASE_DATE] = 0,
85 [INF_NBTHREAD] = INF_NBPROC,
86 [INF_NBPROC] = INF_PROCESS_NUM,
87 [INF_PROCESS_NUM] = INF_UPTIME_SEC,
88 [INF_PID] = 0,
89 [INF_UPTIME] = 0,
90 [INF_UPTIME_SEC] = INF_MEMMAX_MB,
91 [INF_MEMMAX_MB] = INF_POOL_ALLOC_MB,
92 [INF_POOL_ALLOC_MB] = INF_POOL_USED_MB,
93 [INF_POOL_USED_MB] = INF_POOL_FAILED,
94 [INF_POOL_FAILED] = INF_ULIMIT_N,
95 [INF_ULIMIT_N] = INF_MAXSOCK,
96 [INF_MAXSOCK] = INF_MAXCONN,
97 [INF_MAXCONN] = INF_HARD_MAXCONN,
98 [INF_HARD_MAXCONN] = INF_CURR_CONN,
99 [INF_CURR_CONN] = INF_CUM_CONN,
100 [INF_CUM_CONN] = INF_CUM_REQ,
101 [INF_CUM_REQ] = INF_MAX_SSL_CONNS,
102 [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS,
103 [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS,
104 [INF_CUM_SSL_CONNS] = INF_MAXPIPES,
105 [INF_MAXPIPES] = INF_PIPES_USED,
106 [INF_PIPES_USED] = INF_PIPES_FREE,
107 [INF_PIPES_FREE] = INF_CONN_RATE,
108 [INF_CONN_RATE] = INF_CONN_RATE_LIMIT,
109 [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE,
110 [INF_MAX_CONN_RATE] = INF_SESS_RATE,
111 [INF_SESS_RATE] = INF_SESS_RATE_LIMIT,
112 [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE,
113 [INF_MAX_SESS_RATE] = INF_SSL_RATE,
114 [INF_SSL_RATE] = INF_SSL_RATE_LIMIT,
115 [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE,
116 [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE,
117 [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE,
118 [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT,
119 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE,
120 [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE,
121 [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS,
122 [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES,
123 [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN,
124 [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT,
125 [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM,
126 [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE,
127 [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE,
128 [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS,
129 [INF_TASKS] = INF_RUN_QUEUE,
130 [INF_RUN_QUEUE] = INF_IDLE_PCT,
131 [INF_IDLE_PCT] = INF_STOPPING,
132 [INF_NODE] = 0,
133 [INF_DESCRIPTION] = 0,
134 [INF_STOPPING] = INF_JOBS,
135 [INF_JOBS] = INF_UNSTOPPABLE_JOBS,
136 [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS,
137 [INF_LISTENERS] = INF_ACTIVE_PEERS,
138 [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS,
139 [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS,
140 [INF_DROPPED_LOGS] = INF_BUSY_POLLING,
141 [INF_BUSY_POLLING] = 0,
142};
143
144/* Matrix used to dump frontend metrics. Each metric points to the next one to be
145 * processed or 0 to stop the dump. */
146const int promex_front_metrics[ST_F_TOTAL_FIELDS] = {
147 [ST_F_PXNAME] = ST_F_STATUS,
148 [ST_F_SVNAME] = 0,
149 [ST_F_QCUR] = 0,
150 [ST_F_QMAX] = 0,
151 [ST_F_SCUR] = ST_F_SMAX,
152 [ST_F_SMAX] = ST_F_SLIM,
153 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200154 [ST_F_STOT] = ST_F_RATE_LIM,
Christopher Fauletf959d082019-02-07 15:38:42 +0100155 [ST_F_BIN] = ST_F_BOUT,
156 [ST_F_BOUT] = ST_F_DREQ,
157 [ST_F_DREQ] = ST_F_DRESP,
158 [ST_F_DRESP] = ST_F_EREQ,
159 [ST_F_EREQ] = ST_F_DCON,
160 [ST_F_ECON] = 0,
161 [ST_F_ERESP] = 0,
162 [ST_F_WRETR] = 0,
163 [ST_F_WREDIS] = 0,
164 [ST_F_STATUS] = ST_F_SCUR,
165 [ST_F_WEIGHT] = 0,
166 [ST_F_ACT] = 0,
167 [ST_F_BCK] = 0,
168 [ST_F_CHKFAIL] = 0,
169 [ST_F_CHKDOWN] = 0,
170 [ST_F_LASTCHG] = 0,
171 [ST_F_DOWNTIME] = 0,
172 [ST_F_QLIMIT] = 0,
173 [ST_F_PID] = 0,
174 [ST_F_IID] = 0,
175 [ST_F_SID] = 0,
176 [ST_F_THROTTLE] = 0,
177 [ST_F_LBTOT] = 0,
178 [ST_F_TRACKED] = 0,
179 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200180 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100181 [ST_F_RATE_LIM] = ST_F_RATE_MAX,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200182 [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100183 [ST_F_CHECK_STATUS] = 0,
184 [ST_F_CHECK_CODE] = 0,
185 [ST_F_CHECK_DURATION] = 0,
186 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
187 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
188 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
189 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
190 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
191 [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED,
192 [ST_F_HANAFAIL] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200193 [ST_F_REQ_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100194 [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT,
195 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
196 [ST_F_CLI_ABRT] = 0,
197 [ST_F_SRV_ABRT] = 0,
198 [ST_F_COMP_IN] = ST_F_COMP_OUT,
199 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
200 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
201 [ST_F_COMP_RSP] = 0,
202 [ST_F_LASTSESS] = 0,
203 [ST_F_LAST_CHK] = 0,
204 [ST_F_LAST_AGT] = 0,
205 [ST_F_QTIME] = 0,
206 [ST_F_CTIME] = 0,
207 [ST_F_RTIME] = 0,
208 [ST_F_TTIME] = 0,
209 [ST_F_AGENT_STATUS] = 0,
210 [ST_F_AGENT_CODE] = 0,
211 [ST_F_AGENT_DURATION] = 0,
212 [ST_F_CHECK_DESC] = 0,
213 [ST_F_AGENT_DESC] = 0,
214 [ST_F_CHECK_RISE] = 0,
215 [ST_F_CHECK_FALL] = 0,
216 [ST_F_CHECK_HEALTH] = 0,
217 [ST_F_AGENT_RISE] = 0,
218 [ST_F_AGENT_FALL] = 0,
219 [ST_F_AGENT_HEALTH] = 0,
220 [ST_F_ADDR] = 0,
221 [ST_F_COOKIE] = 0,
222 [ST_F_MODE] = 0,
223 [ST_F_ALGO] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200224 [ST_F_CONN_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100225 [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT,
226 [ST_F_CONN_TOT] = ST_F_BIN,
227 [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS,
228 [ST_F_DCON] = ST_F_DSES,
229 [ST_F_DSES] = ST_F_WREW,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200230 [ST_F_WREW] = ST_F_REQ_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100231 [ST_F_CONNECT] = 0,
232 [ST_F_REUSE] = 0,
233 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
234 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100235 [ST_F_QT_MAX] = 0,
236 [ST_F_CT_MAX] = 0,
237 [ST_F_RT_MAX] = 0,
238 [ST_F_TT_MAX] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100239};
240
241/* Matrix used to dump backend metrics. Each metric points to the next one to be
242 * processed or 0 to stop the dump. */
243const int promex_back_metrics[ST_F_TOTAL_FIELDS] = {
244 [ST_F_PXNAME] = ST_F_STATUS,
245 [ST_F_SVNAME] = 0,
246 [ST_F_QCUR] = ST_F_QMAX,
247 [ST_F_QMAX] = ST_F_CONNECT,
248 [ST_F_SCUR] = ST_F_SMAX,
249 [ST_F_SMAX] = ST_F_SLIM,
250 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200251 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100252 [ST_F_BIN] = ST_F_BOUT,
253 [ST_F_BOUT] = ST_F_QTIME,
254 [ST_F_DREQ] = ST_F_DRESP,
255 [ST_F_DRESP] = ST_F_ECON,
256 [ST_F_EREQ] = 0,
257 [ST_F_ECON] = ST_F_ERESP,
258 [ST_F_ERESP] = ST_F_WRETR,
259 [ST_F_WRETR] = ST_F_WREDIS,
260 [ST_F_WREDIS] = ST_F_WREW,
261 [ST_F_STATUS] = ST_F_SCUR,
262 [ST_F_WEIGHT] = ST_F_ACT,
263 [ST_F_ACT] = ST_F_BCK,
264 [ST_F_BCK] = ST_F_CHKDOWN,
265 [ST_F_CHKFAIL] = 0,
266 [ST_F_CHKDOWN] = ST_F_LASTCHG,
267 [ST_F_LASTCHG] = ST_F_DOWNTIME,
268 [ST_F_DOWNTIME] = ST_F_LBTOT,
269 [ST_F_QLIMIT] = 0,
270 [ST_F_PID] = 0,
271 [ST_F_IID] = 0,
272 [ST_F_SID] = 0,
273 [ST_F_THROTTLE] = 0,
274 [ST_F_LBTOT] = ST_F_REQ_TOT,
275 [ST_F_TRACKED] = 9,
276 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200277 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100278 [ST_F_RATE_LIM] = 0,
279 [ST_F_RATE_MAX] = ST_F_LASTSESS,
280 [ST_F_CHECK_STATUS] = 0,
281 [ST_F_CHECK_CODE] = 0,
282 [ST_F_CHECK_DURATION] = 0,
283 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
284 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
285 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
286 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
287 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
288 [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS,
289 [ST_F_HANAFAIL] = 0,
290 [ST_F_REQ_RATE] = 0,
291 [ST_F_REQ_RATE_MAX] = 0,
292 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
293 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
294 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
295 [ST_F_COMP_IN] = ST_F_COMP_OUT,
296 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
297 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
298 [ST_F_COMP_RSP] = 0,
299 [ST_F_LASTSESS] = ST_F_QCUR,
300 [ST_F_LAST_CHK] = 0,
301 [ST_F_LAST_AGT] = 0,
302 [ST_F_QTIME] = ST_F_CTIME,
303 [ST_F_CTIME] = ST_F_RTIME,
304 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100305 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100306 [ST_F_AGENT_STATUS] = 0,
307 [ST_F_AGENT_CODE] = 0,
308 [ST_F_AGENT_DURATION] = 0,
309 [ST_F_CHECK_DESC] = 0,
310 [ST_F_AGENT_DESC] = 0,
311 [ST_F_CHECK_RISE] = 0,
312 [ST_F_CHECK_FALL] = 0,
313 [ST_F_CHECK_HEALTH] = 0,
314 [ST_F_AGENT_RISE] = 0,
315 [ST_F_AGENT_FALL] = 0,
316 [ST_F_AGENT_HEALTH] = 0,
317 [ST_F_ADDR] = 0,
318 [ST_F_COOKIE] = 0,
319 [ST_F_MODE] = 0,
320 [ST_F_ALGO] = 0,
321 [ST_F_CONN_RATE] = 0,
322 [ST_F_CONN_RATE_MAX] = 0,
323 [ST_F_CONN_TOT] = 0,
324 [ST_F_INTERCEPTED] = 0,
325 [ST_F_DCON] = 0,
326 [ST_F_DSES] = 0,
327 [ST_F_WREW] = ST_F_CLI_ABRT,
328 [ST_F_CONNECT] = ST_F_REUSE,
329 [ST_F_REUSE] = ST_F_BIN,
330 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
331 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100332 [ST_F_QT_MAX] = ST_F_CT_MAX,
333 [ST_F_CT_MAX] = ST_F_RT_MAX,
334 [ST_F_RT_MAX] = ST_F_TT_MAX,
335 [ST_F_TT_MAX] = ST_F_DREQ,
Christopher Fauletf959d082019-02-07 15:38:42 +0100336};
337
338/* Matrix used to dump server metrics. Each metric points to the next one to be
339 * processed or 0 to stop the dump. */
340const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = {
341 [ST_F_PXNAME] = ST_F_STATUS,
342 [ST_F_SVNAME] = 0,
343 [ST_F_QCUR] = ST_F_QMAX,
344 [ST_F_QMAX] = ST_F_QLIMIT,
345 [ST_F_SCUR] = ST_F_SMAX,
346 [ST_F_SMAX] = ST_F_SLIM,
347 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200348 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100349 [ST_F_BIN] = ST_F_BOUT,
350 [ST_F_BOUT] = ST_F_QTIME,
351 [ST_F_DREQ] = 0,
352 [ST_F_DRESP] = ST_F_ECON,
353 [ST_F_EREQ] = 0,
354 [ST_F_ECON] = ST_F_ERESP,
355 [ST_F_ERESP] = ST_F_WRETR,
356 [ST_F_WRETR] = ST_F_WREDIS,
357 [ST_F_WREDIS] = ST_F_WREW,
358 [ST_F_STATUS] = ST_F_SCUR,
359 [ST_F_WEIGHT] = ST_F_CHKFAIL,
360 [ST_F_ACT] = 0,
361 [ST_F_BCK] = 0,
362 [ST_F_CHKFAIL] = ST_F_CHKDOWN,
363 [ST_F_CHKDOWN] = ST_F_DOWNTIME,
364 [ST_F_LASTCHG] = ST_F_THROTTLE,
365 [ST_F_DOWNTIME] = ST_F_LASTCHG,
366 [ST_F_QLIMIT] = ST_F_BIN,
367 [ST_F_PID] = 0,
368 [ST_F_IID] = 0,
369 [ST_F_SID] = 0,
370 [ST_F_THROTTLE] = ST_F_LBTOT,
371 [ST_F_LBTOT] = ST_F_HRSP_1XX,
372 [ST_F_TRACKED] = 0,
373 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200374 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100375 [ST_F_RATE_LIM] = 0,
376 [ST_F_RATE_MAX] = ST_F_LASTSESS,
377 [ST_F_CHECK_STATUS] = 0,
378 [ST_F_CHECK_CODE] = 0,
379 [ST_F_CHECK_DURATION] = 0,
380 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
381 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
382 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
383 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
384 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
385 [ST_F_HRSP_OTHER] = 0,
386 [ST_F_HANAFAIL] = 0,
387 [ST_F_REQ_RATE] = 0,
388 [ST_F_REQ_RATE_MAX] = 0,
389 [ST_F_REQ_TOT] = 0,
390 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
391 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
392 [ST_F_COMP_IN] = 0,
393 [ST_F_COMP_OUT] = 0,
394 [ST_F_COMP_BYP] = 0,
395 [ST_F_COMP_RSP] = 0,
396 [ST_F_LASTSESS] = ST_F_QCUR,
397 [ST_F_LAST_CHK] = 0,
398 [ST_F_LAST_AGT] = 0,
399 [ST_F_QTIME] = ST_F_CTIME,
400 [ST_F_CTIME] = ST_F_RTIME,
401 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100402 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100403 [ST_F_AGENT_STATUS] = 0,
404 [ST_F_AGENT_CODE] = 0,
405 [ST_F_AGENT_DURATION] = 0,
406 [ST_F_CHECK_DESC] = 0,
407 [ST_F_AGENT_DESC] = 0,
408 [ST_F_CHECK_RISE] = 0,
409 [ST_F_CHECK_FALL] = 0,
410 [ST_F_CHECK_HEALTH] = 0,
411 [ST_F_AGENT_RISE] = 0,
412 [ST_F_AGENT_FALL] = 0,
413 [ST_F_AGENT_HEALTH] = 0,
414 [ST_F_ADDR] = 0,
415 [ST_F_COOKIE] = 0,
416 [ST_F_MODE] = 0,
417 [ST_F_ALGO] = 0,
418 [ST_F_CONN_RATE] = 0,
419 [ST_F_CONN_RATE_MAX] = 0,
420 [ST_F_CONN_TOT] = 0,
421 [ST_F_INTERCEPTED] = 0,
422 [ST_F_DCON] = 0,
423 [ST_F_DSES] = 0,
424 [ST_F_WREW] = ST_F_CLI_ABRT,
425 [ST_F_CONNECT] = ST_F_REUSE,
426 [ST_F_REUSE] = ST_F_DRESP,
427 [ST_F_CACHE_LOOKUPS] = 0,
428 [ST_F_CACHE_HITS] = 0,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100429 [ST_F_QT_MAX] = ST_F_CT_MAX,
430 [ST_F_CT_MAX] = ST_F_RT_MAX,
431 [ST_F_RT_MAX] = ST_F_TT_MAX,
432 [ST_F_TT_MAX] = ST_F_CONNECT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100433};
434
435/* Name of all info fields */
436const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
437 [INF_NAME] = IST("name"),
438 [INF_VERSION] = IST("version"),
439 [INF_RELEASE_DATE] = IST("release_date"),
440 [INF_NBTHREAD] = IST("nbthread"),
441 [INF_NBPROC] = IST("nbproc"),
442 [INF_PROCESS_NUM] = IST("relative_process_id"),
443 [INF_PID] = IST("pid"),
444 [INF_UPTIME] = IST("uptime"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200445 [INF_UPTIME_SEC] = IST("start_time_seconds"),
446 [INF_MEMMAX_MB] = IST("max_memory_bytes"),
447 [INF_POOL_ALLOC_MB] = IST("pool_allocated_bytes"),
448 [INF_POOL_USED_MB] = IST("pool_used_bytes"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100449 [INF_POOL_FAILED] = IST("pool_failures_total"),
450 [INF_ULIMIT_N] = IST("max_fds"),
451 [INF_MAXSOCK] = IST("max_sockets"),
452 [INF_MAXCONN] = IST("max_connections"),
453 [INF_HARD_MAXCONN] = IST("hard_max_connections"),
454 [INF_CURR_CONN] = IST("current_connections"),
455 [INF_CUM_CONN] = IST("connections_total"),
456 [INF_CUM_REQ] = IST("requests_total"),
457 [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"),
458 [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"),
459 [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"),
460 [INF_MAXPIPES] = IST("max_pipes"),
461 [INF_PIPES_USED] = IST("pipes_used_total"),
462 [INF_PIPES_FREE] = IST("pipes_free_total"),
463 [INF_CONN_RATE] = IST("current_connection_rate"),
464 [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"),
465 [INF_MAX_CONN_RATE] = IST("max_connection_rate"),
466 [INF_SESS_RATE] = IST("current_session_rate"),
467 [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"),
468 [INF_MAX_SESS_RATE] = IST("max_session_rate"),
469 [INF_SSL_RATE] = IST("current_ssl_rate"),
470 [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"),
471 [INF_MAX_SSL_RATE] = IST("max_ssl_rate"),
472 [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"),
473 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"),
474 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontent_ssl_reuse"),
475 [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"),
476 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200477 [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"),
478 [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100479 [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"),
480 [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"),
481 [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"),
482 [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"),
483 [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"),
484 [INF_TASKS] = IST("current_tasks"),
485 [INF_RUN_QUEUE] = IST("current_run_queue"),
486 [INF_IDLE_PCT] = IST("idle_time_percent"),
487 [INF_NODE] = IST("node"),
488 [INF_DESCRIPTION] = IST("description"),
489 [INF_STOPPING] = IST("stopping"),
490 [INF_JOBS] = IST("jobs"),
491 [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"),
492 [INF_LISTENERS] = IST("listeners"),
493 [INF_ACTIVE_PEERS] = IST("active_peers"),
494 [INF_CONNECTED_PEERS] = IST("connected_peers"),
495 [INF_DROPPED_LOGS] = IST("dropped_logs_total"),
496 [INF_BUSY_POLLING] = IST("busy_polling_enabled"),
497};
498
499/* Name of all stats fields */
500const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = {
501 [ST_F_PXNAME] = IST("proxy_name"),
502 [ST_F_SVNAME] = IST("service_name"),
503 [ST_F_QCUR] = IST("current_queue"),
504 [ST_F_QMAX] = IST("max_queue"),
505 [ST_F_SCUR] = IST("current_sessions"),
506 [ST_F_SMAX] = IST("max_sessions"),
507 [ST_F_SLIM] = IST("limit_sessions"),
508 [ST_F_STOT] = IST("sessions_total"),
509 [ST_F_BIN] = IST("bytes_in_total"),
510 [ST_F_BOUT] = IST("bytes_out_total"),
511 [ST_F_DREQ] = IST("requests_denied_total"),
512 [ST_F_DRESP] = IST("responses_denied_total"),
513 [ST_F_EREQ] = IST("request_errors_total"),
514 [ST_F_ECON] = IST("connection_errors_total"),
515 [ST_F_ERESP] = IST("response_errors_total"),
516 [ST_F_WRETR] = IST("retry_warnings_total"),
517 [ST_F_WREDIS] = IST("redispatch_warnings_total"),
518 [ST_F_STATUS] = IST("status"),
519 [ST_F_WEIGHT] = IST("weight"),
520 [ST_F_ACT] = IST("active_servers"),
521 [ST_F_BCK] = IST("backup_servers"),
522 [ST_F_CHKFAIL] = IST("check_failures_total"),
523 [ST_F_CHKDOWN] = IST("check_up_down_total"),
524 [ST_F_LASTCHG] = IST("check_last_change_seconds"),
525 [ST_F_DOWNTIME] = IST("downtime_seconds_total"),
526 [ST_F_QLIMIT] = IST("queue_limit"),
527 [ST_F_PID] = IST("pid"),
528 [ST_F_IID] = IST("proxy_id"),
529 [ST_F_SID] = IST("server_id"),
530 [ST_F_THROTTLE] = IST("current_throttle"),
531 [ST_F_LBTOT] = IST("loadbalanced_total"),
532 [ST_F_TRACKED] = IST("tracked"),
533 [ST_F_TYPE] = IST("type"),
534 [ST_F_RATE] = IST("current_session_rate"),
535 [ST_F_RATE_LIM] = IST("limit_session_rate"),
536 [ST_F_RATE_MAX] = IST("max_session_rate"),
537 [ST_F_CHECK_STATUS] = IST("check_status"),
538 [ST_F_CHECK_CODE] = IST("check_code"),
539 [ST_F_CHECK_DURATION] = IST("check_duration_milliseconds"),
540 [ST_F_HRSP_1XX] = IST("http_responses_total"),
541 [ST_F_HRSP_2XX] = IST("http_responses_total"),
542 [ST_F_HRSP_3XX] = IST("http_responses_total"),
543 [ST_F_HRSP_4XX] = IST("http_responses_total"),
544 [ST_F_HRSP_5XX] = IST("http_responses_total"),
545 [ST_F_HRSP_OTHER] = IST("http_responses_total"),
546 [ST_F_HANAFAIL] = IST("check_analyses_failures_total"),
547 [ST_F_REQ_RATE] = IST("http_requests_rate_current"),
548 [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"),
549 [ST_F_REQ_TOT] = IST("http_requests_total"),
550 [ST_F_CLI_ABRT] = IST("client_aborts_total"),
551 [ST_F_SRV_ABRT] = IST("server_aborts_total"),
552 [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"),
553 [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"),
554 [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"),
555 [ST_F_COMP_RSP] = IST("http_comp_responses_total"),
556 [ST_F_LASTSESS] = IST("last_session_seconds"),
557 [ST_F_LAST_CHK] = IST("check_last_content"),
558 [ST_F_LAST_AGT] = IST("agentcheck_last_content"),
559 [ST_F_QTIME] = IST("http_queue_time_average_seconds"),
560 [ST_F_CTIME] = IST("http_connect_time_average_seconds"),
561 [ST_F_RTIME] = IST("http_response_time_average_seconds"),
562 [ST_F_TTIME] = IST("http_total_time_average_seconds"),
563 [ST_F_AGENT_STATUS] = IST("agentcheck_status"),
564 [ST_F_AGENT_CODE] = IST("agentcheck_code"),
565 [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"),
566 [ST_F_CHECK_DESC] = IST("check_description"),
567 [ST_F_AGENT_DESC] = IST("agentcheck_description"),
568 [ST_F_CHECK_RISE] = IST("check_rise"),
569 [ST_F_CHECK_FALL] = IST("check_fall"),
570 [ST_F_CHECK_HEALTH] = IST("check_value"),
571 [ST_F_AGENT_RISE] = IST("agentcheck_rise"),
572 [ST_F_AGENT_FALL] = IST("agentcheck_fall"),
573 [ST_F_AGENT_HEALTH] = IST("agentcheck_value"),
574 [ST_F_ADDR] = IST("address"),
575 [ST_F_COOKIE] = IST("cookie"),
576 [ST_F_MODE] = IST("mode"),
577 [ST_F_ALGO] = IST("loadbalance_algorithm"),
578 [ST_F_CONN_RATE] = IST("connections_rate_current"),
579 [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"),
580 [ST_F_CONN_TOT] = IST("connections_total"),
581 [ST_F_INTERCEPTED] = IST("intercepted_requests_total"),
582 [ST_F_DCON] = IST("denied_connections_total"),
583 [ST_F_DSES] = IST("denied_sessions_total"),
584 [ST_F_WREW] = IST("failed_header_rewriting_total"),
585 [ST_F_CONNECT] = IST("connection_attempts_total"),
586 [ST_F_REUSE] = IST("connection_reuses_total"),
587 [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"),
588 [ST_F_CACHE_HITS] = IST("http_cache_hits_total"),
Christopher Faulet5df597a2019-11-08 15:05:31 +0100589 [ST_F_QT_MAX] = IST("max_queue_time_seconds"),
590 [ST_F_CT_MAX] = IST("max_connect_time_seconds"),
591 [ST_F_RT_MAX] = IST("max_response_time_seconds"),
592 [ST_F_TT_MAX] = IST("max_total_time_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100593};
594
595/* Description of all info fields */
596const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
597 [INF_NAME] = IST("Product name."),
598 [INF_VERSION] = IST("HAProxy version."),
599 [INF_RELEASE_DATE] = IST("HAProxy realease date."),
600 [INF_NBTHREAD] = IST("Configured number of threads."),
601 [INF_NBPROC] = IST("Configured number of processes."),
602 [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
603 [INF_PID] = IST("HAProxy PID."),
604 [INF_UPTIME] = IST("Uptime in a human readable format."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200605 [INF_UPTIME_SEC] = IST("Start time in seconds."),
606 [INF_MEMMAX_MB] = IST("Per-process memory limit (in bytes); 0=unset."),
607 [INF_POOL_ALLOC_MB] = IST("Total amount of memory allocated in pools (in bytes)."),
608 [INF_POOL_USED_MB] = IST("Total amount of memory used in pools (in bytes)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100609 [INF_POOL_FAILED] = IST("Total number of failed pool allocations."),
610 [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."),
611 [INF_MAXSOCK] = IST("Maximum numer of open sockets."),
612 [INF_MAXCONN] = IST("Maximum number of concurrent connections."),
613 [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."),
614 [INF_CURR_CONN] = IST("Number of active sessions."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200615 [INF_CUM_CONN] = IST("Total number of created sessions."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100616 [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."),
617 [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."),
618 [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."),
619 [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."),
620 [INF_MAXPIPES] = IST("Configured maximum number of pipes."),
621 [INF_PIPES_USED] = IST("Number of pipes in used."),
622 [INF_PIPES_FREE] = IST("Number of pipes unused."),
623 [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."),
624 [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."),
625 [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."),
626 [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."),
627 [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."),
628 [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."),
629 [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."),
630 [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."),
631 [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."),
632 [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."),
633 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."),
634 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."),
635 [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."),
636 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."),
637 [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."),
638 [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."),
639 [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."),
640 [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."),
641 [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."),
642 [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."),
643 [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."),
644 [INF_TASKS] = IST("Current number of tasks."),
645 [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."),
646 [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."),
647 [INF_NODE] = IST("Node name."),
648 [INF_DESCRIPTION] = IST("Node description."),
649 [INF_STOPPING] = IST("Non zero means stopping in progress."),
650 [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."),
651 [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."),
652 [INF_LISTENERS] = IST("Current number of active listeners."),
653 [INF_ACTIVE_PEERS] = IST("Current number of active peers."),
654 [INF_CONNECTED_PEERS] = IST("Current number of connected peers."),
655 [INF_DROPPED_LOGS] = IST("Total number of dropped logs."),
656 [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."),
657};
658
659/* Description of all stats fields */
660const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
661 [ST_F_PXNAME] = IST("The proxy name."),
662 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
663 [ST_F_QCUR] = IST("Current number of queued requests."),
664 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
665 [ST_F_SCUR] = IST("Current number of active sessions."),
666 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
667 [ST_F_SLIM] = IST("Configured session limit."),
668 [ST_F_STOT] = IST("Total number of sessions."),
669 [ST_F_BIN] = IST("Current total of incoming bytes."),
670 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
671 [ST_F_DREQ] = IST("Total number of denied requests."),
672 [ST_F_DRESP] = IST("Total number of denied responses."),
673 [ST_F_EREQ] = IST("Total number of request errors."),
674 [ST_F_ECON] = IST("Total number of connection errors."),
675 [ST_F_ERESP] = IST("Total number of response errors."),
676 [ST_F_WRETR] = IST("Total number of retry warnings."),
677 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Christopher Faulet8e40fa22019-09-06 16:10:19 +0200678 [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 +0100679 [ST_F_WEIGHT] = IST("Service weight."),
680 [ST_F_ACT] = IST("Current number of active servers."),
681 [ST_F_BCK] = IST("Current number of backup servers."),
682 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
683 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
684 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
685 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
686 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
687 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
688 [ST_F_IID] = IST("Unique proxy id."),
689 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
690 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
691 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
692 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
693 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
694 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
695 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
696 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
697 [ST_F_CHECK_STATUS] = IST("Status of last health check (If a check is running, the status will be reported, prefixed with '* ')."),
698 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
699 [ST_F_CHECK_DURATION] = IST("Time in ms took to finish last health check."),
700 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
701 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
702 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
703 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
704 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
705 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
706 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
707 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
708 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
709 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
710 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
711 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
712 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
713 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
714 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
715 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
716 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
717 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
718 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
719 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
720 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
721 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
722 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
723 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
724 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
725 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
726 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
727 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
728 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
729 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
730 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
731 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
732 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
733 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
734 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
735 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
736 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
737 [ST_F_ALGO] = IST("Load balancing algorithm."),
738 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
739 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
740 [ST_F_CONN_TOT] = IST("Total number of connections."),
741 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
742 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
743 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
744 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
745 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
746 [ST_F_REUSE] = IST("Total number of connection reuses."),
747 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
748 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Faulet5df597a2019-11-08 15:05:31 +0100749 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
750 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
751 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
752 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100753};
754
755/* Specific labels for all info fields. Empty by default. */
756const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
757 [INF_NAME] = IST(""),
758 [INF_VERSION] = IST(""),
759 [INF_RELEASE_DATE] = IST(""),
760 [INF_NBTHREAD] = IST(""),
761 [INF_NBPROC] = IST(""),
762 [INF_PROCESS_NUM] = IST(""),
763 [INF_PID] = IST(""),
764 [INF_UPTIME] = IST(""),
765 [INF_UPTIME_SEC] = IST(""),
766 [INF_MEMMAX_MB] = IST(""),
767 [INF_POOL_ALLOC_MB] = IST(""),
768 [INF_POOL_USED_MB] = IST(""),
769 [INF_POOL_FAILED] = IST(""),
770 [INF_ULIMIT_N] = IST(""),
771 [INF_MAXSOCK] = IST(""),
772 [INF_MAXCONN] = IST(""),
773 [INF_HARD_MAXCONN] = IST(""),
774 [INF_CURR_CONN] = IST(""),
775 [INF_CUM_CONN] = IST(""),
776 [INF_CUM_REQ] = IST(""),
777 [INF_MAX_SSL_CONNS] = IST(""),
778 [INF_CURR_SSL_CONNS] = IST(""),
779 [INF_CUM_SSL_CONNS] = IST(""),
780 [INF_MAXPIPES] = IST(""),
781 [INF_PIPES_USED] = IST(""),
782 [INF_PIPES_FREE] = IST(""),
783 [INF_CONN_RATE] = IST(""),
784 [INF_CONN_RATE_LIMIT] = IST(""),
785 [INF_MAX_CONN_RATE] = IST(""),
786 [INF_SESS_RATE] = IST(""),
787 [INF_SESS_RATE_LIMIT] = IST(""),
788 [INF_MAX_SESS_RATE] = IST(""),
789 [INF_SSL_RATE] = IST(""),
790 [INF_SSL_RATE_LIMIT] = IST(""),
791 [INF_MAX_SSL_RATE] = IST(""),
792 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
793 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
794 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
795 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
796 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
797 [INF_SSL_CACHE_LOOKUPS] = IST(""),
798 [INF_SSL_CACHE_MISSES] = IST(""),
799 [INF_COMPRESS_BPS_IN] = IST(""),
800 [INF_COMPRESS_BPS_OUT] = IST(""),
801 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
802 [INF_ZLIB_MEM_USAGE] = IST(""),
803 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
804 [INF_TASKS] = IST(""),
805 [INF_RUN_QUEUE] = IST(""),
806 [INF_IDLE_PCT] = IST(""),
807 [INF_NODE] = IST(""),
808 [INF_DESCRIPTION] = IST(""),
809 [INF_STOPPING] = IST(""),
810 [INF_JOBS] = IST(""),
811 [INF_UNSTOPPABLE_JOBS] = IST(""),
812 [INF_LISTENERS] = IST(""),
813 [INF_ACTIVE_PEERS] = IST(""),
814 [INF_CONNECTED_PEERS] = IST(""),
815 [INF_DROPPED_LOGS] = IST(""),
816 [INF_BUSY_POLLING] = IST(""),
817};
818
819/* Specific labels for all stats fields. Empty by default. */
820const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
821 [ST_F_PXNAME] = IST(""),
822 [ST_F_SVNAME] = IST(""),
823 [ST_F_QCUR] = IST(""),
824 [ST_F_QMAX] = IST(""),
825 [ST_F_SCUR] = IST(""),
826 [ST_F_SMAX] = IST(""),
827 [ST_F_SLIM] = IST(""),
828 [ST_F_STOT] = IST(""),
829 [ST_F_BIN] = IST(""),
830 [ST_F_BOUT] = IST(""),
831 [ST_F_DREQ] = IST(""),
832 [ST_F_DRESP] = IST(""),
833 [ST_F_EREQ] = IST(""),
834 [ST_F_ECON] = IST(""),
835 [ST_F_ERESP] = IST(""),
836 [ST_F_WRETR] = IST(""),
837 [ST_F_WREDIS] = IST(""),
838 [ST_F_STATUS] = IST(""),
839 [ST_F_WEIGHT] = IST(""),
840 [ST_F_ACT] = IST(""),
841 [ST_F_BCK] = IST(""),
842 [ST_F_CHKFAIL] = IST(""),
843 [ST_F_CHKDOWN] = IST(""),
844 [ST_F_LASTCHG] = IST(""),
845 [ST_F_DOWNTIME] = IST(""),
846 [ST_F_QLIMIT] = IST(""),
847 [ST_F_PID] = IST(""),
848 [ST_F_IID] = IST(""),
849 [ST_F_SID] = IST(""),
850 [ST_F_THROTTLE] = IST(""),
851 [ST_F_LBTOT] = IST(""),
852 [ST_F_TRACKED] = IST(""),
853 [ST_F_TYPE] = IST(""),
854 [ST_F_RATE] = IST(""),
855 [ST_F_RATE_LIM] = IST(""),
856 [ST_F_RATE_MAX] = IST(""),
857 [ST_F_CHECK_STATUS] = IST(""),
858 [ST_F_CHECK_CODE] = IST(""),
859 [ST_F_CHECK_DURATION] = IST(""),
860 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
861 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
862 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
863 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
864 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
865 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
866 [ST_F_HANAFAIL] = IST(""),
867 [ST_F_REQ_RATE] = IST(""),
868 [ST_F_REQ_RATE_MAX] = IST(""),
869 [ST_F_REQ_TOT] = IST(""),
870 [ST_F_CLI_ABRT] = IST(""),
871 [ST_F_SRV_ABRT] = IST(""),
872 [ST_F_COMP_IN] = IST(""),
873 [ST_F_COMP_OUT] = IST(""),
874 [ST_F_COMP_BYP] = IST(""),
875 [ST_F_COMP_RSP] = IST(""),
876 [ST_F_LASTSESS] = IST(""),
877 [ST_F_LAST_CHK] = IST(""),
878 [ST_F_LAST_AGT] = IST(""),
879 [ST_F_QTIME] = IST(""),
880 [ST_F_CTIME] = IST(""),
881 [ST_F_RTIME] = IST(""),
882 [ST_F_TTIME] = IST(""),
883 [ST_F_AGENT_STATUS] = IST(""),
884 [ST_F_AGENT_CODE] = IST(""),
885 [ST_F_AGENT_DURATION] = IST(""),
886 [ST_F_CHECK_DESC] = IST(""),
887 [ST_F_AGENT_DESC] = IST(""),
888 [ST_F_CHECK_RISE] = IST(""),
889 [ST_F_CHECK_FALL] = IST(""),
890 [ST_F_CHECK_HEALTH] = IST(""),
891 [ST_F_AGENT_RISE] = IST(""),
892 [ST_F_AGENT_FALL] = IST(""),
893 [ST_F_AGENT_HEALTH] = IST(""),
894 [ST_F_ADDR] = IST(""),
895 [ST_F_COOKIE] = IST(""),
896 [ST_F_MODE] = IST(""),
897 [ST_F_ALGO] = IST(""),
898 [ST_F_CONN_RATE] = IST(""),
899 [ST_F_CONN_RATE_MAX] = IST(""),
900 [ST_F_CONN_TOT] = IST(""),
901 [ST_F_INTERCEPTED] = IST(""),
902 [ST_F_DCON] = IST(""),
903 [ST_F_DSES] = IST(""),
904 [ST_F_WREW] = IST(""),
905 [ST_F_CONNECT] = IST(""),
906 [ST_F_REUSE] = IST(""),
907 [ST_F_CACHE_LOOKUPS] = IST(""),
908 [ST_F_CACHE_HITS] = IST(""),
909};
910
911/* Type for all info fields. "untyped" is used for unsupported field. */
912const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
913 [INF_NAME] = IST("untyped"),
914 [INF_VERSION] = IST("untyped"),
915 [INF_RELEASE_DATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200916 [INF_NBTHREAD] = IST("gauge"),
917 [INF_NBPROC] = IST("gauge"),
918 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100919 [INF_PID] = IST("untyped"),
920 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200921 [INF_UPTIME_SEC] = IST("gauge"),
922 [INF_MEMMAX_MB] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100923 [INF_POOL_ALLOC_MB] = IST("gauge"),
924 [INF_POOL_USED_MB] = IST("gauge"),
925 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200926 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100927 [INF_MAXSOCK] = IST("gauge"),
928 [INF_MAXCONN] = IST("gauge"),
929 [INF_HARD_MAXCONN] = IST("gauge"),
930 [INF_CURR_CONN] = IST("gauge"),
931 [INF_CUM_CONN] = IST("counter"),
932 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200933 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100934 [INF_CURR_SSL_CONNS] = IST("gauge"),
935 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200936 [INF_MAXPIPES] = IST("gauge"),
937 [INF_PIPES_USED] = IST("counter"),
938 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100939 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200940 [INF_CONN_RATE_LIMIT] = IST("gauge"),
941 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100942 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200943 [INF_SESS_RATE_LIMIT] = IST("gauge"),
944 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100945 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200946 [INF_SSL_RATE_LIMIT] = IST("gauge"),
947 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100948 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200949 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100950 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
951 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200952 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100953 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
954 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200955 [INF_COMPRESS_BPS_IN] = IST("counter"),
956 [INF_COMPRESS_BPS_OUT] = IST("counter"),
957 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100958 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200959 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100960 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +0200961 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100962 [INF_IDLE_PCT] = IST("gauge"),
963 [INF_NODE] = IST("untyped"),
964 [INF_DESCRIPTION] = IST("untyped"),
965 [INF_STOPPING] = IST("gauge"),
966 [INF_JOBS] = IST("gauge"),
967 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
968 [INF_LISTENERS] = IST("gauge"),
969 [INF_ACTIVE_PEERS] = IST("gauge"),
970 [INF_CONNECTED_PEERS] = IST("gauge"),
971 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200972 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100973};
974
975/* Type for all stats fields. "untyped" is used for unsupported field. */
976const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
977 [ST_F_PXNAME] = IST("untyped"),
978 [ST_F_SVNAME] = IST("untyped"),
979 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200980 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100981 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200982 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100983 [ST_F_SLIM] = IST("gauge"),
984 [ST_F_STOT] = IST("counter"),
985 [ST_F_BIN] = IST("counter"),
986 [ST_F_BOUT] = IST("counter"),
987 [ST_F_DREQ] = IST("counter"),
988 [ST_F_DRESP] = IST("counter"),
989 [ST_F_EREQ] = IST("counter"),
990 [ST_F_ECON] = IST("counter"),
991 [ST_F_ERESP] = IST("counter"),
992 [ST_F_WRETR] = IST("counter"),
993 [ST_F_WREDIS] = IST("counter"),
994 [ST_F_STATUS] = IST("gauge"),
995 [ST_F_WEIGHT] = IST("gauge"),
996 [ST_F_ACT] = IST("gauge"),
997 [ST_F_BCK] = IST("gauge"),
998 [ST_F_CHKFAIL] = IST("counter"),
999 [ST_F_CHKDOWN] = IST("counter"),
1000 [ST_F_LASTCHG] = IST("gauge"),
1001 [ST_F_DOWNTIME] = IST("counter"),
1002 [ST_F_QLIMIT] = IST("gauge"),
1003 [ST_F_PID] = IST("untyped"),
1004 [ST_F_IID] = IST("untyped"),
1005 [ST_F_SID] = IST("untyped"),
1006 [ST_F_THROTTLE] = IST("gauge"),
1007 [ST_F_LBTOT] = IST("counter"),
1008 [ST_F_TRACKED] = IST("untyped"),
1009 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001010 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001011 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001012 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001013 [ST_F_CHECK_STATUS] = IST("untyped"),
1014 [ST_F_CHECK_CODE] = IST("untyped"),
1015 [ST_F_CHECK_DURATION] = IST("gauge"),
1016 [ST_F_HRSP_1XX] = IST("counter"),
1017 [ST_F_HRSP_2XX] = IST("counter"),
1018 [ST_F_HRSP_3XX] = IST("counter"),
1019 [ST_F_HRSP_4XX] = IST("counter"),
1020 [ST_F_HRSP_5XX] = IST("counter"),
1021 [ST_F_HRSP_OTHER] = IST("counter"),
1022 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001023 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001024 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001025 [ST_F_REQ_TOT] = IST("counter"),
1026 [ST_F_CLI_ABRT] = IST("counter"),
1027 [ST_F_SRV_ABRT] = IST("counter"),
1028 [ST_F_COMP_IN] = IST("counter"),
1029 [ST_F_COMP_OUT] = IST("counter"),
1030 [ST_F_COMP_BYP] = IST("counter"),
1031 [ST_F_COMP_RSP] = IST("counter"),
1032 [ST_F_LASTSESS] = IST("gauge"),
1033 [ST_F_LAST_CHK] = IST("untyped"),
1034 [ST_F_LAST_AGT] = IST("untyped"),
1035 [ST_F_QTIME] = IST("gauge"),
1036 [ST_F_CTIME] = IST("gauge"),
1037 [ST_F_RTIME] = IST("gauge"),
1038 [ST_F_TTIME] = IST("gauge"),
1039 [ST_F_AGENT_STATUS] = IST("untyped"),
1040 [ST_F_AGENT_CODE] = IST("untyped"),
1041 [ST_F_AGENT_DURATION] = IST("gauge"),
1042 [ST_F_CHECK_DESC] = IST("untyped"),
1043 [ST_F_AGENT_DESC] = IST("untyped"),
1044 [ST_F_CHECK_RISE] = IST("gauge"),
1045 [ST_F_CHECK_FALL] = IST("gauge"),
1046 [ST_F_CHECK_HEALTH] = IST("gauge"),
1047 [ST_F_AGENT_RISE] = IST("gauge"),
1048 [ST_F_AGENT_FALL] = IST("gauge"),
1049 [ST_F_AGENT_HEALTH] = IST("gauge"),
1050 [ST_F_ADDR] = IST("untyped"),
1051 [ST_F_COOKIE] = IST("untyped"),
1052 [ST_F_MODE] = IST("untyped"),
1053 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001054 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001055 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001056 [ST_F_CONN_TOT] = IST("counter"),
1057 [ST_F_INTERCEPTED] = IST("counter"),
1058 [ST_F_DCON] = IST("counter"),
1059 [ST_F_DSES] = IST("counter"),
1060 [ST_F_WREW] = IST("counter"),
1061 [ST_F_CONNECT] = IST("counter"),
1062 [ST_F_REUSE] = IST("counter"),
1063 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1064 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Faulet5df597a2019-11-08 15:05:31 +01001065 [ST_F_QT_MAX] = IST("gauge"),
1066 [ST_F_CT_MAX] = IST("gauge"),
1067 [ST_F_RT_MAX] = IST("gauge"),
1068 [ST_F_TT_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001069};
1070
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001071/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001072static int promex_srv_status(struct server *sv)
1073{
Christopher Fauletf959d082019-02-07 15:38:42 +01001074 int state = 0;
1075
Christopher Fauletf959d082019-02-07 15:38:42 +01001076 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1077 state = 1;
1078 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001079 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001080 }
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001081 else if (sv->cur_state == SRV_ST_STOPPING)
1082 state = 4;
1083
1084 if (sv->cur_admin & SRV_ADMF_MAINT)
1085 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001086
1087 return state;
1088}
1089
1090/* Convert a field to its string representation and write it in <out>, followed
1091 * by a newline, if there is enough space. non-numeric value are converted in
1092 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1093 * to process this kind of value). It returns 1 on success. Otherwise, it
1094 * returns 0. The buffer's length must not exceed <max> value.
1095 */
1096static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1097{
1098 int ret = 0;
1099
1100 switch (field_format(f, 0)) {
1101 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1102 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1103 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1104 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1105 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Faulete86bf652019-09-24 16:35:19 +02001106 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001107 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1108 default: ret = chunk_strcat(out, "Nan\n"); break;
1109 }
1110 if (!ret || out->data > max)
1111 return 0;
1112 return 1;
1113}
1114
1115/* Concatenate the <prefix> with the field name using the array
1116 * <promex_st_metric_names> and store it in <name>. The field type is in
1117 * <appctx->st2>. This function never fails but relies on
1118 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enougth to be copied in
1119 * <name>
1120 */
1121static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1122{
1123 const struct ist *names;
1124
1125 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1126 ? promex_inf_metric_names
1127 : promex_st_metric_names);
1128
1129 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1130 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1131}
1132
1133/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1134 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1135 */
1136static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1137 const struct ist name, struct ist *out, size_t max)
1138{
1139 const struct ist *desc, *types;
1140
1141 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1142 desc = promex_inf_metric_desc;
1143 types = promex_inf_metric_types;
1144 }
1145 else {
1146 desc = promex_st_metric_desc;
1147 types = promex_st_metric_types;
1148 }
1149
Anthonin Bonnefoydd4e4ef2019-08-07 17:45:25 +02001150 if (istcat(out, ist("# HELP "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001151 istcat(out, name, max) == -1 ||
1152 istcat(out, ist(" "), max) == -1 ||
1153 istcat(out, desc[appctx->st2], max) == -1 ||
Anthonin Bonnefoydd4e4ef2019-08-07 17:45:25 +02001154 istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001155 istcat(out, name, max) == -1 ||
1156 istcat(out, ist(" "), max) == -1 ||
1157 istcat(out, types[appctx->st2], max) == -1 ||
1158 istcat(out, ist("\n"), max) == -1)
1159 goto full;
1160
1161 return 1;
1162
1163 full:
1164 return 0;
1165}
1166
1167/* Dump the line for <metric>. It starts by the metric name followed by its
1168 * labels (proxy name, server name...) between braces and finally its value. If
1169 * not already done, the header lines are dumped first. It returns 1 on
1170 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1171 */
1172static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1173 const struct ist prefix, struct field *metric,
1174 struct ist *out, size_t max)
1175{
1176 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1177 size_t len = out->len;
1178
1179 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1180 return 0;
1181
1182 promex_metric_name(appctx, &name, prefix);
1183 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1184 !promex_dump_metric_header(appctx, htx, name, out, max))
1185 goto full;
1186
1187 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1188 const struct ist label = promex_inf_metric_labels[appctx->st2];
1189
1190 if (istcat(out, name, max) == -1 ||
1191 (label.len && istcat(out, ist("{"), max) == -1) ||
1192 (label.len && istcat(out, label, max) == -1) ||
1193 (label.len && istcat(out, ist("}"), max) == -1) ||
1194 istcat(out, ist(" "), max) == -1)
1195 goto full;
1196 }
1197 else {
1198 struct proxy *px = appctx->ctx.stats.px;
1199 struct server *srv = appctx->ctx.stats.sv;
1200 const struct ist label = promex_st_metric_labels[appctx->st2];
1201
1202 if (istcat(out, name, max) == -1 ||
1203 istcat(out, ist("{proxy=\""), max) == -1 ||
1204 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1205 istcat(out, ist("\""), max) == -1 ||
1206 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1207 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1208 (srv && istcat(out, ist("\""), max) == -1) ||
1209 (label.len && istcat(out, ist(","), max) == -1) ||
1210 (label.len && istcat(out, label, max) == -1) ||
1211 istcat(out, ist("} "), max) == -1)
1212 goto full;
1213 }
1214
1215 trash.data = out->len;
1216 if (!promex_metric_to_str(&trash, metric, max))
1217 goto full;
1218 out->len = trash.data;
1219
1220 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1221 return 1;
1222 full:
1223 // Restore previous length
1224 out->len = len;
1225 return 0;
1226
1227}
1228
1229
1230/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on sucess,
1231 * 0 if <htx> is full and -1 in case of any error. */
1232static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1233{
1234 static struct ist prefix = IST("haproxy_process_");
1235 struct field metric;
1236 struct channel *chn = si_ic(appctx->owner);
1237 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001238 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001239 int ret = 1;
1240
1241#ifdef USE_OPENSSL
1242 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
1243 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
1244 int ssl_reuse = 0;
1245
1246 if (ssl_key_rate < ssl_sess_rate) {
1247 /* count the ssl reuse ratio and avoid overflows in both directions */
1248 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
1249 }
1250#endif
Christopher Fauletf959d082019-02-07 15:38:42 +01001251 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1252 switch (appctx->st2) {
1253 case INF_NBTHREAD:
1254 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
1255 break;
1256 case INF_NBPROC:
1257 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
1258 break;
1259 case INF_PROCESS_NUM:
1260 metric = mkf_u32(FO_KEY, relative_pid);
1261 break;
1262 case INF_UPTIME_SEC:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001263 metric = mkf_u32(FN_DURATION, start_date.tv_sec);
Christopher Fauletf959d082019-02-07 15:38:42 +01001264 break;
1265 case INF_MEMMAX_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001266 metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
Christopher Fauletf959d082019-02-07 15:38:42 +01001267 break;
1268 case INF_POOL_ALLOC_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001269 metric = mkf_u64(0, pool_total_allocated());
Christopher Fauletf959d082019-02-07 15:38:42 +01001270 break;
1271 case INF_POOL_USED_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001272 metric = mkf_u64(0, pool_total_used());
Christopher Fauletf959d082019-02-07 15:38:42 +01001273 break;
1274 case INF_POOL_FAILED:
1275 metric = mkf_u32(FN_COUNTER, pool_total_failures());
1276 break;
1277 case INF_ULIMIT_N:
1278 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
1279 break;
1280 case INF_MAXSOCK:
1281 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
1282 break;
1283 case INF_MAXCONN:
1284 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
1285 break;
1286 case INF_HARD_MAXCONN:
1287 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
1288 break;
1289 case INF_CURR_CONN:
1290 metric = mkf_u32(0, actconn);
1291 break;
1292 case INF_CUM_CONN:
1293 metric = mkf_u32(FN_COUNTER, totalconn);
1294 break;
1295 case INF_CUM_REQ:
1296 metric = mkf_u32(FN_COUNTER, global.req_count);
1297 break;
1298#ifdef USE_OPENSSL
1299 case INF_MAX_SSL_CONNS:
1300 metric = mkf_u32(FN_MAX, global.maxsslconn);
1301 break;
1302 case INF_CURR_SSL_CONNS:
1303 metric = mkf_u32(0, sslconns);
1304 break;
1305 case INF_CUM_SSL_CONNS:
1306 metric = mkf_u32(FN_COUNTER, totalsslconns);
1307 break;
1308#endif
1309 case INF_MAXPIPES:
1310 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
1311 break;
1312 case INF_PIPES_USED:
1313 metric = mkf_u32(0, pipes_used);
1314 break;
1315 case INF_PIPES_FREE:
1316 metric = mkf_u32(0, pipes_free);
1317 break;
1318 case INF_CONN_RATE:
1319 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
1320 break;
1321 case INF_CONN_RATE_LIMIT:
1322 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
1323 break;
1324 case INF_MAX_CONN_RATE:
1325 metric = mkf_u32(FN_MAX, global.cps_max);
1326 break;
1327 case INF_SESS_RATE:
1328 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
1329 break;
1330 case INF_SESS_RATE_LIMIT:
1331 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
1332 break;
1333 case INF_MAX_SESS_RATE:
1334 metric = mkf_u32(FN_RATE, global.sps_max);
1335 break;
1336#ifdef USE_OPENSSL
1337 case INF_SSL_RATE:
1338 metric = mkf_u32(FN_RATE, ssl_sess_rate);
1339 break;
1340 case INF_SSL_RATE_LIMIT:
1341 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
1342 break;
1343 case INF_MAX_SSL_RATE:
1344 metric = mkf_u32(FN_MAX, global.ssl_max);
1345 break;
1346 case INF_SSL_FRONTEND_KEY_RATE:
1347 metric = mkf_u32(0, ssl_key_rate);
1348 break;
1349 case INF_SSL_FRONTEND_MAX_KEY_RATE:
1350 metric = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
1351 break;
1352 case INF_SSL_FRONTEND_SESSION_REUSE_PCT:
1353 metric = mkf_u32(0, ssl_reuse);
1354 break;
1355 case INF_SSL_BACKEND_KEY_RATE:
1356 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
1357 break;
1358 case INF_SSL_BACKEND_MAX_KEY_RATE:
1359 metric = mkf_u32(FN_MAX, global.ssl_be_keys_max);
1360 break;
1361 case INF_SSL_CACHE_LOOKUPS:
1362 metric = mkf_u32(FN_COUNTER, global.shctx_lookups);
1363 break;
1364 case INF_SSL_CACHE_MISSES:
1365 metric = mkf_u32(FN_COUNTER, global.shctx_misses);
1366 break;
1367#endif
1368 case INF_COMPRESS_BPS_IN:
1369 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
1370 break;
1371 case INF_COMPRESS_BPS_OUT:
1372 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
1373 break;
1374 case INF_COMPRESS_BPS_RATE_LIM:
1375 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
1376 break;
1377#ifdef USE_ZLIB
1378 case INF_ZLIB_MEM_USAGE:
1379 metric = mkf_u32(0, zlib_used_memory);
1380 break;
1381 case INF_MAX_ZLIB_MEM_USAGE:
1382 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
1383 break;
1384#endif
1385 case INF_TASKS:
1386 metric = mkf_u32(0, nb_tasks_cur);
1387 break;
1388 case INF_RUN_QUEUE:
1389 metric = mkf_u32(0, tasks_run_queue_cur);
1390 break;
1391 case INF_IDLE_PCT:
Willy Tarreau76824a82019-06-02 10:38:48 +02001392 metric = mkf_u32(FN_AVG, ti->idle_pct);
Christopher Fauletf959d082019-02-07 15:38:42 +01001393 break;
1394 case INF_STOPPING:
1395 metric = mkf_u32(0, stopping);
1396 break;
1397 case INF_JOBS:
1398 metric = mkf_u32(0, jobs);
1399 break;
1400 case INF_UNSTOPPABLE_JOBS:
1401 metric = mkf_u32(0, unstoppable_jobs);
1402 break;
1403 case INF_LISTENERS:
1404 metric = mkf_u32(0, listeners);
1405 break;
1406 case INF_ACTIVE_PEERS:
1407 metric = mkf_u32(0, active_peers);
1408 break;
1409 case INF_CONNECTED_PEERS:
1410 metric = mkf_u32(0, connected_peers);
1411 break;
1412 case INF_DROPPED_LOGS:
1413 metric = mkf_u32(0, dropped_logs);
1414 break;
1415 case INF_BUSY_POLLING:
1416 metric = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
1417 break;
1418
1419 default:
1420 goto next_metric;
1421 }
1422
1423 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1424 goto full;
1425
1426 next_metric:
1427 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1428 appctx->st2 = promex_global_metrics[appctx->st2];
1429 }
1430
1431 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001432 if (out.len) {
1433 if (!htx_add_data_atonce(htx, out))
1434 return -1; /* Unexpected and unrecoverable error */
1435 channel_add_input(chn, out.len);
1436 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001437 return ret;
1438 full:
1439 ret = 0;
1440 goto end;
1441}
1442
1443/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on sucess,
1444 * 0 if <htx> is full and -1 in case of any error. */
1445static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1446{
1447 static struct ist prefix = IST("haproxy_frontend_");
1448 struct proxy *px;
1449 struct field metric;
1450 struct channel *chn = si_ic(appctx->owner);
1451 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001452 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001453 int ret = 1;
1454
1455 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1456 while (appctx->ctx.stats.px) {
1457 px = appctx->ctx.stats.px;
1458
1459 /* skip the disabled proxies, global frontend and non-networked ones */
1460 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
1461 goto next_px;
1462
1463 switch (appctx->st2) {
1464 case ST_F_STATUS:
1465 metric = mkf_u32(FO_STATUS, px->state == PR_STREADY ? 1 : px->state == PR_STFULL ? 2 : 0);
1466 break;
1467 case ST_F_SCUR:
1468 metric = mkf_u32(0, px->feconn);
1469 break;
1470 case ST_F_SMAX:
1471 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1472 break;
1473 case ST_F_SLIM:
1474 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1475 break;
1476 case ST_F_STOT:
1477 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1478 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001479 case ST_F_RATE_LIM:
1480 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1481 break;
1482 case ST_F_RATE_MAX:
1483 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1484 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001485 case ST_F_CONN_RATE_MAX:
1486 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1487 break;
1488 case ST_F_CONN_TOT:
1489 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1490 break;
1491 case ST_F_BIN:
1492 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1493 break;
1494 case ST_F_BOUT:
1495 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1496 break;
1497 case ST_F_DREQ:
1498 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1499 break;
1500 case ST_F_DRESP:
1501 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1502 break;
1503 case ST_F_EREQ:
1504 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1505 break;
1506 case ST_F_DCON:
1507 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1508 break;
1509 case ST_F_DSES:
1510 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1511 break;
1512 case ST_F_WREW:
1513 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1514 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001515 case ST_F_REQ_RATE_MAX:
1516 if (px->mode != PR_MODE_HTTP)
1517 goto next_px;
1518 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1519 break;
1520 case ST_F_REQ_TOT:
1521 if (px->mode != PR_MODE_HTTP)
1522 goto next_px;
1523 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1524 break;
1525 case ST_F_HRSP_1XX:
1526 if (px->mode != PR_MODE_HTTP)
1527 goto next_px;
1528 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1529 break;
1530 case ST_F_HRSP_2XX:
1531 if (px->mode != PR_MODE_HTTP)
1532 goto next_px;
1533 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1534 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1535 break;
1536 case ST_F_HRSP_3XX:
1537 if (px->mode != PR_MODE_HTTP)
1538 goto next_px;
1539 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1540 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1541 break;
1542 case ST_F_HRSP_4XX:
1543 if (px->mode != PR_MODE_HTTP)
1544 goto next_px;
1545 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1546 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1547 break;
1548 case ST_F_HRSP_5XX:
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[5]);
1553 break;
1554 case ST_F_HRSP_OTHER:
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[0]);
1559 break;
1560 case ST_F_INTERCEPTED:
1561 if (px->mode != PR_MODE_HTTP)
1562 goto next_px;
1563 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1564 break;
1565 case ST_F_CACHE_LOOKUPS:
1566 if (px->mode != PR_MODE_HTTP)
1567 goto next_px;
1568 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1569 break;
1570 case ST_F_CACHE_HITS:
1571 if (px->mode != PR_MODE_HTTP)
1572 goto next_px;
1573 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1574 break;
1575 case ST_F_COMP_IN:
1576 if (px->mode != PR_MODE_HTTP)
1577 goto next_px;
1578 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1579 break;
1580 case ST_F_COMP_OUT:
1581 if (px->mode != PR_MODE_HTTP)
1582 goto next_px;
1583 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1584 break;
1585 case ST_F_COMP_BYP:
1586 if (px->mode != PR_MODE_HTTP)
1587 goto next_px;
1588 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1589 break;
1590 case ST_F_COMP_RSP:
1591 if (px->mode != PR_MODE_HTTP)
1592 goto next_px;
1593 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1594 break;
1595
1596 default:
1597 goto next_metric;
1598 }
1599
1600 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1601 goto full;
1602 next_px:
1603 appctx->ctx.stats.px = px->next;
1604 }
1605 next_metric:
1606 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1607 appctx->ctx.stats.px = proxies_list;
1608 appctx->st2 = promex_front_metrics[appctx->st2];
1609 }
1610
1611 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001612 if (out.len) {
1613 if (!htx_add_data_atonce(htx, out))
1614 return -1; /* Unexpected and unrecoverable error */
1615 channel_add_input(chn, out.len);
1616 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001617 return ret;
1618 full:
1619 ret = 0;
1620 goto end;
1621}
1622
1623/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on sucess,
1624 * 0 if <htx> is full and -1 in case of any error. */
1625static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1626{
1627 static struct ist prefix = IST("haproxy_backend_");
1628 struct proxy *px;
1629 struct field metric;
1630 struct channel *chn = si_ic(appctx->owner);
1631 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001632 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001633 int ret = 1;
1634 uint32_t weight;
Christopher Faulete86bf652019-09-24 16:35:19 +02001635 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001636
1637 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1638 while (appctx->ctx.stats.px) {
1639 px = appctx->ctx.stats.px;
1640
1641 /* skip the disabled proxies, global frontend and non-networked ones */
1642 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1643 goto next_px;
1644
1645 switch (appctx->st2) {
1646 case ST_F_STATUS:
1647 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1648 break;
1649 case ST_F_SCUR:
1650 metric = mkf_u32(0, px->beconn);
1651 break;
1652 case ST_F_SMAX:
1653 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1654 break;
1655 case ST_F_SLIM:
1656 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1657 break;
1658 case ST_F_STOT:
1659 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1660 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001661 case ST_F_RATE_MAX:
1662 metric = mkf_u32(0, px->be_counters.sps_max);
1663 break;
1664 case ST_F_LASTSESS:
1665 metric = mkf_s32(FN_AGE, be_lastsession(px));
1666 break;
1667 case ST_F_QCUR:
1668 metric = mkf_u32(0, px->nbpend);
1669 break;
1670 case ST_F_QMAX:
1671 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1672 break;
1673 case ST_F_CONNECT:
1674 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1675 break;
1676 case ST_F_REUSE:
1677 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1678 break;
1679 case ST_F_BIN:
1680 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1681 break;
1682 case ST_F_BOUT:
1683 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1684 break;
1685 case ST_F_QTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001686 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1687 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001688 break;
1689 case ST_F_CTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001690 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1691 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001692 break;
1693 case ST_F_RTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001694 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1695 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001696 break;
1697 case ST_F_TTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001698 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1699 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001700 break;
Christopher Faulet5df597a2019-11-08 15:05:31 +01001701 case ST_F_QT_MAX:
1702 secs = (double)px->be_counters.qtime_max / 1000.0;
1703 metric = mkf_flt(FN_MAX, secs);
1704 break;
1705 case ST_F_CT_MAX:
1706 secs = (double)px->be_counters.ctime_max / 1000.0;
1707 metric = mkf_flt(FN_MAX, secs);
1708 break;
1709 case ST_F_RT_MAX:
1710 secs = (double)px->be_counters.dtime_max / 1000.0;
1711 metric = mkf_flt(FN_MAX, secs);
1712 break;
1713 case ST_F_TT_MAX:
1714 secs = (double)px->be_counters.ttime_max / 1000.0;
1715 metric = mkf_flt(FN_MAX, secs);
1716 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001717 case ST_F_DREQ:
1718 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1719 break;
1720 case ST_F_DRESP:
1721 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1722 break;
1723 case ST_F_ECON:
1724 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1725 break;
1726 case ST_F_ERESP:
1727 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1728 break;
1729 case ST_F_WRETR:
1730 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1731 break;
1732 case ST_F_WREDIS:
1733 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1734 break;
1735 case ST_F_WREW:
1736 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1737 break;
1738 case ST_F_CLI_ABRT:
1739 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1740 break;
1741 case ST_F_SRV_ABRT:
1742 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1743 break;
1744 case ST_F_WEIGHT:
1745 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1746 metric = mkf_u32(FN_AVG, weight);
1747 break;
1748 case ST_F_ACT:
1749 metric = mkf_u32(0, px->srv_act);
1750 break;
1751 case ST_F_BCK:
1752 metric = mkf_u32(0, px->srv_bck);
1753 break;
1754 case ST_F_CHKDOWN:
1755 metric = mkf_u64(FN_COUNTER, px->down_trans);
1756 break;
1757 case ST_F_LASTCHG:
1758 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1759 break;
1760 case ST_F_DOWNTIME:
1761 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1762 break;
1763 case ST_F_LBTOT:
1764 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1765 break;
1766 case ST_F_REQ_TOT:
1767 if (px->mode != PR_MODE_HTTP)
1768 goto next_px;
1769 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1770 break;
1771 case ST_F_HRSP_1XX:
1772 if (px->mode != PR_MODE_HTTP)
1773 goto next_px;
1774 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1775 break;
1776 case ST_F_HRSP_2XX:
1777 if (px->mode != PR_MODE_HTTP)
1778 goto next_px;
1779 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1780 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1781 break;
1782 case ST_F_HRSP_3XX:
1783 if (px->mode != PR_MODE_HTTP)
1784 goto next_px;
1785 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1786 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1787 break;
1788 case ST_F_HRSP_4XX:
1789 if (px->mode != PR_MODE_HTTP)
1790 goto next_px;
1791 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1792 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1793 break;
1794 case ST_F_HRSP_5XX:
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[5]);
1799 break;
1800 case ST_F_HRSP_OTHER:
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[0]);
1805 break;
1806 case ST_F_CACHE_LOOKUPS:
1807 if (px->mode != PR_MODE_HTTP)
1808 goto next_px;
1809 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1810 break;
1811 case ST_F_CACHE_HITS:
1812 if (px->mode != PR_MODE_HTTP)
1813 goto next_px;
1814 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1815 break;
1816 case ST_F_COMP_IN:
1817 if (px->mode != PR_MODE_HTTP)
1818 goto next_px;
1819 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1820 break;
1821 case ST_F_COMP_OUT:
1822 if (px->mode != PR_MODE_HTTP)
1823 goto next_px;
1824 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1825 break;
1826 case ST_F_COMP_BYP:
1827 if (px->mode != PR_MODE_HTTP)
1828 goto next_px;
1829 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1830 break;
1831 case ST_F_COMP_RSP:
1832 if (px->mode != PR_MODE_HTTP)
1833 goto next_px;
1834 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1835 break;
1836
1837 default:
1838 goto next_metric;
1839 }
1840
1841 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1842 goto full;
1843 next_px:
1844 appctx->ctx.stats.px = px->next;
1845 }
1846 next_metric:
1847 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1848 appctx->ctx.stats.px = proxies_list;
1849 appctx->st2 = promex_back_metrics[appctx->st2];
1850 }
1851
1852 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001853 if (out.len) {
1854 if (!htx_add_data_atonce(htx, out))
1855 return -1; /* Unexpected and unrecoverable error */
1856 channel_add_input(chn, out.len);
1857 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001858 return ret;
1859 full:
1860 ret = 0;
1861 goto end;
1862}
1863
1864/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on sucess,
1865 * 0 if <htx> is full and -1 in case of any error. */
1866static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1867{
1868 static struct ist prefix = IST("haproxy_server_");
1869 struct proxy *px;
1870 struct server *sv;
1871 struct field metric;
1872 struct channel *chn = si_ic(appctx->owner);
1873 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001874 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001875 int ret = 1;
1876 uint32_t weight;
Christopher Faulete86bf652019-09-24 16:35:19 +02001877 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001878
1879 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1880 while (appctx->ctx.stats.px) {
1881 px = appctx->ctx.stats.px;
1882
1883 /* skip the disabled proxies, global frontend and non-networked ones */
1884 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1885 goto next_px;
1886
1887 while (appctx->ctx.stats.sv) {
1888 sv = appctx->ctx.stats.sv;
1889
1890 switch (appctx->st2) {
1891 case ST_F_STATUS:
1892 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1893 break;
1894 case ST_F_SCUR:
1895 metric = mkf_u32(0, sv->cur_sess);
1896 break;
1897 case ST_F_SMAX:
1898 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1899 break;
1900 case ST_F_SLIM:
1901 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1902 break;
1903 case ST_F_STOT:
1904 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1905 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001906 case ST_F_RATE_MAX:
1907 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1908 break;
1909 case ST_F_LASTSESS:
1910 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1911 break;
1912 case ST_F_QCUR:
1913 metric = mkf_u32(0, sv->nbpend);
1914 break;
1915 case ST_F_QMAX:
1916 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1917 break;
1918 case ST_F_QLIMIT:
1919 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1920 break;
1921 case ST_F_BIN:
1922 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1923 break;
1924 case ST_F_BOUT:
1925 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1926 break;
1927 case ST_F_QTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001928 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1929 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001930 break;
1931 case ST_F_CTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001932 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1933 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001934 break;
1935 case ST_F_RTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001936 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1937 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001938 break;
1939 case ST_F_TTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001940 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1941 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001942 break;
Christopher Faulet5df597a2019-11-08 15:05:31 +01001943 case ST_F_QT_MAX:
1944 secs = (double)sv->counters.qtime_max / 1000.0;
1945 metric = mkf_flt(FN_MAX, secs);
1946 break;
1947 case ST_F_CT_MAX:
1948 secs = (double)sv->counters.ctime_max / 1000.0;
1949 metric = mkf_flt(FN_MAX, secs);
1950 break;
1951 case ST_F_RT_MAX:
1952 secs = (double)sv->counters.dtime_max / 1000.0;
1953 metric = mkf_flt(FN_MAX, secs);
1954 break;
1955 case ST_F_TT_MAX:
1956 secs = (double)sv->counters.ttime_max / 1000.0;
1957 metric = mkf_flt(FN_MAX, secs);
1958 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001959 case ST_F_CONNECT:
1960 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1961 break;
1962 case ST_F_REUSE:
1963 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1964 break;
1965 case ST_F_DRESP:
1966 metric = mkf_u64(FN_COUNTER, sv->counters.failed_secu);
1967 break;
1968 case ST_F_ECON:
1969 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1970 break;
1971 case ST_F_ERESP:
1972 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1973 break;
1974 case ST_F_WRETR:
1975 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
1976 break;
1977 case ST_F_WREDIS:
1978 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
1979 break;
1980 case ST_F_WREW:
1981 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
1982 break;
1983 case ST_F_CLI_ABRT:
1984 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1985 break;
1986 case ST_F_SRV_ABRT:
1987 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1988 break;
1989 case ST_F_WEIGHT:
1990 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1991 metric = mkf_u32(FN_AVG, weight);
1992 break;
1993 case ST_F_CHKFAIL:
1994 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1995 break;
1996 case ST_F_CHKDOWN:
1997 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1998 break;
1999 case ST_F_DOWNTIME:
2000 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
2001 break;
2002 case ST_F_LASTCHG:
2003 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
2004 break;
2005 case ST_F_THROTTLE:
2006 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
2007 break;
2008 case ST_F_LBTOT:
2009 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
2010 break;
2011 case ST_F_HRSP_1XX:
2012 if (px->mode != PR_MODE_HTTP)
2013 goto next_px;
2014 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
2015 break;
2016 case ST_F_HRSP_2XX:
2017 if (px->mode != PR_MODE_HTTP)
2018 goto next_px;
2019 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2020 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
2021 break;
2022 case ST_F_HRSP_3XX:
2023 if (px->mode != PR_MODE_HTTP)
2024 goto next_px;
2025 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2026 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
2027 break;
2028 case ST_F_HRSP_4XX:
2029 if (px->mode != PR_MODE_HTTP)
2030 goto next_px;
2031 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2032 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
2033 break;
2034 case ST_F_HRSP_5XX:
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[5]);
2039 break;
2040 case ST_F_HRSP_OTHER:
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[0]);
2045 break;
2046
2047 default:
2048 goto next_metric;
2049 }
2050
2051 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2052 goto full;
2053
2054 appctx->ctx.stats.sv = sv->next;
2055 }
2056
2057 next_px:
2058 appctx->ctx.stats.px = px->next;
2059 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2060 }
2061 next_metric:
2062 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
2063 appctx->ctx.stats.px = proxies_list;
2064 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2065 appctx->st2 = promex_srv_metrics[appctx->st2];
2066 }
2067
2068
2069 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02002070 if (out.len) {
2071 if (!htx_add_data_atonce(htx, out))
2072 return -1; /* Unexpected and unrecoverable error */
2073 channel_add_input(chn, out.len);
2074 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002075 return ret;
2076 full:
2077 ret = 0;
2078 goto end;
2079}
2080
2081/* Dump all metrics (global, frontends, backends and servers) depending on the
2082 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
2083 * -1 in case of any error. */
2084static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2085{
2086 int ret;
2087
2088 switch (appctx->st1) {
2089 case PROMEX_DUMPER_INIT:
2090 appctx->ctx.stats.px = NULL;
2091 appctx->ctx.stats.sv = NULL;
2092 appctx->ctx.stats.flags = (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
2093 appctx->st2 = promex_global_metrics[INF_NAME];
2094 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2095 /* fall through */
2096
2097 case PROMEX_DUMPER_GLOBAL:
2098 ret = promex_dump_global_metrics(appctx, htx);
2099 if (ret <= 0) {
2100 if (ret == -1)
2101 goto error;
2102 goto full;
2103 }
2104
2105 appctx->ctx.stats.px = proxies_list;
2106 appctx->ctx.stats.sv = NULL;
2107 appctx->ctx.stats.flags = (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
2108 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2109 appctx->st1 = PROMEX_DUMPER_FRONT;
2110 /* fall through */
2111
2112 case PROMEX_DUMPER_FRONT:
2113 ret = promex_dump_front_metrics(appctx, htx);
2114 if (ret <= 0) {
2115 if (ret == -1)
2116 goto error;
2117 goto full;
2118 }
2119
2120 appctx->ctx.stats.px = proxies_list;
2121 appctx->ctx.stats.sv = NULL;
2122 appctx->ctx.stats.flags = (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
2123 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2124 appctx->st1 = PROMEX_DUMPER_BACK;
2125 /* fall through */
2126
2127 case PROMEX_DUMPER_BACK:
2128 ret = promex_dump_back_metrics(appctx, htx);
2129 if (ret <= 0) {
2130 if (ret == -1)
2131 goto error;
2132 goto full;
2133 }
2134
2135 appctx->ctx.stats.px = proxies_list;
2136 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2137 appctx->ctx.stats.flags = (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
2138 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2139 appctx->st1 = PROMEX_DUMPER_SRV;
2140 /* fall through */
2141
2142 case PROMEX_DUMPER_SRV:
2143 ret = promex_dump_srv_metrics(appctx, htx);
2144 if (ret <= 0) {
2145 if (ret == -1)
2146 goto error;
2147 goto full;
2148 }
2149
2150 appctx->ctx.stats.px = NULL;
2151 appctx->ctx.stats.sv = NULL;
2152 appctx->ctx.stats.flags = 0;
2153 appctx->st2 = 0;
2154 appctx->st1 = PROMEX_DUMPER_DONE;
2155 /* fall through */
2156
2157 case PROMEX_DUMPER_DONE:
2158 default:
2159 break;
2160 }
2161
2162 return 1;
2163
2164 full:
2165 si_rx_room_blk(si);
2166 return 0;
2167 error:
2168 /* unrecoverable error */
2169 appctx->ctx.stats.px = NULL;
2170 appctx->ctx.stats.sv = NULL;
2171 appctx->ctx.stats.flags = 0;
2172 appctx->st2 = 0;
2173 appctx->st1 = PROMEX_DUMPER_DONE;
2174 return -1;
2175}
2176
2177/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2178 * full. */
2179static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2180{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002181 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002182 struct htx_sl *sl;
2183 unsigned int flags;
2184
2185 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);
2186 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2187 if (!sl)
2188 goto full;
2189 sl->info.res.status = 200;
2190 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
2191 !htx_add_header(htx, ist("Connection"), ist("close")) ||
2192 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2193 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2194 !htx_add_endof(htx, HTX_BLK_EOH))
2195 goto full;
2196
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002197 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002198 return 1;
2199 full:
2200 htx_reset(htx);
2201 si_rx_room_blk(si);
2202 return 0;
2203}
2204
2205/* The function returns 1 if the initialisation is complete, 0 if
2206 * an errors occurs and -1 if more data are required for initializing
2207 * the applet.
2208 */
2209static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2210{
2211 appctx->st0 = PROMEX_ST_INIT;
2212 return 1;
2213}
2214
2215/* The main I/O handler for the promex applet. */
2216static void promex_appctx_handle_io(struct appctx *appctx)
2217{
2218 struct stream_interface *si = appctx->owner;
2219 struct stream *s = si_strm(si);
2220 struct channel *req = si_oc(si);
2221 struct channel *res = si_ic(si);
2222 struct htx *req_htx, *res_htx;
2223 int ret;
2224
2225 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002226 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2227 goto out;
2228
2229 /* Check if the input buffer is avalaible. */
2230 if (!b_size(&res->buf)) {
2231 si_rx_room_blk(si);
2232 goto out;
2233 }
2234
2235 switch (appctx->st0) {
2236 case PROMEX_ST_INIT:
2237 appctx->st0 = PROMEX_ST_HEAD;
2238 appctx->st1 = PROMEX_DUMPER_INIT;
2239 /* fall through */
2240
2241 case PROMEX_ST_HEAD:
2242 if (!promex_send_headers(appctx, si, res_htx))
2243 goto out;
2244 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2245 /* fall through */
2246
2247 case PROMEX_ST_DUMP:
2248 ret = promex_dump_metrics(appctx, si, res_htx);
2249 if (ret <= 0) {
2250 if (ret == -1)
2251 goto error;
2252 goto out;
2253 }
2254 appctx->st0 = PROMEX_ST_DONE;
2255 /* fall through */
2256
2257 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002258 /* Don't add TLR because mux-h1 will take care of it */
Christopher Fauletf959d082019-02-07 15:38:42 +01002259 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2260 si_rx_room_blk(si);
2261 goto out;
2262 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002263 channel_add_input(res, 1);
2264 appctx->st0 = PROMEX_ST_END;
2265 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002266
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002267 case PROMEX_ST_END:
2268 if (!(res->flags & CF_SHUTR)) {
2269 res->flags |= CF_READ_NULL;
2270 si_shutr(si);
2271 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002272 }
2273
Christopher Fauletf959d082019-02-07 15:38:42 +01002274 out:
2275 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002276
2277 /* eat the whole request */
2278 if (co_data(req)) {
2279 req_htx = htx_from_buf(&req->buf);
2280 co_htx_skip(req, req_htx, co_data(req));
2281 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002282 return;
2283
2284 error:
2285 res->flags |= CF_READ_NULL;
2286 si_shutr(si);
2287 si_shutw(si);
2288}
2289
2290struct applet promex_applet = {
2291 .obj_type = OBJ_TYPE_APPLET,
2292 .name = "<PROMEX>", /* used for logging */
2293 .init = promex_appctx_init,
2294 .fct = promex_appctx_handle_io,
2295};
2296
2297static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2298 struct act_rule *rule, char **err)
2299{
2300 /* Prometheus exporter service is only available on "http-request" rulesets */
2301 if (rule->from != ACT_F_HTTP_REQ) {
2302 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2303 return ACT_RET_PRS_ERR;
2304 }
2305 if (!(px->options2 & PR_O2_USE_HTX)) {
2306 memprintf(err, "Prometheus exporter service only available for HTX proxies");
2307 return ACT_RET_PRS_ERR;
2308 }
2309
2310 /* Add applet pointer in the rule. */
2311 rule->applet = promex_applet;
2312
2313 return ACT_RET_PRS_OK;
2314}
2315static void promex_register_build_options(void)
2316{
2317 char *ptr = NULL;
2318
2319 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2320 hap_register_build_opts(ptr, 1);
2321}
2322
2323
2324static struct action_kw_list service_actions = { ILH, {
2325 { "prometheus-exporter", service_parse_prometheus_exporter },
2326 { /* END */ }
2327}};
2328
2329INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2330INITCALL0(STG_REGISTER, promex_register_build_options);