blob: dfd5e1a43c3e34593f4ae5c45e595fb797850ce5 [file] [log] [blame]
Christopher Fauletf959d082019-02-07 15:38:42 +01001/*
2 * Promex is a Prometheus exporter for HAProxy
3 *
4 * It is highly inspired by the official Prometheus exporter.
5 * See: https://github.com/prometheus/haproxy_exporter
6 *
7 * Copyright 2019 Christopher Faulet <cfaulet@haproxy.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
16#include <common/cfgparse.h>
17#include <common/config.h>
18#include <common/buffer.h>
19#include <common/htx.h>
20#include <common/initcall.h>
21#include <common/memory.h>
22#include <common/mini-clist.h>
23
24#include <types/global.h>
25
26#include <proto/action.h>
27#include <proto/applet.h>
28#include <proto/backend.h>
29#include <proto/compression.h>
30#include <proto/frontend.h>
31#include <proto/listener.h>
32#include <proto/http_htx.h>
33#include <proto/pipe.h>
34#include <proto/proxy.h>
35#include <proto/sample.h>
36#include <proto/server.h>
37#include <proto/ssl_sock.h>
38#include <proto/stats.h>
39#include <proto/stream.h>
40#include <proto/stream_interface.h>
41#include <proto/task.h>
42
43/* Prometheus exporter applet states (appctx->st0) */
44enum {
45 PROMEX_ST_INIT = 0, /* initialized */
46 PROMEX_ST_HEAD, /* send headers before dump */
47 PROMEX_ST_DUMP, /* dumping stats */
48 PROMEX_ST_DONE, /* finished */
Christopher Faulet9744f7c2019-03-27 15:48:53 +010049 PROMEX_ST_END, /* treatment terminated */
Christopher Fauletf959d082019-02-07 15:38:42 +010050};
51
52/* Prometheus exporter dumper states (appctx->st1) */
53enum {
54 PROMEX_DUMPER_INIT = 0, /* initialized */
55 PROMEX_DUMPER_GLOBAL, /* dump metrics of globals */
56 PROMEX_DUMPER_FRONT, /* dump metrics of frontend proxies */
57 PROMEX_DUMPER_BACK, /* dump metrics of backend proxies */
58 PROMEX_DUMPER_LI, /* dump metrics of listeners */
59 PROMEX_DUMPER_SRV, /* dump metrics of servers */
60 PROMEX_DUMPER_DONE, /* finished */
61};
62
63/* Prometheus exporter flags (appctx->ctx.stats.flags) */
64#define PROMEX_FL_METRIC_HDR 0x00000001
65#define PROMEX_FL_INFO_METRIC 0x00000002
66#define PROMEX_FL_STATS_METRIC 0x00000004
Christopher Faulet78407ce2019-11-18 14:47:08 +010067#define PROMEX_FL_SCOPE_GLOBAL 0x00000008
68#define PROMEX_FL_SCOPE_FRONT 0x00000010
69#define PROMEX_FL_SCOPE_BACK 0x00000020
70#define PROMEX_FL_SCOPE_SERVER 0x00000040
Christopher Fauleteba22942019-11-19 14:18:24 +010071#define PROMEX_FL_NO_MAINT_SRV 0x00000080
Christopher Faulet78407ce2019-11-18 14:47:08 +010072
73#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 +010074
75/* The max length for metrics name. It is a hard limit but it should be
Ilya Shipitsince7b00f2020-03-23 22:28:40 +050076 * enough.
Christopher Fauletf959d082019-02-07 15:38:42 +010077 */
78#define PROMEX_MAX_NAME_LEN 128
79
80/* The expected max length for a metric dump, including its header lines. It is
81 * just a soft limit to avoid extra work. We don't try to dump a metric if less
82 * than this size is available in the HTX.
83 */
84#define PROMEX_MAX_METRIC_LENGTH 512
85
86/* Matrix used to dump global metrics. Each metric points to the next one to be
87 * processed or 0 to stop the dump. */
88const int promex_global_metrics[INF_TOTAL_FIELDS] = {
89 [INF_NAME] = INF_NBTHREAD,
90 [INF_VERSION] = 0,
91 [INF_RELEASE_DATE] = 0,
92 [INF_NBTHREAD] = INF_NBPROC,
93 [INF_NBPROC] = INF_PROCESS_NUM,
94 [INF_PROCESS_NUM] = INF_UPTIME_SEC,
95 [INF_PID] = 0,
96 [INF_UPTIME] = 0,
97 [INF_UPTIME_SEC] = INF_MEMMAX_MB,
98 [INF_MEMMAX_MB] = INF_POOL_ALLOC_MB,
99 [INF_POOL_ALLOC_MB] = INF_POOL_USED_MB,
100 [INF_POOL_USED_MB] = INF_POOL_FAILED,
101 [INF_POOL_FAILED] = INF_ULIMIT_N,
102 [INF_ULIMIT_N] = INF_MAXSOCK,
103 [INF_MAXSOCK] = INF_MAXCONN,
104 [INF_MAXCONN] = INF_HARD_MAXCONN,
105 [INF_HARD_MAXCONN] = INF_CURR_CONN,
106 [INF_CURR_CONN] = INF_CUM_CONN,
107 [INF_CUM_CONN] = INF_CUM_REQ,
108 [INF_CUM_REQ] = INF_MAX_SSL_CONNS,
109 [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS,
110 [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS,
111 [INF_CUM_SSL_CONNS] = INF_MAXPIPES,
112 [INF_MAXPIPES] = INF_PIPES_USED,
113 [INF_PIPES_USED] = INF_PIPES_FREE,
114 [INF_PIPES_FREE] = INF_CONN_RATE,
115 [INF_CONN_RATE] = INF_CONN_RATE_LIMIT,
116 [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE,
117 [INF_MAX_CONN_RATE] = INF_SESS_RATE,
118 [INF_SESS_RATE] = INF_SESS_RATE_LIMIT,
119 [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE,
120 [INF_MAX_SESS_RATE] = INF_SSL_RATE,
121 [INF_SSL_RATE] = INF_SSL_RATE_LIMIT,
122 [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE,
123 [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE,
124 [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE,
125 [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT,
126 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE,
127 [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE,
128 [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS,
129 [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES,
130 [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN,
131 [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT,
132 [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM,
133 [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE,
134 [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE,
135 [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS,
136 [INF_TASKS] = INF_RUN_QUEUE,
137 [INF_RUN_QUEUE] = INF_IDLE_PCT,
138 [INF_IDLE_PCT] = INF_STOPPING,
139 [INF_NODE] = 0,
140 [INF_DESCRIPTION] = 0,
141 [INF_STOPPING] = INF_JOBS,
142 [INF_JOBS] = INF_UNSTOPPABLE_JOBS,
143 [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS,
144 [INF_LISTENERS] = INF_ACTIVE_PEERS,
145 [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS,
146 [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS,
147 [INF_DROPPED_LOGS] = INF_BUSY_POLLING,
148 [INF_BUSY_POLLING] = 0,
149};
150
151/* Matrix used to dump frontend metrics. Each metric points to the next one to be
152 * processed or 0 to stop the dump. */
153const int promex_front_metrics[ST_F_TOTAL_FIELDS] = {
154 [ST_F_PXNAME] = ST_F_STATUS,
155 [ST_F_SVNAME] = 0,
156 [ST_F_QCUR] = 0,
157 [ST_F_QMAX] = 0,
158 [ST_F_SCUR] = ST_F_SMAX,
159 [ST_F_SMAX] = ST_F_SLIM,
160 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200161 [ST_F_STOT] = ST_F_RATE_LIM,
Christopher Fauletf959d082019-02-07 15:38:42 +0100162 [ST_F_BIN] = ST_F_BOUT,
163 [ST_F_BOUT] = ST_F_DREQ,
164 [ST_F_DREQ] = ST_F_DRESP,
165 [ST_F_DRESP] = ST_F_EREQ,
166 [ST_F_EREQ] = ST_F_DCON,
167 [ST_F_ECON] = 0,
168 [ST_F_ERESP] = 0,
169 [ST_F_WRETR] = 0,
170 [ST_F_WREDIS] = 0,
171 [ST_F_STATUS] = ST_F_SCUR,
172 [ST_F_WEIGHT] = 0,
173 [ST_F_ACT] = 0,
174 [ST_F_BCK] = 0,
175 [ST_F_CHKFAIL] = 0,
176 [ST_F_CHKDOWN] = 0,
177 [ST_F_LASTCHG] = 0,
178 [ST_F_DOWNTIME] = 0,
179 [ST_F_QLIMIT] = 0,
180 [ST_F_PID] = 0,
181 [ST_F_IID] = 0,
182 [ST_F_SID] = 0,
183 [ST_F_THROTTLE] = 0,
184 [ST_F_LBTOT] = 0,
185 [ST_F_TRACKED] = 0,
186 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200187 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100188 [ST_F_RATE_LIM] = ST_F_RATE_MAX,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200189 [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100190 [ST_F_CHECK_STATUS] = 0,
191 [ST_F_CHECK_CODE] = 0,
192 [ST_F_CHECK_DURATION] = 0,
193 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
194 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
195 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
196 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
197 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
198 [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED,
199 [ST_F_HANAFAIL] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200200 [ST_F_REQ_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100201 [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT,
202 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
203 [ST_F_CLI_ABRT] = 0,
204 [ST_F_SRV_ABRT] = 0,
205 [ST_F_COMP_IN] = ST_F_COMP_OUT,
206 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
207 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
208 [ST_F_COMP_RSP] = 0,
209 [ST_F_LASTSESS] = 0,
210 [ST_F_LAST_CHK] = 0,
211 [ST_F_LAST_AGT] = 0,
212 [ST_F_QTIME] = 0,
213 [ST_F_CTIME] = 0,
214 [ST_F_RTIME] = 0,
215 [ST_F_TTIME] = 0,
216 [ST_F_AGENT_STATUS] = 0,
217 [ST_F_AGENT_CODE] = 0,
218 [ST_F_AGENT_DURATION] = 0,
219 [ST_F_CHECK_DESC] = 0,
220 [ST_F_AGENT_DESC] = 0,
221 [ST_F_CHECK_RISE] = 0,
222 [ST_F_CHECK_FALL] = 0,
223 [ST_F_CHECK_HEALTH] = 0,
224 [ST_F_AGENT_RISE] = 0,
225 [ST_F_AGENT_FALL] = 0,
226 [ST_F_AGENT_HEALTH] = 0,
227 [ST_F_ADDR] = 0,
228 [ST_F_COOKIE] = 0,
229 [ST_F_MODE] = 0,
230 [ST_F_ALGO] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200231 [ST_F_CONN_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100232 [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT,
233 [ST_F_CONN_TOT] = ST_F_BIN,
234 [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS,
235 [ST_F_DCON] = ST_F_DSES,
236 [ST_F_DSES] = ST_F_WREW,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100237 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100238 [ST_F_CONNECT] = 0,
239 [ST_F_REUSE] = 0,
240 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
241 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100242 [ST_F_SRV_ICUR] = 0,
243 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100244 [ST_F_QT_MAX] = 0,
245 [ST_F_CT_MAX] = 0,
246 [ST_F_RT_MAX] = 0,
247 [ST_F_TT_MAX] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100248 [ST_F_EINT] = ST_F_REQ_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100249};
250
251/* Matrix used to dump backend metrics. Each metric points to the next one to be
252 * processed or 0 to stop the dump. */
253const int promex_back_metrics[ST_F_TOTAL_FIELDS] = {
254 [ST_F_PXNAME] = ST_F_STATUS,
255 [ST_F_SVNAME] = 0,
256 [ST_F_QCUR] = ST_F_QMAX,
257 [ST_F_QMAX] = ST_F_CONNECT,
258 [ST_F_SCUR] = ST_F_SMAX,
259 [ST_F_SMAX] = ST_F_SLIM,
260 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200261 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100262 [ST_F_BIN] = ST_F_BOUT,
263 [ST_F_BOUT] = ST_F_QTIME,
264 [ST_F_DREQ] = ST_F_DRESP,
265 [ST_F_DRESP] = ST_F_ECON,
266 [ST_F_EREQ] = 0,
267 [ST_F_ECON] = ST_F_ERESP,
268 [ST_F_ERESP] = ST_F_WRETR,
269 [ST_F_WRETR] = ST_F_WREDIS,
270 [ST_F_WREDIS] = ST_F_WREW,
271 [ST_F_STATUS] = ST_F_SCUR,
272 [ST_F_WEIGHT] = ST_F_ACT,
273 [ST_F_ACT] = ST_F_BCK,
274 [ST_F_BCK] = ST_F_CHKDOWN,
275 [ST_F_CHKFAIL] = 0,
276 [ST_F_CHKDOWN] = ST_F_LASTCHG,
277 [ST_F_LASTCHG] = ST_F_DOWNTIME,
278 [ST_F_DOWNTIME] = ST_F_LBTOT,
279 [ST_F_QLIMIT] = 0,
280 [ST_F_PID] = 0,
281 [ST_F_IID] = 0,
282 [ST_F_SID] = 0,
283 [ST_F_THROTTLE] = 0,
284 [ST_F_LBTOT] = ST_F_REQ_TOT,
285 [ST_F_TRACKED] = 9,
286 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200287 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100288 [ST_F_RATE_LIM] = 0,
289 [ST_F_RATE_MAX] = ST_F_LASTSESS,
290 [ST_F_CHECK_STATUS] = 0,
291 [ST_F_CHECK_CODE] = 0,
292 [ST_F_CHECK_DURATION] = 0,
293 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
294 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
295 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
296 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
297 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
298 [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS,
299 [ST_F_HANAFAIL] = 0,
300 [ST_F_REQ_RATE] = 0,
301 [ST_F_REQ_RATE_MAX] = 0,
302 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
303 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
304 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
305 [ST_F_COMP_IN] = ST_F_COMP_OUT,
306 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
307 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
308 [ST_F_COMP_RSP] = 0,
309 [ST_F_LASTSESS] = ST_F_QCUR,
310 [ST_F_LAST_CHK] = 0,
311 [ST_F_LAST_AGT] = 0,
312 [ST_F_QTIME] = ST_F_CTIME,
313 [ST_F_CTIME] = ST_F_RTIME,
314 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100315 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100316 [ST_F_AGENT_STATUS] = 0,
317 [ST_F_AGENT_CODE] = 0,
318 [ST_F_AGENT_DURATION] = 0,
319 [ST_F_CHECK_DESC] = 0,
320 [ST_F_AGENT_DESC] = 0,
321 [ST_F_CHECK_RISE] = 0,
322 [ST_F_CHECK_FALL] = 0,
323 [ST_F_CHECK_HEALTH] = 0,
324 [ST_F_AGENT_RISE] = 0,
325 [ST_F_AGENT_FALL] = 0,
326 [ST_F_AGENT_HEALTH] = 0,
327 [ST_F_ADDR] = 0,
328 [ST_F_COOKIE] = 0,
329 [ST_F_MODE] = 0,
330 [ST_F_ALGO] = 0,
331 [ST_F_CONN_RATE] = 0,
332 [ST_F_CONN_RATE_MAX] = 0,
333 [ST_F_CONN_TOT] = 0,
334 [ST_F_INTERCEPTED] = 0,
335 [ST_F_DCON] = 0,
336 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100337 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100338 [ST_F_CONNECT] = ST_F_REUSE,
339 [ST_F_REUSE] = ST_F_BIN,
340 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
341 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100342 [ST_F_SRV_ICUR] = 0,
343 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100344 [ST_F_QT_MAX] = ST_F_CT_MAX,
345 [ST_F_CT_MAX] = ST_F_RT_MAX,
346 [ST_F_RT_MAX] = ST_F_TT_MAX,
347 [ST_F_TT_MAX] = ST_F_DREQ,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100348 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100349};
350
351/* Matrix used to dump server metrics. Each metric points to the next one to be
352 * processed or 0 to stop the dump. */
353const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = {
354 [ST_F_PXNAME] = ST_F_STATUS,
355 [ST_F_SVNAME] = 0,
356 [ST_F_QCUR] = ST_F_QMAX,
357 [ST_F_QMAX] = ST_F_QLIMIT,
358 [ST_F_SCUR] = ST_F_SMAX,
359 [ST_F_SMAX] = ST_F_SLIM,
360 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200361 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100362 [ST_F_BIN] = ST_F_BOUT,
363 [ST_F_BOUT] = ST_F_QTIME,
364 [ST_F_DREQ] = 0,
365 [ST_F_DRESP] = ST_F_ECON,
366 [ST_F_EREQ] = 0,
367 [ST_F_ECON] = ST_F_ERESP,
368 [ST_F_ERESP] = ST_F_WRETR,
369 [ST_F_WRETR] = ST_F_WREDIS,
370 [ST_F_WREDIS] = ST_F_WREW,
371 [ST_F_STATUS] = ST_F_SCUR,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100372 [ST_F_WEIGHT] = ST_F_CHECK_STATUS,
Christopher Fauletf959d082019-02-07 15:38:42 +0100373 [ST_F_ACT] = 0,
374 [ST_F_BCK] = 0,
375 [ST_F_CHKFAIL] = ST_F_CHKDOWN,
376 [ST_F_CHKDOWN] = ST_F_DOWNTIME,
377 [ST_F_LASTCHG] = ST_F_THROTTLE,
378 [ST_F_DOWNTIME] = ST_F_LASTCHG,
379 [ST_F_QLIMIT] = ST_F_BIN,
380 [ST_F_PID] = 0,
381 [ST_F_IID] = 0,
382 [ST_F_SID] = 0,
383 [ST_F_THROTTLE] = ST_F_LBTOT,
384 [ST_F_LBTOT] = ST_F_HRSP_1XX,
385 [ST_F_TRACKED] = 0,
386 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200387 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100388 [ST_F_RATE_LIM] = 0,
389 [ST_F_RATE_MAX] = ST_F_LASTSESS,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100390 [ST_F_CHECK_STATUS] = ST_F_CHECK_CODE,
Christopher Faulet2711e512020-02-27 16:12:07 +0100391 [ST_F_CHECK_CODE] = ST_F_CHECK_DURATION,
392 [ST_F_CHECK_DURATION] = ST_F_CHKFAIL,
Christopher Fauletf959d082019-02-07 15:38:42 +0100393 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
394 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
395 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
396 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
397 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100398 [ST_F_HRSP_OTHER] = ST_F_SRV_ICUR,
Christopher Fauletf959d082019-02-07 15:38:42 +0100399 [ST_F_HANAFAIL] = 0,
400 [ST_F_REQ_RATE] = 0,
401 [ST_F_REQ_RATE_MAX] = 0,
402 [ST_F_REQ_TOT] = 0,
403 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
404 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
405 [ST_F_COMP_IN] = 0,
406 [ST_F_COMP_OUT] = 0,
407 [ST_F_COMP_BYP] = 0,
408 [ST_F_COMP_RSP] = 0,
409 [ST_F_LASTSESS] = ST_F_QCUR,
410 [ST_F_LAST_CHK] = 0,
411 [ST_F_LAST_AGT] = 0,
412 [ST_F_QTIME] = ST_F_CTIME,
413 [ST_F_CTIME] = ST_F_RTIME,
414 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100415 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100416 [ST_F_AGENT_STATUS] = 0,
417 [ST_F_AGENT_CODE] = 0,
418 [ST_F_AGENT_DURATION] = 0,
419 [ST_F_CHECK_DESC] = 0,
420 [ST_F_AGENT_DESC] = 0,
421 [ST_F_CHECK_RISE] = 0,
422 [ST_F_CHECK_FALL] = 0,
423 [ST_F_CHECK_HEALTH] = 0,
424 [ST_F_AGENT_RISE] = 0,
425 [ST_F_AGENT_FALL] = 0,
426 [ST_F_AGENT_HEALTH] = 0,
427 [ST_F_ADDR] = 0,
428 [ST_F_COOKIE] = 0,
429 [ST_F_MODE] = 0,
430 [ST_F_ALGO] = 0,
431 [ST_F_CONN_RATE] = 0,
432 [ST_F_CONN_RATE_MAX] = 0,
433 [ST_F_CONN_TOT] = 0,
434 [ST_F_INTERCEPTED] = 0,
435 [ST_F_DCON] = 0,
436 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100437 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100438 [ST_F_CONNECT] = ST_F_REUSE,
439 [ST_F_REUSE] = ST_F_DRESP,
440 [ST_F_CACHE_LOOKUPS] = 0,
441 [ST_F_CACHE_HITS] = 0,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100442 [ST_F_SRV_ICUR] = ST_F_SRV_ILIM,
443 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100444 [ST_F_QT_MAX] = ST_F_CT_MAX,
445 [ST_F_CT_MAX] = ST_F_RT_MAX,
446 [ST_F_RT_MAX] = ST_F_TT_MAX,
447 [ST_F_TT_MAX] = ST_F_CONNECT,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100448 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100449};
450
451/* Name of all info fields */
452const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
453 [INF_NAME] = IST("name"),
454 [INF_VERSION] = IST("version"),
455 [INF_RELEASE_DATE] = IST("release_date"),
456 [INF_NBTHREAD] = IST("nbthread"),
457 [INF_NBPROC] = IST("nbproc"),
458 [INF_PROCESS_NUM] = IST("relative_process_id"),
459 [INF_PID] = IST("pid"),
460 [INF_UPTIME] = IST("uptime"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200461 [INF_UPTIME_SEC] = IST("start_time_seconds"),
462 [INF_MEMMAX_MB] = IST("max_memory_bytes"),
463 [INF_POOL_ALLOC_MB] = IST("pool_allocated_bytes"),
464 [INF_POOL_USED_MB] = IST("pool_used_bytes"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100465 [INF_POOL_FAILED] = IST("pool_failures_total"),
466 [INF_ULIMIT_N] = IST("max_fds"),
467 [INF_MAXSOCK] = IST("max_sockets"),
468 [INF_MAXCONN] = IST("max_connections"),
469 [INF_HARD_MAXCONN] = IST("hard_max_connections"),
470 [INF_CURR_CONN] = IST("current_connections"),
471 [INF_CUM_CONN] = IST("connections_total"),
472 [INF_CUM_REQ] = IST("requests_total"),
473 [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"),
474 [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"),
475 [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"),
476 [INF_MAXPIPES] = IST("max_pipes"),
477 [INF_PIPES_USED] = IST("pipes_used_total"),
478 [INF_PIPES_FREE] = IST("pipes_free_total"),
479 [INF_CONN_RATE] = IST("current_connection_rate"),
480 [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"),
481 [INF_MAX_CONN_RATE] = IST("max_connection_rate"),
482 [INF_SESS_RATE] = IST("current_session_rate"),
483 [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"),
484 [INF_MAX_SESS_RATE] = IST("max_session_rate"),
485 [INF_SSL_RATE] = IST("current_ssl_rate"),
486 [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"),
487 [INF_MAX_SSL_RATE] = IST("max_ssl_rate"),
488 [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"),
489 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"),
490 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontent_ssl_reuse"),
491 [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"),
492 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200493 [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"),
494 [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100495 [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"),
496 [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"),
497 [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"),
498 [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"),
499 [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"),
500 [INF_TASKS] = IST("current_tasks"),
501 [INF_RUN_QUEUE] = IST("current_run_queue"),
502 [INF_IDLE_PCT] = IST("idle_time_percent"),
503 [INF_NODE] = IST("node"),
504 [INF_DESCRIPTION] = IST("description"),
505 [INF_STOPPING] = IST("stopping"),
506 [INF_JOBS] = IST("jobs"),
507 [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"),
508 [INF_LISTENERS] = IST("listeners"),
509 [INF_ACTIVE_PEERS] = IST("active_peers"),
510 [INF_CONNECTED_PEERS] = IST("connected_peers"),
511 [INF_DROPPED_LOGS] = IST("dropped_logs_total"),
512 [INF_BUSY_POLLING] = IST("busy_polling_enabled"),
513};
514
515/* Name of all stats fields */
516const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = {
517 [ST_F_PXNAME] = IST("proxy_name"),
518 [ST_F_SVNAME] = IST("service_name"),
519 [ST_F_QCUR] = IST("current_queue"),
520 [ST_F_QMAX] = IST("max_queue"),
521 [ST_F_SCUR] = IST("current_sessions"),
522 [ST_F_SMAX] = IST("max_sessions"),
523 [ST_F_SLIM] = IST("limit_sessions"),
524 [ST_F_STOT] = IST("sessions_total"),
525 [ST_F_BIN] = IST("bytes_in_total"),
526 [ST_F_BOUT] = IST("bytes_out_total"),
527 [ST_F_DREQ] = IST("requests_denied_total"),
528 [ST_F_DRESP] = IST("responses_denied_total"),
529 [ST_F_EREQ] = IST("request_errors_total"),
530 [ST_F_ECON] = IST("connection_errors_total"),
531 [ST_F_ERESP] = IST("response_errors_total"),
532 [ST_F_WRETR] = IST("retry_warnings_total"),
533 [ST_F_WREDIS] = IST("redispatch_warnings_total"),
534 [ST_F_STATUS] = IST("status"),
535 [ST_F_WEIGHT] = IST("weight"),
536 [ST_F_ACT] = IST("active_servers"),
537 [ST_F_BCK] = IST("backup_servers"),
538 [ST_F_CHKFAIL] = IST("check_failures_total"),
539 [ST_F_CHKDOWN] = IST("check_up_down_total"),
540 [ST_F_LASTCHG] = IST("check_last_change_seconds"),
541 [ST_F_DOWNTIME] = IST("downtime_seconds_total"),
542 [ST_F_QLIMIT] = IST("queue_limit"),
543 [ST_F_PID] = IST("pid"),
544 [ST_F_IID] = IST("proxy_id"),
545 [ST_F_SID] = IST("server_id"),
546 [ST_F_THROTTLE] = IST("current_throttle"),
547 [ST_F_LBTOT] = IST("loadbalanced_total"),
548 [ST_F_TRACKED] = IST("tracked"),
549 [ST_F_TYPE] = IST("type"),
550 [ST_F_RATE] = IST("current_session_rate"),
551 [ST_F_RATE_LIM] = IST("limit_session_rate"),
552 [ST_F_RATE_MAX] = IST("max_session_rate"),
553 [ST_F_CHECK_STATUS] = IST("check_status"),
554 [ST_F_CHECK_CODE] = IST("check_code"),
Christopher Faulet2711e512020-02-27 16:12:07 +0100555 [ST_F_CHECK_DURATION] = IST("check_duration_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100556 [ST_F_HRSP_1XX] = IST("http_responses_total"),
557 [ST_F_HRSP_2XX] = IST("http_responses_total"),
558 [ST_F_HRSP_3XX] = IST("http_responses_total"),
559 [ST_F_HRSP_4XX] = IST("http_responses_total"),
560 [ST_F_HRSP_5XX] = IST("http_responses_total"),
561 [ST_F_HRSP_OTHER] = IST("http_responses_total"),
562 [ST_F_HANAFAIL] = IST("check_analyses_failures_total"),
563 [ST_F_REQ_RATE] = IST("http_requests_rate_current"),
564 [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"),
565 [ST_F_REQ_TOT] = IST("http_requests_total"),
566 [ST_F_CLI_ABRT] = IST("client_aborts_total"),
567 [ST_F_SRV_ABRT] = IST("server_aborts_total"),
568 [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"),
569 [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"),
570 [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"),
571 [ST_F_COMP_RSP] = IST("http_comp_responses_total"),
572 [ST_F_LASTSESS] = IST("last_session_seconds"),
573 [ST_F_LAST_CHK] = IST("check_last_content"),
574 [ST_F_LAST_AGT] = IST("agentcheck_last_content"),
Christopher Faulet68b69682019-11-08 15:12:29 +0100575 [ST_F_QTIME] = IST("queue_time_average_seconds"),
576 [ST_F_CTIME] = IST("connect_time_average_seconds"),
577 [ST_F_RTIME] = IST("response_time_average_seconds"),
578 [ST_F_TTIME] = IST("total_time_average_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100579 [ST_F_AGENT_STATUS] = IST("agentcheck_status"),
580 [ST_F_AGENT_CODE] = IST("agentcheck_code"),
581 [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"),
582 [ST_F_CHECK_DESC] = IST("check_description"),
583 [ST_F_AGENT_DESC] = IST("agentcheck_description"),
584 [ST_F_CHECK_RISE] = IST("check_rise"),
585 [ST_F_CHECK_FALL] = IST("check_fall"),
586 [ST_F_CHECK_HEALTH] = IST("check_value"),
587 [ST_F_AGENT_RISE] = IST("agentcheck_rise"),
588 [ST_F_AGENT_FALL] = IST("agentcheck_fall"),
589 [ST_F_AGENT_HEALTH] = IST("agentcheck_value"),
590 [ST_F_ADDR] = IST("address"),
591 [ST_F_COOKIE] = IST("cookie"),
592 [ST_F_MODE] = IST("mode"),
593 [ST_F_ALGO] = IST("loadbalance_algorithm"),
594 [ST_F_CONN_RATE] = IST("connections_rate_current"),
595 [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"),
596 [ST_F_CONN_TOT] = IST("connections_total"),
597 [ST_F_INTERCEPTED] = IST("intercepted_requests_total"),
598 [ST_F_DCON] = IST("denied_connections_total"),
599 [ST_F_DSES] = IST("denied_sessions_total"),
600 [ST_F_WREW] = IST("failed_header_rewriting_total"),
601 [ST_F_CONNECT] = IST("connection_attempts_total"),
602 [ST_F_REUSE] = IST("connection_reuses_total"),
603 [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"),
604 [ST_F_CACHE_HITS] = IST("http_cache_hits_total"),
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100605 [ST_F_SRV_ICUR] = IST("server_idle_connections_current"),
606 [ST_F_SRV_ILIM] = IST("server_idle_connections_limit"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100607 [ST_F_QT_MAX] = IST("max_queue_time_seconds"),
608 [ST_F_CT_MAX] = IST("max_connect_time_seconds"),
609 [ST_F_RT_MAX] = IST("max_response_time_seconds"),
610 [ST_F_TT_MAX] = IST("max_total_time_seconds"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100611 [ST_F_EINT] = IST("internal_errors_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100612};
613
614/* Description of all info fields */
615const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
616 [INF_NAME] = IST("Product name."),
617 [INF_VERSION] = IST("HAProxy version."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500618 [INF_RELEASE_DATE] = IST("HAProxy release date."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100619 [INF_NBTHREAD] = IST("Configured number of threads."),
620 [INF_NBPROC] = IST("Configured number of processes."),
621 [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
622 [INF_PID] = IST("HAProxy PID."),
623 [INF_UPTIME] = IST("Uptime in a human readable format."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200624 [INF_UPTIME_SEC] = IST("Start time in seconds."),
625 [INF_MEMMAX_MB] = IST("Per-process memory limit (in bytes); 0=unset."),
626 [INF_POOL_ALLOC_MB] = IST("Total amount of memory allocated in pools (in bytes)."),
627 [INF_POOL_USED_MB] = IST("Total amount of memory used in pools (in bytes)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100628 [INF_POOL_FAILED] = IST("Total number of failed pool allocations."),
629 [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500630 [INF_MAXSOCK] = IST("Maximum number of open sockets."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100631 [INF_MAXCONN] = IST("Maximum number of concurrent connections."),
632 [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."),
633 [INF_CURR_CONN] = IST("Number of active sessions."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200634 [INF_CUM_CONN] = IST("Total number of created sessions."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100635 [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."),
636 [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."),
637 [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."),
638 [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."),
639 [INF_MAXPIPES] = IST("Configured maximum number of pipes."),
640 [INF_PIPES_USED] = IST("Number of pipes in used."),
641 [INF_PIPES_FREE] = IST("Number of pipes unused."),
642 [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."),
643 [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."),
644 [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."),
645 [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."),
646 [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."),
647 [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."),
648 [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."),
649 [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."),
650 [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."),
651 [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."),
652 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."),
653 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."),
654 [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."),
655 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."),
656 [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."),
657 [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."),
658 [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."),
659 [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."),
660 [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."),
661 [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."),
662 [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."),
663 [INF_TASKS] = IST("Current number of tasks."),
664 [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."),
665 [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."),
666 [INF_NODE] = IST("Node name."),
667 [INF_DESCRIPTION] = IST("Node description."),
668 [INF_STOPPING] = IST("Non zero means stopping in progress."),
669 [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."),
670 [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."),
671 [INF_LISTENERS] = IST("Current number of active listeners."),
672 [INF_ACTIVE_PEERS] = IST("Current number of active peers."),
673 [INF_CONNECTED_PEERS] = IST("Current number of connected peers."),
674 [INF_DROPPED_LOGS] = IST("Total number of dropped logs."),
675 [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."),
676};
677
678/* Description of all stats fields */
679const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
680 [ST_F_PXNAME] = IST("The proxy name."),
681 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
682 [ST_F_QCUR] = IST("Current number of queued requests."),
683 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
684 [ST_F_SCUR] = IST("Current number of active sessions."),
685 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
686 [ST_F_SLIM] = IST("Configured session limit."),
687 [ST_F_STOT] = IST("Total number of sessions."),
688 [ST_F_BIN] = IST("Current total of incoming bytes."),
689 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
690 [ST_F_DREQ] = IST("Total number of denied requests."),
691 [ST_F_DRESP] = IST("Total number of denied responses."),
692 [ST_F_EREQ] = IST("Total number of request errors."),
693 [ST_F_ECON] = IST("Total number of connection errors."),
694 [ST_F_ERESP] = IST("Total number of response errors."),
695 [ST_F_WRETR] = IST("Total number of retry warnings."),
696 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Christopher Fauletd45d1052019-09-06 16:10:19 +0200697 [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 +0100698 [ST_F_WEIGHT] = IST("Service weight."),
699 [ST_F_ACT] = IST("Current number of active servers."),
700 [ST_F_BCK] = IST("Current number of backup servers."),
701 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
702 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
703 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
704 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
705 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
706 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
707 [ST_F_IID] = IST("Unique proxy id."),
708 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
709 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
710 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
711 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
712 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
713 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
714 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
715 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
Christopher Fauletcf403f32019-11-21 14:35:46 +0100716 [ST_F_CHECK_STATUS] = IST("Status of last health check (HCHK_STATUS_* values)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100717 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
Christopher Faulet2711e512020-02-27 16:12:07 +0100718 [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100719 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
720 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
721 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
722 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
723 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
724 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
725 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
726 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
727 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
728 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
729 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
730 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
731 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
732 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
733 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
734 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
735 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
736 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
737 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
738 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
739 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
740 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
741 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
742 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
743 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
744 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
745 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
746 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
747 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
748 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
749 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
750 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
751 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
752 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
753 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
754 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
755 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
756 [ST_F_ALGO] = IST("Load balancing algorithm."),
757 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
758 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
759 [ST_F_CONN_TOT] = IST("Total number of connections."),
760 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
761 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
762 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
763 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
764 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
765 [ST_F_REUSE] = IST("Total number of connection reuses."),
766 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
767 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100768 [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"),
769 [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100770 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
771 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
772 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
773 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100774 [ST_F_EINT] = IST("Total number of internal errors."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100775};
776
777/* Specific labels for all info fields. Empty by default. */
778const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
779 [INF_NAME] = IST(""),
780 [INF_VERSION] = IST(""),
781 [INF_RELEASE_DATE] = IST(""),
782 [INF_NBTHREAD] = IST(""),
783 [INF_NBPROC] = IST(""),
784 [INF_PROCESS_NUM] = IST(""),
785 [INF_PID] = IST(""),
786 [INF_UPTIME] = IST(""),
787 [INF_UPTIME_SEC] = IST(""),
788 [INF_MEMMAX_MB] = IST(""),
789 [INF_POOL_ALLOC_MB] = IST(""),
790 [INF_POOL_USED_MB] = IST(""),
791 [INF_POOL_FAILED] = IST(""),
792 [INF_ULIMIT_N] = IST(""),
793 [INF_MAXSOCK] = IST(""),
794 [INF_MAXCONN] = IST(""),
795 [INF_HARD_MAXCONN] = IST(""),
796 [INF_CURR_CONN] = IST(""),
797 [INF_CUM_CONN] = IST(""),
798 [INF_CUM_REQ] = IST(""),
799 [INF_MAX_SSL_CONNS] = IST(""),
800 [INF_CURR_SSL_CONNS] = IST(""),
801 [INF_CUM_SSL_CONNS] = IST(""),
802 [INF_MAXPIPES] = IST(""),
803 [INF_PIPES_USED] = IST(""),
804 [INF_PIPES_FREE] = IST(""),
805 [INF_CONN_RATE] = IST(""),
806 [INF_CONN_RATE_LIMIT] = IST(""),
807 [INF_MAX_CONN_RATE] = IST(""),
808 [INF_SESS_RATE] = IST(""),
809 [INF_SESS_RATE_LIMIT] = IST(""),
810 [INF_MAX_SESS_RATE] = IST(""),
811 [INF_SSL_RATE] = IST(""),
812 [INF_SSL_RATE_LIMIT] = IST(""),
813 [INF_MAX_SSL_RATE] = IST(""),
814 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
815 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
816 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
817 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
818 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
819 [INF_SSL_CACHE_LOOKUPS] = IST(""),
820 [INF_SSL_CACHE_MISSES] = IST(""),
821 [INF_COMPRESS_BPS_IN] = IST(""),
822 [INF_COMPRESS_BPS_OUT] = IST(""),
823 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
824 [INF_ZLIB_MEM_USAGE] = IST(""),
825 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
826 [INF_TASKS] = IST(""),
827 [INF_RUN_QUEUE] = IST(""),
828 [INF_IDLE_PCT] = IST(""),
829 [INF_NODE] = IST(""),
830 [INF_DESCRIPTION] = IST(""),
831 [INF_STOPPING] = IST(""),
832 [INF_JOBS] = IST(""),
833 [INF_UNSTOPPABLE_JOBS] = IST(""),
834 [INF_LISTENERS] = IST(""),
835 [INF_ACTIVE_PEERS] = IST(""),
836 [INF_CONNECTED_PEERS] = IST(""),
837 [INF_DROPPED_LOGS] = IST(""),
838 [INF_BUSY_POLLING] = IST(""),
839};
840
841/* Specific labels for all stats fields. Empty by default. */
842const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
843 [ST_F_PXNAME] = IST(""),
844 [ST_F_SVNAME] = IST(""),
845 [ST_F_QCUR] = IST(""),
846 [ST_F_QMAX] = IST(""),
847 [ST_F_SCUR] = IST(""),
848 [ST_F_SMAX] = IST(""),
849 [ST_F_SLIM] = IST(""),
850 [ST_F_STOT] = IST(""),
851 [ST_F_BIN] = IST(""),
852 [ST_F_BOUT] = IST(""),
853 [ST_F_DREQ] = IST(""),
854 [ST_F_DRESP] = IST(""),
855 [ST_F_EREQ] = IST(""),
856 [ST_F_ECON] = IST(""),
857 [ST_F_ERESP] = IST(""),
858 [ST_F_WRETR] = IST(""),
859 [ST_F_WREDIS] = IST(""),
860 [ST_F_STATUS] = IST(""),
861 [ST_F_WEIGHT] = IST(""),
862 [ST_F_ACT] = IST(""),
863 [ST_F_BCK] = IST(""),
864 [ST_F_CHKFAIL] = IST(""),
865 [ST_F_CHKDOWN] = IST(""),
866 [ST_F_LASTCHG] = IST(""),
867 [ST_F_DOWNTIME] = IST(""),
868 [ST_F_QLIMIT] = IST(""),
869 [ST_F_PID] = IST(""),
870 [ST_F_IID] = IST(""),
871 [ST_F_SID] = IST(""),
872 [ST_F_THROTTLE] = IST(""),
873 [ST_F_LBTOT] = IST(""),
874 [ST_F_TRACKED] = IST(""),
875 [ST_F_TYPE] = IST(""),
876 [ST_F_RATE] = IST(""),
877 [ST_F_RATE_LIM] = IST(""),
878 [ST_F_RATE_MAX] = IST(""),
879 [ST_F_CHECK_STATUS] = IST(""),
880 [ST_F_CHECK_CODE] = IST(""),
881 [ST_F_CHECK_DURATION] = IST(""),
882 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
883 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
884 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
885 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
886 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
887 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
888 [ST_F_HANAFAIL] = IST(""),
889 [ST_F_REQ_RATE] = IST(""),
890 [ST_F_REQ_RATE_MAX] = IST(""),
891 [ST_F_REQ_TOT] = IST(""),
892 [ST_F_CLI_ABRT] = IST(""),
893 [ST_F_SRV_ABRT] = IST(""),
894 [ST_F_COMP_IN] = IST(""),
895 [ST_F_COMP_OUT] = IST(""),
896 [ST_F_COMP_BYP] = IST(""),
897 [ST_F_COMP_RSP] = IST(""),
898 [ST_F_LASTSESS] = IST(""),
899 [ST_F_LAST_CHK] = IST(""),
900 [ST_F_LAST_AGT] = IST(""),
901 [ST_F_QTIME] = IST(""),
902 [ST_F_CTIME] = IST(""),
903 [ST_F_RTIME] = IST(""),
904 [ST_F_TTIME] = IST(""),
905 [ST_F_AGENT_STATUS] = IST(""),
906 [ST_F_AGENT_CODE] = IST(""),
907 [ST_F_AGENT_DURATION] = IST(""),
908 [ST_F_CHECK_DESC] = IST(""),
909 [ST_F_AGENT_DESC] = IST(""),
910 [ST_F_CHECK_RISE] = IST(""),
911 [ST_F_CHECK_FALL] = IST(""),
912 [ST_F_CHECK_HEALTH] = IST(""),
913 [ST_F_AGENT_RISE] = IST(""),
914 [ST_F_AGENT_FALL] = IST(""),
915 [ST_F_AGENT_HEALTH] = IST(""),
916 [ST_F_ADDR] = IST(""),
917 [ST_F_COOKIE] = IST(""),
918 [ST_F_MODE] = IST(""),
919 [ST_F_ALGO] = IST(""),
920 [ST_F_CONN_RATE] = IST(""),
921 [ST_F_CONN_RATE_MAX] = IST(""),
922 [ST_F_CONN_TOT] = IST(""),
923 [ST_F_INTERCEPTED] = IST(""),
924 [ST_F_DCON] = IST(""),
925 [ST_F_DSES] = IST(""),
926 [ST_F_WREW] = IST(""),
927 [ST_F_CONNECT] = IST(""),
928 [ST_F_REUSE] = IST(""),
929 [ST_F_CACHE_LOOKUPS] = IST(""),
930 [ST_F_CACHE_HITS] = IST(""),
931};
932
933/* Type for all info fields. "untyped" is used for unsupported field. */
934const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
935 [INF_NAME] = IST("untyped"),
936 [INF_VERSION] = IST("untyped"),
937 [INF_RELEASE_DATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200938 [INF_NBTHREAD] = IST("gauge"),
939 [INF_NBPROC] = IST("gauge"),
940 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100941 [INF_PID] = IST("untyped"),
942 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200943 [INF_UPTIME_SEC] = IST("gauge"),
944 [INF_MEMMAX_MB] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100945 [INF_POOL_ALLOC_MB] = IST("gauge"),
946 [INF_POOL_USED_MB] = IST("gauge"),
947 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200948 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100949 [INF_MAXSOCK] = IST("gauge"),
950 [INF_MAXCONN] = IST("gauge"),
951 [INF_HARD_MAXCONN] = IST("gauge"),
952 [INF_CURR_CONN] = IST("gauge"),
953 [INF_CUM_CONN] = IST("counter"),
954 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200955 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100956 [INF_CURR_SSL_CONNS] = IST("gauge"),
957 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200958 [INF_MAXPIPES] = IST("gauge"),
959 [INF_PIPES_USED] = IST("counter"),
960 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100961 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200962 [INF_CONN_RATE_LIMIT] = IST("gauge"),
963 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100964 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200965 [INF_SESS_RATE_LIMIT] = IST("gauge"),
966 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100967 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200968 [INF_SSL_RATE_LIMIT] = IST("gauge"),
969 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100970 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200971 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100972 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
973 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200974 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100975 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
976 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200977 [INF_COMPRESS_BPS_IN] = IST("counter"),
978 [INF_COMPRESS_BPS_OUT] = IST("counter"),
979 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100980 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200981 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100982 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +0200983 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100984 [INF_IDLE_PCT] = IST("gauge"),
985 [INF_NODE] = IST("untyped"),
986 [INF_DESCRIPTION] = IST("untyped"),
987 [INF_STOPPING] = IST("gauge"),
988 [INF_JOBS] = IST("gauge"),
989 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
990 [INF_LISTENERS] = IST("gauge"),
991 [INF_ACTIVE_PEERS] = IST("gauge"),
992 [INF_CONNECTED_PEERS] = IST("gauge"),
993 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200994 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100995};
996
997/* Type for all stats fields. "untyped" is used for unsupported field. */
998const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
999 [ST_F_PXNAME] = IST("untyped"),
1000 [ST_F_SVNAME] = IST("untyped"),
1001 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001002 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001003 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001004 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001005 [ST_F_SLIM] = IST("gauge"),
1006 [ST_F_STOT] = IST("counter"),
1007 [ST_F_BIN] = IST("counter"),
1008 [ST_F_BOUT] = IST("counter"),
1009 [ST_F_DREQ] = IST("counter"),
1010 [ST_F_DRESP] = IST("counter"),
1011 [ST_F_EREQ] = IST("counter"),
1012 [ST_F_ECON] = IST("counter"),
1013 [ST_F_ERESP] = IST("counter"),
1014 [ST_F_WRETR] = IST("counter"),
1015 [ST_F_WREDIS] = IST("counter"),
1016 [ST_F_STATUS] = IST("gauge"),
1017 [ST_F_WEIGHT] = IST("gauge"),
1018 [ST_F_ACT] = IST("gauge"),
1019 [ST_F_BCK] = IST("gauge"),
1020 [ST_F_CHKFAIL] = IST("counter"),
1021 [ST_F_CHKDOWN] = IST("counter"),
1022 [ST_F_LASTCHG] = IST("gauge"),
1023 [ST_F_DOWNTIME] = IST("counter"),
1024 [ST_F_QLIMIT] = IST("gauge"),
1025 [ST_F_PID] = IST("untyped"),
1026 [ST_F_IID] = IST("untyped"),
1027 [ST_F_SID] = IST("untyped"),
1028 [ST_F_THROTTLE] = IST("gauge"),
1029 [ST_F_LBTOT] = IST("counter"),
1030 [ST_F_TRACKED] = IST("untyped"),
1031 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001032 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001033 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001034 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Fauletcf403f32019-11-21 14:35:46 +01001035 [ST_F_CHECK_STATUS] = IST("gauge"),
1036 [ST_F_CHECK_CODE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001037 [ST_F_CHECK_DURATION] = IST("gauge"),
1038 [ST_F_HRSP_1XX] = IST("counter"),
1039 [ST_F_HRSP_2XX] = IST("counter"),
1040 [ST_F_HRSP_3XX] = IST("counter"),
1041 [ST_F_HRSP_4XX] = IST("counter"),
1042 [ST_F_HRSP_5XX] = IST("counter"),
1043 [ST_F_HRSP_OTHER] = IST("counter"),
1044 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001045 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001046 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001047 [ST_F_REQ_TOT] = IST("counter"),
1048 [ST_F_CLI_ABRT] = IST("counter"),
1049 [ST_F_SRV_ABRT] = IST("counter"),
1050 [ST_F_COMP_IN] = IST("counter"),
1051 [ST_F_COMP_OUT] = IST("counter"),
1052 [ST_F_COMP_BYP] = IST("counter"),
1053 [ST_F_COMP_RSP] = IST("counter"),
1054 [ST_F_LASTSESS] = IST("gauge"),
1055 [ST_F_LAST_CHK] = IST("untyped"),
1056 [ST_F_LAST_AGT] = IST("untyped"),
1057 [ST_F_QTIME] = IST("gauge"),
1058 [ST_F_CTIME] = IST("gauge"),
1059 [ST_F_RTIME] = IST("gauge"),
1060 [ST_F_TTIME] = IST("gauge"),
1061 [ST_F_AGENT_STATUS] = IST("untyped"),
1062 [ST_F_AGENT_CODE] = IST("untyped"),
1063 [ST_F_AGENT_DURATION] = IST("gauge"),
1064 [ST_F_CHECK_DESC] = IST("untyped"),
1065 [ST_F_AGENT_DESC] = IST("untyped"),
1066 [ST_F_CHECK_RISE] = IST("gauge"),
1067 [ST_F_CHECK_FALL] = IST("gauge"),
1068 [ST_F_CHECK_HEALTH] = IST("gauge"),
1069 [ST_F_AGENT_RISE] = IST("gauge"),
1070 [ST_F_AGENT_FALL] = IST("gauge"),
1071 [ST_F_AGENT_HEALTH] = IST("gauge"),
1072 [ST_F_ADDR] = IST("untyped"),
1073 [ST_F_COOKIE] = IST("untyped"),
1074 [ST_F_MODE] = IST("untyped"),
1075 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001076 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001077 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001078 [ST_F_CONN_TOT] = IST("counter"),
1079 [ST_F_INTERCEPTED] = IST("counter"),
1080 [ST_F_DCON] = IST("counter"),
1081 [ST_F_DSES] = IST("counter"),
1082 [ST_F_WREW] = IST("counter"),
1083 [ST_F_CONNECT] = IST("counter"),
1084 [ST_F_REUSE] = IST("counter"),
1085 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1086 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Faulet20ab80c2019-11-08 15:24:32 +01001087 [ST_F_SRV_ICUR] = IST("gauge"),
1088 [ST_F_SRV_ILIM] = IST("gauge"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001089 [ST_F_QT_MAX] = IST("gauge"),
1090 [ST_F_CT_MAX] = IST("gauge"),
1091 [ST_F_RT_MAX] = IST("gauge"),
1092 [ST_F_TT_MAX] = IST("gauge"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001093 [ST_F_EINT] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001094};
1095
Christopher Fauletd45d1052019-09-06 16:10:19 +02001096/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001097static int promex_srv_status(struct server *sv)
1098{
Christopher Fauletf959d082019-02-07 15:38:42 +01001099 int state = 0;
1100
Christopher Fauletf959d082019-02-07 15:38:42 +01001101 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1102 state = 1;
1103 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Fauletd45d1052019-09-06 16:10:19 +02001104 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001105 }
Christopher Fauletd45d1052019-09-06 16:10:19 +02001106 else if (sv->cur_state == SRV_ST_STOPPING)
1107 state = 4;
1108
1109 if (sv->cur_admin & SRV_ADMF_MAINT)
1110 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001111
1112 return state;
1113}
1114
1115/* Convert a field to its string representation and write it in <out>, followed
1116 * by a newline, if there is enough space. non-numeric value are converted in
1117 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1118 * to process this kind of value). It returns 1 on success. Otherwise, it
1119 * returns 0. The buffer's length must not exceed <max> value.
1120 */
1121static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1122{
1123 int ret = 0;
1124
1125 switch (field_format(f, 0)) {
1126 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1127 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1128 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1129 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1130 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001131 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001132 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1133 default: ret = chunk_strcat(out, "Nan\n"); break;
1134 }
1135 if (!ret || out->data > max)
1136 return 0;
1137 return 1;
1138}
1139
1140/* Concatenate the <prefix> with the field name using the array
1141 * <promex_st_metric_names> and store it in <name>. The field type is in
1142 * <appctx->st2>. This function never fails but relies on
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001143 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enough to be copied in
Christopher Fauletf959d082019-02-07 15:38:42 +01001144 * <name>
1145 */
1146static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1147{
1148 const struct ist *names;
1149
1150 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1151 ? promex_inf_metric_names
1152 : promex_st_metric_names);
1153
1154 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1155 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1156}
1157
1158/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1159 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1160 */
1161static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1162 const struct ist name, struct ist *out, size_t max)
1163{
1164 const struct ist *desc, *types;
1165
1166 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1167 desc = promex_inf_metric_desc;
1168 types = promex_inf_metric_types;
1169 }
1170 else {
1171 desc = promex_st_metric_desc;
1172 types = promex_st_metric_types;
1173 }
1174
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001175 if (istcat(out, ist("# HELP "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001176 istcat(out, name, max) == -1 ||
1177 istcat(out, ist(" "), max) == -1 ||
1178 istcat(out, desc[appctx->st2], max) == -1 ||
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001179 istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001180 istcat(out, name, max) == -1 ||
1181 istcat(out, ist(" "), max) == -1 ||
1182 istcat(out, types[appctx->st2], max) == -1 ||
1183 istcat(out, ist("\n"), max) == -1)
1184 goto full;
1185
1186 return 1;
1187
1188 full:
1189 return 0;
1190}
1191
1192/* Dump the line for <metric>. It starts by the metric name followed by its
1193 * labels (proxy name, server name...) between braces and finally its value. If
1194 * not already done, the header lines are dumped first. It returns 1 on
1195 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1196 */
1197static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1198 const struct ist prefix, struct field *metric,
1199 struct ist *out, size_t max)
1200{
1201 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1202 size_t len = out->len;
1203
1204 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1205 return 0;
1206
1207 promex_metric_name(appctx, &name, prefix);
1208 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1209 !promex_dump_metric_header(appctx, htx, name, out, max))
1210 goto full;
1211
1212 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1213 const struct ist label = promex_inf_metric_labels[appctx->st2];
1214
1215 if (istcat(out, name, max) == -1 ||
1216 (label.len && istcat(out, ist("{"), max) == -1) ||
1217 (label.len && istcat(out, label, max) == -1) ||
1218 (label.len && istcat(out, ist("}"), max) == -1) ||
1219 istcat(out, ist(" "), max) == -1)
1220 goto full;
1221 }
1222 else {
1223 struct proxy *px = appctx->ctx.stats.px;
1224 struct server *srv = appctx->ctx.stats.sv;
1225 const struct ist label = promex_st_metric_labels[appctx->st2];
1226
1227 if (istcat(out, name, max) == -1 ||
1228 istcat(out, ist("{proxy=\""), max) == -1 ||
1229 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1230 istcat(out, ist("\""), max) == -1 ||
1231 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1232 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1233 (srv && istcat(out, ist("\""), max) == -1) ||
1234 (label.len && istcat(out, ist(","), max) == -1) ||
1235 (label.len && istcat(out, label, max) == -1) ||
1236 istcat(out, ist("} "), max) == -1)
1237 goto full;
1238 }
1239
1240 trash.data = out->len;
1241 if (!promex_metric_to_str(&trash, metric, max))
1242 goto full;
1243 out->len = trash.data;
1244
1245 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1246 return 1;
1247 full:
1248 // Restore previous length
1249 out->len = len;
1250 return 0;
1251
1252}
1253
1254
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001255/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001256 * 0 if <htx> is full and -1 in case of any error. */
1257static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1258{
1259 static struct ist prefix = IST("haproxy_process_");
1260 struct field metric;
1261 struct channel *chn = si_ic(appctx->owner);
1262 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001263 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001264 int ret = 1;
1265
1266#ifdef USE_OPENSSL
1267 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
1268 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
1269 int ssl_reuse = 0;
1270
1271 if (ssl_key_rate < ssl_sess_rate) {
1272 /* count the ssl reuse ratio and avoid overflows in both directions */
1273 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
1274 }
1275#endif
Christopher Fauletf959d082019-02-07 15:38:42 +01001276 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1277 switch (appctx->st2) {
1278 case INF_NBTHREAD:
1279 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
1280 break;
1281 case INF_NBPROC:
1282 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
1283 break;
1284 case INF_PROCESS_NUM:
1285 metric = mkf_u32(FO_KEY, relative_pid);
1286 break;
1287 case INF_UPTIME_SEC:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001288 metric = mkf_u32(FN_DURATION, start_date.tv_sec);
Christopher Fauletf959d082019-02-07 15:38:42 +01001289 break;
1290 case INF_MEMMAX_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001291 metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
Christopher Fauletf959d082019-02-07 15:38:42 +01001292 break;
1293 case INF_POOL_ALLOC_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001294 metric = mkf_u64(0, pool_total_allocated());
Christopher Fauletf959d082019-02-07 15:38:42 +01001295 break;
1296 case INF_POOL_USED_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001297 metric = mkf_u64(0, pool_total_used());
Christopher Fauletf959d082019-02-07 15:38:42 +01001298 break;
1299 case INF_POOL_FAILED:
1300 metric = mkf_u32(FN_COUNTER, pool_total_failures());
1301 break;
1302 case INF_ULIMIT_N:
1303 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
1304 break;
1305 case INF_MAXSOCK:
1306 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
1307 break;
1308 case INF_MAXCONN:
1309 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
1310 break;
1311 case INF_HARD_MAXCONN:
1312 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
1313 break;
1314 case INF_CURR_CONN:
1315 metric = mkf_u32(0, actconn);
1316 break;
1317 case INF_CUM_CONN:
1318 metric = mkf_u32(FN_COUNTER, totalconn);
1319 break;
1320 case INF_CUM_REQ:
1321 metric = mkf_u32(FN_COUNTER, global.req_count);
1322 break;
1323#ifdef USE_OPENSSL
1324 case INF_MAX_SSL_CONNS:
1325 metric = mkf_u32(FN_MAX, global.maxsslconn);
1326 break;
1327 case INF_CURR_SSL_CONNS:
1328 metric = mkf_u32(0, sslconns);
1329 break;
1330 case INF_CUM_SSL_CONNS:
1331 metric = mkf_u32(FN_COUNTER, totalsslconns);
1332 break;
1333#endif
1334 case INF_MAXPIPES:
1335 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
1336 break;
1337 case INF_PIPES_USED:
1338 metric = mkf_u32(0, pipes_used);
1339 break;
1340 case INF_PIPES_FREE:
1341 metric = mkf_u32(0, pipes_free);
1342 break;
1343 case INF_CONN_RATE:
1344 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
1345 break;
1346 case INF_CONN_RATE_LIMIT:
1347 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
1348 break;
1349 case INF_MAX_CONN_RATE:
1350 metric = mkf_u32(FN_MAX, global.cps_max);
1351 break;
1352 case INF_SESS_RATE:
1353 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
1354 break;
1355 case INF_SESS_RATE_LIMIT:
1356 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
1357 break;
1358 case INF_MAX_SESS_RATE:
1359 metric = mkf_u32(FN_RATE, global.sps_max);
1360 break;
1361#ifdef USE_OPENSSL
1362 case INF_SSL_RATE:
1363 metric = mkf_u32(FN_RATE, ssl_sess_rate);
1364 break;
1365 case INF_SSL_RATE_LIMIT:
1366 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
1367 break;
1368 case INF_MAX_SSL_RATE:
1369 metric = mkf_u32(FN_MAX, global.ssl_max);
1370 break;
1371 case INF_SSL_FRONTEND_KEY_RATE:
1372 metric = mkf_u32(0, ssl_key_rate);
1373 break;
1374 case INF_SSL_FRONTEND_MAX_KEY_RATE:
1375 metric = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
1376 break;
1377 case INF_SSL_FRONTEND_SESSION_REUSE_PCT:
1378 metric = mkf_u32(0, ssl_reuse);
1379 break;
1380 case INF_SSL_BACKEND_KEY_RATE:
1381 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
1382 break;
1383 case INF_SSL_BACKEND_MAX_KEY_RATE:
1384 metric = mkf_u32(FN_MAX, global.ssl_be_keys_max);
1385 break;
1386 case INF_SSL_CACHE_LOOKUPS:
1387 metric = mkf_u32(FN_COUNTER, global.shctx_lookups);
1388 break;
1389 case INF_SSL_CACHE_MISSES:
1390 metric = mkf_u32(FN_COUNTER, global.shctx_misses);
1391 break;
1392#endif
1393 case INF_COMPRESS_BPS_IN:
1394 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
1395 break;
1396 case INF_COMPRESS_BPS_OUT:
1397 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
1398 break;
1399 case INF_COMPRESS_BPS_RATE_LIM:
1400 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
1401 break;
1402#ifdef USE_ZLIB
1403 case INF_ZLIB_MEM_USAGE:
1404 metric = mkf_u32(0, zlib_used_memory);
1405 break;
1406 case INF_MAX_ZLIB_MEM_USAGE:
1407 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
1408 break;
1409#endif
1410 case INF_TASKS:
1411 metric = mkf_u32(0, nb_tasks_cur);
1412 break;
1413 case INF_RUN_QUEUE:
1414 metric = mkf_u32(0, tasks_run_queue_cur);
1415 break;
1416 case INF_IDLE_PCT:
Willy Tarreau76824a82019-06-02 10:38:48 +02001417 metric = mkf_u32(FN_AVG, ti->idle_pct);
Christopher Fauletf959d082019-02-07 15:38:42 +01001418 break;
1419 case INF_STOPPING:
1420 metric = mkf_u32(0, stopping);
1421 break;
1422 case INF_JOBS:
1423 metric = mkf_u32(0, jobs);
1424 break;
1425 case INF_UNSTOPPABLE_JOBS:
1426 metric = mkf_u32(0, unstoppable_jobs);
1427 break;
1428 case INF_LISTENERS:
1429 metric = mkf_u32(0, listeners);
1430 break;
1431 case INF_ACTIVE_PEERS:
1432 metric = mkf_u32(0, active_peers);
1433 break;
1434 case INF_CONNECTED_PEERS:
1435 metric = mkf_u32(0, connected_peers);
1436 break;
1437 case INF_DROPPED_LOGS:
1438 metric = mkf_u32(0, dropped_logs);
1439 break;
1440 case INF_BUSY_POLLING:
1441 metric = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
1442 break;
1443
1444 default:
1445 goto next_metric;
1446 }
1447
1448 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1449 goto full;
1450
1451 next_metric:
1452 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1453 appctx->st2 = promex_global_metrics[appctx->st2];
1454 }
1455
1456 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001457 if (out.len) {
1458 if (!htx_add_data_atonce(htx, out))
1459 return -1; /* Unexpected and unrecoverable error */
1460 channel_add_input(chn, out.len);
1461 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001462 return ret;
1463 full:
1464 ret = 0;
1465 goto end;
1466}
1467
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001468/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001469 * 0 if <htx> is full and -1 in case of any error. */
1470static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1471{
1472 static struct ist prefix = IST("haproxy_frontend_");
1473 struct proxy *px;
1474 struct field metric;
1475 struct channel *chn = si_ic(appctx->owner);
1476 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001477 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001478 int ret = 1;
1479
1480 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1481 while (appctx->ctx.stats.px) {
1482 px = appctx->ctx.stats.px;
1483
1484 /* skip the disabled proxies, global frontend and non-networked ones */
1485 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
1486 goto next_px;
1487
1488 switch (appctx->st2) {
1489 case ST_F_STATUS:
1490 metric = mkf_u32(FO_STATUS, px->state == PR_STREADY ? 1 : px->state == PR_STFULL ? 2 : 0);
1491 break;
1492 case ST_F_SCUR:
1493 metric = mkf_u32(0, px->feconn);
1494 break;
1495 case ST_F_SMAX:
1496 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1497 break;
1498 case ST_F_SLIM:
1499 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1500 break;
1501 case ST_F_STOT:
1502 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1503 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001504 case ST_F_RATE_LIM:
1505 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1506 break;
1507 case ST_F_RATE_MAX:
1508 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1509 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001510 case ST_F_CONN_RATE_MAX:
1511 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1512 break;
1513 case ST_F_CONN_TOT:
1514 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1515 break;
1516 case ST_F_BIN:
1517 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1518 break;
1519 case ST_F_BOUT:
1520 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1521 break;
1522 case ST_F_DREQ:
1523 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1524 break;
1525 case ST_F_DRESP:
1526 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1527 break;
1528 case ST_F_EREQ:
1529 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1530 break;
1531 case ST_F_DCON:
1532 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1533 break;
1534 case ST_F_DSES:
1535 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1536 break;
1537 case ST_F_WREW:
1538 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1539 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001540 case ST_F_EINT:
1541 metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors);
1542 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001543 case ST_F_REQ_RATE_MAX:
1544 if (px->mode != PR_MODE_HTTP)
1545 goto next_px;
1546 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1547 break;
1548 case ST_F_REQ_TOT:
1549 if (px->mode != PR_MODE_HTTP)
1550 goto next_px;
1551 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1552 break;
1553 case ST_F_HRSP_1XX:
1554 if (px->mode != PR_MODE_HTTP)
1555 goto next_px;
1556 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1557 break;
1558 case ST_F_HRSP_2XX:
1559 if (px->mode != PR_MODE_HTTP)
1560 goto next_px;
1561 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1562 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1563 break;
1564 case ST_F_HRSP_3XX:
1565 if (px->mode != PR_MODE_HTTP)
1566 goto next_px;
1567 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1568 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1569 break;
1570 case ST_F_HRSP_4XX:
1571 if (px->mode != PR_MODE_HTTP)
1572 goto next_px;
1573 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1574 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1575 break;
1576 case ST_F_HRSP_5XX:
1577 if (px->mode != PR_MODE_HTTP)
1578 goto next_px;
1579 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1580 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1581 break;
1582 case ST_F_HRSP_OTHER:
1583 if (px->mode != PR_MODE_HTTP)
1584 goto next_px;
1585 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1586 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1587 break;
1588 case ST_F_INTERCEPTED:
1589 if (px->mode != PR_MODE_HTTP)
1590 goto next_px;
1591 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1592 break;
1593 case ST_F_CACHE_LOOKUPS:
1594 if (px->mode != PR_MODE_HTTP)
1595 goto next_px;
1596 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1597 break;
1598 case ST_F_CACHE_HITS:
1599 if (px->mode != PR_MODE_HTTP)
1600 goto next_px;
1601 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1602 break;
1603 case ST_F_COMP_IN:
1604 if (px->mode != PR_MODE_HTTP)
1605 goto next_px;
1606 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1607 break;
1608 case ST_F_COMP_OUT:
1609 if (px->mode != PR_MODE_HTTP)
1610 goto next_px;
1611 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1612 break;
1613 case ST_F_COMP_BYP:
1614 if (px->mode != PR_MODE_HTTP)
1615 goto next_px;
1616 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1617 break;
1618 case ST_F_COMP_RSP:
1619 if (px->mode != PR_MODE_HTTP)
1620 goto next_px;
1621 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1622 break;
1623
1624 default:
1625 goto next_metric;
1626 }
1627
1628 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1629 goto full;
1630 next_px:
1631 appctx->ctx.stats.px = px->next;
1632 }
1633 next_metric:
1634 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1635 appctx->ctx.stats.px = proxies_list;
1636 appctx->st2 = promex_front_metrics[appctx->st2];
1637 }
1638
1639 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001640 if (out.len) {
1641 if (!htx_add_data_atonce(htx, out))
1642 return -1; /* Unexpected and unrecoverable error */
1643 channel_add_input(chn, out.len);
1644 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001645 return ret;
1646 full:
1647 ret = 0;
1648 goto end;
1649}
1650
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001651/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001652 * 0 if <htx> is full and -1 in case of any error. */
1653static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1654{
1655 static struct ist prefix = IST("haproxy_backend_");
1656 struct proxy *px;
1657 struct field metric;
1658 struct channel *chn = si_ic(appctx->owner);
1659 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001660 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001661 int ret = 1;
1662 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001663 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001664
1665 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1666 while (appctx->ctx.stats.px) {
1667 px = appctx->ctx.stats.px;
1668
1669 /* skip the disabled proxies, global frontend and non-networked ones */
1670 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1671 goto next_px;
1672
1673 switch (appctx->st2) {
1674 case ST_F_STATUS:
1675 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1676 break;
1677 case ST_F_SCUR:
1678 metric = mkf_u32(0, px->beconn);
1679 break;
1680 case ST_F_SMAX:
1681 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1682 break;
1683 case ST_F_SLIM:
1684 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1685 break;
1686 case ST_F_STOT:
1687 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1688 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001689 case ST_F_RATE_MAX:
1690 metric = mkf_u32(0, px->be_counters.sps_max);
1691 break;
1692 case ST_F_LASTSESS:
1693 metric = mkf_s32(FN_AGE, be_lastsession(px));
1694 break;
1695 case ST_F_QCUR:
1696 metric = mkf_u32(0, px->nbpend);
1697 break;
1698 case ST_F_QMAX:
1699 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1700 break;
1701 case ST_F_CONNECT:
1702 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1703 break;
1704 case ST_F_REUSE:
1705 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1706 break;
1707 case ST_F_BIN:
1708 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1709 break;
1710 case ST_F_BOUT:
1711 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1712 break;
1713 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001714 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1715 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001716 break;
1717 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001718 secs = (double)swrate_avg(px->be_counters.c_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_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001722 secs = (double)swrate_avg(px->be_counters.d_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_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001726 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1727 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001728 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001729 case ST_F_QT_MAX:
1730 secs = (double)px->be_counters.qtime_max / 1000.0;
1731 metric = mkf_flt(FN_MAX, secs);
1732 break;
1733 case ST_F_CT_MAX:
1734 secs = (double)px->be_counters.ctime_max / 1000.0;
1735 metric = mkf_flt(FN_MAX, secs);
1736 break;
1737 case ST_F_RT_MAX:
1738 secs = (double)px->be_counters.dtime_max / 1000.0;
1739 metric = mkf_flt(FN_MAX, secs);
1740 break;
1741 case ST_F_TT_MAX:
1742 secs = (double)px->be_counters.ttime_max / 1000.0;
1743 metric = mkf_flt(FN_MAX, secs);
1744 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001745 case ST_F_DREQ:
1746 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1747 break;
1748 case ST_F_DRESP:
1749 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1750 break;
1751 case ST_F_ECON:
1752 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1753 break;
1754 case ST_F_ERESP:
1755 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1756 break;
1757 case ST_F_WRETR:
1758 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1759 break;
1760 case ST_F_WREDIS:
1761 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1762 break;
1763 case ST_F_WREW:
1764 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1765 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001766 case ST_F_EINT:
1767 metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors);
1768 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001769 case ST_F_CLI_ABRT:
1770 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1771 break;
1772 case ST_F_SRV_ABRT:
1773 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1774 break;
1775 case ST_F_WEIGHT:
1776 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1777 metric = mkf_u32(FN_AVG, weight);
1778 break;
1779 case ST_F_ACT:
1780 metric = mkf_u32(0, px->srv_act);
1781 break;
1782 case ST_F_BCK:
1783 metric = mkf_u32(0, px->srv_bck);
1784 break;
1785 case ST_F_CHKDOWN:
1786 metric = mkf_u64(FN_COUNTER, px->down_trans);
1787 break;
1788 case ST_F_LASTCHG:
1789 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1790 break;
1791 case ST_F_DOWNTIME:
1792 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1793 break;
1794 case ST_F_LBTOT:
1795 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1796 break;
1797 case ST_F_REQ_TOT:
1798 if (px->mode != PR_MODE_HTTP)
1799 goto next_px;
1800 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1801 break;
1802 case ST_F_HRSP_1XX:
1803 if (px->mode != PR_MODE_HTTP)
1804 goto next_px;
1805 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1806 break;
1807 case ST_F_HRSP_2XX:
1808 if (px->mode != PR_MODE_HTTP)
1809 goto next_px;
1810 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1811 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1812 break;
1813 case ST_F_HRSP_3XX:
1814 if (px->mode != PR_MODE_HTTP)
1815 goto next_px;
1816 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1817 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1818 break;
1819 case ST_F_HRSP_4XX:
1820 if (px->mode != PR_MODE_HTTP)
1821 goto next_px;
1822 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1823 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1824 break;
1825 case ST_F_HRSP_5XX:
1826 if (px->mode != PR_MODE_HTTP)
1827 goto next_px;
1828 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1829 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1830 break;
1831 case ST_F_HRSP_OTHER:
1832 if (px->mode != PR_MODE_HTTP)
1833 goto next_px;
1834 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1835 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1836 break;
1837 case ST_F_CACHE_LOOKUPS:
1838 if (px->mode != PR_MODE_HTTP)
1839 goto next_px;
1840 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1841 break;
1842 case ST_F_CACHE_HITS:
1843 if (px->mode != PR_MODE_HTTP)
1844 goto next_px;
1845 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1846 break;
1847 case ST_F_COMP_IN:
1848 if (px->mode != PR_MODE_HTTP)
1849 goto next_px;
1850 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1851 break;
1852 case ST_F_COMP_OUT:
1853 if (px->mode != PR_MODE_HTTP)
1854 goto next_px;
1855 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1856 break;
1857 case ST_F_COMP_BYP:
1858 if (px->mode != PR_MODE_HTTP)
1859 goto next_px;
1860 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1861 break;
1862 case ST_F_COMP_RSP:
1863 if (px->mode != PR_MODE_HTTP)
1864 goto next_px;
1865 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1866 break;
1867
1868 default:
1869 goto next_metric;
1870 }
1871
1872 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1873 goto full;
1874 next_px:
1875 appctx->ctx.stats.px = px->next;
1876 }
1877 next_metric:
1878 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1879 appctx->ctx.stats.px = proxies_list;
1880 appctx->st2 = promex_back_metrics[appctx->st2];
1881 }
1882
1883 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001884 if (out.len) {
1885 if (!htx_add_data_atonce(htx, out))
1886 return -1; /* Unexpected and unrecoverable error */
1887 channel_add_input(chn, out.len);
1888 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001889 return ret;
1890 full:
1891 ret = 0;
1892 goto end;
1893}
1894
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001895/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001896 * 0 if <htx> is full and -1 in case of any error. */
1897static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1898{
1899 static struct ist prefix = IST("haproxy_server_");
1900 struct proxy *px;
1901 struct server *sv;
1902 struct field metric;
1903 struct channel *chn = si_ic(appctx->owner);
1904 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001905 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001906 int ret = 1;
1907 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001908 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001909
1910 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1911 while (appctx->ctx.stats.px) {
1912 px = appctx->ctx.stats.px;
1913
1914 /* skip the disabled proxies, global frontend and non-networked ones */
1915 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1916 goto next_px;
1917
1918 while (appctx->ctx.stats.sv) {
1919 sv = appctx->ctx.stats.sv;
1920
Christopher Fauleteba22942019-11-19 14:18:24 +01001921 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1922 goto next_sv;
1923
Christopher Fauletf959d082019-02-07 15:38:42 +01001924 switch (appctx->st2) {
1925 case ST_F_STATUS:
1926 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1927 break;
1928 case ST_F_SCUR:
1929 metric = mkf_u32(0, sv->cur_sess);
1930 break;
1931 case ST_F_SMAX:
1932 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1933 break;
1934 case ST_F_SLIM:
1935 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1936 break;
1937 case ST_F_STOT:
1938 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1939 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001940 case ST_F_RATE_MAX:
1941 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1942 break;
1943 case ST_F_LASTSESS:
1944 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1945 break;
1946 case ST_F_QCUR:
1947 metric = mkf_u32(0, sv->nbpend);
1948 break;
1949 case ST_F_QMAX:
1950 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1951 break;
1952 case ST_F_QLIMIT:
1953 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1954 break;
1955 case ST_F_BIN:
1956 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1957 break;
1958 case ST_F_BOUT:
1959 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1960 break;
1961 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001962 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1963 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001964 break;
1965 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001966 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1967 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001968 break;
1969 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001970 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1971 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001972 break;
1973 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001974 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1975 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001976 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001977 case ST_F_QT_MAX:
1978 secs = (double)sv->counters.qtime_max / 1000.0;
1979 metric = mkf_flt(FN_MAX, secs);
1980 break;
1981 case ST_F_CT_MAX:
1982 secs = (double)sv->counters.ctime_max / 1000.0;
1983 metric = mkf_flt(FN_MAX, secs);
1984 break;
1985 case ST_F_RT_MAX:
1986 secs = (double)sv->counters.dtime_max / 1000.0;
1987 metric = mkf_flt(FN_MAX, secs);
1988 break;
1989 case ST_F_TT_MAX:
1990 secs = (double)sv->counters.ttime_max / 1000.0;
1991 metric = mkf_flt(FN_MAX, secs);
1992 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001993 case ST_F_CONNECT:
1994 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1995 break;
1996 case ST_F_REUSE:
1997 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1998 break;
1999 case ST_F_DRESP:
Christopher Fauleta08546b2019-12-16 16:07:34 +01002000 metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp);
Christopher Fauletf959d082019-02-07 15:38:42 +01002001 break;
2002 case ST_F_ECON:
2003 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
2004 break;
2005 case ST_F_ERESP:
2006 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
2007 break;
2008 case ST_F_WRETR:
2009 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
2010 break;
2011 case ST_F_WREDIS:
2012 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
2013 break;
2014 case ST_F_WREW:
2015 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
2016 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01002017 case ST_F_EINT:
2018 metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors);
2019 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002020 case ST_F_CLI_ABRT:
2021 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
2022 break;
2023 case ST_F_SRV_ABRT:
2024 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
2025 break;
2026 case ST_F_WEIGHT:
2027 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
2028 metric = mkf_u32(FN_AVG, weight);
2029 break;
Christopher Fauletcf403f32019-11-21 14:35:46 +01002030 case ST_F_CHECK_STATUS:
2031 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2032 goto next_sv;
2033 metric = mkf_u32(FN_OUTPUT, sv->check.status);
2034 break;
2035 case ST_F_CHECK_CODE:
2036 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2037 goto next_sv;
2038 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
2039 break;
Christopher Faulet2711e512020-02-27 16:12:07 +01002040 case ST_F_CHECK_DURATION:
2041 if (sv->check.status < HCHK_STATUS_CHECKED)
2042 goto next_sv;
2043 secs = (double)sv->check.duration / 1000.0;
2044 metric = mkf_flt(FN_DURATION, secs);
2045 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002046 case ST_F_CHKFAIL:
2047 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
2048 break;
2049 case ST_F_CHKDOWN:
2050 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
2051 break;
2052 case ST_F_DOWNTIME:
2053 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
2054 break;
2055 case ST_F_LASTCHG:
2056 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
2057 break;
2058 case ST_F_THROTTLE:
2059 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
2060 break;
2061 case ST_F_LBTOT:
2062 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
2063 break;
Marcin Deranek3c27dda2020-05-15 18:32:51 +02002064 case ST_F_REQ_TOT:
2065 if (px->mode != PR_MODE_HTTP)
2066 goto next_px;
2067 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
2068 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002069 case ST_F_HRSP_1XX:
2070 if (px->mode != PR_MODE_HTTP)
2071 goto next_px;
2072 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
2073 break;
2074 case ST_F_HRSP_2XX:
2075 if (px->mode != PR_MODE_HTTP)
2076 goto next_px;
2077 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2078 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
2079 break;
2080 case ST_F_HRSP_3XX:
2081 if (px->mode != PR_MODE_HTTP)
2082 goto next_px;
2083 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2084 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
2085 break;
2086 case ST_F_HRSP_4XX:
2087 if (px->mode != PR_MODE_HTTP)
2088 goto next_px;
2089 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2090 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
2091 break;
2092 case ST_F_HRSP_5XX:
2093 if (px->mode != PR_MODE_HTTP)
2094 goto next_px;
2095 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2096 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
2097 break;
2098 case ST_F_HRSP_OTHER:
2099 if (px->mode != PR_MODE_HTTP)
2100 goto next_px;
2101 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2102 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
2103 break;
Christopher Faulet20ab80c2019-11-08 15:24:32 +01002104 case ST_F_SRV_ICUR:
2105 metric = mkf_u32(0, sv->curr_idle_conns);
2106 break;
2107 case ST_F_SRV_ILIM:
2108 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2109 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002110
2111 default:
2112 goto next_metric;
2113 }
2114
2115 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2116 goto full;
2117
Christopher Fauleteba22942019-11-19 14:18:24 +01002118 next_sv:
Christopher Fauletf959d082019-02-07 15:38:42 +01002119 appctx->ctx.stats.sv = sv->next;
2120 }
2121
2122 next_px:
2123 appctx->ctx.stats.px = px->next;
2124 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2125 }
2126 next_metric:
2127 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
2128 appctx->ctx.stats.px = proxies_list;
2129 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2130 appctx->st2 = promex_srv_metrics[appctx->st2];
2131 }
2132
2133
2134 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02002135 if (out.len) {
2136 if (!htx_add_data_atonce(htx, out))
2137 return -1; /* Unexpected and unrecoverable error */
2138 channel_add_input(chn, out.len);
2139 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002140 return ret;
2141 full:
2142 ret = 0;
2143 goto end;
2144}
2145
2146/* Dump all metrics (global, frontends, backends and servers) depending on the
2147 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
2148 * -1 in case of any error. */
2149static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2150{
2151 int ret;
2152
2153 switch (appctx->st1) {
2154 case PROMEX_DUMPER_INIT:
2155 appctx->ctx.stats.px = NULL;
2156 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002157 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002158 appctx->st2 = promex_global_metrics[INF_NAME];
2159 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2160 /* fall through */
2161
2162 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002163 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2164 ret = promex_dump_global_metrics(appctx, htx);
2165 if (ret <= 0) {
2166 if (ret == -1)
2167 goto error;
2168 goto full;
2169 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002170 }
2171
2172 appctx->ctx.stats.px = proxies_list;
2173 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002174 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
2175 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002176 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2177 appctx->st1 = PROMEX_DUMPER_FRONT;
2178 /* fall through */
2179
2180 case PROMEX_DUMPER_FRONT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002181 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2182 ret = promex_dump_front_metrics(appctx, htx);
2183 if (ret <= 0) {
2184 if (ret == -1)
2185 goto error;
2186 goto full;
2187 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002188 }
2189
2190 appctx->ctx.stats.px = proxies_list;
2191 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002192 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002193 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2194 appctx->st1 = PROMEX_DUMPER_BACK;
2195 /* fall through */
2196
2197 case PROMEX_DUMPER_BACK:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002198 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2199 ret = promex_dump_back_metrics(appctx, htx);
2200 if (ret <= 0) {
2201 if (ret == -1)
2202 goto error;
2203 goto full;
2204 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002205 }
2206
2207 appctx->ctx.stats.px = proxies_list;
2208 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
Christopher Fauletefde9552020-06-05 08:18:56 +02002209 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002210 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2211 appctx->st1 = PROMEX_DUMPER_SRV;
2212 /* fall through */
2213
2214 case PROMEX_DUMPER_SRV:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002215 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2216 ret = promex_dump_srv_metrics(appctx, htx);
2217 if (ret <= 0) {
2218 if (ret == -1)
2219 goto error;
2220 goto full;
2221 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002222 }
2223
2224 appctx->ctx.stats.px = NULL;
2225 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002226 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002227 appctx->st2 = 0;
2228 appctx->st1 = PROMEX_DUMPER_DONE;
2229 /* fall through */
2230
2231 case PROMEX_DUMPER_DONE:
2232 default:
2233 break;
2234 }
2235
2236 return 1;
2237
2238 full:
2239 si_rx_room_blk(si);
2240 return 0;
2241 error:
2242 /* unrecoverable error */
2243 appctx->ctx.stats.px = NULL;
2244 appctx->ctx.stats.sv = NULL;
2245 appctx->ctx.stats.flags = 0;
2246 appctx->st2 = 0;
2247 appctx->st1 = PROMEX_DUMPER_DONE;
2248 return -1;
2249}
2250
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002251/* Parse the query string of request URI to filter the metrics. It returns 1 on
Christopher Faulet78407ce2019-11-18 14:47:08 +01002252 * success and -1 on error. */
2253static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2254{
2255 struct channel *req = si_oc(si);
2256 struct channel *res = si_ic(si);
2257 struct htx *req_htx, *res_htx;
2258 struct htx_sl *sl;
William Dauchyc65f6562019-11-26 12:56:26 +01002259 char *p, *key, *value;
2260 const char *end;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002261 struct buffer *err;
2262 int default_scopes = PROMEX_FL_SCOPE_ALL;
2263 int len;
2264
2265 /* Get the query-string */
2266 req_htx = htxbuf(&req->buf);
2267 sl = http_get_stline(req_htx);
2268 if (!sl)
2269 goto error;
2270 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2271 if (!p)
2272 goto end;
2273 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet78407ce2019-11-18 14:47:08 +01002274
William Dauchyc65f6562019-11-26 12:56:26 +01002275 /* copy the query-string */
2276 len = end - p;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002277 chunk_reset(&trash);
2278 memcpy(trash.area, p, len);
2279 trash.area[len] = 0;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002280 p = trash.area;
William Dauchyc65f6562019-11-26 12:56:26 +01002281 end = trash.area + len;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002282
2283 /* Parse the query-string */
William Dauchyc65f6562019-11-26 12:56:26 +01002284 while (p < end && *p && *p != '#') {
2285 value = NULL;
2286
2287 /* decode parameter name */
2288 key = p;
2289 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002290 ++p;
William Dauchyc65f6562019-11-26 12:56:26 +01002291 /* found a value */
2292 if (*p == '=') {
2293 *(p++) = 0;
2294 value = p;
2295 }
2296 else if (*p == '&')
2297 *(p++) = 0;
2298 else if (*p == '#')
2299 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002300 len = url_decode(key, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002301 if (len == -1)
2302 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002303
William Dauchyc65f6562019-11-26 12:56:26 +01002304 /* decode value */
2305 if (value) {
2306 while (p < end && *p != '=' && *p != '&' && *p != '#')
2307 ++p;
2308 if (*p == '=')
2309 goto error;
2310 if (*p == '&')
2311 *(p++) = 0;
2312 else if (*p == '#')
2313 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002314 len = url_decode(value, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002315 if (len == -1)
2316 goto error;
2317 }
2318
2319 if (!strcmp(key, "scope")) {
2320 default_scopes = 0; /* at least a scope defined, unset default scopes */
2321 if (!value)
2322 goto error;
2323 else if (*value == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002324 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002325 else if (*value == '*')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002326 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002327 else if (!strcmp(value, "global"))
2328 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
2329 else if (!strcmp(value, "server"))
2330 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
2331 else if (!strcmp(value, "backend"))
Christopher Faulet78407ce2019-11-18 14:47:08 +01002332 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
William Dauchyc65f6562019-11-26 12:56:26 +01002333 else if (!strcmp(value, "frontend"))
Christopher Faulet78407ce2019-11-18 14:47:08 +01002334 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2335 else
2336 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002337 }
William Dauchyc65f6562019-11-26 12:56:26 +01002338 else if (!strcmp(key, "no-maint"))
Christopher Fauleteba22942019-11-19 14:18:24 +01002339 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002340 }
2341
2342 end:
2343 appctx->ctx.stats.flags |= default_scopes;
2344 return 1;
2345
2346 error:
2347 err = &http_err_chunks[HTTP_ERR_400];
2348 channel_erase(res);
2349 res->buf.data = b_data(err);
2350 memcpy(res->buf.area, b_head(err), b_data(err));
2351 res_htx = htx_from_buf(&res->buf);
2352 channel_add_input(res, res_htx->data);
2353 appctx->st0 = PROMEX_ST_END;
2354 return -1;
2355}
2356
Christopher Fauletf959d082019-02-07 15:38:42 +01002357/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2358 * full. */
2359static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2360{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002361 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002362 struct htx_sl *sl;
2363 unsigned int flags;
2364
2365 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);
2366 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2367 if (!sl)
2368 goto full;
2369 sl->info.res.status = 200;
2370 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
2371 !htx_add_header(htx, ist("Connection"), ist("close")) ||
2372 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2373 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2374 !htx_add_endof(htx, HTX_BLK_EOH))
2375 goto full;
2376
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002377 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002378 return 1;
2379 full:
2380 htx_reset(htx);
2381 si_rx_room_blk(si);
2382 return 0;
2383}
2384
2385/* The function returns 1 if the initialisation is complete, 0 if
2386 * an errors occurs and -1 if more data are required for initializing
2387 * the applet.
2388 */
2389static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2390{
2391 appctx->st0 = PROMEX_ST_INIT;
2392 return 1;
2393}
2394
2395/* The main I/O handler for the promex applet. */
2396static void promex_appctx_handle_io(struct appctx *appctx)
2397{
2398 struct stream_interface *si = appctx->owner;
2399 struct stream *s = si_strm(si);
2400 struct channel *req = si_oc(si);
2401 struct channel *res = si_ic(si);
2402 struct htx *req_htx, *res_htx;
2403 int ret;
2404
2405 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002406 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2407 goto out;
2408
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002409 /* Check if the input buffer is available. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002410 if (!b_size(&res->buf)) {
2411 si_rx_room_blk(si);
2412 goto out;
2413 }
2414
2415 switch (appctx->st0) {
2416 case PROMEX_ST_INIT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002417 ret = promex_parse_uri(appctx, si);
2418 if (ret <= 0) {
2419 if (ret == -1)
2420 goto error;
2421 goto out;
2422 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002423 appctx->st0 = PROMEX_ST_HEAD;
2424 appctx->st1 = PROMEX_DUMPER_INIT;
2425 /* fall through */
2426
2427 case PROMEX_ST_HEAD:
2428 if (!promex_send_headers(appctx, si, res_htx))
2429 goto out;
2430 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2431 /* fall through */
2432
2433 case PROMEX_ST_DUMP:
2434 ret = promex_dump_metrics(appctx, si, res_htx);
2435 if (ret <= 0) {
2436 if (ret == -1)
2437 goto error;
2438 goto out;
2439 }
2440 appctx->st0 = PROMEX_ST_DONE;
2441 /* fall through */
2442
2443 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002444 /* Don't add TLR because mux-h1 will take care of it */
Christopher Fauletf959d082019-02-07 15:38:42 +01002445 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2446 si_rx_room_blk(si);
2447 goto out;
2448 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002449 channel_add_input(res, 1);
2450 appctx->st0 = PROMEX_ST_END;
2451 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002452
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002453 case PROMEX_ST_END:
2454 if (!(res->flags & CF_SHUTR)) {
2455 res->flags |= CF_READ_NULL;
2456 si_shutr(si);
2457 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002458 }
2459
Christopher Fauletf959d082019-02-07 15:38:42 +01002460 out:
2461 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002462
2463 /* eat the whole request */
2464 if (co_data(req)) {
2465 req_htx = htx_from_buf(&req->buf);
2466 co_htx_skip(req, req_htx, co_data(req));
2467 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002468 return;
2469
2470 error:
2471 res->flags |= CF_READ_NULL;
2472 si_shutr(si);
2473 si_shutw(si);
2474}
2475
2476struct applet promex_applet = {
2477 .obj_type = OBJ_TYPE_APPLET,
2478 .name = "<PROMEX>", /* used for logging */
2479 .init = promex_appctx_init,
2480 .fct = promex_appctx_handle_io,
2481};
2482
2483static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2484 struct act_rule *rule, char **err)
2485{
2486 /* Prometheus exporter service is only available on "http-request" rulesets */
2487 if (rule->from != ACT_F_HTTP_REQ) {
2488 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2489 return ACT_RET_PRS_ERR;
2490 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002491
2492 /* Add applet pointer in the rule. */
2493 rule->applet = promex_applet;
2494
2495 return ACT_RET_PRS_OK;
2496}
2497static void promex_register_build_options(void)
2498{
2499 char *ptr = NULL;
2500
2501 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2502 hap_register_build_opts(ptr, 1);
2503}
2504
2505
2506static struct action_kw_list service_actions = { ILH, {
2507 { "prometheus-exporter", service_parse_prometheus_exporter },
2508 { /* END */ }
2509}};
2510
2511INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2512INITCALL0(STG_REGISTER, promex_register_build_options);