blob: f636777bcd04ba44934ec5727e023f69c4ae6a04 [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
Willy Tarreau122eba92020-06-04 10:15:32 +020016#include <haproxy/action-t.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020017#include <haproxy/api.h>
Willy Tarreau3f0f82e2020-06-04 19:42:41 +020018#include <haproxy/applet.h>
Willy Tarreau49801602020-06-04 22:50:02 +020019#include <haproxy/backend.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020020#include <haproxy/cfgparse.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020021#include <haproxy/compression.h>
Christopher Fauletc55a6262020-07-10 15:39:39 +020022#include <haproxy/dns.h>
Willy Tarreau762d7a52020-06-04 11:23:07 +020023#include <haproxy/frontend.h>
Willy Tarreauf268ee82020-06-04 17:05:57 +020024#include <haproxy/global.h>
Willy Tarreaucd72d8c2020-06-02 19:11:26 +020025#include <haproxy/http.h>
Willy Tarreau87735332020-06-04 09:08:41 +020026#include <haproxy/http_htx.h>
Willy Tarreau16f958c2020-06-03 08:44:35 +020027#include <haproxy/htx.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020028#include <haproxy/list.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020029#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020030#include <haproxy/log.h>
Willy Tarreau551271d2020-06-04 08:32:23 +020031#include <haproxy/pipe.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020032#include <haproxy/pool.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020033#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020034#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020035#include <haproxy/server.h>
Willy Tarreau209108d2020-06-04 20:30:20 +020036#include <haproxy/ssl_sock.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020037#include <haproxy/stats.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020038#include <haproxy/stream.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020039#include <haproxy/stream_interface.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020040#include <haproxy/task.h>
William Dauchy5a982a72021-01-08 13:18:06 +010041#include <haproxy/version.h>
Christopher Fauletf959d082019-02-07 15:38:42 +010042
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
William Dauchy5a982a72021-01-08 13:18:06 +010086/* Some labels for build_info */
87#define PROMEX_VERSION_LABEL "version=\"" HAPROXY_VERSION "\""
88#define PROMEX_BUILDINFO_LABEL PROMEX_VERSION_LABEL
89
Christopher Fauletf959d082019-02-07 15:38:42 +010090/* Matrix used to dump global metrics. Each metric points to the next one to be
91 * processed or 0 to stop the dump. */
92const int promex_global_metrics[INF_TOTAL_FIELDS] = {
William Dauchy5a982a72021-01-08 13:18:06 +010093 [INF_NAME] = INF_BUILD_INFO,
Christopher Fauletf959d082019-02-07 15:38:42 +010094 [INF_VERSION] = 0,
95 [INF_RELEASE_DATE] = 0,
William Dauchy5a982a72021-01-08 13:18:06 +010096 [INF_BUILD_INFO] = INF_NBTHREAD,
Christopher Fauletf959d082019-02-07 15:38:42 +010097 [INF_NBTHREAD] = INF_NBPROC,
98 [INF_NBPROC] = INF_PROCESS_NUM,
99 [INF_PROCESS_NUM] = INF_UPTIME_SEC,
100 [INF_PID] = 0,
101 [INF_UPTIME] = 0,
William Dauchya8766cf2021-01-15 22:41:37 +0100102 [INF_UPTIME_SEC] = INF_MEMMAX_BYTES,
103 [INF_MEMMAX_BYTES] = INF_POOL_ALLOC_BYTES,
104 [INF_POOL_ALLOC_BYTES] = INF_POOL_USED_BYTES,
105 [INF_POOL_USED_BYTES] = INF_POOL_FAILED,
Christopher Fauletf959d082019-02-07 15:38:42 +0100106 [INF_POOL_FAILED] = INF_ULIMIT_N,
107 [INF_ULIMIT_N] = INF_MAXSOCK,
108 [INF_MAXSOCK] = INF_MAXCONN,
109 [INF_MAXCONN] = INF_HARD_MAXCONN,
110 [INF_HARD_MAXCONN] = INF_CURR_CONN,
111 [INF_CURR_CONN] = INF_CUM_CONN,
112 [INF_CUM_CONN] = INF_CUM_REQ,
113 [INF_CUM_REQ] = INF_MAX_SSL_CONNS,
114 [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS,
115 [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS,
116 [INF_CUM_SSL_CONNS] = INF_MAXPIPES,
117 [INF_MAXPIPES] = INF_PIPES_USED,
118 [INF_PIPES_USED] = INF_PIPES_FREE,
119 [INF_PIPES_FREE] = INF_CONN_RATE,
120 [INF_CONN_RATE] = INF_CONN_RATE_LIMIT,
121 [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE,
122 [INF_MAX_CONN_RATE] = INF_SESS_RATE,
123 [INF_SESS_RATE] = INF_SESS_RATE_LIMIT,
124 [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE,
125 [INF_MAX_SESS_RATE] = INF_SSL_RATE,
126 [INF_SSL_RATE] = INF_SSL_RATE_LIMIT,
127 [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE,
128 [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE,
129 [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE,
130 [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT,
131 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE,
132 [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE,
133 [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS,
134 [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES,
135 [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN,
136 [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT,
137 [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM,
138 [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE,
139 [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE,
140 [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS,
141 [INF_TASKS] = INF_RUN_QUEUE,
142 [INF_RUN_QUEUE] = INF_IDLE_PCT,
143 [INF_IDLE_PCT] = INF_STOPPING,
144 [INF_NODE] = 0,
145 [INF_DESCRIPTION] = 0,
146 [INF_STOPPING] = INF_JOBS,
147 [INF_JOBS] = INF_UNSTOPPABLE_JOBS,
148 [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS,
149 [INF_LISTENERS] = INF_ACTIVE_PEERS,
150 [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS,
151 [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS,
152 [INF_DROPPED_LOGS] = INF_BUSY_POLLING,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200153 [INF_BUSY_POLLING] = INF_FAILED_RESOLUTIONS,
154 [INF_FAILED_RESOLUTIONS] = INF_TOTAL_BYTES_OUT,
155 [INF_TOTAL_BYTES_OUT] = INF_TOTAL_SPLICED_BYTES_OUT,
156 [INF_TOTAL_SPLICED_BYTES_OUT] = INF_BYTES_OUT_RATE,
157 [INF_BYTES_OUT_RATE] = 0,
158 [INF_DEBUG_COMMANDS_ISSUED] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100159};
160
161/* Matrix used to dump frontend metrics. Each metric points to the next one to be
162 * processed or 0 to stop the dump. */
163const int promex_front_metrics[ST_F_TOTAL_FIELDS] = {
164 [ST_F_PXNAME] = ST_F_STATUS,
165 [ST_F_SVNAME] = 0,
166 [ST_F_QCUR] = 0,
167 [ST_F_QMAX] = 0,
168 [ST_F_SCUR] = ST_F_SMAX,
169 [ST_F_SMAX] = ST_F_SLIM,
170 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200171 [ST_F_STOT] = ST_F_RATE_LIM,
Christopher Fauletf959d082019-02-07 15:38:42 +0100172 [ST_F_BIN] = ST_F_BOUT,
173 [ST_F_BOUT] = ST_F_DREQ,
174 [ST_F_DREQ] = ST_F_DRESP,
175 [ST_F_DRESP] = ST_F_EREQ,
176 [ST_F_EREQ] = ST_F_DCON,
177 [ST_F_ECON] = 0,
178 [ST_F_ERESP] = 0,
179 [ST_F_WRETR] = 0,
180 [ST_F_WREDIS] = 0,
181 [ST_F_STATUS] = ST_F_SCUR,
182 [ST_F_WEIGHT] = 0,
183 [ST_F_ACT] = 0,
184 [ST_F_BCK] = 0,
185 [ST_F_CHKFAIL] = 0,
186 [ST_F_CHKDOWN] = 0,
187 [ST_F_LASTCHG] = 0,
188 [ST_F_DOWNTIME] = 0,
189 [ST_F_QLIMIT] = 0,
190 [ST_F_PID] = 0,
191 [ST_F_IID] = 0,
192 [ST_F_SID] = 0,
193 [ST_F_THROTTLE] = 0,
194 [ST_F_LBTOT] = 0,
195 [ST_F_TRACKED] = 0,
196 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200197 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100198 [ST_F_RATE_LIM] = ST_F_RATE_MAX,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200199 [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100200 [ST_F_CHECK_STATUS] = 0,
201 [ST_F_CHECK_CODE] = 0,
202 [ST_F_CHECK_DURATION] = 0,
203 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
204 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
205 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
206 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
207 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
208 [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED,
209 [ST_F_HANAFAIL] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200210 [ST_F_REQ_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100211 [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT,
212 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
213 [ST_F_CLI_ABRT] = 0,
214 [ST_F_SRV_ABRT] = 0,
215 [ST_F_COMP_IN] = ST_F_COMP_OUT,
216 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
217 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
218 [ST_F_COMP_RSP] = 0,
219 [ST_F_LASTSESS] = 0,
220 [ST_F_LAST_CHK] = 0,
221 [ST_F_LAST_AGT] = 0,
222 [ST_F_QTIME] = 0,
223 [ST_F_CTIME] = 0,
224 [ST_F_RTIME] = 0,
225 [ST_F_TTIME] = 0,
226 [ST_F_AGENT_STATUS] = 0,
227 [ST_F_AGENT_CODE] = 0,
228 [ST_F_AGENT_DURATION] = 0,
229 [ST_F_CHECK_DESC] = 0,
230 [ST_F_AGENT_DESC] = 0,
231 [ST_F_CHECK_RISE] = 0,
232 [ST_F_CHECK_FALL] = 0,
233 [ST_F_CHECK_HEALTH] = 0,
234 [ST_F_AGENT_RISE] = 0,
235 [ST_F_AGENT_FALL] = 0,
236 [ST_F_AGENT_HEALTH] = 0,
237 [ST_F_ADDR] = 0,
238 [ST_F_COOKIE] = 0,
239 [ST_F_MODE] = 0,
240 [ST_F_ALGO] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200241 [ST_F_CONN_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100242 [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT,
243 [ST_F_CONN_TOT] = ST_F_BIN,
244 [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS,
245 [ST_F_DCON] = ST_F_DSES,
246 [ST_F_DSES] = ST_F_WREW,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100247 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100248 [ST_F_CONNECT] = 0,
249 [ST_F_REUSE] = 0,
250 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
251 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100252 [ST_F_SRV_ICUR] = 0,
253 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100254 [ST_F_QT_MAX] = 0,
255 [ST_F_CT_MAX] = 0,
256 [ST_F_RT_MAX] = 0,
257 [ST_F_TT_MAX] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100258 [ST_F_EINT] = ST_F_REQ_RATE_MAX,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200259 [ST_F_IDLE_CONN_CUR] = 0,
260 [ST_F_SAFE_CONN_CUR] = 0,
261 [ST_F_USED_CONN_CUR] = 0,
262 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100263};
264
265/* Matrix used to dump backend metrics. Each metric points to the next one to be
266 * processed or 0 to stop the dump. */
267const int promex_back_metrics[ST_F_TOTAL_FIELDS] = {
268 [ST_F_PXNAME] = ST_F_STATUS,
269 [ST_F_SVNAME] = 0,
270 [ST_F_QCUR] = ST_F_QMAX,
271 [ST_F_QMAX] = ST_F_CONNECT,
272 [ST_F_SCUR] = ST_F_SMAX,
273 [ST_F_SMAX] = ST_F_SLIM,
274 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200275 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100276 [ST_F_BIN] = ST_F_BOUT,
277 [ST_F_BOUT] = ST_F_QTIME,
278 [ST_F_DREQ] = ST_F_DRESP,
279 [ST_F_DRESP] = ST_F_ECON,
280 [ST_F_EREQ] = 0,
281 [ST_F_ECON] = ST_F_ERESP,
282 [ST_F_ERESP] = ST_F_WRETR,
283 [ST_F_WRETR] = ST_F_WREDIS,
284 [ST_F_WREDIS] = ST_F_WREW,
285 [ST_F_STATUS] = ST_F_SCUR,
286 [ST_F_WEIGHT] = ST_F_ACT,
287 [ST_F_ACT] = ST_F_BCK,
288 [ST_F_BCK] = ST_F_CHKDOWN,
289 [ST_F_CHKFAIL] = 0,
290 [ST_F_CHKDOWN] = ST_F_LASTCHG,
291 [ST_F_LASTCHG] = ST_F_DOWNTIME,
292 [ST_F_DOWNTIME] = ST_F_LBTOT,
293 [ST_F_QLIMIT] = 0,
294 [ST_F_PID] = 0,
295 [ST_F_IID] = 0,
296 [ST_F_SID] = 0,
297 [ST_F_THROTTLE] = 0,
298 [ST_F_LBTOT] = ST_F_REQ_TOT,
299 [ST_F_TRACKED] = 9,
300 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200301 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100302 [ST_F_RATE_LIM] = 0,
303 [ST_F_RATE_MAX] = ST_F_LASTSESS,
304 [ST_F_CHECK_STATUS] = 0,
305 [ST_F_CHECK_CODE] = 0,
306 [ST_F_CHECK_DURATION] = 0,
307 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
308 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
309 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
310 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
311 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
312 [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS,
313 [ST_F_HANAFAIL] = 0,
314 [ST_F_REQ_RATE] = 0,
315 [ST_F_REQ_RATE_MAX] = 0,
316 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
317 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
318 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
319 [ST_F_COMP_IN] = ST_F_COMP_OUT,
320 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
321 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
322 [ST_F_COMP_RSP] = 0,
323 [ST_F_LASTSESS] = ST_F_QCUR,
324 [ST_F_LAST_CHK] = 0,
325 [ST_F_LAST_AGT] = 0,
326 [ST_F_QTIME] = ST_F_CTIME,
327 [ST_F_CTIME] = ST_F_RTIME,
328 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100329 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100330 [ST_F_AGENT_STATUS] = 0,
331 [ST_F_AGENT_CODE] = 0,
332 [ST_F_AGENT_DURATION] = 0,
333 [ST_F_CHECK_DESC] = 0,
334 [ST_F_AGENT_DESC] = 0,
335 [ST_F_CHECK_RISE] = 0,
336 [ST_F_CHECK_FALL] = 0,
337 [ST_F_CHECK_HEALTH] = 0,
338 [ST_F_AGENT_RISE] = 0,
339 [ST_F_AGENT_FALL] = 0,
340 [ST_F_AGENT_HEALTH] = 0,
341 [ST_F_ADDR] = 0,
342 [ST_F_COOKIE] = 0,
343 [ST_F_MODE] = 0,
344 [ST_F_ALGO] = 0,
345 [ST_F_CONN_RATE] = 0,
346 [ST_F_CONN_RATE_MAX] = 0,
347 [ST_F_CONN_TOT] = 0,
348 [ST_F_INTERCEPTED] = 0,
349 [ST_F_DCON] = 0,
350 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100351 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100352 [ST_F_CONNECT] = ST_F_REUSE,
353 [ST_F_REUSE] = ST_F_BIN,
354 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
355 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100356 [ST_F_SRV_ICUR] = 0,
357 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100358 [ST_F_QT_MAX] = ST_F_CT_MAX,
359 [ST_F_CT_MAX] = ST_F_RT_MAX,
360 [ST_F_RT_MAX] = ST_F_TT_MAX,
361 [ST_F_TT_MAX] = ST_F_DREQ,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100362 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200363 [ST_F_IDLE_CONN_CUR] = 0,
364 [ST_F_SAFE_CONN_CUR] = 0,
365 [ST_F_USED_CONN_CUR] = 0,
366 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100367};
368
369/* Matrix used to dump server metrics. Each metric points to the next one to be
370 * processed or 0 to stop the dump. */
371const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = {
372 [ST_F_PXNAME] = ST_F_STATUS,
373 [ST_F_SVNAME] = 0,
374 [ST_F_QCUR] = ST_F_QMAX,
375 [ST_F_QMAX] = ST_F_QLIMIT,
376 [ST_F_SCUR] = ST_F_SMAX,
377 [ST_F_SMAX] = ST_F_SLIM,
378 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200379 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100380 [ST_F_BIN] = ST_F_BOUT,
381 [ST_F_BOUT] = ST_F_QTIME,
382 [ST_F_DREQ] = 0,
383 [ST_F_DRESP] = ST_F_ECON,
384 [ST_F_EREQ] = 0,
385 [ST_F_ECON] = ST_F_ERESP,
386 [ST_F_ERESP] = ST_F_WRETR,
387 [ST_F_WRETR] = ST_F_WREDIS,
388 [ST_F_WREDIS] = ST_F_WREW,
389 [ST_F_STATUS] = ST_F_SCUR,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100390 [ST_F_WEIGHT] = ST_F_CHECK_STATUS,
Christopher Fauletf959d082019-02-07 15:38:42 +0100391 [ST_F_ACT] = 0,
392 [ST_F_BCK] = 0,
393 [ST_F_CHKFAIL] = ST_F_CHKDOWN,
394 [ST_F_CHKDOWN] = ST_F_DOWNTIME,
395 [ST_F_LASTCHG] = ST_F_THROTTLE,
396 [ST_F_DOWNTIME] = ST_F_LASTCHG,
397 [ST_F_QLIMIT] = ST_F_BIN,
398 [ST_F_PID] = 0,
399 [ST_F_IID] = 0,
400 [ST_F_SID] = 0,
401 [ST_F_THROTTLE] = ST_F_LBTOT,
402 [ST_F_LBTOT] = ST_F_HRSP_1XX,
403 [ST_F_TRACKED] = 0,
404 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200405 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100406 [ST_F_RATE_LIM] = 0,
407 [ST_F_RATE_MAX] = ST_F_LASTSESS,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100408 [ST_F_CHECK_STATUS] = ST_F_CHECK_CODE,
Christopher Faulet2711e512020-02-27 16:12:07 +0100409 [ST_F_CHECK_CODE] = ST_F_CHECK_DURATION,
410 [ST_F_CHECK_DURATION] = ST_F_CHKFAIL,
Christopher Fauletf959d082019-02-07 15:38:42 +0100411 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
412 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
413 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
414 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
415 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100416 [ST_F_HRSP_OTHER] = ST_F_SRV_ICUR,
Christopher Fauletf959d082019-02-07 15:38:42 +0100417 [ST_F_HANAFAIL] = 0,
418 [ST_F_REQ_RATE] = 0,
419 [ST_F_REQ_RATE_MAX] = 0,
420 [ST_F_REQ_TOT] = 0,
421 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
422 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
423 [ST_F_COMP_IN] = 0,
424 [ST_F_COMP_OUT] = 0,
425 [ST_F_COMP_BYP] = 0,
426 [ST_F_COMP_RSP] = 0,
427 [ST_F_LASTSESS] = ST_F_QCUR,
428 [ST_F_LAST_CHK] = 0,
429 [ST_F_LAST_AGT] = 0,
430 [ST_F_QTIME] = ST_F_CTIME,
431 [ST_F_CTIME] = ST_F_RTIME,
432 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100433 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100434 [ST_F_AGENT_STATUS] = 0,
435 [ST_F_AGENT_CODE] = 0,
436 [ST_F_AGENT_DURATION] = 0,
437 [ST_F_CHECK_DESC] = 0,
438 [ST_F_AGENT_DESC] = 0,
439 [ST_F_CHECK_RISE] = 0,
440 [ST_F_CHECK_FALL] = 0,
441 [ST_F_CHECK_HEALTH] = 0,
442 [ST_F_AGENT_RISE] = 0,
443 [ST_F_AGENT_FALL] = 0,
444 [ST_F_AGENT_HEALTH] = 0,
445 [ST_F_ADDR] = 0,
446 [ST_F_COOKIE] = 0,
447 [ST_F_MODE] = 0,
448 [ST_F_ALGO] = 0,
449 [ST_F_CONN_RATE] = 0,
450 [ST_F_CONN_RATE_MAX] = 0,
451 [ST_F_CONN_TOT] = 0,
452 [ST_F_INTERCEPTED] = 0,
453 [ST_F_DCON] = 0,
454 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100455 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100456 [ST_F_CONNECT] = ST_F_REUSE,
457 [ST_F_REUSE] = ST_F_DRESP,
458 [ST_F_CACHE_LOOKUPS] = 0,
459 [ST_F_CACHE_HITS] = 0,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100460 [ST_F_SRV_ICUR] = ST_F_SRV_ILIM,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200461 [ST_F_SRV_ILIM] = ST_F_IDLE_CONN_CUR,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100462 [ST_F_QT_MAX] = ST_F_CT_MAX,
463 [ST_F_CT_MAX] = ST_F_RT_MAX,
464 [ST_F_RT_MAX] = ST_F_TT_MAX,
465 [ST_F_TT_MAX] = ST_F_CONNECT,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100466 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200467 [ST_F_IDLE_CONN_CUR] = ST_F_SAFE_CONN_CUR,
468 [ST_F_SAFE_CONN_CUR] = ST_F_USED_CONN_CUR,
469 [ST_F_USED_CONN_CUR] = ST_F_NEED_CONN_EST,
470 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100471};
472
473/* Name of all info fields */
474const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
475 [INF_NAME] = IST("name"),
476 [INF_VERSION] = IST("version"),
477 [INF_RELEASE_DATE] = IST("release_date"),
William Dauchy5a982a72021-01-08 13:18:06 +0100478 [INF_BUILD_INFO] = IST("build_info"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100479 [INF_NBTHREAD] = IST("nbthread"),
480 [INF_NBPROC] = IST("nbproc"),
481 [INF_PROCESS_NUM] = IST("relative_process_id"),
482 [INF_PID] = IST("pid"),
483 [INF_UPTIME] = IST("uptime"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200484 [INF_UPTIME_SEC] = IST("start_time_seconds"),
William Dauchya8766cf2021-01-15 22:41:37 +0100485 [INF_MEMMAX_BYTES] = IST("max_memory_bytes"),
486 [INF_POOL_ALLOC_BYTES] = IST("pool_allocated_bytes"),
487 [INF_POOL_USED_BYTES] = IST("pool_used_bytes"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100488 [INF_POOL_FAILED] = IST("pool_failures_total"),
489 [INF_ULIMIT_N] = IST("max_fds"),
490 [INF_MAXSOCK] = IST("max_sockets"),
491 [INF_MAXCONN] = IST("max_connections"),
492 [INF_HARD_MAXCONN] = IST("hard_max_connections"),
493 [INF_CURR_CONN] = IST("current_connections"),
494 [INF_CUM_CONN] = IST("connections_total"),
495 [INF_CUM_REQ] = IST("requests_total"),
496 [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"),
497 [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"),
498 [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"),
499 [INF_MAXPIPES] = IST("max_pipes"),
500 [INF_PIPES_USED] = IST("pipes_used_total"),
501 [INF_PIPES_FREE] = IST("pipes_free_total"),
502 [INF_CONN_RATE] = IST("current_connection_rate"),
503 [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"),
504 [INF_MAX_CONN_RATE] = IST("max_connection_rate"),
505 [INF_SESS_RATE] = IST("current_session_rate"),
506 [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"),
507 [INF_MAX_SESS_RATE] = IST("max_session_rate"),
508 [INF_SSL_RATE] = IST("current_ssl_rate"),
509 [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"),
510 [INF_MAX_SSL_RATE] = IST("max_ssl_rate"),
511 [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"),
512 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"),
Pierre Cheynier1e369762020-07-07 19:14:08 +0200513 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontend_ssl_reuse"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100514 [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"),
515 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200516 [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"),
517 [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100518 [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"),
519 [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"),
520 [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"),
521 [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"),
522 [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"),
523 [INF_TASKS] = IST("current_tasks"),
524 [INF_RUN_QUEUE] = IST("current_run_queue"),
525 [INF_IDLE_PCT] = IST("idle_time_percent"),
526 [INF_NODE] = IST("node"),
527 [INF_DESCRIPTION] = IST("description"),
528 [INF_STOPPING] = IST("stopping"),
529 [INF_JOBS] = IST("jobs"),
530 [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"),
531 [INF_LISTENERS] = IST("listeners"),
532 [INF_ACTIVE_PEERS] = IST("active_peers"),
533 [INF_CONNECTED_PEERS] = IST("connected_peers"),
534 [INF_DROPPED_LOGS] = IST("dropped_logs_total"),
535 [INF_BUSY_POLLING] = IST("busy_polling_enabled"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200536 [INF_FAILED_RESOLUTIONS] = IST("failed_resolutions"),
537 [INF_TOTAL_BYTES_OUT] = IST("bytes_out_total"),
538 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("spliced_bytes_out_total"),
539 [INF_BYTES_OUT_RATE] = IST("bytes_out_rate"),
540 [INF_DEBUG_COMMANDS_ISSUED] = IST("debug_commands_issued"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100541};
542
543/* Name of all stats fields */
544const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = {
545 [ST_F_PXNAME] = IST("proxy_name"),
546 [ST_F_SVNAME] = IST("service_name"),
547 [ST_F_QCUR] = IST("current_queue"),
548 [ST_F_QMAX] = IST("max_queue"),
549 [ST_F_SCUR] = IST("current_sessions"),
550 [ST_F_SMAX] = IST("max_sessions"),
551 [ST_F_SLIM] = IST("limit_sessions"),
552 [ST_F_STOT] = IST("sessions_total"),
553 [ST_F_BIN] = IST("bytes_in_total"),
554 [ST_F_BOUT] = IST("bytes_out_total"),
555 [ST_F_DREQ] = IST("requests_denied_total"),
556 [ST_F_DRESP] = IST("responses_denied_total"),
557 [ST_F_EREQ] = IST("request_errors_total"),
558 [ST_F_ECON] = IST("connection_errors_total"),
559 [ST_F_ERESP] = IST("response_errors_total"),
560 [ST_F_WRETR] = IST("retry_warnings_total"),
561 [ST_F_WREDIS] = IST("redispatch_warnings_total"),
562 [ST_F_STATUS] = IST("status"),
563 [ST_F_WEIGHT] = IST("weight"),
564 [ST_F_ACT] = IST("active_servers"),
565 [ST_F_BCK] = IST("backup_servers"),
566 [ST_F_CHKFAIL] = IST("check_failures_total"),
567 [ST_F_CHKDOWN] = IST("check_up_down_total"),
568 [ST_F_LASTCHG] = IST("check_last_change_seconds"),
569 [ST_F_DOWNTIME] = IST("downtime_seconds_total"),
570 [ST_F_QLIMIT] = IST("queue_limit"),
571 [ST_F_PID] = IST("pid"),
572 [ST_F_IID] = IST("proxy_id"),
573 [ST_F_SID] = IST("server_id"),
574 [ST_F_THROTTLE] = IST("current_throttle"),
575 [ST_F_LBTOT] = IST("loadbalanced_total"),
576 [ST_F_TRACKED] = IST("tracked"),
577 [ST_F_TYPE] = IST("type"),
578 [ST_F_RATE] = IST("current_session_rate"),
579 [ST_F_RATE_LIM] = IST("limit_session_rate"),
580 [ST_F_RATE_MAX] = IST("max_session_rate"),
581 [ST_F_CHECK_STATUS] = IST("check_status"),
582 [ST_F_CHECK_CODE] = IST("check_code"),
Christopher Faulet2711e512020-02-27 16:12:07 +0100583 [ST_F_CHECK_DURATION] = IST("check_duration_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100584 [ST_F_HRSP_1XX] = IST("http_responses_total"),
585 [ST_F_HRSP_2XX] = IST("http_responses_total"),
586 [ST_F_HRSP_3XX] = IST("http_responses_total"),
587 [ST_F_HRSP_4XX] = IST("http_responses_total"),
588 [ST_F_HRSP_5XX] = IST("http_responses_total"),
589 [ST_F_HRSP_OTHER] = IST("http_responses_total"),
590 [ST_F_HANAFAIL] = IST("check_analyses_failures_total"),
591 [ST_F_REQ_RATE] = IST("http_requests_rate_current"),
592 [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"),
593 [ST_F_REQ_TOT] = IST("http_requests_total"),
594 [ST_F_CLI_ABRT] = IST("client_aborts_total"),
595 [ST_F_SRV_ABRT] = IST("server_aborts_total"),
596 [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"),
597 [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"),
598 [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"),
599 [ST_F_COMP_RSP] = IST("http_comp_responses_total"),
600 [ST_F_LASTSESS] = IST("last_session_seconds"),
601 [ST_F_LAST_CHK] = IST("check_last_content"),
602 [ST_F_LAST_AGT] = IST("agentcheck_last_content"),
Christopher Faulet68b69682019-11-08 15:12:29 +0100603 [ST_F_QTIME] = IST("queue_time_average_seconds"),
604 [ST_F_CTIME] = IST("connect_time_average_seconds"),
605 [ST_F_RTIME] = IST("response_time_average_seconds"),
606 [ST_F_TTIME] = IST("total_time_average_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100607 [ST_F_AGENT_STATUS] = IST("agentcheck_status"),
608 [ST_F_AGENT_CODE] = IST("agentcheck_code"),
609 [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"),
610 [ST_F_CHECK_DESC] = IST("check_description"),
611 [ST_F_AGENT_DESC] = IST("agentcheck_description"),
612 [ST_F_CHECK_RISE] = IST("check_rise"),
613 [ST_F_CHECK_FALL] = IST("check_fall"),
614 [ST_F_CHECK_HEALTH] = IST("check_value"),
615 [ST_F_AGENT_RISE] = IST("agentcheck_rise"),
616 [ST_F_AGENT_FALL] = IST("agentcheck_fall"),
617 [ST_F_AGENT_HEALTH] = IST("agentcheck_value"),
618 [ST_F_ADDR] = IST("address"),
619 [ST_F_COOKIE] = IST("cookie"),
620 [ST_F_MODE] = IST("mode"),
621 [ST_F_ALGO] = IST("loadbalance_algorithm"),
622 [ST_F_CONN_RATE] = IST("connections_rate_current"),
623 [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"),
624 [ST_F_CONN_TOT] = IST("connections_total"),
625 [ST_F_INTERCEPTED] = IST("intercepted_requests_total"),
626 [ST_F_DCON] = IST("denied_connections_total"),
627 [ST_F_DSES] = IST("denied_sessions_total"),
628 [ST_F_WREW] = IST("failed_header_rewriting_total"),
629 [ST_F_CONNECT] = IST("connection_attempts_total"),
630 [ST_F_REUSE] = IST("connection_reuses_total"),
631 [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"),
632 [ST_F_CACHE_HITS] = IST("http_cache_hits_total"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200633 [ST_F_SRV_ICUR] = IST("idle_connections_current"),
634 [ST_F_SRV_ILIM] = IST("idle_connections_limit"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100635 [ST_F_QT_MAX] = IST("max_queue_time_seconds"),
636 [ST_F_CT_MAX] = IST("max_connect_time_seconds"),
637 [ST_F_RT_MAX] = IST("max_response_time_seconds"),
638 [ST_F_TT_MAX] = IST("max_total_time_seconds"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100639 [ST_F_EINT] = IST("internal_errors_total"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200640 [ST_F_IDLE_CONN_CUR] = IST("unsafe_idle_connections_current"),
641 [ST_F_SAFE_CONN_CUR] = IST("safe_idle_connections_current"),
642 [ST_F_USED_CONN_CUR] = IST("used_connections_current"),
643 [ST_F_NEED_CONN_EST] = IST("need_connections_current"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100644};
645
646/* Description of all info fields */
647const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
648 [INF_NAME] = IST("Product name."),
649 [INF_VERSION] = IST("HAProxy version."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500650 [INF_RELEASE_DATE] = IST("HAProxy release date."),
William Dauchy5a982a72021-01-08 13:18:06 +0100651 [INF_BUILD_INFO] = IST("HAProxy build info."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100652 [INF_NBTHREAD] = IST("Configured number of threads."),
653 [INF_NBPROC] = IST("Configured number of processes."),
654 [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
655 [INF_PID] = IST("HAProxy PID."),
656 [INF_UPTIME] = IST("Uptime in a human readable format."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200657 [INF_UPTIME_SEC] = IST("Start time in seconds."),
William Dauchya8766cf2021-01-15 22:41:37 +0100658 [INF_MEMMAX_BYTES] = IST("Per-process memory limit (in bytes); 0=unset."),
659 [INF_POOL_ALLOC_BYTES] = IST("Total amount of memory allocated in pools (in bytes)."),
660 [INF_POOL_USED_BYTES] = IST("Total amount of memory used in pools (in bytes)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100661 [INF_POOL_FAILED] = IST("Total number of failed pool allocations."),
662 [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500663 [INF_MAXSOCK] = IST("Maximum number of open sockets."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100664 [INF_MAXCONN] = IST("Maximum number of concurrent connections."),
665 [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."),
666 [INF_CURR_CONN] = IST("Number of active sessions."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200667 [INF_CUM_CONN] = IST("Total number of created sessions."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100668 [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."),
669 [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."),
670 [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."),
671 [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."),
672 [INF_MAXPIPES] = IST("Configured maximum number of pipes."),
673 [INF_PIPES_USED] = IST("Number of pipes in used."),
674 [INF_PIPES_FREE] = IST("Number of pipes unused."),
675 [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."),
676 [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."),
677 [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."),
678 [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."),
679 [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."),
680 [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."),
681 [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."),
682 [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."),
683 [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."),
684 [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."),
685 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."),
686 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."),
687 [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."),
688 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."),
689 [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."),
690 [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."),
691 [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."),
692 [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."),
693 [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."),
694 [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."),
695 [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."),
696 [INF_TASKS] = IST("Current number of tasks."),
697 [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."),
698 [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."),
699 [INF_NODE] = IST("Node name."),
700 [INF_DESCRIPTION] = IST("Node description."),
701 [INF_STOPPING] = IST("Non zero means stopping in progress."),
702 [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."),
703 [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."),
704 [INF_LISTENERS] = IST("Current number of active listeners."),
705 [INF_ACTIVE_PEERS] = IST("Current number of active peers."),
706 [INF_CONNECTED_PEERS] = IST("Current number of connected peers."),
707 [INF_DROPPED_LOGS] = IST("Total number of dropped logs."),
708 [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200709 [INF_FAILED_RESOLUTIONS] = IST("Total number of failed DNS resolutions."),
710 [INF_TOTAL_BYTES_OUT] = IST("Total number of bytes emitted."),
711 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("Total number of bytes emitted through a kernel pipe."),
712 [INF_BYTES_OUT_RATE] = IST("Number of bytes emitted over the last elapsed second."),
713 [INF_DEBUG_COMMANDS_ISSUED] = IST("Number of debug commands issued on this process (anything > 0 is unsafe)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100714};
715
716/* Description of all stats fields */
717const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
718 [ST_F_PXNAME] = IST("The proxy name."),
719 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
720 [ST_F_QCUR] = IST("Current number of queued requests."),
721 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
722 [ST_F_SCUR] = IST("Current number of active sessions."),
723 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
724 [ST_F_SLIM] = IST("Configured session limit."),
725 [ST_F_STOT] = IST("Total number of sessions."),
726 [ST_F_BIN] = IST("Current total of incoming bytes."),
727 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
728 [ST_F_DREQ] = IST("Total number of denied requests."),
729 [ST_F_DRESP] = IST("Total number of denied responses."),
730 [ST_F_EREQ] = IST("Total number of request errors."),
731 [ST_F_ECON] = IST("Total number of connection errors."),
732 [ST_F_ERESP] = IST("Total number of response errors."),
733 [ST_F_WRETR] = IST("Total number of retry warnings."),
734 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Willy Tarreau6b3bf732020-09-24 07:35:46 +0200735 [ST_F_STATUS] = IST("Current status of the service (frontend: 0=STOP, 1=UP - backend: 0=DOWN, 1=UP - server: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100736 [ST_F_WEIGHT] = IST("Service weight."),
737 [ST_F_ACT] = IST("Current number of active servers."),
738 [ST_F_BCK] = IST("Current number of backup servers."),
739 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
740 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
741 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
742 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
743 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
744 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
745 [ST_F_IID] = IST("Unique proxy id."),
746 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
747 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
748 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
749 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
750 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
751 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
752 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
753 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
Christopher Fauletcf403f32019-11-21 14:35:46 +0100754 [ST_F_CHECK_STATUS] = IST("Status of last health check (HCHK_STATUS_* values)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100755 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
Christopher Faulet2711e512020-02-27 16:12:07 +0100756 [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100757 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
758 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
759 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
760 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
761 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
762 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
763 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
764 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
765 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
766 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
767 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
768 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
769 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
770 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
771 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
772 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
773 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
774 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
775 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
776 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
777 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
778 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
779 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
780 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
781 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
782 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
783 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
784 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
785 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
786 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
787 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
788 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
789 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
790 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
791 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
792 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
793 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
794 [ST_F_ALGO] = IST("Load balancing algorithm."),
795 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
796 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
797 [ST_F_CONN_TOT] = IST("Total number of connections."),
798 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
799 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
800 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
801 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
802 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
803 [ST_F_REUSE] = IST("Total number of connection reuses."),
804 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
805 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100806 [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"),
807 [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100808 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
809 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
810 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
811 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100812 [ST_F_EINT] = IST("Total number of internal errors."),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200813 [ST_F_IDLE_CONN_CUR] = IST("Current number of unsafe idle connections."),
814 [ST_F_SAFE_CONN_CUR] = IST("Current number of safe idle connections."),
815 [ST_F_USED_CONN_CUR] = IST("Current number of connections in use."),
816 [ST_F_NEED_CONN_EST] = IST("Estimated needed number of connections."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100817};
818
819/* Specific labels for all info fields. Empty by default. */
820const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
821 [INF_NAME] = IST(""),
822 [INF_VERSION] = IST(""),
823 [INF_RELEASE_DATE] = IST(""),
William Dauchy5a982a72021-01-08 13:18:06 +0100824 [INF_BUILD_INFO] = IST(PROMEX_BUILDINFO_LABEL),
Christopher Fauletf959d082019-02-07 15:38:42 +0100825 [INF_NBTHREAD] = IST(""),
826 [INF_NBPROC] = IST(""),
827 [INF_PROCESS_NUM] = IST(""),
828 [INF_PID] = IST(""),
829 [INF_UPTIME] = IST(""),
830 [INF_UPTIME_SEC] = IST(""),
William Dauchya8766cf2021-01-15 22:41:37 +0100831 [INF_MEMMAX_BYTES] = IST(""),
832 [INF_POOL_ALLOC_BYTES] = IST(""),
833 [INF_POOL_USED_BYTES] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100834 [INF_POOL_FAILED] = IST(""),
835 [INF_ULIMIT_N] = IST(""),
836 [INF_MAXSOCK] = IST(""),
837 [INF_MAXCONN] = IST(""),
838 [INF_HARD_MAXCONN] = IST(""),
839 [INF_CURR_CONN] = IST(""),
840 [INF_CUM_CONN] = IST(""),
841 [INF_CUM_REQ] = IST(""),
842 [INF_MAX_SSL_CONNS] = IST(""),
843 [INF_CURR_SSL_CONNS] = IST(""),
844 [INF_CUM_SSL_CONNS] = IST(""),
845 [INF_MAXPIPES] = IST(""),
846 [INF_PIPES_USED] = IST(""),
847 [INF_PIPES_FREE] = IST(""),
848 [INF_CONN_RATE] = IST(""),
849 [INF_CONN_RATE_LIMIT] = IST(""),
850 [INF_MAX_CONN_RATE] = IST(""),
851 [INF_SESS_RATE] = IST(""),
852 [INF_SESS_RATE_LIMIT] = IST(""),
853 [INF_MAX_SESS_RATE] = IST(""),
854 [INF_SSL_RATE] = IST(""),
855 [INF_SSL_RATE_LIMIT] = IST(""),
856 [INF_MAX_SSL_RATE] = IST(""),
857 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
858 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
859 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
860 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
861 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
862 [INF_SSL_CACHE_LOOKUPS] = IST(""),
863 [INF_SSL_CACHE_MISSES] = IST(""),
864 [INF_COMPRESS_BPS_IN] = IST(""),
865 [INF_COMPRESS_BPS_OUT] = IST(""),
866 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
867 [INF_ZLIB_MEM_USAGE] = IST(""),
868 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
869 [INF_TASKS] = IST(""),
870 [INF_RUN_QUEUE] = IST(""),
871 [INF_IDLE_PCT] = IST(""),
872 [INF_NODE] = IST(""),
873 [INF_DESCRIPTION] = IST(""),
874 [INF_STOPPING] = IST(""),
875 [INF_JOBS] = IST(""),
876 [INF_UNSTOPPABLE_JOBS] = IST(""),
877 [INF_LISTENERS] = IST(""),
878 [INF_ACTIVE_PEERS] = IST(""),
879 [INF_CONNECTED_PEERS] = IST(""),
880 [INF_DROPPED_LOGS] = IST(""),
881 [INF_BUSY_POLLING] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200882 [INF_FAILED_RESOLUTIONS] = IST(""),
883 [INF_TOTAL_BYTES_OUT] = IST(""),
884 [INF_TOTAL_SPLICED_BYTES_OUT] = IST(""),
885 [INF_BYTES_OUT_RATE] = IST(""),
886 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100887};
888
889/* Specific labels for all stats fields. Empty by default. */
890const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
891 [ST_F_PXNAME] = IST(""),
892 [ST_F_SVNAME] = IST(""),
893 [ST_F_QCUR] = IST(""),
894 [ST_F_QMAX] = IST(""),
895 [ST_F_SCUR] = IST(""),
896 [ST_F_SMAX] = IST(""),
897 [ST_F_SLIM] = IST(""),
898 [ST_F_STOT] = IST(""),
899 [ST_F_BIN] = IST(""),
900 [ST_F_BOUT] = IST(""),
901 [ST_F_DREQ] = IST(""),
902 [ST_F_DRESP] = IST(""),
903 [ST_F_EREQ] = IST(""),
904 [ST_F_ECON] = IST(""),
905 [ST_F_ERESP] = IST(""),
906 [ST_F_WRETR] = IST(""),
907 [ST_F_WREDIS] = IST(""),
908 [ST_F_STATUS] = IST(""),
909 [ST_F_WEIGHT] = IST(""),
910 [ST_F_ACT] = IST(""),
911 [ST_F_BCK] = IST(""),
912 [ST_F_CHKFAIL] = IST(""),
913 [ST_F_CHKDOWN] = IST(""),
914 [ST_F_LASTCHG] = IST(""),
915 [ST_F_DOWNTIME] = IST(""),
916 [ST_F_QLIMIT] = IST(""),
917 [ST_F_PID] = IST(""),
918 [ST_F_IID] = IST(""),
919 [ST_F_SID] = IST(""),
920 [ST_F_THROTTLE] = IST(""),
921 [ST_F_LBTOT] = IST(""),
922 [ST_F_TRACKED] = IST(""),
923 [ST_F_TYPE] = IST(""),
924 [ST_F_RATE] = IST(""),
925 [ST_F_RATE_LIM] = IST(""),
926 [ST_F_RATE_MAX] = IST(""),
927 [ST_F_CHECK_STATUS] = IST(""),
928 [ST_F_CHECK_CODE] = IST(""),
929 [ST_F_CHECK_DURATION] = IST(""),
930 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
931 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
932 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
933 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
934 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
935 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
936 [ST_F_HANAFAIL] = IST(""),
937 [ST_F_REQ_RATE] = IST(""),
938 [ST_F_REQ_RATE_MAX] = IST(""),
939 [ST_F_REQ_TOT] = IST(""),
940 [ST_F_CLI_ABRT] = IST(""),
941 [ST_F_SRV_ABRT] = IST(""),
942 [ST_F_COMP_IN] = IST(""),
943 [ST_F_COMP_OUT] = IST(""),
944 [ST_F_COMP_BYP] = IST(""),
945 [ST_F_COMP_RSP] = IST(""),
946 [ST_F_LASTSESS] = IST(""),
947 [ST_F_LAST_CHK] = IST(""),
948 [ST_F_LAST_AGT] = IST(""),
949 [ST_F_QTIME] = IST(""),
950 [ST_F_CTIME] = IST(""),
951 [ST_F_RTIME] = IST(""),
952 [ST_F_TTIME] = IST(""),
953 [ST_F_AGENT_STATUS] = IST(""),
954 [ST_F_AGENT_CODE] = IST(""),
955 [ST_F_AGENT_DURATION] = IST(""),
956 [ST_F_CHECK_DESC] = IST(""),
957 [ST_F_AGENT_DESC] = IST(""),
958 [ST_F_CHECK_RISE] = IST(""),
959 [ST_F_CHECK_FALL] = IST(""),
960 [ST_F_CHECK_HEALTH] = IST(""),
961 [ST_F_AGENT_RISE] = IST(""),
962 [ST_F_AGENT_FALL] = IST(""),
963 [ST_F_AGENT_HEALTH] = IST(""),
964 [ST_F_ADDR] = IST(""),
965 [ST_F_COOKIE] = IST(""),
966 [ST_F_MODE] = IST(""),
967 [ST_F_ALGO] = IST(""),
968 [ST_F_CONN_RATE] = IST(""),
969 [ST_F_CONN_RATE_MAX] = IST(""),
970 [ST_F_CONN_TOT] = IST(""),
971 [ST_F_INTERCEPTED] = IST(""),
972 [ST_F_DCON] = IST(""),
973 [ST_F_DSES] = IST(""),
974 [ST_F_WREW] = IST(""),
975 [ST_F_CONNECT] = IST(""),
976 [ST_F_REUSE] = IST(""),
977 [ST_F_CACHE_LOOKUPS] = IST(""),
978 [ST_F_CACHE_HITS] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200979 [ST_F_IDLE_CONN_CUR] = IST(""),
980 [ST_F_SAFE_CONN_CUR] = IST(""),
981 [ST_F_USED_CONN_CUR] = IST(""),
982 [ST_F_NEED_CONN_EST] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100983};
984
985/* Type for all info fields. "untyped" is used for unsupported field. */
986const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
987 [INF_NAME] = IST("untyped"),
988 [INF_VERSION] = IST("untyped"),
989 [INF_RELEASE_DATE] = IST("untyped"),
William Dauchy5a982a72021-01-08 13:18:06 +0100990 [INF_BUILD_INFO] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200991 [INF_NBTHREAD] = IST("gauge"),
992 [INF_NBPROC] = IST("gauge"),
993 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100994 [INF_PID] = IST("untyped"),
995 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200996 [INF_UPTIME_SEC] = IST("gauge"),
William Dauchya8766cf2021-01-15 22:41:37 +0100997 [INF_MEMMAX_BYTES] = IST("gauge"),
998 [INF_POOL_ALLOC_BYTES] = IST("gauge"),
999 [INF_POOL_USED_BYTES] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001000 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001001 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001002 [INF_MAXSOCK] = IST("gauge"),
1003 [INF_MAXCONN] = IST("gauge"),
1004 [INF_HARD_MAXCONN] = IST("gauge"),
1005 [INF_CURR_CONN] = IST("gauge"),
1006 [INF_CUM_CONN] = IST("counter"),
1007 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001008 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001009 [INF_CURR_SSL_CONNS] = IST("gauge"),
1010 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001011 [INF_MAXPIPES] = IST("gauge"),
1012 [INF_PIPES_USED] = IST("counter"),
1013 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001014 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001015 [INF_CONN_RATE_LIMIT] = IST("gauge"),
1016 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001017 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001018 [INF_SESS_RATE_LIMIT] = IST("gauge"),
1019 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001020 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001021 [INF_SSL_RATE_LIMIT] = IST("gauge"),
1022 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001023 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001024 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001025 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
1026 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001027 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001028 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
1029 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001030 [INF_COMPRESS_BPS_IN] = IST("counter"),
1031 [INF_COMPRESS_BPS_OUT] = IST("counter"),
1032 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001033 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001034 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001035 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +02001036 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001037 [INF_IDLE_PCT] = IST("gauge"),
1038 [INF_NODE] = IST("untyped"),
1039 [INF_DESCRIPTION] = IST("untyped"),
1040 [INF_STOPPING] = IST("gauge"),
1041 [INF_JOBS] = IST("gauge"),
1042 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
1043 [INF_LISTENERS] = IST("gauge"),
1044 [INF_ACTIVE_PEERS] = IST("gauge"),
1045 [INF_CONNECTED_PEERS] = IST("gauge"),
1046 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001047 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletc55a6262020-07-10 15:39:39 +02001048 [INF_FAILED_RESOLUTIONS] = IST("counter"),
1049 [INF_TOTAL_BYTES_OUT] = IST("counter"),
1050 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("counter"),
1051 [INF_BYTES_OUT_RATE] = IST("gauge"),
1052 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +01001053};
1054
1055/* Type for all stats fields. "untyped" is used for unsupported field. */
1056const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
1057 [ST_F_PXNAME] = IST("untyped"),
1058 [ST_F_SVNAME] = IST("untyped"),
1059 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001060 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001061 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001062 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001063 [ST_F_SLIM] = IST("gauge"),
1064 [ST_F_STOT] = IST("counter"),
1065 [ST_F_BIN] = IST("counter"),
1066 [ST_F_BOUT] = IST("counter"),
1067 [ST_F_DREQ] = IST("counter"),
1068 [ST_F_DRESP] = IST("counter"),
1069 [ST_F_EREQ] = IST("counter"),
1070 [ST_F_ECON] = IST("counter"),
1071 [ST_F_ERESP] = IST("counter"),
1072 [ST_F_WRETR] = IST("counter"),
1073 [ST_F_WREDIS] = IST("counter"),
1074 [ST_F_STATUS] = IST("gauge"),
1075 [ST_F_WEIGHT] = IST("gauge"),
1076 [ST_F_ACT] = IST("gauge"),
1077 [ST_F_BCK] = IST("gauge"),
1078 [ST_F_CHKFAIL] = IST("counter"),
1079 [ST_F_CHKDOWN] = IST("counter"),
1080 [ST_F_LASTCHG] = IST("gauge"),
1081 [ST_F_DOWNTIME] = IST("counter"),
1082 [ST_F_QLIMIT] = IST("gauge"),
1083 [ST_F_PID] = IST("untyped"),
1084 [ST_F_IID] = IST("untyped"),
1085 [ST_F_SID] = IST("untyped"),
1086 [ST_F_THROTTLE] = IST("gauge"),
1087 [ST_F_LBTOT] = IST("counter"),
1088 [ST_F_TRACKED] = IST("untyped"),
1089 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001090 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001091 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001092 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Fauletcf403f32019-11-21 14:35:46 +01001093 [ST_F_CHECK_STATUS] = IST("gauge"),
1094 [ST_F_CHECK_CODE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001095 [ST_F_CHECK_DURATION] = IST("gauge"),
1096 [ST_F_HRSP_1XX] = IST("counter"),
1097 [ST_F_HRSP_2XX] = IST("counter"),
1098 [ST_F_HRSP_3XX] = IST("counter"),
1099 [ST_F_HRSP_4XX] = IST("counter"),
1100 [ST_F_HRSP_5XX] = IST("counter"),
1101 [ST_F_HRSP_OTHER] = IST("counter"),
1102 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001103 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001104 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001105 [ST_F_REQ_TOT] = IST("counter"),
1106 [ST_F_CLI_ABRT] = IST("counter"),
1107 [ST_F_SRV_ABRT] = IST("counter"),
1108 [ST_F_COMP_IN] = IST("counter"),
1109 [ST_F_COMP_OUT] = IST("counter"),
1110 [ST_F_COMP_BYP] = IST("counter"),
1111 [ST_F_COMP_RSP] = IST("counter"),
1112 [ST_F_LASTSESS] = IST("gauge"),
1113 [ST_F_LAST_CHK] = IST("untyped"),
1114 [ST_F_LAST_AGT] = IST("untyped"),
1115 [ST_F_QTIME] = IST("gauge"),
1116 [ST_F_CTIME] = IST("gauge"),
1117 [ST_F_RTIME] = IST("gauge"),
1118 [ST_F_TTIME] = IST("gauge"),
1119 [ST_F_AGENT_STATUS] = IST("untyped"),
1120 [ST_F_AGENT_CODE] = IST("untyped"),
1121 [ST_F_AGENT_DURATION] = IST("gauge"),
1122 [ST_F_CHECK_DESC] = IST("untyped"),
1123 [ST_F_AGENT_DESC] = IST("untyped"),
1124 [ST_F_CHECK_RISE] = IST("gauge"),
1125 [ST_F_CHECK_FALL] = IST("gauge"),
1126 [ST_F_CHECK_HEALTH] = IST("gauge"),
1127 [ST_F_AGENT_RISE] = IST("gauge"),
1128 [ST_F_AGENT_FALL] = IST("gauge"),
1129 [ST_F_AGENT_HEALTH] = IST("gauge"),
1130 [ST_F_ADDR] = IST("untyped"),
1131 [ST_F_COOKIE] = IST("untyped"),
1132 [ST_F_MODE] = IST("untyped"),
1133 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001134 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001135 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001136 [ST_F_CONN_TOT] = IST("counter"),
1137 [ST_F_INTERCEPTED] = IST("counter"),
1138 [ST_F_DCON] = IST("counter"),
1139 [ST_F_DSES] = IST("counter"),
1140 [ST_F_WREW] = IST("counter"),
1141 [ST_F_CONNECT] = IST("counter"),
1142 [ST_F_REUSE] = IST("counter"),
1143 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1144 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Faulet20ab80c2019-11-08 15:24:32 +01001145 [ST_F_SRV_ICUR] = IST("gauge"),
1146 [ST_F_SRV_ILIM] = IST("gauge"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001147 [ST_F_QT_MAX] = IST("gauge"),
1148 [ST_F_CT_MAX] = IST("gauge"),
1149 [ST_F_RT_MAX] = IST("gauge"),
1150 [ST_F_TT_MAX] = IST("gauge"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001151 [ST_F_EINT] = IST("counter"),
Christopher Fauletc55a6262020-07-10 15:39:39 +02001152 [ST_F_IDLE_CONN_CUR] = IST("gauge"),
1153 [ST_F_SAFE_CONN_CUR] = IST("gauge"),
1154 [ST_F_USED_CONN_CUR] = IST("gauge"),
1155 [ST_F_NEED_CONN_EST] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001156};
1157
Christopher Fauletd45d1052019-09-06 16:10:19 +02001158/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001159static int promex_srv_status(struct server *sv)
1160{
Christopher Fauletf959d082019-02-07 15:38:42 +01001161 int state = 0;
1162
Christopher Fauletf959d082019-02-07 15:38:42 +01001163 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1164 state = 1;
1165 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Fauletd45d1052019-09-06 16:10:19 +02001166 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001167 }
Christopher Fauletd45d1052019-09-06 16:10:19 +02001168 else if (sv->cur_state == SRV_ST_STOPPING)
1169 state = 4;
1170
1171 if (sv->cur_admin & SRV_ADMF_MAINT)
1172 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001173
1174 return state;
1175}
1176
1177/* Convert a field to its string representation and write it in <out>, followed
1178 * by a newline, if there is enough space. non-numeric value are converted in
1179 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1180 * to process this kind of value). It returns 1 on success. Otherwise, it
1181 * returns 0. The buffer's length must not exceed <max> value.
1182 */
1183static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1184{
1185 int ret = 0;
1186
1187 switch (field_format(f, 0)) {
1188 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1189 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1190 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1191 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1192 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001193 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001194 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1195 default: ret = chunk_strcat(out, "Nan\n"); break;
1196 }
1197 if (!ret || out->data > max)
1198 return 0;
1199 return 1;
1200}
1201
1202/* Concatenate the <prefix> with the field name using the array
1203 * <promex_st_metric_names> and store it in <name>. The field type is in
1204 * <appctx->st2>. This function never fails but relies on
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001205 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enough to be copied in
Christopher Fauletf959d082019-02-07 15:38:42 +01001206 * <name>
1207 */
1208static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1209{
1210 const struct ist *names;
1211
1212 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1213 ? promex_inf_metric_names
1214 : promex_st_metric_names);
1215
1216 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1217 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1218}
1219
1220/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1221 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1222 */
1223static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1224 const struct ist name, struct ist *out, size_t max)
1225{
1226 const struct ist *desc, *types;
1227
1228 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1229 desc = promex_inf_metric_desc;
1230 types = promex_inf_metric_types;
1231 }
1232 else {
1233 desc = promex_st_metric_desc;
1234 types = promex_st_metric_types;
1235 }
1236
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001237 if (istcat(out, ist("# HELP "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001238 istcat(out, name, max) == -1 ||
1239 istcat(out, ist(" "), max) == -1 ||
1240 istcat(out, desc[appctx->st2], max) == -1 ||
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001241 istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001242 istcat(out, name, max) == -1 ||
1243 istcat(out, ist(" "), max) == -1 ||
1244 istcat(out, types[appctx->st2], max) == -1 ||
1245 istcat(out, ist("\n"), max) == -1)
1246 goto full;
1247
1248 return 1;
1249
1250 full:
1251 return 0;
1252}
1253
1254/* Dump the line for <metric>. It starts by the metric name followed by its
1255 * labels (proxy name, server name...) between braces and finally its value. If
1256 * not already done, the header lines are dumped first. It returns 1 on
1257 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1258 */
1259static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1260 const struct ist prefix, struct field *metric,
1261 struct ist *out, size_t max)
1262{
1263 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1264 size_t len = out->len;
1265
1266 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1267 return 0;
1268
1269 promex_metric_name(appctx, &name, prefix);
1270 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1271 !promex_dump_metric_header(appctx, htx, name, out, max))
1272 goto full;
1273
1274 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1275 const struct ist label = promex_inf_metric_labels[appctx->st2];
1276
1277 if (istcat(out, name, max) == -1 ||
1278 (label.len && istcat(out, ist("{"), max) == -1) ||
1279 (label.len && istcat(out, label, max) == -1) ||
1280 (label.len && istcat(out, ist("}"), max) == -1) ||
1281 istcat(out, ist(" "), max) == -1)
1282 goto full;
1283 }
1284 else {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001285 struct proxy *px = appctx->ctx.stats.obj1;
1286 struct server *srv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001287 const struct ist label = promex_st_metric_labels[appctx->st2];
1288
1289 if (istcat(out, name, max) == -1 ||
1290 istcat(out, ist("{proxy=\""), max) == -1 ||
1291 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1292 istcat(out, ist("\""), max) == -1 ||
1293 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1294 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1295 (srv && istcat(out, ist("\""), max) == -1) ||
1296 (label.len && istcat(out, ist(","), max) == -1) ||
1297 (label.len && istcat(out, label, max) == -1) ||
1298 istcat(out, ist("} "), max) == -1)
1299 goto full;
1300 }
1301
1302 trash.data = out->len;
1303 if (!promex_metric_to_str(&trash, metric, max))
1304 goto full;
1305 out->len = trash.data;
1306
1307 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1308 return 1;
1309 full:
1310 // Restore previous length
1311 out->len = len;
1312 return 0;
1313
1314}
1315
1316
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001317/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001318 * 0 if <htx> is full and -1 in case of any error. */
1319static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1320{
1321 static struct ist prefix = IST("haproxy_process_");
1322 struct field metric;
1323 struct channel *chn = si_ic(appctx->owner);
1324 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001325 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001326 int ret = 1;
1327
William Dauchy5d9b8f32021-01-11 20:07:49 +01001328 if (!stats_fill_info(info, INF_TOTAL_FIELDS))
1329 return -1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001330
Christopher Fauletf959d082019-02-07 15:38:42 +01001331 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1332 switch (appctx->st2) {
William Dauchy5a982a72021-01-08 13:18:06 +01001333 case INF_BUILD_INFO:
1334 metric = mkf_u32(FN_GAUGE, 1);
1335 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001336 case INF_UPTIME_SEC:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001337 metric = mkf_u32(FN_DURATION, start_date.tv_sec);
Christopher Fauletf959d082019-02-07 15:38:42 +01001338 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001339
1340 default:
William Dauchy5d9b8f32021-01-11 20:07:49 +01001341 metric = info[appctx->st2];
Christopher Fauletf959d082019-02-07 15:38:42 +01001342 }
1343
1344 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1345 goto full;
1346
Christopher Fauletf959d082019-02-07 15:38:42 +01001347 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1348 appctx->st2 = promex_global_metrics[appctx->st2];
1349 }
1350
1351 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001352 if (out.len) {
1353 if (!htx_add_data_atonce(htx, out))
1354 return -1; /* Unexpected and unrecoverable error */
1355 channel_add_input(chn, out.len);
1356 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001357 return ret;
1358 full:
1359 ret = 0;
1360 goto end;
1361}
1362
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001363/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001364 * 0 if <htx> is full and -1 in case of any error. */
1365static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1366{
1367 static struct ist prefix = IST("haproxy_frontend_");
1368 struct proxy *px;
1369 struct field metric;
1370 struct channel *chn = si_ic(appctx->owner);
1371 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001372 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001373 int ret = 1;
1374
1375 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001376 while (appctx->ctx.stats.obj1) {
1377 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001378
1379 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001380 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001381 goto next_px;
1382
1383 switch (appctx->st2) {
1384 case ST_F_STATUS:
Willy Tarreauc3914d42020-09-24 08:39:22 +02001385 metric = mkf_u32(FO_STATUS, !px->disabled);
Christopher Fauletf959d082019-02-07 15:38:42 +01001386 break;
1387 case ST_F_SCUR:
1388 metric = mkf_u32(0, px->feconn);
1389 break;
1390 case ST_F_SMAX:
1391 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1392 break;
1393 case ST_F_SLIM:
1394 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1395 break;
1396 case ST_F_STOT:
1397 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1398 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001399 case ST_F_RATE_LIM:
1400 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1401 break;
1402 case ST_F_RATE_MAX:
1403 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1404 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001405 case ST_F_CONN_RATE_MAX:
1406 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1407 break;
1408 case ST_F_CONN_TOT:
1409 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1410 break;
1411 case ST_F_BIN:
1412 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1413 break;
1414 case ST_F_BOUT:
1415 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1416 break;
1417 case ST_F_DREQ:
1418 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1419 break;
1420 case ST_F_DRESP:
1421 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1422 break;
1423 case ST_F_EREQ:
1424 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1425 break;
1426 case ST_F_DCON:
1427 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1428 break;
1429 case ST_F_DSES:
1430 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1431 break;
1432 case ST_F_WREW:
1433 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1434 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001435 case ST_F_EINT:
1436 metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors);
1437 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001438 case ST_F_REQ_RATE_MAX:
1439 if (px->mode != PR_MODE_HTTP)
1440 goto next_px;
1441 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1442 break;
1443 case ST_F_REQ_TOT:
1444 if (px->mode != PR_MODE_HTTP)
1445 goto next_px;
1446 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1447 break;
1448 case ST_F_HRSP_1XX:
1449 if (px->mode != PR_MODE_HTTP)
1450 goto next_px;
1451 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1452 break;
1453 case ST_F_HRSP_2XX:
1454 if (px->mode != PR_MODE_HTTP)
1455 goto next_px;
1456 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1457 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1458 break;
1459 case ST_F_HRSP_3XX:
1460 if (px->mode != PR_MODE_HTTP)
1461 goto next_px;
1462 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1463 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1464 break;
1465 case ST_F_HRSP_4XX:
1466 if (px->mode != PR_MODE_HTTP)
1467 goto next_px;
1468 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1469 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1470 break;
1471 case ST_F_HRSP_5XX:
1472 if (px->mode != PR_MODE_HTTP)
1473 goto next_px;
1474 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1475 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1476 break;
1477 case ST_F_HRSP_OTHER:
1478 if (px->mode != PR_MODE_HTTP)
1479 goto next_px;
1480 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1481 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1482 break;
1483 case ST_F_INTERCEPTED:
1484 if (px->mode != PR_MODE_HTTP)
1485 goto next_px;
1486 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1487 break;
1488 case ST_F_CACHE_LOOKUPS:
1489 if (px->mode != PR_MODE_HTTP)
1490 goto next_px;
1491 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1492 break;
1493 case ST_F_CACHE_HITS:
1494 if (px->mode != PR_MODE_HTTP)
1495 goto next_px;
1496 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1497 break;
1498 case ST_F_COMP_IN:
1499 if (px->mode != PR_MODE_HTTP)
1500 goto next_px;
1501 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1502 break;
1503 case ST_F_COMP_OUT:
1504 if (px->mode != PR_MODE_HTTP)
1505 goto next_px;
1506 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1507 break;
1508 case ST_F_COMP_BYP:
1509 if (px->mode != PR_MODE_HTTP)
1510 goto next_px;
1511 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1512 break;
1513 case ST_F_COMP_RSP:
1514 if (px->mode != PR_MODE_HTTP)
1515 goto next_px;
1516 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1517 break;
1518
1519 default:
1520 goto next_metric;
1521 }
1522
1523 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1524 goto full;
1525 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001526 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001527 }
1528 next_metric:
1529 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001530 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001531 appctx->st2 = promex_front_metrics[appctx->st2];
1532 }
1533
1534 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001535 if (out.len) {
1536 if (!htx_add_data_atonce(htx, out))
1537 return -1; /* Unexpected and unrecoverable error */
1538 channel_add_input(chn, out.len);
1539 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001540 return ret;
1541 full:
1542 ret = 0;
1543 goto end;
1544}
1545
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001546/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001547 * 0 if <htx> is full and -1 in case of any error. */
1548static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1549{
1550 static struct ist prefix = IST("haproxy_backend_");
1551 struct proxy *px;
1552 struct field metric;
1553 struct channel *chn = si_ic(appctx->owner);
1554 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001555 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001556 int ret = 1;
1557 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001558 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001559
1560 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001561 while (appctx->ctx.stats.obj1) {
1562 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001563
1564 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001565 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001566 goto next_px;
1567
1568 switch (appctx->st2) {
1569 case ST_F_STATUS:
1570 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1571 break;
1572 case ST_F_SCUR:
1573 metric = mkf_u32(0, px->beconn);
1574 break;
1575 case ST_F_SMAX:
1576 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1577 break;
1578 case ST_F_SLIM:
1579 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1580 break;
1581 case ST_F_STOT:
1582 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1583 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001584 case ST_F_RATE_MAX:
1585 metric = mkf_u32(0, px->be_counters.sps_max);
1586 break;
1587 case ST_F_LASTSESS:
1588 metric = mkf_s32(FN_AGE, be_lastsession(px));
1589 break;
1590 case ST_F_QCUR:
1591 metric = mkf_u32(0, px->nbpend);
1592 break;
1593 case ST_F_QMAX:
1594 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1595 break;
1596 case ST_F_CONNECT:
1597 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1598 break;
1599 case ST_F_REUSE:
1600 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1601 break;
1602 case ST_F_BIN:
1603 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1604 break;
1605 case ST_F_BOUT:
1606 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1607 break;
1608 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001609 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1610 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001611 break;
1612 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001613 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1614 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001615 break;
1616 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001617 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1618 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001619 break;
1620 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001621 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1622 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001623 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001624 case ST_F_QT_MAX:
1625 secs = (double)px->be_counters.qtime_max / 1000.0;
1626 metric = mkf_flt(FN_MAX, secs);
1627 break;
1628 case ST_F_CT_MAX:
1629 secs = (double)px->be_counters.ctime_max / 1000.0;
1630 metric = mkf_flt(FN_MAX, secs);
1631 break;
1632 case ST_F_RT_MAX:
1633 secs = (double)px->be_counters.dtime_max / 1000.0;
1634 metric = mkf_flt(FN_MAX, secs);
1635 break;
1636 case ST_F_TT_MAX:
1637 secs = (double)px->be_counters.ttime_max / 1000.0;
1638 metric = mkf_flt(FN_MAX, secs);
1639 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001640 case ST_F_DREQ:
1641 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1642 break;
1643 case ST_F_DRESP:
1644 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1645 break;
1646 case ST_F_ECON:
1647 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1648 break;
1649 case ST_F_ERESP:
1650 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1651 break;
1652 case ST_F_WRETR:
1653 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1654 break;
1655 case ST_F_WREDIS:
1656 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1657 break;
1658 case ST_F_WREW:
1659 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1660 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001661 case ST_F_EINT:
1662 metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors);
1663 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001664 case ST_F_CLI_ABRT:
1665 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1666 break;
1667 case ST_F_SRV_ABRT:
1668 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1669 break;
1670 case ST_F_WEIGHT:
1671 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1672 metric = mkf_u32(FN_AVG, weight);
1673 break;
1674 case ST_F_ACT:
1675 metric = mkf_u32(0, px->srv_act);
1676 break;
1677 case ST_F_BCK:
1678 metric = mkf_u32(0, px->srv_bck);
1679 break;
1680 case ST_F_CHKDOWN:
1681 metric = mkf_u64(FN_COUNTER, px->down_trans);
1682 break;
1683 case ST_F_LASTCHG:
1684 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1685 break;
1686 case ST_F_DOWNTIME:
1687 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1688 break;
1689 case ST_F_LBTOT:
1690 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1691 break;
1692 case ST_F_REQ_TOT:
1693 if (px->mode != PR_MODE_HTTP)
1694 goto next_px;
1695 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1696 break;
1697 case ST_F_HRSP_1XX:
1698 if (px->mode != PR_MODE_HTTP)
1699 goto next_px;
1700 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1701 break;
1702 case ST_F_HRSP_2XX:
1703 if (px->mode != PR_MODE_HTTP)
1704 goto next_px;
1705 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1706 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1707 break;
1708 case ST_F_HRSP_3XX:
1709 if (px->mode != PR_MODE_HTTP)
1710 goto next_px;
1711 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1712 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1713 break;
1714 case ST_F_HRSP_4XX:
1715 if (px->mode != PR_MODE_HTTP)
1716 goto next_px;
1717 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1718 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1719 break;
1720 case ST_F_HRSP_5XX:
1721 if (px->mode != PR_MODE_HTTP)
1722 goto next_px;
1723 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1724 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1725 break;
1726 case ST_F_HRSP_OTHER:
1727 if (px->mode != PR_MODE_HTTP)
1728 goto next_px;
1729 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1730 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1731 break;
1732 case ST_F_CACHE_LOOKUPS:
1733 if (px->mode != PR_MODE_HTTP)
1734 goto next_px;
1735 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1736 break;
1737 case ST_F_CACHE_HITS:
1738 if (px->mode != PR_MODE_HTTP)
1739 goto next_px;
1740 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1741 break;
1742 case ST_F_COMP_IN:
1743 if (px->mode != PR_MODE_HTTP)
1744 goto next_px;
1745 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1746 break;
1747 case ST_F_COMP_OUT:
1748 if (px->mode != PR_MODE_HTTP)
1749 goto next_px;
1750 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1751 break;
1752 case ST_F_COMP_BYP:
1753 if (px->mode != PR_MODE_HTTP)
1754 goto next_px;
1755 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1756 break;
1757 case ST_F_COMP_RSP:
1758 if (px->mode != PR_MODE_HTTP)
1759 goto next_px;
1760 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1761 break;
1762
1763 default:
1764 goto next_metric;
1765 }
1766
1767 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1768 goto full;
1769 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001770 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001771 }
1772 next_metric:
1773 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001774 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001775 appctx->st2 = promex_back_metrics[appctx->st2];
1776 }
1777
1778 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001779 if (out.len) {
1780 if (!htx_add_data_atonce(htx, out))
1781 return -1; /* Unexpected and unrecoverable error */
1782 channel_add_input(chn, out.len);
1783 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001784 return ret;
1785 full:
1786 ret = 0;
1787 goto end;
1788}
1789
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001790/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001791 * 0 if <htx> is full and -1 in case of any error. */
1792static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1793{
1794 static struct ist prefix = IST("haproxy_server_");
1795 struct proxy *px;
1796 struct server *sv;
1797 struct field metric;
1798 struct channel *chn = si_ic(appctx->owner);
1799 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001800 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001801 int ret = 1;
1802 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001803 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001804
1805 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001806 while (appctx->ctx.stats.obj1) {
1807 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001808
1809 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001810 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001811 goto next_px;
1812
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001813 while (appctx->ctx.stats.obj2) {
1814 sv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001815
Christopher Fauleteba22942019-11-19 14:18:24 +01001816 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1817 goto next_sv;
1818
Christopher Fauletf959d082019-02-07 15:38:42 +01001819 switch (appctx->st2) {
1820 case ST_F_STATUS:
1821 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1822 break;
1823 case ST_F_SCUR:
1824 metric = mkf_u32(0, sv->cur_sess);
1825 break;
1826 case ST_F_SMAX:
1827 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1828 break;
1829 case ST_F_SLIM:
1830 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1831 break;
1832 case ST_F_STOT:
1833 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1834 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001835 case ST_F_RATE_MAX:
1836 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1837 break;
1838 case ST_F_LASTSESS:
1839 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1840 break;
1841 case ST_F_QCUR:
1842 metric = mkf_u32(0, sv->nbpend);
1843 break;
1844 case ST_F_QMAX:
1845 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1846 break;
1847 case ST_F_QLIMIT:
1848 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1849 break;
1850 case ST_F_BIN:
1851 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1852 break;
1853 case ST_F_BOUT:
1854 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1855 break;
1856 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001857 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1858 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001859 break;
1860 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001861 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1862 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001863 break;
1864 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001865 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1866 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001867 break;
1868 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001869 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1870 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001871 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001872 case ST_F_QT_MAX:
1873 secs = (double)sv->counters.qtime_max / 1000.0;
1874 metric = mkf_flt(FN_MAX, secs);
1875 break;
1876 case ST_F_CT_MAX:
1877 secs = (double)sv->counters.ctime_max / 1000.0;
1878 metric = mkf_flt(FN_MAX, secs);
1879 break;
1880 case ST_F_RT_MAX:
1881 secs = (double)sv->counters.dtime_max / 1000.0;
1882 metric = mkf_flt(FN_MAX, secs);
1883 break;
1884 case ST_F_TT_MAX:
1885 secs = (double)sv->counters.ttime_max / 1000.0;
1886 metric = mkf_flt(FN_MAX, secs);
1887 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001888 case ST_F_CONNECT:
1889 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1890 break;
1891 case ST_F_REUSE:
1892 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1893 break;
1894 case ST_F_DRESP:
Christopher Fauleta08546b2019-12-16 16:07:34 +01001895 metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp);
Christopher Fauletf959d082019-02-07 15:38:42 +01001896 break;
1897 case ST_F_ECON:
1898 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1899 break;
1900 case ST_F_ERESP:
1901 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1902 break;
1903 case ST_F_WRETR:
1904 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
1905 break;
1906 case ST_F_WREDIS:
1907 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
1908 break;
1909 case ST_F_WREW:
1910 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
1911 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001912 case ST_F_EINT:
1913 metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors);
1914 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001915 case ST_F_CLI_ABRT:
1916 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1917 break;
1918 case ST_F_SRV_ABRT:
1919 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1920 break;
1921 case ST_F_WEIGHT:
1922 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1923 metric = mkf_u32(FN_AVG, weight);
1924 break;
Christopher Fauletcf403f32019-11-21 14:35:46 +01001925 case ST_F_CHECK_STATUS:
1926 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1927 goto next_sv;
1928 metric = mkf_u32(FN_OUTPUT, sv->check.status);
1929 break;
1930 case ST_F_CHECK_CODE:
1931 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1932 goto next_sv;
1933 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
1934 break;
Christopher Faulet2711e512020-02-27 16:12:07 +01001935 case ST_F_CHECK_DURATION:
1936 if (sv->check.status < HCHK_STATUS_CHECKED)
1937 goto next_sv;
1938 secs = (double)sv->check.duration / 1000.0;
1939 metric = mkf_flt(FN_DURATION, secs);
1940 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001941 case ST_F_CHKFAIL:
1942 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1943 break;
1944 case ST_F_CHKDOWN:
1945 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1946 break;
1947 case ST_F_DOWNTIME:
1948 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
1949 break;
1950 case ST_F_LASTCHG:
1951 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
1952 break;
1953 case ST_F_THROTTLE:
1954 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
1955 break;
1956 case ST_F_LBTOT:
1957 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1958 break;
Marcin Deranek3c27dda2020-05-15 18:32:51 +02001959 case ST_F_REQ_TOT:
1960 if (px->mode != PR_MODE_HTTP)
1961 goto next_px;
1962 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
1963 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001964 case ST_F_HRSP_1XX:
1965 if (px->mode != PR_MODE_HTTP)
1966 goto next_px;
1967 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1968 break;
1969 case ST_F_HRSP_2XX:
1970 if (px->mode != PR_MODE_HTTP)
1971 goto next_px;
1972 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1973 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1974 break;
1975 case ST_F_HRSP_3XX:
1976 if (px->mode != PR_MODE_HTTP)
1977 goto next_px;
1978 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1979 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1980 break;
1981 case ST_F_HRSP_4XX:
1982 if (px->mode != PR_MODE_HTTP)
1983 goto next_px;
1984 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1985 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1986 break;
1987 case ST_F_HRSP_5XX:
1988 if (px->mode != PR_MODE_HTTP)
1989 goto next_px;
1990 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1991 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
1992 break;
1993 case ST_F_HRSP_OTHER:
1994 if (px->mode != PR_MODE_HTTP)
1995 goto next_px;
1996 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1997 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
1998 break;
Christopher Faulet20ab80c2019-11-08 15:24:32 +01001999 case ST_F_SRV_ICUR:
2000 metric = mkf_u32(0, sv->curr_idle_conns);
2001 break;
2002 case ST_F_SRV_ILIM:
2003 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2004 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02002005 case ST_F_IDLE_CONN_CUR:
2006 metric = mkf_u32(0, sv->curr_idle_nb);
2007 break;
2008 case ST_F_SAFE_CONN_CUR:
2009 metric = mkf_u32(0, sv->curr_safe_nb);
2010 break;
2011 case ST_F_USED_CONN_CUR:
2012 metric = mkf_u32(0, sv->curr_used_conns);
2013 break;
2014 case ST_F_NEED_CONN_EST:
2015 metric = mkf_u32(0, sv->est_need_conns);
2016 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002017
2018 default:
2019 goto next_metric;
2020 }
2021
2022 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2023 goto full;
2024
Christopher Fauleteba22942019-11-19 14:18:24 +01002025 next_sv:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002026 appctx->ctx.stats.obj2 = sv->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01002027 }
2028
2029 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002030 appctx->ctx.stats.obj1 = px->next;
2031 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002032 }
2033 next_metric:
2034 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002035 appctx->ctx.stats.obj1 = proxies_list;
2036 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002037 appctx->st2 = promex_srv_metrics[appctx->st2];
2038 }
2039
2040
2041 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02002042 if (out.len) {
2043 if (!htx_add_data_atonce(htx, out))
2044 return -1; /* Unexpected and unrecoverable error */
2045 channel_add_input(chn, out.len);
2046 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002047 return ret;
2048 full:
2049 ret = 0;
2050 goto end;
2051}
2052
2053/* Dump all metrics (global, frontends, backends and servers) depending on the
2054 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002055 * -1 in case of any error.
2056 * Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as
2057 * a pointer to the current server/listener. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002058static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2059{
2060 int ret;
2061
2062 switch (appctx->st1) {
2063 case PROMEX_DUMPER_INIT:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002064 appctx->ctx.stats.obj1 = NULL;
2065 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002066 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002067 appctx->st2 = promex_global_metrics[INF_NAME];
2068 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2069 /* fall through */
2070
2071 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002072 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2073 ret = promex_dump_global_metrics(appctx, htx);
2074 if (ret <= 0) {
2075 if (ret == -1)
2076 goto error;
2077 goto full;
2078 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002079 }
2080
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002081 appctx->ctx.stats.obj1 = proxies_list;
2082 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002083 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
2084 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002085 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2086 appctx->st1 = PROMEX_DUMPER_FRONT;
2087 /* fall through */
2088
2089 case PROMEX_DUMPER_FRONT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002090 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2091 ret = promex_dump_front_metrics(appctx, htx);
2092 if (ret <= 0) {
2093 if (ret == -1)
2094 goto error;
2095 goto full;
2096 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002097 }
2098
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002099 appctx->ctx.stats.obj1 = proxies_list;
2100 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002101 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002102 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2103 appctx->st1 = PROMEX_DUMPER_BACK;
2104 /* fall through */
2105
2106 case PROMEX_DUMPER_BACK:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002107 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2108 ret = promex_dump_back_metrics(appctx, htx);
2109 if (ret <= 0) {
2110 if (ret == -1)
2111 goto error;
2112 goto full;
2113 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002114 }
2115
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002116 appctx->ctx.stats.obj1 = proxies_list;
2117 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletefde9552020-06-05 08:18:56 +02002118 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002119 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2120 appctx->st1 = PROMEX_DUMPER_SRV;
2121 /* fall through */
2122
2123 case PROMEX_DUMPER_SRV:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002124 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2125 ret = promex_dump_srv_metrics(appctx, htx);
2126 if (ret <= 0) {
2127 if (ret == -1)
2128 goto error;
2129 goto full;
2130 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002131 }
2132
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002133 appctx->ctx.stats.obj1 = NULL;
2134 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002135 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002136 appctx->st2 = 0;
2137 appctx->st1 = PROMEX_DUMPER_DONE;
2138 /* fall through */
2139
2140 case PROMEX_DUMPER_DONE:
2141 default:
2142 break;
2143 }
2144
2145 return 1;
2146
2147 full:
2148 si_rx_room_blk(si);
2149 return 0;
2150 error:
2151 /* unrecoverable error */
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002152 appctx->ctx.stats.obj1 = NULL;
2153 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletf959d082019-02-07 15:38:42 +01002154 appctx->ctx.stats.flags = 0;
2155 appctx->st2 = 0;
2156 appctx->st1 = PROMEX_DUMPER_DONE;
2157 return -1;
2158}
2159
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002160/* Parse the query string of request URI to filter the metrics. It returns 1 on
Christopher Faulet78407ce2019-11-18 14:47:08 +01002161 * success and -1 on error. */
2162static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2163{
2164 struct channel *req = si_oc(si);
2165 struct channel *res = si_ic(si);
2166 struct htx *req_htx, *res_htx;
2167 struct htx_sl *sl;
William Dauchyc65f6562019-11-26 12:56:26 +01002168 char *p, *key, *value;
2169 const char *end;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002170 struct buffer *err;
2171 int default_scopes = PROMEX_FL_SCOPE_ALL;
2172 int len;
2173
2174 /* Get the query-string */
2175 req_htx = htxbuf(&req->buf);
2176 sl = http_get_stline(req_htx);
2177 if (!sl)
2178 goto error;
2179 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2180 if (!p)
2181 goto end;
2182 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet78407ce2019-11-18 14:47:08 +01002183
William Dauchyc65f6562019-11-26 12:56:26 +01002184 /* copy the query-string */
2185 len = end - p;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002186 chunk_reset(&trash);
2187 memcpy(trash.area, p, len);
2188 trash.area[len] = 0;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002189 p = trash.area;
William Dauchyc65f6562019-11-26 12:56:26 +01002190 end = trash.area + len;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002191
2192 /* Parse the query-string */
William Dauchyc65f6562019-11-26 12:56:26 +01002193 while (p < end && *p && *p != '#') {
2194 value = NULL;
2195
2196 /* decode parameter name */
2197 key = p;
2198 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002199 ++p;
William Dauchyc65f6562019-11-26 12:56:26 +01002200 /* found a value */
2201 if (*p == '=') {
2202 *(p++) = 0;
2203 value = p;
2204 }
2205 else if (*p == '&')
2206 *(p++) = 0;
2207 else if (*p == '#')
2208 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002209 len = url_decode(key, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002210 if (len == -1)
2211 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002212
William Dauchyc65f6562019-11-26 12:56:26 +01002213 /* decode value */
2214 if (value) {
2215 while (p < end && *p != '=' && *p != '&' && *p != '#')
2216 ++p;
2217 if (*p == '=')
2218 goto error;
2219 if (*p == '&')
2220 *(p++) = 0;
2221 else if (*p == '#')
2222 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002223 len = url_decode(value, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002224 if (len == -1)
2225 goto error;
2226 }
2227
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002228 if (strcmp(key, "scope") == 0) {
William Dauchyc65f6562019-11-26 12:56:26 +01002229 default_scopes = 0; /* at least a scope defined, unset default scopes */
2230 if (!value)
2231 goto error;
2232 else if (*value == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002233 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002234 else if (*value == '*')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002235 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002236 else if (strcmp(value, "global") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002237 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002238 else if (strcmp(value, "server") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002239 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002240 else if (strcmp(value, "backend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002241 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002242 else if (strcmp(value, "frontend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002243 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2244 else
2245 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002246 }
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002247 else if (strcmp(key, "no-maint") == 0)
Christopher Fauleteba22942019-11-19 14:18:24 +01002248 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002249 }
2250
2251 end:
2252 appctx->ctx.stats.flags |= default_scopes;
2253 return 1;
2254
2255 error:
2256 err = &http_err_chunks[HTTP_ERR_400];
2257 channel_erase(res);
2258 res->buf.data = b_data(err);
2259 memcpy(res->buf.area, b_head(err), b_data(err));
2260 res_htx = htx_from_buf(&res->buf);
2261 channel_add_input(res, res_htx->data);
2262 appctx->st0 = PROMEX_ST_END;
2263 return -1;
2264}
2265
Christopher Fauletf959d082019-02-07 15:38:42 +01002266/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2267 * full. */
2268static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2269{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002270 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002271 struct htx_sl *sl;
2272 unsigned int flags;
2273
2274 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);
2275 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2276 if (!sl)
2277 goto full;
2278 sl->info.res.status = 200;
2279 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
Christopher Fauletf959d082019-02-07 15:38:42 +01002280 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2281 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2282 !htx_add_endof(htx, HTX_BLK_EOH))
2283 goto full;
2284
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002285 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002286 return 1;
2287 full:
2288 htx_reset(htx);
2289 si_rx_room_blk(si);
2290 return 0;
2291}
2292
2293/* The function returns 1 if the initialisation is complete, 0 if
2294 * an errors occurs and -1 if more data are required for initializing
2295 * the applet.
2296 */
2297static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2298{
2299 appctx->st0 = PROMEX_ST_INIT;
2300 return 1;
2301}
2302
2303/* The main I/O handler for the promex applet. */
2304static void promex_appctx_handle_io(struct appctx *appctx)
2305{
2306 struct stream_interface *si = appctx->owner;
2307 struct stream *s = si_strm(si);
2308 struct channel *req = si_oc(si);
2309 struct channel *res = si_ic(si);
2310 struct htx *req_htx, *res_htx;
2311 int ret;
2312
2313 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002314 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2315 goto out;
2316
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002317 /* Check if the input buffer is available. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002318 if (!b_size(&res->buf)) {
2319 si_rx_room_blk(si);
2320 goto out;
2321 }
2322
2323 switch (appctx->st0) {
2324 case PROMEX_ST_INIT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002325 ret = promex_parse_uri(appctx, si);
2326 if (ret <= 0) {
2327 if (ret == -1)
2328 goto error;
2329 goto out;
2330 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002331 appctx->st0 = PROMEX_ST_HEAD;
2332 appctx->st1 = PROMEX_DUMPER_INIT;
2333 /* fall through */
2334
2335 case PROMEX_ST_HEAD:
2336 if (!promex_send_headers(appctx, si, res_htx))
2337 goto out;
2338 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2339 /* fall through */
2340
2341 case PROMEX_ST_DUMP:
2342 ret = promex_dump_metrics(appctx, si, res_htx);
2343 if (ret <= 0) {
2344 if (ret == -1)
2345 goto error;
2346 goto out;
2347 }
2348 appctx->st0 = PROMEX_ST_DONE;
2349 /* fall through */
2350
2351 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002352 /* Don't add TLR because mux-h1 will take care of it */
Willy Tarreauf1ea47d2020-07-23 06:53:27 +02002353 res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
Christopher Fauletf959d082019-02-07 15:38:42 +01002354 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2355 si_rx_room_blk(si);
2356 goto out;
2357 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002358 channel_add_input(res, 1);
2359 appctx->st0 = PROMEX_ST_END;
2360 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002361
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002362 case PROMEX_ST_END:
2363 if (!(res->flags & CF_SHUTR)) {
2364 res->flags |= CF_READ_NULL;
2365 si_shutr(si);
2366 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002367 }
2368
Christopher Fauletf959d082019-02-07 15:38:42 +01002369 out:
2370 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002371
2372 /* eat the whole request */
2373 if (co_data(req)) {
2374 req_htx = htx_from_buf(&req->buf);
2375 co_htx_skip(req, req_htx, co_data(req));
2376 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002377 return;
2378
2379 error:
2380 res->flags |= CF_READ_NULL;
2381 si_shutr(si);
2382 si_shutw(si);
2383}
2384
2385struct applet promex_applet = {
2386 .obj_type = OBJ_TYPE_APPLET,
2387 .name = "<PROMEX>", /* used for logging */
2388 .init = promex_appctx_init,
2389 .fct = promex_appctx_handle_io,
2390};
2391
2392static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2393 struct act_rule *rule, char **err)
2394{
2395 /* Prometheus exporter service is only available on "http-request" rulesets */
2396 if (rule->from != ACT_F_HTTP_REQ) {
2397 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2398 return ACT_RET_PRS_ERR;
2399 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002400
2401 /* Add applet pointer in the rule. */
2402 rule->applet = promex_applet;
2403
2404 return ACT_RET_PRS_OK;
2405}
2406static void promex_register_build_options(void)
2407{
2408 char *ptr = NULL;
2409
2410 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2411 hap_register_build_opts(ptr, 1);
2412}
2413
2414
2415static struct action_kw_list service_actions = { ILH, {
2416 { "prometheus-exporter", service_parse_prometheus_exporter },
2417 { /* END */ }
2418}};
2419
2420INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2421INITCALL0(STG_REGISTER, promex_register_build_options);