blob: fb50db25a7f66ea2ec0438831ef92467a40492ee [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>
William Dauchy63495eb2021-01-08 13:18:06 +010023#include <common/version.h>
Christopher Fauletf959d082019-02-07 15:38:42 +010024
25#include <types/global.h>
26
27#include <proto/action.h>
28#include <proto/applet.h>
29#include <proto/backend.h>
30#include <proto/compression.h>
31#include <proto/frontend.h>
32#include <proto/listener.h>
33#include <proto/http_htx.h>
34#include <proto/pipe.h>
35#include <proto/proxy.h>
36#include <proto/sample.h>
37#include <proto/server.h>
38#include <proto/ssl_sock.h>
39#include <proto/stats.h>
40#include <proto/stream.h>
41#include <proto/stream_interface.h>
42#include <proto/task.h>
43
44/* Prometheus exporter applet states (appctx->st0) */
45enum {
46 PROMEX_ST_INIT = 0, /* initialized */
47 PROMEX_ST_HEAD, /* send headers before dump */
48 PROMEX_ST_DUMP, /* dumping stats */
49 PROMEX_ST_DONE, /* finished */
Christopher Faulet9744f7c2019-03-27 15:48:53 +010050 PROMEX_ST_END, /* treatment terminated */
Christopher Fauletf959d082019-02-07 15:38:42 +010051};
52
53/* Prometheus exporter dumper states (appctx->st1) */
54enum {
55 PROMEX_DUMPER_INIT = 0, /* initialized */
56 PROMEX_DUMPER_GLOBAL, /* dump metrics of globals */
57 PROMEX_DUMPER_FRONT, /* dump metrics of frontend proxies */
58 PROMEX_DUMPER_BACK, /* dump metrics of backend proxies */
59 PROMEX_DUMPER_LI, /* dump metrics of listeners */
60 PROMEX_DUMPER_SRV, /* dump metrics of servers */
61 PROMEX_DUMPER_DONE, /* finished */
62};
63
64/* Prometheus exporter flags (appctx->ctx.stats.flags) */
65#define PROMEX_FL_METRIC_HDR 0x00000001
66#define PROMEX_FL_INFO_METRIC 0x00000002
67#define PROMEX_FL_STATS_METRIC 0x00000004
Christopher Faulet32d634f2019-11-18 14:47:08 +010068#define PROMEX_FL_SCOPE_GLOBAL 0x00000008
69#define PROMEX_FL_SCOPE_FRONT 0x00000010
70#define PROMEX_FL_SCOPE_BACK 0x00000020
71#define PROMEX_FL_SCOPE_SERVER 0x00000040
Christopher Faulete48e9962019-11-19 14:18:24 +010072#define PROMEX_FL_NO_MAINT_SRV 0x00000080
Christopher Faulet32d634f2019-11-18 14:47:08 +010073
74#define PROMEX_FL_SCOPE_ALL (PROMEX_FL_SCOPE_GLOBAL|PROMEX_FL_SCOPE_FRONT|PROMEX_FL_SCOPE_BACK|PROMEX_FL_SCOPE_SERVER)
Christopher Fauletf959d082019-02-07 15:38:42 +010075
76/* The max length for metrics name. It is a hard limit but it should be
77 * enougth.
78 */
79#define PROMEX_MAX_NAME_LEN 128
80
81/* The expected max length for a metric dump, including its header lines. It is
82 * just a soft limit to avoid extra work. We don't try to dump a metric if less
83 * than this size is available in the HTX.
84 */
85#define PROMEX_MAX_METRIC_LENGTH 512
86
William Dauchy63495eb2021-01-08 13:18:06 +010087/* Some labels for build_info */
88#define PROMEX_VERSION_LABEL "version=\"" HAPROXY_VERSION "\""
89#define PROMEX_BUILDINFO_LABEL PROMEX_VERSION_LABEL
90
Christopher Fauletf959d082019-02-07 15:38:42 +010091/* Matrix used to dump global metrics. Each metric points to the next one to be
92 * processed or 0 to stop the dump. */
93const int promex_global_metrics[INF_TOTAL_FIELDS] = {
William Dauchy63495eb2021-01-08 13:18:06 +010094 [INF_NAME] = INF_BUILD_INFO,
Christopher Fauletf959d082019-02-07 15:38:42 +010095 [INF_VERSION] = 0,
96 [INF_RELEASE_DATE] = 0,
William Dauchy63495eb2021-01-08 13:18:06 +010097 [INF_BUILD_INFO] = INF_NBTHREAD,
Christopher Fauletf959d082019-02-07 15:38:42 +010098 [INF_NBTHREAD] = INF_NBPROC,
99 [INF_NBPROC] = INF_PROCESS_NUM,
100 [INF_PROCESS_NUM] = INF_UPTIME_SEC,
101 [INF_PID] = 0,
102 [INF_UPTIME] = 0,
103 [INF_UPTIME_SEC] = INF_MEMMAX_MB,
104 [INF_MEMMAX_MB] = INF_POOL_ALLOC_MB,
105 [INF_POOL_ALLOC_MB] = INF_POOL_USED_MB,
106 [INF_POOL_USED_MB] = INF_POOL_FAILED,
107 [INF_POOL_FAILED] = INF_ULIMIT_N,
108 [INF_ULIMIT_N] = INF_MAXSOCK,
109 [INF_MAXSOCK] = INF_MAXCONN,
110 [INF_MAXCONN] = INF_HARD_MAXCONN,
111 [INF_HARD_MAXCONN] = INF_CURR_CONN,
112 [INF_CURR_CONN] = INF_CUM_CONN,
113 [INF_CUM_CONN] = INF_CUM_REQ,
114 [INF_CUM_REQ] = INF_MAX_SSL_CONNS,
115 [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS,
116 [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS,
117 [INF_CUM_SSL_CONNS] = INF_MAXPIPES,
118 [INF_MAXPIPES] = INF_PIPES_USED,
119 [INF_PIPES_USED] = INF_PIPES_FREE,
120 [INF_PIPES_FREE] = INF_CONN_RATE,
121 [INF_CONN_RATE] = INF_CONN_RATE_LIMIT,
122 [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE,
123 [INF_MAX_CONN_RATE] = INF_SESS_RATE,
124 [INF_SESS_RATE] = INF_SESS_RATE_LIMIT,
125 [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE,
126 [INF_MAX_SESS_RATE] = INF_SSL_RATE,
127 [INF_SSL_RATE] = INF_SSL_RATE_LIMIT,
128 [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE,
129 [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE,
130 [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE,
131 [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT,
132 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE,
133 [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE,
134 [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS,
135 [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES,
136 [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN,
137 [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT,
138 [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM,
139 [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE,
140 [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE,
141 [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS,
142 [INF_TASKS] = INF_RUN_QUEUE,
143 [INF_RUN_QUEUE] = INF_IDLE_PCT,
144 [INF_IDLE_PCT] = INF_STOPPING,
145 [INF_NODE] = 0,
146 [INF_DESCRIPTION] = 0,
147 [INF_STOPPING] = INF_JOBS,
148 [INF_JOBS] = INF_UNSTOPPABLE_JOBS,
149 [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS,
150 [INF_LISTENERS] = INF_ACTIVE_PEERS,
151 [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS,
152 [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS,
153 [INF_DROPPED_LOGS] = INF_BUSY_POLLING,
154 [INF_BUSY_POLLING] = 0,
155};
156
157/* Matrix used to dump frontend metrics. Each metric points to the next one to be
158 * processed or 0 to stop the dump. */
159const int promex_front_metrics[ST_F_TOTAL_FIELDS] = {
160 [ST_F_PXNAME] = ST_F_STATUS,
161 [ST_F_SVNAME] = 0,
162 [ST_F_QCUR] = 0,
163 [ST_F_QMAX] = 0,
164 [ST_F_SCUR] = ST_F_SMAX,
165 [ST_F_SMAX] = ST_F_SLIM,
166 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200167 [ST_F_STOT] = ST_F_RATE_LIM,
Christopher Fauletf959d082019-02-07 15:38:42 +0100168 [ST_F_BIN] = ST_F_BOUT,
169 [ST_F_BOUT] = ST_F_DREQ,
170 [ST_F_DREQ] = ST_F_DRESP,
171 [ST_F_DRESP] = ST_F_EREQ,
172 [ST_F_EREQ] = ST_F_DCON,
173 [ST_F_ECON] = 0,
174 [ST_F_ERESP] = 0,
175 [ST_F_WRETR] = 0,
176 [ST_F_WREDIS] = 0,
177 [ST_F_STATUS] = ST_F_SCUR,
178 [ST_F_WEIGHT] = 0,
179 [ST_F_ACT] = 0,
180 [ST_F_BCK] = 0,
181 [ST_F_CHKFAIL] = 0,
182 [ST_F_CHKDOWN] = 0,
183 [ST_F_LASTCHG] = 0,
184 [ST_F_DOWNTIME] = 0,
185 [ST_F_QLIMIT] = 0,
186 [ST_F_PID] = 0,
187 [ST_F_IID] = 0,
188 [ST_F_SID] = 0,
189 [ST_F_THROTTLE] = 0,
190 [ST_F_LBTOT] = 0,
191 [ST_F_TRACKED] = 0,
192 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200193 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100194 [ST_F_RATE_LIM] = ST_F_RATE_MAX,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200195 [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100196 [ST_F_CHECK_STATUS] = 0,
197 [ST_F_CHECK_CODE] = 0,
198 [ST_F_CHECK_DURATION] = 0,
199 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
200 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
201 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
202 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
203 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
204 [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED,
205 [ST_F_HANAFAIL] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200206 [ST_F_REQ_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100207 [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT,
208 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
209 [ST_F_CLI_ABRT] = 0,
210 [ST_F_SRV_ABRT] = 0,
211 [ST_F_COMP_IN] = ST_F_COMP_OUT,
212 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
213 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
214 [ST_F_COMP_RSP] = 0,
215 [ST_F_LASTSESS] = 0,
216 [ST_F_LAST_CHK] = 0,
217 [ST_F_LAST_AGT] = 0,
218 [ST_F_QTIME] = 0,
219 [ST_F_CTIME] = 0,
220 [ST_F_RTIME] = 0,
221 [ST_F_TTIME] = 0,
222 [ST_F_AGENT_STATUS] = 0,
223 [ST_F_AGENT_CODE] = 0,
224 [ST_F_AGENT_DURATION] = 0,
225 [ST_F_CHECK_DESC] = 0,
226 [ST_F_AGENT_DESC] = 0,
227 [ST_F_CHECK_RISE] = 0,
228 [ST_F_CHECK_FALL] = 0,
229 [ST_F_CHECK_HEALTH] = 0,
230 [ST_F_AGENT_RISE] = 0,
231 [ST_F_AGENT_FALL] = 0,
232 [ST_F_AGENT_HEALTH] = 0,
233 [ST_F_ADDR] = 0,
234 [ST_F_COOKIE] = 0,
235 [ST_F_MODE] = 0,
236 [ST_F_ALGO] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200237 [ST_F_CONN_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100238 [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT,
239 [ST_F_CONN_TOT] = ST_F_BIN,
240 [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS,
241 [ST_F_DCON] = ST_F_DSES,
242 [ST_F_DSES] = ST_F_WREW,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200243 [ST_F_WREW] = ST_F_REQ_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100244 [ST_F_CONNECT] = 0,
245 [ST_F_REUSE] = 0,
246 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
247 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100248 [ST_F_SRV_ICUR] = 0,
249 [ST_F_SRV_ILIM] = 0,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100250 [ST_F_QT_MAX] = 0,
251 [ST_F_CT_MAX] = 0,
252 [ST_F_RT_MAX] = 0,
253 [ST_F_TT_MAX] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100254};
255
256/* Matrix used to dump backend metrics. Each metric points to the next one to be
257 * processed or 0 to stop the dump. */
258const int promex_back_metrics[ST_F_TOTAL_FIELDS] = {
259 [ST_F_PXNAME] = ST_F_STATUS,
260 [ST_F_SVNAME] = 0,
261 [ST_F_QCUR] = ST_F_QMAX,
262 [ST_F_QMAX] = ST_F_CONNECT,
263 [ST_F_SCUR] = ST_F_SMAX,
264 [ST_F_SMAX] = ST_F_SLIM,
265 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200266 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100267 [ST_F_BIN] = ST_F_BOUT,
268 [ST_F_BOUT] = ST_F_QTIME,
269 [ST_F_DREQ] = ST_F_DRESP,
270 [ST_F_DRESP] = ST_F_ECON,
271 [ST_F_EREQ] = 0,
272 [ST_F_ECON] = ST_F_ERESP,
273 [ST_F_ERESP] = ST_F_WRETR,
274 [ST_F_WRETR] = ST_F_WREDIS,
275 [ST_F_WREDIS] = ST_F_WREW,
276 [ST_F_STATUS] = ST_F_SCUR,
277 [ST_F_WEIGHT] = ST_F_ACT,
278 [ST_F_ACT] = ST_F_BCK,
279 [ST_F_BCK] = ST_F_CHKDOWN,
280 [ST_F_CHKFAIL] = 0,
281 [ST_F_CHKDOWN] = ST_F_LASTCHG,
282 [ST_F_LASTCHG] = ST_F_DOWNTIME,
283 [ST_F_DOWNTIME] = ST_F_LBTOT,
284 [ST_F_QLIMIT] = 0,
285 [ST_F_PID] = 0,
286 [ST_F_IID] = 0,
287 [ST_F_SID] = 0,
288 [ST_F_THROTTLE] = 0,
289 [ST_F_LBTOT] = ST_F_REQ_TOT,
290 [ST_F_TRACKED] = 9,
291 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200292 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100293 [ST_F_RATE_LIM] = 0,
294 [ST_F_RATE_MAX] = ST_F_LASTSESS,
295 [ST_F_CHECK_STATUS] = 0,
296 [ST_F_CHECK_CODE] = 0,
297 [ST_F_CHECK_DURATION] = 0,
298 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
299 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
300 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
301 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
302 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
303 [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS,
304 [ST_F_HANAFAIL] = 0,
305 [ST_F_REQ_RATE] = 0,
306 [ST_F_REQ_RATE_MAX] = 0,
307 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
308 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
309 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
310 [ST_F_COMP_IN] = ST_F_COMP_OUT,
311 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
312 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
313 [ST_F_COMP_RSP] = 0,
314 [ST_F_LASTSESS] = ST_F_QCUR,
315 [ST_F_LAST_CHK] = 0,
316 [ST_F_LAST_AGT] = 0,
317 [ST_F_QTIME] = ST_F_CTIME,
318 [ST_F_CTIME] = ST_F_RTIME,
319 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100320 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100321 [ST_F_AGENT_STATUS] = 0,
322 [ST_F_AGENT_CODE] = 0,
323 [ST_F_AGENT_DURATION] = 0,
324 [ST_F_CHECK_DESC] = 0,
325 [ST_F_AGENT_DESC] = 0,
326 [ST_F_CHECK_RISE] = 0,
327 [ST_F_CHECK_FALL] = 0,
328 [ST_F_CHECK_HEALTH] = 0,
329 [ST_F_AGENT_RISE] = 0,
330 [ST_F_AGENT_FALL] = 0,
331 [ST_F_AGENT_HEALTH] = 0,
332 [ST_F_ADDR] = 0,
333 [ST_F_COOKIE] = 0,
334 [ST_F_MODE] = 0,
335 [ST_F_ALGO] = 0,
336 [ST_F_CONN_RATE] = 0,
337 [ST_F_CONN_RATE_MAX] = 0,
338 [ST_F_CONN_TOT] = 0,
339 [ST_F_INTERCEPTED] = 0,
340 [ST_F_DCON] = 0,
341 [ST_F_DSES] = 0,
342 [ST_F_WREW] = ST_F_CLI_ABRT,
343 [ST_F_CONNECT] = ST_F_REUSE,
344 [ST_F_REUSE] = ST_F_BIN,
345 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
346 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100347 [ST_F_SRV_ICUR] = 0,
348 [ST_F_SRV_ILIM] = 0,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100349 [ST_F_QT_MAX] = ST_F_CT_MAX,
350 [ST_F_CT_MAX] = ST_F_RT_MAX,
351 [ST_F_RT_MAX] = ST_F_TT_MAX,
352 [ST_F_TT_MAX] = ST_F_DREQ,
Christopher Fauletf959d082019-02-07 15:38:42 +0100353};
354
355/* Matrix used to dump server metrics. Each metric points to the next one to be
356 * processed or 0 to stop the dump. */
357const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = {
358 [ST_F_PXNAME] = ST_F_STATUS,
359 [ST_F_SVNAME] = 0,
360 [ST_F_QCUR] = ST_F_QMAX,
361 [ST_F_QMAX] = ST_F_QLIMIT,
362 [ST_F_SCUR] = ST_F_SMAX,
363 [ST_F_SMAX] = ST_F_SLIM,
364 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200365 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100366 [ST_F_BIN] = ST_F_BOUT,
367 [ST_F_BOUT] = ST_F_QTIME,
368 [ST_F_DREQ] = 0,
369 [ST_F_DRESP] = ST_F_ECON,
370 [ST_F_EREQ] = 0,
371 [ST_F_ECON] = ST_F_ERESP,
372 [ST_F_ERESP] = ST_F_WRETR,
373 [ST_F_WRETR] = ST_F_WREDIS,
374 [ST_F_WREDIS] = ST_F_WREW,
375 [ST_F_STATUS] = ST_F_SCUR,
Christopher Faulete019d182019-11-21 14:35:46 +0100376 [ST_F_WEIGHT] = ST_F_CHECK_STATUS,
Christopher Fauletf959d082019-02-07 15:38:42 +0100377 [ST_F_ACT] = 0,
378 [ST_F_BCK] = 0,
379 [ST_F_CHKFAIL] = ST_F_CHKDOWN,
380 [ST_F_CHKDOWN] = ST_F_DOWNTIME,
381 [ST_F_LASTCHG] = ST_F_THROTTLE,
382 [ST_F_DOWNTIME] = ST_F_LASTCHG,
383 [ST_F_QLIMIT] = ST_F_BIN,
384 [ST_F_PID] = 0,
385 [ST_F_IID] = 0,
386 [ST_F_SID] = 0,
387 [ST_F_THROTTLE] = ST_F_LBTOT,
388 [ST_F_LBTOT] = ST_F_HRSP_1XX,
389 [ST_F_TRACKED] = 0,
390 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200391 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100392 [ST_F_RATE_LIM] = 0,
393 [ST_F_RATE_MAX] = ST_F_LASTSESS,
Christopher Faulete019d182019-11-21 14:35:46 +0100394 [ST_F_CHECK_STATUS] = ST_F_CHECK_CODE,
Christopher Faulet4ab0efb2020-02-27 16:12:07 +0100395 [ST_F_CHECK_CODE] = ST_F_CHECK_DURATION,
396 [ST_F_CHECK_DURATION] = ST_F_CHKFAIL,
Christopher Fauletf959d082019-02-07 15:38:42 +0100397 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
398 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
399 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
400 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
401 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100402 [ST_F_HRSP_OTHER] = ST_F_SRV_ICUR,
Christopher Fauletf959d082019-02-07 15:38:42 +0100403 [ST_F_HANAFAIL] = 0,
404 [ST_F_REQ_RATE] = 0,
405 [ST_F_REQ_RATE_MAX] = 0,
406 [ST_F_REQ_TOT] = 0,
407 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
408 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
409 [ST_F_COMP_IN] = 0,
410 [ST_F_COMP_OUT] = 0,
411 [ST_F_COMP_BYP] = 0,
412 [ST_F_COMP_RSP] = 0,
413 [ST_F_LASTSESS] = ST_F_QCUR,
414 [ST_F_LAST_CHK] = 0,
415 [ST_F_LAST_AGT] = 0,
416 [ST_F_QTIME] = ST_F_CTIME,
417 [ST_F_CTIME] = ST_F_RTIME,
418 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100419 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100420 [ST_F_AGENT_STATUS] = 0,
421 [ST_F_AGENT_CODE] = 0,
422 [ST_F_AGENT_DURATION] = 0,
423 [ST_F_CHECK_DESC] = 0,
424 [ST_F_AGENT_DESC] = 0,
425 [ST_F_CHECK_RISE] = 0,
426 [ST_F_CHECK_FALL] = 0,
427 [ST_F_CHECK_HEALTH] = 0,
428 [ST_F_AGENT_RISE] = 0,
429 [ST_F_AGENT_FALL] = 0,
430 [ST_F_AGENT_HEALTH] = 0,
431 [ST_F_ADDR] = 0,
432 [ST_F_COOKIE] = 0,
433 [ST_F_MODE] = 0,
434 [ST_F_ALGO] = 0,
435 [ST_F_CONN_RATE] = 0,
436 [ST_F_CONN_RATE_MAX] = 0,
437 [ST_F_CONN_TOT] = 0,
438 [ST_F_INTERCEPTED] = 0,
439 [ST_F_DCON] = 0,
440 [ST_F_DSES] = 0,
441 [ST_F_WREW] = ST_F_CLI_ABRT,
442 [ST_F_CONNECT] = ST_F_REUSE,
443 [ST_F_REUSE] = ST_F_DRESP,
444 [ST_F_CACHE_LOOKUPS] = 0,
445 [ST_F_CACHE_HITS] = 0,
Christopher Fauletbd767f72019-11-08 15:24:32 +0100446 [ST_F_SRV_ICUR] = ST_F_SRV_ILIM,
447 [ST_F_SRV_ILIM] = 0,
Christopher Faulet5df597a2019-11-08 15:05:31 +0100448 [ST_F_QT_MAX] = ST_F_CT_MAX,
449 [ST_F_CT_MAX] = ST_F_RT_MAX,
450 [ST_F_RT_MAX] = ST_F_TT_MAX,
451 [ST_F_TT_MAX] = ST_F_CONNECT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100452};
453
454/* Name of all info fields */
455const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
456 [INF_NAME] = IST("name"),
457 [INF_VERSION] = IST("version"),
458 [INF_RELEASE_DATE] = IST("release_date"),
William Dauchy63495eb2021-01-08 13:18:06 +0100459 [INF_BUILD_INFO] = IST("build_info"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100460 [INF_NBTHREAD] = IST("nbthread"),
461 [INF_NBPROC] = IST("nbproc"),
462 [INF_PROCESS_NUM] = IST("relative_process_id"),
463 [INF_PID] = IST("pid"),
464 [INF_UPTIME] = IST("uptime"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200465 [INF_UPTIME_SEC] = IST("start_time_seconds"),
466 [INF_MEMMAX_MB] = IST("max_memory_bytes"),
467 [INF_POOL_ALLOC_MB] = IST("pool_allocated_bytes"),
468 [INF_POOL_USED_MB] = IST("pool_used_bytes"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100469 [INF_POOL_FAILED] = IST("pool_failures_total"),
470 [INF_ULIMIT_N] = IST("max_fds"),
471 [INF_MAXSOCK] = IST("max_sockets"),
472 [INF_MAXCONN] = IST("max_connections"),
473 [INF_HARD_MAXCONN] = IST("hard_max_connections"),
474 [INF_CURR_CONN] = IST("current_connections"),
475 [INF_CUM_CONN] = IST("connections_total"),
476 [INF_CUM_REQ] = IST("requests_total"),
477 [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"),
478 [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"),
479 [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"),
480 [INF_MAXPIPES] = IST("max_pipes"),
481 [INF_PIPES_USED] = IST("pipes_used_total"),
482 [INF_PIPES_FREE] = IST("pipes_free_total"),
483 [INF_CONN_RATE] = IST("current_connection_rate"),
484 [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"),
485 [INF_MAX_CONN_RATE] = IST("max_connection_rate"),
486 [INF_SESS_RATE] = IST("current_session_rate"),
487 [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"),
488 [INF_MAX_SESS_RATE] = IST("max_session_rate"),
489 [INF_SSL_RATE] = IST("current_ssl_rate"),
490 [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"),
491 [INF_MAX_SSL_RATE] = IST("max_ssl_rate"),
492 [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"),
493 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"),
Pierre Cheynierd1930112020-07-07 19:14:08 +0200494 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontend_ssl_reuse"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100495 [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"),
496 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200497 [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"),
498 [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100499 [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"),
500 [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"),
501 [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"),
502 [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"),
503 [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"),
504 [INF_TASKS] = IST("current_tasks"),
505 [INF_RUN_QUEUE] = IST("current_run_queue"),
506 [INF_IDLE_PCT] = IST("idle_time_percent"),
507 [INF_NODE] = IST("node"),
508 [INF_DESCRIPTION] = IST("description"),
509 [INF_STOPPING] = IST("stopping"),
510 [INF_JOBS] = IST("jobs"),
511 [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"),
512 [INF_LISTENERS] = IST("listeners"),
513 [INF_ACTIVE_PEERS] = IST("active_peers"),
514 [INF_CONNECTED_PEERS] = IST("connected_peers"),
515 [INF_DROPPED_LOGS] = IST("dropped_logs_total"),
516 [INF_BUSY_POLLING] = IST("busy_polling_enabled"),
517};
518
519/* Name of all stats fields */
520const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = {
521 [ST_F_PXNAME] = IST("proxy_name"),
522 [ST_F_SVNAME] = IST("service_name"),
523 [ST_F_QCUR] = IST("current_queue"),
524 [ST_F_QMAX] = IST("max_queue"),
525 [ST_F_SCUR] = IST("current_sessions"),
526 [ST_F_SMAX] = IST("max_sessions"),
527 [ST_F_SLIM] = IST("limit_sessions"),
528 [ST_F_STOT] = IST("sessions_total"),
529 [ST_F_BIN] = IST("bytes_in_total"),
530 [ST_F_BOUT] = IST("bytes_out_total"),
531 [ST_F_DREQ] = IST("requests_denied_total"),
532 [ST_F_DRESP] = IST("responses_denied_total"),
533 [ST_F_EREQ] = IST("request_errors_total"),
534 [ST_F_ECON] = IST("connection_errors_total"),
535 [ST_F_ERESP] = IST("response_errors_total"),
536 [ST_F_WRETR] = IST("retry_warnings_total"),
537 [ST_F_WREDIS] = IST("redispatch_warnings_total"),
538 [ST_F_STATUS] = IST("status"),
539 [ST_F_WEIGHT] = IST("weight"),
540 [ST_F_ACT] = IST("active_servers"),
541 [ST_F_BCK] = IST("backup_servers"),
542 [ST_F_CHKFAIL] = IST("check_failures_total"),
543 [ST_F_CHKDOWN] = IST("check_up_down_total"),
544 [ST_F_LASTCHG] = IST("check_last_change_seconds"),
545 [ST_F_DOWNTIME] = IST("downtime_seconds_total"),
546 [ST_F_QLIMIT] = IST("queue_limit"),
547 [ST_F_PID] = IST("pid"),
548 [ST_F_IID] = IST("proxy_id"),
549 [ST_F_SID] = IST("server_id"),
550 [ST_F_THROTTLE] = IST("current_throttle"),
551 [ST_F_LBTOT] = IST("loadbalanced_total"),
552 [ST_F_TRACKED] = IST("tracked"),
553 [ST_F_TYPE] = IST("type"),
554 [ST_F_RATE] = IST("current_session_rate"),
555 [ST_F_RATE_LIM] = IST("limit_session_rate"),
556 [ST_F_RATE_MAX] = IST("max_session_rate"),
557 [ST_F_CHECK_STATUS] = IST("check_status"),
558 [ST_F_CHECK_CODE] = IST("check_code"),
Christopher Faulet4ab0efb2020-02-27 16:12:07 +0100559 [ST_F_CHECK_DURATION] = IST("check_duration_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100560 [ST_F_HRSP_1XX] = IST("http_responses_total"),
561 [ST_F_HRSP_2XX] = IST("http_responses_total"),
562 [ST_F_HRSP_3XX] = IST("http_responses_total"),
563 [ST_F_HRSP_4XX] = IST("http_responses_total"),
564 [ST_F_HRSP_5XX] = IST("http_responses_total"),
565 [ST_F_HRSP_OTHER] = IST("http_responses_total"),
566 [ST_F_HANAFAIL] = IST("check_analyses_failures_total"),
567 [ST_F_REQ_RATE] = IST("http_requests_rate_current"),
568 [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"),
569 [ST_F_REQ_TOT] = IST("http_requests_total"),
570 [ST_F_CLI_ABRT] = IST("client_aborts_total"),
571 [ST_F_SRV_ABRT] = IST("server_aborts_total"),
572 [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"),
573 [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"),
574 [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"),
575 [ST_F_COMP_RSP] = IST("http_comp_responses_total"),
576 [ST_F_LASTSESS] = IST("last_session_seconds"),
577 [ST_F_LAST_CHK] = IST("check_last_content"),
578 [ST_F_LAST_AGT] = IST("agentcheck_last_content"),
Christopher Faulet3388fd22019-11-08 15:12:29 +0100579 [ST_F_QTIME] = IST("queue_time_average_seconds"),
580 [ST_F_CTIME] = IST("connect_time_average_seconds"),
581 [ST_F_RTIME] = IST("response_time_average_seconds"),
582 [ST_F_TTIME] = IST("total_time_average_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100583 [ST_F_AGENT_STATUS] = IST("agentcheck_status"),
584 [ST_F_AGENT_CODE] = IST("agentcheck_code"),
585 [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"),
586 [ST_F_CHECK_DESC] = IST("check_description"),
587 [ST_F_AGENT_DESC] = IST("agentcheck_description"),
588 [ST_F_CHECK_RISE] = IST("check_rise"),
589 [ST_F_CHECK_FALL] = IST("check_fall"),
590 [ST_F_CHECK_HEALTH] = IST("check_value"),
591 [ST_F_AGENT_RISE] = IST("agentcheck_rise"),
592 [ST_F_AGENT_FALL] = IST("agentcheck_fall"),
593 [ST_F_AGENT_HEALTH] = IST("agentcheck_value"),
594 [ST_F_ADDR] = IST("address"),
595 [ST_F_COOKIE] = IST("cookie"),
596 [ST_F_MODE] = IST("mode"),
597 [ST_F_ALGO] = IST("loadbalance_algorithm"),
598 [ST_F_CONN_RATE] = IST("connections_rate_current"),
599 [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"),
600 [ST_F_CONN_TOT] = IST("connections_total"),
601 [ST_F_INTERCEPTED] = IST("intercepted_requests_total"),
602 [ST_F_DCON] = IST("denied_connections_total"),
603 [ST_F_DSES] = IST("denied_sessions_total"),
604 [ST_F_WREW] = IST("failed_header_rewriting_total"),
605 [ST_F_CONNECT] = IST("connection_attempts_total"),
606 [ST_F_REUSE] = IST("connection_reuses_total"),
607 [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"),
608 [ST_F_CACHE_HITS] = IST("http_cache_hits_total"),
Christopher Fauletbd767f72019-11-08 15:24:32 +0100609 [ST_F_SRV_ICUR] = IST("server_idle_connections_current"),
610 [ST_F_SRV_ILIM] = IST("server_idle_connections_limit"),
Christopher Faulet5df597a2019-11-08 15:05:31 +0100611 [ST_F_QT_MAX] = IST("max_queue_time_seconds"),
612 [ST_F_CT_MAX] = IST("max_connect_time_seconds"),
613 [ST_F_RT_MAX] = IST("max_response_time_seconds"),
614 [ST_F_TT_MAX] = IST("max_total_time_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100615};
616
617/* Description of all info fields */
618const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
619 [INF_NAME] = IST("Product name."),
620 [INF_VERSION] = IST("HAProxy version."),
William Dauchy63495eb2021-01-08 13:18:06 +0100621 [INF_RELEASE_DATE] = IST("HAProxy release date."),
622 [INF_BUILD_INFO] = IST("HAProxy build info."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100623 [INF_NBTHREAD] = IST("Configured number of threads."),
624 [INF_NBPROC] = IST("Configured number of processes."),
625 [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
626 [INF_PID] = IST("HAProxy PID."),
627 [INF_UPTIME] = IST("Uptime in a human readable format."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200628 [INF_UPTIME_SEC] = IST("Start time in seconds."),
629 [INF_MEMMAX_MB] = IST("Per-process memory limit (in bytes); 0=unset."),
630 [INF_POOL_ALLOC_MB] = IST("Total amount of memory allocated in pools (in bytes)."),
631 [INF_POOL_USED_MB] = IST("Total amount of memory used in pools (in bytes)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100632 [INF_POOL_FAILED] = IST("Total number of failed pool allocations."),
633 [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."),
634 [INF_MAXSOCK] = IST("Maximum numer of open sockets."),
635 [INF_MAXCONN] = IST("Maximum number of concurrent connections."),
636 [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."),
637 [INF_CURR_CONN] = IST("Number of active sessions."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200638 [INF_CUM_CONN] = IST("Total number of created sessions."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100639 [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."),
640 [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."),
641 [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."),
642 [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."),
643 [INF_MAXPIPES] = IST("Configured maximum number of pipes."),
644 [INF_PIPES_USED] = IST("Number of pipes in used."),
645 [INF_PIPES_FREE] = IST("Number of pipes unused."),
646 [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."),
647 [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."),
648 [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."),
649 [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."),
650 [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."),
651 [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."),
652 [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."),
653 [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."),
654 [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."),
655 [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."),
656 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."),
657 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."),
658 [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."),
659 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."),
660 [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."),
661 [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."),
662 [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."),
663 [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."),
664 [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."),
665 [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."),
666 [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."),
667 [INF_TASKS] = IST("Current number of tasks."),
668 [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."),
669 [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."),
670 [INF_NODE] = IST("Node name."),
671 [INF_DESCRIPTION] = IST("Node description."),
672 [INF_STOPPING] = IST("Non zero means stopping in progress."),
673 [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."),
674 [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."),
675 [INF_LISTENERS] = IST("Current number of active listeners."),
676 [INF_ACTIVE_PEERS] = IST("Current number of active peers."),
677 [INF_CONNECTED_PEERS] = IST("Current number of connected peers."),
678 [INF_DROPPED_LOGS] = IST("Total number of dropped logs."),
679 [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."),
680};
681
682/* Description of all stats fields */
683const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
684 [ST_F_PXNAME] = IST("The proxy name."),
685 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
686 [ST_F_QCUR] = IST("Current number of queued requests."),
687 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
688 [ST_F_SCUR] = IST("Current number of active sessions."),
689 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
690 [ST_F_SLIM] = IST("Configured session limit."),
691 [ST_F_STOT] = IST("Total number of sessions."),
692 [ST_F_BIN] = IST("Current total of incoming bytes."),
693 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
694 [ST_F_DREQ] = IST("Total number of denied requests."),
695 [ST_F_DRESP] = IST("Total number of denied responses."),
696 [ST_F_EREQ] = IST("Total number of request errors."),
697 [ST_F_ECON] = IST("Total number of connection errors."),
698 [ST_F_ERESP] = IST("Total number of response errors."),
699 [ST_F_WRETR] = IST("Total number of retry warnings."),
700 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Christopher Faulet8e40fa22019-09-06 16:10:19 +0200701 [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 +0100702 [ST_F_WEIGHT] = IST("Service weight."),
703 [ST_F_ACT] = IST("Current number of active servers."),
704 [ST_F_BCK] = IST("Current number of backup servers."),
705 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
706 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
707 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
708 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
709 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
710 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
711 [ST_F_IID] = IST("Unique proxy id."),
712 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
713 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
714 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
715 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
716 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
717 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
718 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
719 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
Christopher Faulete019d182019-11-21 14:35:46 +0100720 [ST_F_CHECK_STATUS] = IST("Status of last health check (HCHK_STATUS_* values)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100721 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
Christopher Faulet4ab0efb2020-02-27 16:12:07 +0100722 [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100723 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
724 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
725 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
726 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
727 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
728 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
729 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
730 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
731 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
732 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
733 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
734 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
735 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
736 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
737 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
738 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
739 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
740 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
741 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
742 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
743 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
744 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
745 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
746 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
747 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
748 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
749 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
750 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
751 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
752 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
753 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
754 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
755 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
756 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
757 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
758 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
759 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
760 [ST_F_ALGO] = IST("Load balancing algorithm."),
761 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
762 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
763 [ST_F_CONN_TOT] = IST("Total number of connections."),
764 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
765 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
766 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
767 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
768 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
769 [ST_F_REUSE] = IST("Total number of connection reuses."),
770 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
771 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Fauletbd767f72019-11-08 15:24:32 +0100772 [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"),
773 [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"),
Christopher Faulet5df597a2019-11-08 15:05:31 +0100774 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
775 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
776 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
777 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100778};
779
780/* Specific labels for all info fields. Empty by default. */
781const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
782 [INF_NAME] = IST(""),
783 [INF_VERSION] = IST(""),
784 [INF_RELEASE_DATE] = IST(""),
William Dauchy63495eb2021-01-08 13:18:06 +0100785 [INF_BUILD_INFO] = IST(PROMEX_BUILDINFO_LABEL),
Christopher Fauletf959d082019-02-07 15:38:42 +0100786 [INF_NBTHREAD] = IST(""),
787 [INF_NBPROC] = IST(""),
788 [INF_PROCESS_NUM] = IST(""),
789 [INF_PID] = IST(""),
790 [INF_UPTIME] = IST(""),
791 [INF_UPTIME_SEC] = IST(""),
792 [INF_MEMMAX_MB] = IST(""),
793 [INF_POOL_ALLOC_MB] = IST(""),
794 [INF_POOL_USED_MB] = IST(""),
795 [INF_POOL_FAILED] = IST(""),
796 [INF_ULIMIT_N] = IST(""),
797 [INF_MAXSOCK] = IST(""),
798 [INF_MAXCONN] = IST(""),
799 [INF_HARD_MAXCONN] = IST(""),
800 [INF_CURR_CONN] = IST(""),
801 [INF_CUM_CONN] = IST(""),
802 [INF_CUM_REQ] = IST(""),
803 [INF_MAX_SSL_CONNS] = IST(""),
804 [INF_CURR_SSL_CONNS] = IST(""),
805 [INF_CUM_SSL_CONNS] = IST(""),
806 [INF_MAXPIPES] = IST(""),
807 [INF_PIPES_USED] = IST(""),
808 [INF_PIPES_FREE] = IST(""),
809 [INF_CONN_RATE] = IST(""),
810 [INF_CONN_RATE_LIMIT] = IST(""),
811 [INF_MAX_CONN_RATE] = IST(""),
812 [INF_SESS_RATE] = IST(""),
813 [INF_SESS_RATE_LIMIT] = IST(""),
814 [INF_MAX_SESS_RATE] = IST(""),
815 [INF_SSL_RATE] = IST(""),
816 [INF_SSL_RATE_LIMIT] = IST(""),
817 [INF_MAX_SSL_RATE] = IST(""),
818 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
819 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
820 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
821 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
822 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
823 [INF_SSL_CACHE_LOOKUPS] = IST(""),
824 [INF_SSL_CACHE_MISSES] = IST(""),
825 [INF_COMPRESS_BPS_IN] = IST(""),
826 [INF_COMPRESS_BPS_OUT] = IST(""),
827 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
828 [INF_ZLIB_MEM_USAGE] = IST(""),
829 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
830 [INF_TASKS] = IST(""),
831 [INF_RUN_QUEUE] = IST(""),
832 [INF_IDLE_PCT] = IST(""),
833 [INF_NODE] = IST(""),
834 [INF_DESCRIPTION] = IST(""),
835 [INF_STOPPING] = IST(""),
836 [INF_JOBS] = IST(""),
837 [INF_UNSTOPPABLE_JOBS] = IST(""),
838 [INF_LISTENERS] = IST(""),
839 [INF_ACTIVE_PEERS] = IST(""),
840 [INF_CONNECTED_PEERS] = IST(""),
841 [INF_DROPPED_LOGS] = IST(""),
842 [INF_BUSY_POLLING] = IST(""),
843};
844
845/* Specific labels for all stats fields. Empty by default. */
846const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
847 [ST_F_PXNAME] = IST(""),
848 [ST_F_SVNAME] = IST(""),
849 [ST_F_QCUR] = IST(""),
850 [ST_F_QMAX] = IST(""),
851 [ST_F_SCUR] = IST(""),
852 [ST_F_SMAX] = IST(""),
853 [ST_F_SLIM] = IST(""),
854 [ST_F_STOT] = IST(""),
855 [ST_F_BIN] = IST(""),
856 [ST_F_BOUT] = IST(""),
857 [ST_F_DREQ] = IST(""),
858 [ST_F_DRESP] = IST(""),
859 [ST_F_EREQ] = IST(""),
860 [ST_F_ECON] = IST(""),
861 [ST_F_ERESP] = IST(""),
862 [ST_F_WRETR] = IST(""),
863 [ST_F_WREDIS] = IST(""),
864 [ST_F_STATUS] = IST(""),
865 [ST_F_WEIGHT] = IST(""),
866 [ST_F_ACT] = IST(""),
867 [ST_F_BCK] = IST(""),
868 [ST_F_CHKFAIL] = IST(""),
869 [ST_F_CHKDOWN] = IST(""),
870 [ST_F_LASTCHG] = IST(""),
871 [ST_F_DOWNTIME] = IST(""),
872 [ST_F_QLIMIT] = IST(""),
873 [ST_F_PID] = IST(""),
874 [ST_F_IID] = IST(""),
875 [ST_F_SID] = IST(""),
876 [ST_F_THROTTLE] = IST(""),
877 [ST_F_LBTOT] = IST(""),
878 [ST_F_TRACKED] = IST(""),
879 [ST_F_TYPE] = IST(""),
880 [ST_F_RATE] = IST(""),
881 [ST_F_RATE_LIM] = IST(""),
882 [ST_F_RATE_MAX] = IST(""),
883 [ST_F_CHECK_STATUS] = IST(""),
884 [ST_F_CHECK_CODE] = IST(""),
885 [ST_F_CHECK_DURATION] = IST(""),
886 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
887 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
888 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
889 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
890 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
891 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
892 [ST_F_HANAFAIL] = IST(""),
893 [ST_F_REQ_RATE] = IST(""),
894 [ST_F_REQ_RATE_MAX] = IST(""),
895 [ST_F_REQ_TOT] = IST(""),
896 [ST_F_CLI_ABRT] = IST(""),
897 [ST_F_SRV_ABRT] = IST(""),
898 [ST_F_COMP_IN] = IST(""),
899 [ST_F_COMP_OUT] = IST(""),
900 [ST_F_COMP_BYP] = IST(""),
901 [ST_F_COMP_RSP] = IST(""),
902 [ST_F_LASTSESS] = IST(""),
903 [ST_F_LAST_CHK] = IST(""),
904 [ST_F_LAST_AGT] = IST(""),
905 [ST_F_QTIME] = IST(""),
906 [ST_F_CTIME] = IST(""),
907 [ST_F_RTIME] = IST(""),
908 [ST_F_TTIME] = IST(""),
909 [ST_F_AGENT_STATUS] = IST(""),
910 [ST_F_AGENT_CODE] = IST(""),
911 [ST_F_AGENT_DURATION] = IST(""),
912 [ST_F_CHECK_DESC] = IST(""),
913 [ST_F_AGENT_DESC] = IST(""),
914 [ST_F_CHECK_RISE] = IST(""),
915 [ST_F_CHECK_FALL] = IST(""),
916 [ST_F_CHECK_HEALTH] = IST(""),
917 [ST_F_AGENT_RISE] = IST(""),
918 [ST_F_AGENT_FALL] = IST(""),
919 [ST_F_AGENT_HEALTH] = IST(""),
920 [ST_F_ADDR] = IST(""),
921 [ST_F_COOKIE] = IST(""),
922 [ST_F_MODE] = IST(""),
923 [ST_F_ALGO] = IST(""),
924 [ST_F_CONN_RATE] = IST(""),
925 [ST_F_CONN_RATE_MAX] = IST(""),
926 [ST_F_CONN_TOT] = IST(""),
927 [ST_F_INTERCEPTED] = IST(""),
928 [ST_F_DCON] = IST(""),
929 [ST_F_DSES] = IST(""),
930 [ST_F_WREW] = IST(""),
931 [ST_F_CONNECT] = IST(""),
932 [ST_F_REUSE] = IST(""),
933 [ST_F_CACHE_LOOKUPS] = IST(""),
934 [ST_F_CACHE_HITS] = IST(""),
935};
936
937/* Type for all info fields. "untyped" is used for unsupported field. */
938const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
939 [INF_NAME] = IST("untyped"),
940 [INF_VERSION] = IST("untyped"),
941 [INF_RELEASE_DATE] = IST("untyped"),
William Dauchy63495eb2021-01-08 13:18:06 +0100942 [INF_BUILD_INFO] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200943 [INF_NBTHREAD] = IST("gauge"),
944 [INF_NBPROC] = IST("gauge"),
945 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100946 [INF_PID] = IST("untyped"),
947 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200948 [INF_UPTIME_SEC] = IST("gauge"),
949 [INF_MEMMAX_MB] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100950 [INF_POOL_ALLOC_MB] = IST("gauge"),
951 [INF_POOL_USED_MB] = IST("gauge"),
952 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200953 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100954 [INF_MAXSOCK] = IST("gauge"),
955 [INF_MAXCONN] = IST("gauge"),
956 [INF_HARD_MAXCONN] = IST("gauge"),
957 [INF_CURR_CONN] = IST("gauge"),
958 [INF_CUM_CONN] = IST("counter"),
959 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200960 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100961 [INF_CURR_SSL_CONNS] = IST("gauge"),
962 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200963 [INF_MAXPIPES] = IST("gauge"),
964 [INF_PIPES_USED] = IST("counter"),
965 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100966 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200967 [INF_CONN_RATE_LIMIT] = IST("gauge"),
968 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100969 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200970 [INF_SESS_RATE_LIMIT] = IST("gauge"),
971 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100972 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200973 [INF_SSL_RATE_LIMIT] = IST("gauge"),
974 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100975 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200976 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100977 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
978 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200979 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100980 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
981 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200982 [INF_COMPRESS_BPS_IN] = IST("counter"),
983 [INF_COMPRESS_BPS_OUT] = IST("counter"),
984 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100985 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200986 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100987 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +0200988 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100989 [INF_IDLE_PCT] = IST("gauge"),
990 [INF_NODE] = IST("untyped"),
991 [INF_DESCRIPTION] = IST("untyped"),
992 [INF_STOPPING] = IST("gauge"),
993 [INF_JOBS] = IST("gauge"),
994 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
995 [INF_LISTENERS] = IST("gauge"),
996 [INF_ACTIVE_PEERS] = IST("gauge"),
997 [INF_CONNECTED_PEERS] = IST("gauge"),
998 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200999 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001000};
1001
1002/* Type for all stats fields. "untyped" is used for unsupported field. */
1003const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
1004 [ST_F_PXNAME] = IST("untyped"),
1005 [ST_F_SVNAME] = IST("untyped"),
1006 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001007 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001008 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001009 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001010 [ST_F_SLIM] = IST("gauge"),
1011 [ST_F_STOT] = IST("counter"),
1012 [ST_F_BIN] = IST("counter"),
1013 [ST_F_BOUT] = IST("counter"),
1014 [ST_F_DREQ] = IST("counter"),
1015 [ST_F_DRESP] = IST("counter"),
1016 [ST_F_EREQ] = IST("counter"),
1017 [ST_F_ECON] = IST("counter"),
1018 [ST_F_ERESP] = IST("counter"),
1019 [ST_F_WRETR] = IST("counter"),
1020 [ST_F_WREDIS] = IST("counter"),
1021 [ST_F_STATUS] = IST("gauge"),
1022 [ST_F_WEIGHT] = IST("gauge"),
1023 [ST_F_ACT] = IST("gauge"),
1024 [ST_F_BCK] = IST("gauge"),
1025 [ST_F_CHKFAIL] = IST("counter"),
1026 [ST_F_CHKDOWN] = IST("counter"),
1027 [ST_F_LASTCHG] = IST("gauge"),
1028 [ST_F_DOWNTIME] = IST("counter"),
1029 [ST_F_QLIMIT] = IST("gauge"),
1030 [ST_F_PID] = IST("untyped"),
1031 [ST_F_IID] = IST("untyped"),
1032 [ST_F_SID] = IST("untyped"),
1033 [ST_F_THROTTLE] = IST("gauge"),
1034 [ST_F_LBTOT] = IST("counter"),
1035 [ST_F_TRACKED] = IST("untyped"),
1036 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001037 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001038 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001039 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Faulete019d182019-11-21 14:35:46 +01001040 [ST_F_CHECK_STATUS] = IST("gauge"),
1041 [ST_F_CHECK_CODE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001042 [ST_F_CHECK_DURATION] = IST("gauge"),
1043 [ST_F_HRSP_1XX] = IST("counter"),
1044 [ST_F_HRSP_2XX] = IST("counter"),
1045 [ST_F_HRSP_3XX] = IST("counter"),
1046 [ST_F_HRSP_4XX] = IST("counter"),
1047 [ST_F_HRSP_5XX] = IST("counter"),
1048 [ST_F_HRSP_OTHER] = IST("counter"),
1049 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001050 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001051 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001052 [ST_F_REQ_TOT] = IST("counter"),
1053 [ST_F_CLI_ABRT] = IST("counter"),
1054 [ST_F_SRV_ABRT] = IST("counter"),
1055 [ST_F_COMP_IN] = IST("counter"),
1056 [ST_F_COMP_OUT] = IST("counter"),
1057 [ST_F_COMP_BYP] = IST("counter"),
1058 [ST_F_COMP_RSP] = IST("counter"),
1059 [ST_F_LASTSESS] = IST("gauge"),
1060 [ST_F_LAST_CHK] = IST("untyped"),
1061 [ST_F_LAST_AGT] = IST("untyped"),
1062 [ST_F_QTIME] = IST("gauge"),
1063 [ST_F_CTIME] = IST("gauge"),
1064 [ST_F_RTIME] = IST("gauge"),
1065 [ST_F_TTIME] = IST("gauge"),
1066 [ST_F_AGENT_STATUS] = IST("untyped"),
1067 [ST_F_AGENT_CODE] = IST("untyped"),
1068 [ST_F_AGENT_DURATION] = IST("gauge"),
1069 [ST_F_CHECK_DESC] = IST("untyped"),
1070 [ST_F_AGENT_DESC] = IST("untyped"),
1071 [ST_F_CHECK_RISE] = IST("gauge"),
1072 [ST_F_CHECK_FALL] = IST("gauge"),
1073 [ST_F_CHECK_HEALTH] = IST("gauge"),
1074 [ST_F_AGENT_RISE] = IST("gauge"),
1075 [ST_F_AGENT_FALL] = IST("gauge"),
1076 [ST_F_AGENT_HEALTH] = IST("gauge"),
1077 [ST_F_ADDR] = IST("untyped"),
1078 [ST_F_COOKIE] = IST("untyped"),
1079 [ST_F_MODE] = IST("untyped"),
1080 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001081 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001082 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001083 [ST_F_CONN_TOT] = IST("counter"),
1084 [ST_F_INTERCEPTED] = IST("counter"),
1085 [ST_F_DCON] = IST("counter"),
1086 [ST_F_DSES] = IST("counter"),
1087 [ST_F_WREW] = IST("counter"),
1088 [ST_F_CONNECT] = IST("counter"),
1089 [ST_F_REUSE] = IST("counter"),
1090 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1091 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Fauletbd767f72019-11-08 15:24:32 +01001092 [ST_F_SRV_ICUR] = IST("gauge"),
1093 [ST_F_SRV_ILIM] = IST("gauge"),
Christopher Faulet5df597a2019-11-08 15:05:31 +01001094 [ST_F_QT_MAX] = IST("gauge"),
1095 [ST_F_CT_MAX] = IST("gauge"),
1096 [ST_F_RT_MAX] = IST("gauge"),
1097 [ST_F_TT_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001098};
1099
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001100/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001101static int promex_srv_status(struct server *sv)
1102{
Christopher Fauletf959d082019-02-07 15:38:42 +01001103 int state = 0;
1104
Christopher Fauletf959d082019-02-07 15:38:42 +01001105 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1106 state = 1;
1107 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001108 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001109 }
Christopher Faulet8e40fa22019-09-06 16:10:19 +02001110 else if (sv->cur_state == SRV_ST_STOPPING)
1111 state = 4;
1112
1113 if (sv->cur_admin & SRV_ADMF_MAINT)
1114 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001115
1116 return state;
1117}
1118
1119/* Convert a field to its string representation and write it in <out>, followed
1120 * by a newline, if there is enough space. non-numeric value are converted in
1121 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1122 * to process this kind of value). It returns 1 on success. Otherwise, it
1123 * returns 0. The buffer's length must not exceed <max> value.
1124 */
1125static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1126{
1127 int ret = 0;
1128
1129 switch (field_format(f, 0)) {
1130 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1131 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1132 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1133 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1134 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Faulete86bf652019-09-24 16:35:19 +02001135 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001136 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1137 default: ret = chunk_strcat(out, "Nan\n"); break;
1138 }
1139 if (!ret || out->data > max)
1140 return 0;
1141 return 1;
1142}
1143
1144/* Concatenate the <prefix> with the field name using the array
1145 * <promex_st_metric_names> and store it in <name>. The field type is in
1146 * <appctx->st2>. This function never fails but relies on
1147 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enougth to be copied in
1148 * <name>
1149 */
1150static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1151{
1152 const struct ist *names;
1153
1154 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1155 ? promex_inf_metric_names
1156 : promex_st_metric_names);
1157
1158 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1159 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1160}
1161
1162/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1163 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1164 */
1165static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1166 const struct ist name, struct ist *out, size_t max)
1167{
1168 const struct ist *desc, *types;
1169
1170 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1171 desc = promex_inf_metric_desc;
1172 types = promex_inf_metric_types;
1173 }
1174 else {
1175 desc = promex_st_metric_desc;
1176 types = promex_st_metric_types;
1177 }
1178
Anthonin Bonnefoydd4e4ef2019-08-07 17:45:25 +02001179 if (istcat(out, ist("# HELP "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001180 istcat(out, name, max) == -1 ||
1181 istcat(out, ist(" "), max) == -1 ||
1182 istcat(out, desc[appctx->st2], max) == -1 ||
Anthonin Bonnefoydd4e4ef2019-08-07 17:45:25 +02001183 istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001184 istcat(out, name, max) == -1 ||
1185 istcat(out, ist(" "), max) == -1 ||
1186 istcat(out, types[appctx->st2], max) == -1 ||
1187 istcat(out, ist("\n"), max) == -1)
1188 goto full;
1189
1190 return 1;
1191
1192 full:
1193 return 0;
1194}
1195
1196/* Dump the line for <metric>. It starts by the metric name followed by its
1197 * labels (proxy name, server name...) between braces and finally its value. If
1198 * not already done, the header lines are dumped first. It returns 1 on
1199 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1200 */
1201static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1202 const struct ist prefix, struct field *metric,
1203 struct ist *out, size_t max)
1204{
1205 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1206 size_t len = out->len;
1207
1208 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1209 return 0;
1210
1211 promex_metric_name(appctx, &name, prefix);
1212 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1213 !promex_dump_metric_header(appctx, htx, name, out, max))
1214 goto full;
1215
1216 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1217 const struct ist label = promex_inf_metric_labels[appctx->st2];
1218
1219 if (istcat(out, name, max) == -1 ||
1220 (label.len && istcat(out, ist("{"), max) == -1) ||
1221 (label.len && istcat(out, label, max) == -1) ||
1222 (label.len && istcat(out, ist("}"), max) == -1) ||
1223 istcat(out, ist(" "), max) == -1)
1224 goto full;
1225 }
1226 else {
1227 struct proxy *px = appctx->ctx.stats.px;
1228 struct server *srv = appctx->ctx.stats.sv;
1229 const struct ist label = promex_st_metric_labels[appctx->st2];
1230
1231 if (istcat(out, name, max) == -1 ||
1232 istcat(out, ist("{proxy=\""), max) == -1 ||
1233 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1234 istcat(out, ist("\""), max) == -1 ||
1235 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1236 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1237 (srv && istcat(out, ist("\""), max) == -1) ||
1238 (label.len && istcat(out, ist(","), max) == -1) ||
1239 (label.len && istcat(out, label, max) == -1) ||
1240 istcat(out, ist("} "), max) == -1)
1241 goto full;
1242 }
1243
1244 trash.data = out->len;
1245 if (!promex_metric_to_str(&trash, metric, max))
1246 goto full;
1247 out->len = trash.data;
1248
1249 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1250 return 1;
1251 full:
1252 // Restore previous length
1253 out->len = len;
1254 return 0;
1255
1256}
1257
1258
1259/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on sucess,
1260 * 0 if <htx> is full and -1 in case of any error. */
1261static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1262{
1263 static struct ist prefix = IST("haproxy_process_");
1264 struct field metric;
1265 struct channel *chn = si_ic(appctx->owner);
1266 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001267 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001268 int ret = 1;
1269
1270#ifdef USE_OPENSSL
1271 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
1272 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
1273 int ssl_reuse = 0;
1274
1275 if (ssl_key_rate < ssl_sess_rate) {
1276 /* count the ssl reuse ratio and avoid overflows in both directions */
1277 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
1278 }
1279#endif
Christopher Fauletf959d082019-02-07 15:38:42 +01001280 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1281 switch (appctx->st2) {
William Dauchy63495eb2021-01-08 13:18:06 +01001282 case INF_BUILD_INFO:
1283 metric = mkf_u32(FN_GAUGE, 1);
1284 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001285 case INF_NBTHREAD:
1286 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
1287 break;
1288 case INF_NBPROC:
1289 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
1290 break;
1291 case INF_PROCESS_NUM:
1292 metric = mkf_u32(FO_KEY, relative_pid);
1293 break;
1294 case INF_UPTIME_SEC:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001295 metric = mkf_u32(FN_DURATION, start_date.tv_sec);
Christopher Fauletf959d082019-02-07 15:38:42 +01001296 break;
1297 case INF_MEMMAX_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001298 metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
Christopher Fauletf959d082019-02-07 15:38:42 +01001299 break;
1300 case INF_POOL_ALLOC_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001301 metric = mkf_u64(0, pool_total_allocated());
Christopher Fauletf959d082019-02-07 15:38:42 +01001302 break;
1303 case INF_POOL_USED_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001304 metric = mkf_u64(0, pool_total_used());
Christopher Fauletf959d082019-02-07 15:38:42 +01001305 break;
1306 case INF_POOL_FAILED:
1307 metric = mkf_u32(FN_COUNTER, pool_total_failures());
1308 break;
1309 case INF_ULIMIT_N:
1310 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
1311 break;
1312 case INF_MAXSOCK:
1313 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
1314 break;
1315 case INF_MAXCONN:
1316 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
1317 break;
1318 case INF_HARD_MAXCONN:
1319 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
1320 break;
1321 case INF_CURR_CONN:
1322 metric = mkf_u32(0, actconn);
1323 break;
1324 case INF_CUM_CONN:
1325 metric = mkf_u32(FN_COUNTER, totalconn);
1326 break;
1327 case INF_CUM_REQ:
1328 metric = mkf_u32(FN_COUNTER, global.req_count);
1329 break;
1330#ifdef USE_OPENSSL
1331 case INF_MAX_SSL_CONNS:
1332 metric = mkf_u32(FN_MAX, global.maxsslconn);
1333 break;
1334 case INF_CURR_SSL_CONNS:
1335 metric = mkf_u32(0, sslconns);
1336 break;
1337 case INF_CUM_SSL_CONNS:
1338 metric = mkf_u32(FN_COUNTER, totalsslconns);
1339 break;
1340#endif
1341 case INF_MAXPIPES:
1342 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
1343 break;
1344 case INF_PIPES_USED:
1345 metric = mkf_u32(0, pipes_used);
1346 break;
1347 case INF_PIPES_FREE:
1348 metric = mkf_u32(0, pipes_free);
1349 break;
1350 case INF_CONN_RATE:
1351 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
1352 break;
1353 case INF_CONN_RATE_LIMIT:
1354 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
1355 break;
1356 case INF_MAX_CONN_RATE:
1357 metric = mkf_u32(FN_MAX, global.cps_max);
1358 break;
1359 case INF_SESS_RATE:
1360 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
1361 break;
1362 case INF_SESS_RATE_LIMIT:
1363 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
1364 break;
1365 case INF_MAX_SESS_RATE:
1366 metric = mkf_u32(FN_RATE, global.sps_max);
1367 break;
1368#ifdef USE_OPENSSL
1369 case INF_SSL_RATE:
1370 metric = mkf_u32(FN_RATE, ssl_sess_rate);
1371 break;
1372 case INF_SSL_RATE_LIMIT:
1373 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
1374 break;
1375 case INF_MAX_SSL_RATE:
1376 metric = mkf_u32(FN_MAX, global.ssl_max);
1377 break;
1378 case INF_SSL_FRONTEND_KEY_RATE:
1379 metric = mkf_u32(0, ssl_key_rate);
1380 break;
1381 case INF_SSL_FRONTEND_MAX_KEY_RATE:
1382 metric = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
1383 break;
1384 case INF_SSL_FRONTEND_SESSION_REUSE_PCT:
1385 metric = mkf_u32(0, ssl_reuse);
1386 break;
1387 case INF_SSL_BACKEND_KEY_RATE:
1388 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
1389 break;
1390 case INF_SSL_BACKEND_MAX_KEY_RATE:
1391 metric = mkf_u32(FN_MAX, global.ssl_be_keys_max);
1392 break;
1393 case INF_SSL_CACHE_LOOKUPS:
1394 metric = mkf_u32(FN_COUNTER, global.shctx_lookups);
1395 break;
1396 case INF_SSL_CACHE_MISSES:
1397 metric = mkf_u32(FN_COUNTER, global.shctx_misses);
1398 break;
1399#endif
1400 case INF_COMPRESS_BPS_IN:
1401 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
1402 break;
1403 case INF_COMPRESS_BPS_OUT:
1404 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
1405 break;
1406 case INF_COMPRESS_BPS_RATE_LIM:
1407 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
1408 break;
1409#ifdef USE_ZLIB
1410 case INF_ZLIB_MEM_USAGE:
1411 metric = mkf_u32(0, zlib_used_memory);
1412 break;
1413 case INF_MAX_ZLIB_MEM_USAGE:
1414 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
1415 break;
1416#endif
1417 case INF_TASKS:
1418 metric = mkf_u32(0, nb_tasks_cur);
1419 break;
1420 case INF_RUN_QUEUE:
1421 metric = mkf_u32(0, tasks_run_queue_cur);
1422 break;
1423 case INF_IDLE_PCT:
Willy Tarreau76824a82019-06-02 10:38:48 +02001424 metric = mkf_u32(FN_AVG, ti->idle_pct);
Christopher Fauletf959d082019-02-07 15:38:42 +01001425 break;
1426 case INF_STOPPING:
1427 metric = mkf_u32(0, stopping);
1428 break;
1429 case INF_JOBS:
1430 metric = mkf_u32(0, jobs);
1431 break;
1432 case INF_UNSTOPPABLE_JOBS:
1433 metric = mkf_u32(0, unstoppable_jobs);
1434 break;
1435 case INF_LISTENERS:
1436 metric = mkf_u32(0, listeners);
1437 break;
1438 case INF_ACTIVE_PEERS:
1439 metric = mkf_u32(0, active_peers);
1440 break;
1441 case INF_CONNECTED_PEERS:
1442 metric = mkf_u32(0, connected_peers);
1443 break;
1444 case INF_DROPPED_LOGS:
1445 metric = mkf_u32(0, dropped_logs);
1446 break;
1447 case INF_BUSY_POLLING:
1448 metric = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
1449 break;
1450
1451 default:
1452 goto next_metric;
1453 }
1454
1455 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1456 goto full;
1457
1458 next_metric:
1459 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1460 appctx->st2 = promex_global_metrics[appctx->st2];
1461 }
1462
1463 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001464 if (out.len) {
1465 if (!htx_add_data_atonce(htx, out))
1466 return -1; /* Unexpected and unrecoverable error */
1467 channel_add_input(chn, out.len);
1468 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001469 return ret;
1470 full:
1471 ret = 0;
1472 goto end;
1473}
1474
1475/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on sucess,
1476 * 0 if <htx> is full and -1 in case of any error. */
1477static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1478{
1479 static struct ist prefix = IST("haproxy_frontend_");
1480 struct proxy *px;
1481 struct field metric;
1482 struct channel *chn = si_ic(appctx->owner);
1483 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001484 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001485 int ret = 1;
1486
1487 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1488 while (appctx->ctx.stats.px) {
1489 px = appctx->ctx.stats.px;
1490
1491 /* skip the disabled proxies, global frontend and non-networked ones */
1492 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
1493 goto next_px;
1494
1495 switch (appctx->st2) {
1496 case ST_F_STATUS:
1497 metric = mkf_u32(FO_STATUS, px->state == PR_STREADY ? 1 : px->state == PR_STFULL ? 2 : 0);
1498 break;
1499 case ST_F_SCUR:
1500 metric = mkf_u32(0, px->feconn);
1501 break;
1502 case ST_F_SMAX:
1503 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1504 break;
1505 case ST_F_SLIM:
1506 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1507 break;
1508 case ST_F_STOT:
1509 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1510 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001511 case ST_F_RATE_LIM:
1512 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1513 break;
1514 case ST_F_RATE_MAX:
1515 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1516 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001517 case ST_F_CONN_RATE_MAX:
1518 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1519 break;
1520 case ST_F_CONN_TOT:
1521 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1522 break;
1523 case ST_F_BIN:
1524 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1525 break;
1526 case ST_F_BOUT:
1527 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1528 break;
1529 case ST_F_DREQ:
1530 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1531 break;
1532 case ST_F_DRESP:
1533 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1534 break;
1535 case ST_F_EREQ:
1536 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1537 break;
1538 case ST_F_DCON:
1539 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1540 break;
1541 case ST_F_DSES:
1542 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1543 break;
1544 case ST_F_WREW:
1545 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1546 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001547 case ST_F_REQ_RATE_MAX:
1548 if (px->mode != PR_MODE_HTTP)
1549 goto next_px;
1550 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1551 break;
1552 case ST_F_REQ_TOT:
1553 if (px->mode != PR_MODE_HTTP)
1554 goto next_px;
1555 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1556 break;
1557 case ST_F_HRSP_1XX:
1558 if (px->mode != PR_MODE_HTTP)
1559 goto next_px;
1560 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1561 break;
1562 case ST_F_HRSP_2XX:
1563 if (px->mode != PR_MODE_HTTP)
1564 goto next_px;
1565 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1566 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1567 break;
1568 case ST_F_HRSP_3XX:
1569 if (px->mode != PR_MODE_HTTP)
1570 goto next_px;
1571 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1572 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1573 break;
1574 case ST_F_HRSP_4XX:
1575 if (px->mode != PR_MODE_HTTP)
1576 goto next_px;
1577 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1578 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1579 break;
1580 case ST_F_HRSP_5XX:
1581 if (px->mode != PR_MODE_HTTP)
1582 goto next_px;
1583 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1584 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1585 break;
1586 case ST_F_HRSP_OTHER:
1587 if (px->mode != PR_MODE_HTTP)
1588 goto next_px;
1589 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1590 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1591 break;
1592 case ST_F_INTERCEPTED:
1593 if (px->mode != PR_MODE_HTTP)
1594 goto next_px;
1595 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1596 break;
1597 case ST_F_CACHE_LOOKUPS:
1598 if (px->mode != PR_MODE_HTTP)
1599 goto next_px;
1600 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1601 break;
1602 case ST_F_CACHE_HITS:
1603 if (px->mode != PR_MODE_HTTP)
1604 goto next_px;
1605 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1606 break;
1607 case ST_F_COMP_IN:
1608 if (px->mode != PR_MODE_HTTP)
1609 goto next_px;
1610 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1611 break;
1612 case ST_F_COMP_OUT:
1613 if (px->mode != PR_MODE_HTTP)
1614 goto next_px;
1615 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1616 break;
1617 case ST_F_COMP_BYP:
1618 if (px->mode != PR_MODE_HTTP)
1619 goto next_px;
1620 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1621 break;
1622 case ST_F_COMP_RSP:
1623 if (px->mode != PR_MODE_HTTP)
1624 goto next_px;
1625 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1626 break;
1627
1628 default:
1629 goto next_metric;
1630 }
1631
1632 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1633 goto full;
1634 next_px:
1635 appctx->ctx.stats.px = px->next;
1636 }
1637 next_metric:
1638 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1639 appctx->ctx.stats.px = proxies_list;
1640 appctx->st2 = promex_front_metrics[appctx->st2];
1641 }
1642
1643 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001644 if (out.len) {
1645 if (!htx_add_data_atonce(htx, out))
1646 return -1; /* Unexpected and unrecoverable error */
1647 channel_add_input(chn, out.len);
1648 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001649 return ret;
1650 full:
1651 ret = 0;
1652 goto end;
1653}
1654
1655/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on sucess,
1656 * 0 if <htx> is full and -1 in case of any error. */
1657static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1658{
1659 static struct ist prefix = IST("haproxy_backend_");
1660 struct proxy *px;
1661 struct field metric;
1662 struct channel *chn = si_ic(appctx->owner);
1663 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001664 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001665 int ret = 1;
1666 uint32_t weight;
Christopher Faulete86bf652019-09-24 16:35:19 +02001667 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001668
1669 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1670 while (appctx->ctx.stats.px) {
1671 px = appctx->ctx.stats.px;
1672
1673 /* skip the disabled proxies, global frontend and non-networked ones */
1674 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1675 goto next_px;
1676
1677 switch (appctx->st2) {
1678 case ST_F_STATUS:
1679 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1680 break;
1681 case ST_F_SCUR:
1682 metric = mkf_u32(0, px->beconn);
1683 break;
1684 case ST_F_SMAX:
1685 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1686 break;
1687 case ST_F_SLIM:
1688 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1689 break;
1690 case ST_F_STOT:
1691 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1692 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001693 case ST_F_RATE_MAX:
1694 metric = mkf_u32(0, px->be_counters.sps_max);
1695 break;
1696 case ST_F_LASTSESS:
1697 metric = mkf_s32(FN_AGE, be_lastsession(px));
1698 break;
1699 case ST_F_QCUR:
1700 metric = mkf_u32(0, px->nbpend);
1701 break;
1702 case ST_F_QMAX:
1703 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1704 break;
1705 case ST_F_CONNECT:
1706 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1707 break;
1708 case ST_F_REUSE:
1709 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1710 break;
1711 case ST_F_BIN:
1712 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1713 break;
1714 case ST_F_BOUT:
1715 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1716 break;
1717 case ST_F_QTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001718 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1719 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001720 break;
1721 case ST_F_CTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001722 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1723 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001724 break;
1725 case ST_F_RTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001726 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1727 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001728 break;
1729 case ST_F_TTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001730 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1731 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001732 break;
Christopher Faulet5df597a2019-11-08 15:05:31 +01001733 case ST_F_QT_MAX:
1734 secs = (double)px->be_counters.qtime_max / 1000.0;
1735 metric = mkf_flt(FN_MAX, secs);
1736 break;
1737 case ST_F_CT_MAX:
1738 secs = (double)px->be_counters.ctime_max / 1000.0;
1739 metric = mkf_flt(FN_MAX, secs);
1740 break;
1741 case ST_F_RT_MAX:
1742 secs = (double)px->be_counters.dtime_max / 1000.0;
1743 metric = mkf_flt(FN_MAX, secs);
1744 break;
1745 case ST_F_TT_MAX:
1746 secs = (double)px->be_counters.ttime_max / 1000.0;
1747 metric = mkf_flt(FN_MAX, secs);
1748 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001749 case ST_F_DREQ:
1750 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1751 break;
1752 case ST_F_DRESP:
1753 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1754 break;
1755 case ST_F_ECON:
1756 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1757 break;
1758 case ST_F_ERESP:
1759 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1760 break;
1761 case ST_F_WRETR:
1762 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1763 break;
1764 case ST_F_WREDIS:
1765 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1766 break;
1767 case ST_F_WREW:
1768 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1769 break;
1770 case ST_F_CLI_ABRT:
1771 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1772 break;
1773 case ST_F_SRV_ABRT:
1774 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1775 break;
1776 case ST_F_WEIGHT:
1777 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1778 metric = mkf_u32(FN_AVG, weight);
1779 break;
1780 case ST_F_ACT:
1781 metric = mkf_u32(0, px->srv_act);
1782 break;
1783 case ST_F_BCK:
1784 metric = mkf_u32(0, px->srv_bck);
1785 break;
1786 case ST_F_CHKDOWN:
1787 metric = mkf_u64(FN_COUNTER, px->down_trans);
1788 break;
1789 case ST_F_LASTCHG:
1790 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1791 break;
1792 case ST_F_DOWNTIME:
1793 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1794 break;
1795 case ST_F_LBTOT:
1796 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1797 break;
1798 case ST_F_REQ_TOT:
1799 if (px->mode != PR_MODE_HTTP)
1800 goto next_px;
1801 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1802 break;
1803 case ST_F_HRSP_1XX:
1804 if (px->mode != PR_MODE_HTTP)
1805 goto next_px;
1806 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1807 break;
1808 case ST_F_HRSP_2XX:
1809 if (px->mode != PR_MODE_HTTP)
1810 goto next_px;
1811 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1812 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1813 break;
1814 case ST_F_HRSP_3XX:
1815 if (px->mode != PR_MODE_HTTP)
1816 goto next_px;
1817 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1818 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1819 break;
1820 case ST_F_HRSP_4XX:
1821 if (px->mode != PR_MODE_HTTP)
1822 goto next_px;
1823 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1824 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1825 break;
1826 case ST_F_HRSP_5XX:
1827 if (px->mode != PR_MODE_HTTP)
1828 goto next_px;
1829 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1830 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1831 break;
1832 case ST_F_HRSP_OTHER:
1833 if (px->mode != PR_MODE_HTTP)
1834 goto next_px;
1835 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1836 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1837 break;
1838 case ST_F_CACHE_LOOKUPS:
1839 if (px->mode != PR_MODE_HTTP)
1840 goto next_px;
1841 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1842 break;
1843 case ST_F_CACHE_HITS:
1844 if (px->mode != PR_MODE_HTTP)
1845 goto next_px;
1846 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1847 break;
1848 case ST_F_COMP_IN:
1849 if (px->mode != PR_MODE_HTTP)
1850 goto next_px;
1851 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1852 break;
1853 case ST_F_COMP_OUT:
1854 if (px->mode != PR_MODE_HTTP)
1855 goto next_px;
1856 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1857 break;
1858 case ST_F_COMP_BYP:
1859 if (px->mode != PR_MODE_HTTP)
1860 goto next_px;
1861 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1862 break;
1863 case ST_F_COMP_RSP:
1864 if (px->mode != PR_MODE_HTTP)
1865 goto next_px;
1866 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1867 break;
1868
1869 default:
1870 goto next_metric;
1871 }
1872
1873 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1874 goto full;
1875 next_px:
1876 appctx->ctx.stats.px = px->next;
1877 }
1878 next_metric:
1879 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1880 appctx->ctx.stats.px = proxies_list;
1881 appctx->st2 = promex_back_metrics[appctx->st2];
1882 }
1883
1884 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02001885 if (out.len) {
1886 if (!htx_add_data_atonce(htx, out))
1887 return -1; /* Unexpected and unrecoverable error */
1888 channel_add_input(chn, out.len);
1889 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001890 return ret;
1891 full:
1892 ret = 0;
1893 goto end;
1894}
1895
1896/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on sucess,
1897 * 0 if <htx> is full and -1 in case of any error. */
1898static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1899{
1900 static struct ist prefix = IST("haproxy_server_");
1901 struct proxy *px;
1902 struct server *sv;
1903 struct field metric;
1904 struct channel *chn = si_ic(appctx->owner);
1905 struct ist out = ist2(trash.area, 0);
Christopher Faulet94d837e2019-07-03 11:43:17 +02001906 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001907 int ret = 1;
1908 uint32_t weight;
Christopher Faulete86bf652019-09-24 16:35:19 +02001909 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001910
1911 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1912 while (appctx->ctx.stats.px) {
1913 px = appctx->ctx.stats.px;
1914
1915 /* skip the disabled proxies, global frontend and non-networked ones */
1916 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1917 goto next_px;
1918
1919 while (appctx->ctx.stats.sv) {
1920 sv = appctx->ctx.stats.sv;
1921
Christopher Faulete48e9962019-11-19 14:18:24 +01001922 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1923 goto next_sv;
1924
Christopher Fauletf959d082019-02-07 15:38:42 +01001925 switch (appctx->st2) {
1926 case ST_F_STATUS:
1927 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1928 break;
1929 case ST_F_SCUR:
1930 metric = mkf_u32(0, sv->cur_sess);
1931 break;
1932 case ST_F_SMAX:
1933 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1934 break;
1935 case ST_F_SLIM:
1936 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1937 break;
1938 case ST_F_STOT:
1939 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1940 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001941 case ST_F_RATE_MAX:
1942 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1943 break;
1944 case ST_F_LASTSESS:
1945 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1946 break;
1947 case ST_F_QCUR:
1948 metric = mkf_u32(0, sv->nbpend);
1949 break;
1950 case ST_F_QMAX:
1951 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1952 break;
1953 case ST_F_QLIMIT:
1954 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1955 break;
1956 case ST_F_BIN:
1957 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1958 break;
1959 case ST_F_BOUT:
1960 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1961 break;
1962 case ST_F_QTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001963 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1964 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001965 break;
1966 case ST_F_CTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001967 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1968 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001969 break;
1970 case ST_F_RTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001971 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1972 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001973 break;
1974 case ST_F_TTIME:
Christopher Faulete86bf652019-09-24 16:35:19 +02001975 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1976 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001977 break;
Christopher Faulet5df597a2019-11-08 15:05:31 +01001978 case ST_F_QT_MAX:
1979 secs = (double)sv->counters.qtime_max / 1000.0;
1980 metric = mkf_flt(FN_MAX, secs);
1981 break;
1982 case ST_F_CT_MAX:
1983 secs = (double)sv->counters.ctime_max / 1000.0;
1984 metric = mkf_flt(FN_MAX, secs);
1985 break;
1986 case ST_F_RT_MAX:
1987 secs = (double)sv->counters.dtime_max / 1000.0;
1988 metric = mkf_flt(FN_MAX, secs);
1989 break;
1990 case ST_F_TT_MAX:
1991 secs = (double)sv->counters.ttime_max / 1000.0;
1992 metric = mkf_flt(FN_MAX, secs);
1993 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001994 case ST_F_CONNECT:
1995 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1996 break;
1997 case ST_F_REUSE:
1998 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1999 break;
2000 case ST_F_DRESP:
2001 metric = mkf_u64(FN_COUNTER, sv->counters.failed_secu);
2002 break;
2003 case ST_F_ECON:
2004 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
2005 break;
2006 case ST_F_ERESP:
2007 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
2008 break;
2009 case ST_F_WRETR:
2010 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
2011 break;
2012 case ST_F_WREDIS:
2013 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
2014 break;
2015 case ST_F_WREW:
2016 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
2017 break;
2018 case ST_F_CLI_ABRT:
2019 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
2020 break;
2021 case ST_F_SRV_ABRT:
2022 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
2023 break;
2024 case ST_F_WEIGHT:
2025 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
2026 metric = mkf_u32(FN_AVG, weight);
2027 break;
Christopher Faulete019d182019-11-21 14:35:46 +01002028 case ST_F_CHECK_STATUS:
2029 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2030 goto next_sv;
2031 metric = mkf_u32(FN_OUTPUT, sv->check.status);
2032 break;
2033 case ST_F_CHECK_CODE:
2034 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2035 goto next_sv;
2036 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
2037 break;
Christopher Faulet4ab0efb2020-02-27 16:12:07 +01002038 case ST_F_CHECK_DURATION:
2039 if (sv->check.status < HCHK_STATUS_CHECKED)
2040 goto next_sv;
2041 secs = (double)sv->check.duration / 1000.0;
2042 metric = mkf_flt(FN_DURATION, secs);
2043 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002044 case ST_F_CHKFAIL:
2045 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
2046 break;
2047 case ST_F_CHKDOWN:
2048 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
2049 break;
2050 case ST_F_DOWNTIME:
2051 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
2052 break;
2053 case ST_F_LASTCHG:
2054 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
2055 break;
2056 case ST_F_THROTTLE:
2057 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
2058 break;
2059 case ST_F_LBTOT:
2060 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
2061 break;
2062 case ST_F_HRSP_1XX:
2063 if (px->mode != PR_MODE_HTTP)
2064 goto next_px;
2065 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
2066 break;
2067 case ST_F_HRSP_2XX:
2068 if (px->mode != PR_MODE_HTTP)
2069 goto next_px;
2070 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2071 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
2072 break;
2073 case ST_F_HRSP_3XX:
2074 if (px->mode != PR_MODE_HTTP)
2075 goto next_px;
2076 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2077 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
2078 break;
2079 case ST_F_HRSP_4XX:
2080 if (px->mode != PR_MODE_HTTP)
2081 goto next_px;
2082 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2083 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
2084 break;
2085 case ST_F_HRSP_5XX:
2086 if (px->mode != PR_MODE_HTTP)
2087 goto next_px;
2088 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2089 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
2090 break;
2091 case ST_F_HRSP_OTHER:
2092 if (px->mode != PR_MODE_HTTP)
2093 goto next_px;
2094 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2095 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
2096 break;
Christopher Fauletbd767f72019-11-08 15:24:32 +01002097 case ST_F_SRV_ICUR:
2098 metric = mkf_u32(0, sv->curr_idle_conns);
2099 break;
2100 case ST_F_SRV_ILIM:
2101 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2102 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002103
2104 default:
2105 goto next_metric;
2106 }
2107
2108 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2109 goto full;
2110
Christopher Faulete48e9962019-11-19 14:18:24 +01002111 next_sv:
Christopher Fauletf959d082019-02-07 15:38:42 +01002112 appctx->ctx.stats.sv = sv->next;
2113 }
2114
2115 next_px:
2116 appctx->ctx.stats.px = px->next;
2117 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2118 }
2119 next_metric:
2120 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
2121 appctx->ctx.stats.px = proxies_list;
2122 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2123 appctx->st2 = promex_srv_metrics[appctx->st2];
2124 }
2125
2126
2127 end:
Christopher Faulet0f58c0b2019-07-04 10:03:28 +02002128 if (out.len) {
2129 if (!htx_add_data_atonce(htx, out))
2130 return -1; /* Unexpected and unrecoverable error */
2131 channel_add_input(chn, out.len);
2132 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002133 return ret;
2134 full:
2135 ret = 0;
2136 goto end;
2137}
2138
2139/* Dump all metrics (global, frontends, backends and servers) depending on the
2140 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
2141 * -1 in case of any error. */
2142static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2143{
2144 int ret;
2145
2146 switch (appctx->st1) {
2147 case PROMEX_DUMPER_INIT:
2148 appctx->ctx.stats.px = NULL;
2149 appctx->ctx.stats.sv = NULL;
Christopher Faulet47d1e202020-06-05 08:18:56 +02002150 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002151 appctx->st2 = promex_global_metrics[INF_NAME];
2152 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2153 /* fall through */
2154
2155 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002156 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2157 ret = promex_dump_global_metrics(appctx, htx);
2158 if (ret <= 0) {
2159 if (ret == -1)
2160 goto error;
2161 goto full;
2162 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002163 }
2164
2165 appctx->ctx.stats.px = proxies_list;
2166 appctx->ctx.stats.sv = NULL;
Christopher Faulet47d1e202020-06-05 08:18:56 +02002167 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
2168 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002169 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2170 appctx->st1 = PROMEX_DUMPER_FRONT;
2171 /* fall through */
2172
2173 case PROMEX_DUMPER_FRONT:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002174 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2175 ret = promex_dump_front_metrics(appctx, htx);
2176 if (ret <= 0) {
2177 if (ret == -1)
2178 goto error;
2179 goto full;
2180 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002181 }
2182
2183 appctx->ctx.stats.px = proxies_list;
2184 appctx->ctx.stats.sv = NULL;
Christopher Faulet47d1e202020-06-05 08:18:56 +02002185 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002186 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2187 appctx->st1 = PROMEX_DUMPER_BACK;
2188 /* fall through */
2189
2190 case PROMEX_DUMPER_BACK:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002191 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2192 ret = promex_dump_back_metrics(appctx, htx);
2193 if (ret <= 0) {
2194 if (ret == -1)
2195 goto error;
2196 goto full;
2197 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002198 }
2199
2200 appctx->ctx.stats.px = proxies_list;
2201 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
Christopher Faulet47d1e202020-06-05 08:18:56 +02002202 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002203 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2204 appctx->st1 = PROMEX_DUMPER_SRV;
2205 /* fall through */
2206
2207 case PROMEX_DUMPER_SRV:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002208 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2209 ret = promex_dump_srv_metrics(appctx, htx);
2210 if (ret <= 0) {
2211 if (ret == -1)
2212 goto error;
2213 goto full;
2214 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002215 }
2216
2217 appctx->ctx.stats.px = NULL;
2218 appctx->ctx.stats.sv = NULL;
Christopher Faulet47d1e202020-06-05 08:18:56 +02002219 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002220 appctx->st2 = 0;
2221 appctx->st1 = PROMEX_DUMPER_DONE;
2222 /* fall through */
2223
2224 case PROMEX_DUMPER_DONE:
2225 default:
2226 break;
2227 }
2228
2229 return 1;
2230
2231 full:
2232 si_rx_room_blk(si);
2233 return 0;
2234 error:
2235 /* unrecoverable error */
2236 appctx->ctx.stats.px = NULL;
2237 appctx->ctx.stats.sv = NULL;
2238 appctx->ctx.stats.flags = 0;
2239 appctx->st2 = 0;
2240 appctx->st1 = PROMEX_DUMPER_DONE;
2241 return -1;
2242}
2243
Christopher Faulet32d634f2019-11-18 14:47:08 +01002244/* Parse the query stirng of request URI to filter the metrics. It returns 1 on
2245 * success and -1 on error. */
2246static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2247{
2248 struct channel *req = si_oc(si);
2249 struct channel *res = si_ic(si);
2250 struct htx *req_htx, *res_htx;
2251 struct htx_sl *sl;
William Dauchy200c6212019-11-26 12:56:26 +01002252 char *p, *key, *value;
2253 const char *end;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002254 struct buffer *err;
2255 int default_scopes = PROMEX_FL_SCOPE_ALL;
2256 int len;
2257
2258 /* Get the query-string */
2259 req_htx = htxbuf(&req->buf);
2260 sl = http_get_stline(req_htx);
2261 if (!sl)
2262 goto error;
2263 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2264 if (!p)
2265 goto end;
2266 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet32d634f2019-11-18 14:47:08 +01002267
William Dauchy200c6212019-11-26 12:56:26 +01002268 /* copy the query-string */
2269 len = end - p;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002270 chunk_reset(&trash);
2271 memcpy(trash.area, p, len);
2272 trash.area[len] = 0;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002273 p = trash.area;
William Dauchy200c6212019-11-26 12:56:26 +01002274 end = trash.area + len;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002275
2276 /* Parse the query-string */
William Dauchy200c6212019-11-26 12:56:26 +01002277 while (p < end && *p && *p != '#') {
2278 value = NULL;
2279
2280 /* decode parameter name */
2281 key = p;
2282 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet32d634f2019-11-18 14:47:08 +01002283 ++p;
William Dauchy200c6212019-11-26 12:56:26 +01002284 /* found a value */
2285 if (*p == '=') {
2286 *(p++) = 0;
2287 value = p;
2288 }
2289 else if (*p == '&')
2290 *(p++) = 0;
2291 else if (*p == '#')
2292 *p = 0;
Willy Tarreau7e913cb2020-04-23 17:54:47 +02002293 len = url_decode(key, 1);
William Dauchy200c6212019-11-26 12:56:26 +01002294 if (len == -1)
2295 goto error;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002296
William Dauchy200c6212019-11-26 12:56:26 +01002297 /* decode value */
2298 if (value) {
2299 while (p < end && *p != '=' && *p != '&' && *p != '#')
2300 ++p;
2301 if (*p == '=')
2302 goto error;
2303 if (*p == '&')
2304 *(p++) = 0;
2305 else if (*p == '#')
2306 *p = 0;
Willy Tarreau7e913cb2020-04-23 17:54:47 +02002307 len = url_decode(value, 1);
William Dauchy200c6212019-11-26 12:56:26 +01002308 if (len == -1)
2309 goto error;
2310 }
2311
2312 if (!strcmp(key, "scope")) {
2313 default_scopes = 0; /* at least a scope defined, unset default scopes */
2314 if (!value)
2315 goto error;
2316 else if (*value == 0)
Christopher Faulet32d634f2019-11-18 14:47:08 +01002317 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchy200c6212019-11-26 12:56:26 +01002318 else if (*value == '*')
Christopher Faulet32d634f2019-11-18 14:47:08 +01002319 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
William Dauchy200c6212019-11-26 12:56:26 +01002320 else if (!strcmp(value, "global"))
2321 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
2322 else if (!strcmp(value, "server"))
2323 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
2324 else if (!strcmp(value, "backend"))
Christopher Faulet32d634f2019-11-18 14:47:08 +01002325 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
William Dauchy200c6212019-11-26 12:56:26 +01002326 else if (!strcmp(value, "frontend"))
Christopher Faulet32d634f2019-11-18 14:47:08 +01002327 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2328 else
2329 goto error;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002330 }
William Dauchy200c6212019-11-26 12:56:26 +01002331 else if (!strcmp(key, "no-maint"))
Christopher Faulete48e9962019-11-19 14:18:24 +01002332 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet32d634f2019-11-18 14:47:08 +01002333 }
2334
2335 end:
2336 appctx->ctx.stats.flags |= default_scopes;
2337 return 1;
2338
2339 error:
Christopher Faulet3a00e5f2019-11-27 11:22:37 +01002340 err = &htx_err_chunks[HTTP_ERR_400];
Christopher Faulet32d634f2019-11-18 14:47:08 +01002341 channel_erase(res);
2342 res->buf.data = b_data(err);
2343 memcpy(res->buf.area, b_head(err), b_data(err));
2344 res_htx = htx_from_buf(&res->buf);
2345 channel_add_input(res, res_htx->data);
2346 appctx->st0 = PROMEX_ST_END;
2347 return -1;
2348}
2349
Christopher Fauletf959d082019-02-07 15:38:42 +01002350/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2351 * full. */
2352static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2353{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002354 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002355 struct htx_sl *sl;
2356 unsigned int flags;
2357
2358 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);
2359 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2360 if (!sl)
2361 goto full;
2362 sl->info.res.status = 200;
2363 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
2364 !htx_add_header(htx, ist("Connection"), ist("close")) ||
2365 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2366 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2367 !htx_add_endof(htx, HTX_BLK_EOH))
2368 goto full;
2369
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002370 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002371 return 1;
2372 full:
2373 htx_reset(htx);
2374 si_rx_room_blk(si);
2375 return 0;
2376}
2377
2378/* The function returns 1 if the initialisation is complete, 0 if
2379 * an errors occurs and -1 if more data are required for initializing
2380 * the applet.
2381 */
2382static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2383{
2384 appctx->st0 = PROMEX_ST_INIT;
2385 return 1;
2386}
2387
2388/* The main I/O handler for the promex applet. */
2389static void promex_appctx_handle_io(struct appctx *appctx)
2390{
2391 struct stream_interface *si = appctx->owner;
2392 struct stream *s = si_strm(si);
2393 struct channel *req = si_oc(si);
2394 struct channel *res = si_ic(si);
2395 struct htx *req_htx, *res_htx;
2396 int ret;
2397
2398 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002399 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2400 goto out;
2401
2402 /* Check if the input buffer is avalaible. */
2403 if (!b_size(&res->buf)) {
2404 si_rx_room_blk(si);
2405 goto out;
2406 }
2407
2408 switch (appctx->st0) {
2409 case PROMEX_ST_INIT:
Christopher Faulet32d634f2019-11-18 14:47:08 +01002410 ret = promex_parse_uri(appctx, si);
2411 if (ret <= 0) {
2412 if (ret == -1)
2413 goto error;
2414 goto out;
2415 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002416 appctx->st0 = PROMEX_ST_HEAD;
2417 appctx->st1 = PROMEX_DUMPER_INIT;
2418 /* fall through */
2419
2420 case PROMEX_ST_HEAD:
2421 if (!promex_send_headers(appctx, si, res_htx))
2422 goto out;
2423 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2424 /* fall through */
2425
2426 case PROMEX_ST_DUMP:
2427 ret = promex_dump_metrics(appctx, si, res_htx);
2428 if (ret <= 0) {
2429 if (ret == -1)
2430 goto error;
2431 goto out;
2432 }
2433 appctx->st0 = PROMEX_ST_DONE;
2434 /* fall through */
2435
2436 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002437 /* Don't add TLR because mux-h1 will take care of it */
Christopher Fauletf959d082019-02-07 15:38:42 +01002438 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2439 si_rx_room_blk(si);
2440 goto out;
2441 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002442 channel_add_input(res, 1);
2443 appctx->st0 = PROMEX_ST_END;
2444 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002445
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002446 case PROMEX_ST_END:
2447 if (!(res->flags & CF_SHUTR)) {
2448 res->flags |= CF_READ_NULL;
2449 si_shutr(si);
2450 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002451 }
2452
Christopher Fauletf959d082019-02-07 15:38:42 +01002453 out:
2454 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002455
2456 /* eat the whole request */
2457 if (co_data(req)) {
2458 req_htx = htx_from_buf(&req->buf);
2459 co_htx_skip(req, req_htx, co_data(req));
2460 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002461 return;
2462
2463 error:
2464 res->flags |= CF_READ_NULL;
2465 si_shutr(si);
2466 si_shutw(si);
2467}
2468
2469struct applet promex_applet = {
2470 .obj_type = OBJ_TYPE_APPLET,
2471 .name = "<PROMEX>", /* used for logging */
2472 .init = promex_appctx_init,
2473 .fct = promex_appctx_handle_io,
2474};
2475
2476static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2477 struct act_rule *rule, char **err)
2478{
2479 /* Prometheus exporter service is only available on "http-request" rulesets */
2480 if (rule->from != ACT_F_HTTP_REQ) {
2481 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2482 return ACT_RET_PRS_ERR;
2483 }
2484 if (!(px->options2 & PR_O2_USE_HTX)) {
2485 memprintf(err, "Prometheus exporter service only available for HTX proxies");
2486 return ACT_RET_PRS_ERR;
2487 }
2488
2489 /* Add applet pointer in the rule. */
2490 rule->applet = promex_applet;
2491
2492 return ACT_RET_PRS_OK;
2493}
2494static void promex_register_build_options(void)
2495{
2496 char *ptr = NULL;
2497
2498 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2499 hap_register_build_opts(ptr, 1);
2500}
2501
2502
2503static struct action_kw_list service_actions = { ILH, {
2504 { "prometheus-exporter", service_parse_prometheus_exporter },
2505 { /* END */ }
2506}};
2507
2508INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2509INITCALL0(STG_REGISTER, promex_register_build_options);