blob: 790b2f88e38e59e6ed28fe0ace8a442c33865842 [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,
102 [INF_UPTIME_SEC] = INF_MEMMAX_MB,
103 [INF_MEMMAX_MB] = INF_POOL_ALLOC_MB,
104 [INF_POOL_ALLOC_MB] = INF_POOL_USED_MB,
105 [INF_POOL_USED_MB] = INF_POOL_FAILED,
106 [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"),
485 [INF_MEMMAX_MB] = IST("max_memory_bytes"),
486 [INF_POOL_ALLOC_MB] = IST("pool_allocated_bytes"),
487 [INF_POOL_USED_MB] = 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."),
658 [INF_MEMMAX_MB] = IST("Per-process memory limit (in bytes); 0=unset."),
659 [INF_POOL_ALLOC_MB] = IST("Total amount of memory allocated in pools (in bytes)."),
660 [INF_POOL_USED_MB] = 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(""),
831 [INF_MEMMAX_MB] = IST(""),
832 [INF_POOL_ALLOC_MB] = IST(""),
833 [INF_POOL_USED_MB] = IST(""),
834 [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"),
997 [INF_MEMMAX_MB] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100998 [INF_POOL_ALLOC_MB] = IST("gauge"),
999 [INF_POOL_USED_MB] = IST("gauge"),
1000 [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;
1339 case INF_MEMMAX_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001340 metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
Christopher Fauletf959d082019-02-07 15:38:42 +01001341 break;
1342 case INF_POOL_ALLOC_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001343 metric = mkf_u64(0, pool_total_allocated());
Christopher Fauletf959d082019-02-07 15:38:42 +01001344 break;
1345 case INF_POOL_USED_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001346 metric = mkf_u64(0, pool_total_used());
Christopher Fauletf959d082019-02-07 15:38:42 +01001347 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001348
1349 default:
William Dauchy5d9b8f32021-01-11 20:07:49 +01001350 metric = info[appctx->st2];
Christopher Fauletf959d082019-02-07 15:38:42 +01001351 }
1352
1353 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1354 goto full;
1355
Christopher Fauletf959d082019-02-07 15:38:42 +01001356 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1357 appctx->st2 = promex_global_metrics[appctx->st2];
1358 }
1359
1360 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001361 if (out.len) {
1362 if (!htx_add_data_atonce(htx, out))
1363 return -1; /* Unexpected and unrecoverable error */
1364 channel_add_input(chn, out.len);
1365 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001366 return ret;
1367 full:
1368 ret = 0;
1369 goto end;
1370}
1371
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001372/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001373 * 0 if <htx> is full and -1 in case of any error. */
1374static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1375{
1376 static struct ist prefix = IST("haproxy_frontend_");
1377 struct proxy *px;
1378 struct field metric;
1379 struct channel *chn = si_ic(appctx->owner);
1380 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001381 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001382 int ret = 1;
1383
1384 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001385 while (appctx->ctx.stats.obj1) {
1386 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001387
1388 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001389 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001390 goto next_px;
1391
1392 switch (appctx->st2) {
1393 case ST_F_STATUS:
Willy Tarreauc3914d42020-09-24 08:39:22 +02001394 metric = mkf_u32(FO_STATUS, !px->disabled);
Christopher Fauletf959d082019-02-07 15:38:42 +01001395 break;
1396 case ST_F_SCUR:
1397 metric = mkf_u32(0, px->feconn);
1398 break;
1399 case ST_F_SMAX:
1400 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1401 break;
1402 case ST_F_SLIM:
1403 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1404 break;
1405 case ST_F_STOT:
1406 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1407 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001408 case ST_F_RATE_LIM:
1409 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1410 break;
1411 case ST_F_RATE_MAX:
1412 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1413 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001414 case ST_F_CONN_RATE_MAX:
1415 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1416 break;
1417 case ST_F_CONN_TOT:
1418 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1419 break;
1420 case ST_F_BIN:
1421 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1422 break;
1423 case ST_F_BOUT:
1424 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1425 break;
1426 case ST_F_DREQ:
1427 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1428 break;
1429 case ST_F_DRESP:
1430 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1431 break;
1432 case ST_F_EREQ:
1433 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1434 break;
1435 case ST_F_DCON:
1436 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1437 break;
1438 case ST_F_DSES:
1439 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1440 break;
1441 case ST_F_WREW:
1442 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1443 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001444 case ST_F_EINT:
1445 metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors);
1446 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001447 case ST_F_REQ_RATE_MAX:
1448 if (px->mode != PR_MODE_HTTP)
1449 goto next_px;
1450 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1451 break;
1452 case ST_F_REQ_TOT:
1453 if (px->mode != PR_MODE_HTTP)
1454 goto next_px;
1455 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1456 break;
1457 case ST_F_HRSP_1XX:
1458 if (px->mode != PR_MODE_HTTP)
1459 goto next_px;
1460 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1461 break;
1462 case ST_F_HRSP_2XX:
1463 if (px->mode != PR_MODE_HTTP)
1464 goto next_px;
1465 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1466 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1467 break;
1468 case ST_F_HRSP_3XX:
1469 if (px->mode != PR_MODE_HTTP)
1470 goto next_px;
1471 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1472 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1473 break;
1474 case ST_F_HRSP_4XX:
1475 if (px->mode != PR_MODE_HTTP)
1476 goto next_px;
1477 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1478 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1479 break;
1480 case ST_F_HRSP_5XX:
1481 if (px->mode != PR_MODE_HTTP)
1482 goto next_px;
1483 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1484 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1485 break;
1486 case ST_F_HRSP_OTHER:
1487 if (px->mode != PR_MODE_HTTP)
1488 goto next_px;
1489 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1490 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1491 break;
1492 case ST_F_INTERCEPTED:
1493 if (px->mode != PR_MODE_HTTP)
1494 goto next_px;
1495 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1496 break;
1497 case ST_F_CACHE_LOOKUPS:
1498 if (px->mode != PR_MODE_HTTP)
1499 goto next_px;
1500 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1501 break;
1502 case ST_F_CACHE_HITS:
1503 if (px->mode != PR_MODE_HTTP)
1504 goto next_px;
1505 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1506 break;
1507 case ST_F_COMP_IN:
1508 if (px->mode != PR_MODE_HTTP)
1509 goto next_px;
1510 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1511 break;
1512 case ST_F_COMP_OUT:
1513 if (px->mode != PR_MODE_HTTP)
1514 goto next_px;
1515 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1516 break;
1517 case ST_F_COMP_BYP:
1518 if (px->mode != PR_MODE_HTTP)
1519 goto next_px;
1520 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1521 break;
1522 case ST_F_COMP_RSP:
1523 if (px->mode != PR_MODE_HTTP)
1524 goto next_px;
1525 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1526 break;
1527
1528 default:
1529 goto next_metric;
1530 }
1531
1532 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1533 goto full;
1534 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001535 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001536 }
1537 next_metric:
1538 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001539 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001540 appctx->st2 = promex_front_metrics[appctx->st2];
1541 }
1542
1543 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001544 if (out.len) {
1545 if (!htx_add_data_atonce(htx, out))
1546 return -1; /* Unexpected and unrecoverable error */
1547 channel_add_input(chn, out.len);
1548 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001549 return ret;
1550 full:
1551 ret = 0;
1552 goto end;
1553}
1554
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001555/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001556 * 0 if <htx> is full and -1 in case of any error. */
1557static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1558{
1559 static struct ist prefix = IST("haproxy_backend_");
1560 struct proxy *px;
1561 struct field metric;
1562 struct channel *chn = si_ic(appctx->owner);
1563 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001564 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001565 int ret = 1;
1566 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001567 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001568
1569 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001570 while (appctx->ctx.stats.obj1) {
1571 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001572
1573 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001574 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001575 goto next_px;
1576
1577 switch (appctx->st2) {
1578 case ST_F_STATUS:
1579 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1580 break;
1581 case ST_F_SCUR:
1582 metric = mkf_u32(0, px->beconn);
1583 break;
1584 case ST_F_SMAX:
1585 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1586 break;
1587 case ST_F_SLIM:
1588 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1589 break;
1590 case ST_F_STOT:
1591 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1592 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001593 case ST_F_RATE_MAX:
1594 metric = mkf_u32(0, px->be_counters.sps_max);
1595 break;
1596 case ST_F_LASTSESS:
1597 metric = mkf_s32(FN_AGE, be_lastsession(px));
1598 break;
1599 case ST_F_QCUR:
1600 metric = mkf_u32(0, px->nbpend);
1601 break;
1602 case ST_F_QMAX:
1603 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1604 break;
1605 case ST_F_CONNECT:
1606 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1607 break;
1608 case ST_F_REUSE:
1609 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1610 break;
1611 case ST_F_BIN:
1612 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1613 break;
1614 case ST_F_BOUT:
1615 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1616 break;
1617 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001618 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1619 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001620 break;
1621 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001622 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1623 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001624 break;
1625 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001626 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1627 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001628 break;
1629 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001630 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1631 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001632 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001633 case ST_F_QT_MAX:
1634 secs = (double)px->be_counters.qtime_max / 1000.0;
1635 metric = mkf_flt(FN_MAX, secs);
1636 break;
1637 case ST_F_CT_MAX:
1638 secs = (double)px->be_counters.ctime_max / 1000.0;
1639 metric = mkf_flt(FN_MAX, secs);
1640 break;
1641 case ST_F_RT_MAX:
1642 secs = (double)px->be_counters.dtime_max / 1000.0;
1643 metric = mkf_flt(FN_MAX, secs);
1644 break;
1645 case ST_F_TT_MAX:
1646 secs = (double)px->be_counters.ttime_max / 1000.0;
1647 metric = mkf_flt(FN_MAX, secs);
1648 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001649 case ST_F_DREQ:
1650 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1651 break;
1652 case ST_F_DRESP:
1653 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1654 break;
1655 case ST_F_ECON:
1656 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1657 break;
1658 case ST_F_ERESP:
1659 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1660 break;
1661 case ST_F_WRETR:
1662 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1663 break;
1664 case ST_F_WREDIS:
1665 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1666 break;
1667 case ST_F_WREW:
1668 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1669 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001670 case ST_F_EINT:
1671 metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors);
1672 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001673 case ST_F_CLI_ABRT:
1674 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1675 break;
1676 case ST_F_SRV_ABRT:
1677 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1678 break;
1679 case ST_F_WEIGHT:
1680 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1681 metric = mkf_u32(FN_AVG, weight);
1682 break;
1683 case ST_F_ACT:
1684 metric = mkf_u32(0, px->srv_act);
1685 break;
1686 case ST_F_BCK:
1687 metric = mkf_u32(0, px->srv_bck);
1688 break;
1689 case ST_F_CHKDOWN:
1690 metric = mkf_u64(FN_COUNTER, px->down_trans);
1691 break;
1692 case ST_F_LASTCHG:
1693 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1694 break;
1695 case ST_F_DOWNTIME:
1696 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1697 break;
1698 case ST_F_LBTOT:
1699 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1700 break;
1701 case ST_F_REQ_TOT:
1702 if (px->mode != PR_MODE_HTTP)
1703 goto next_px;
1704 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1705 break;
1706 case ST_F_HRSP_1XX:
1707 if (px->mode != PR_MODE_HTTP)
1708 goto next_px;
1709 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1710 break;
1711 case ST_F_HRSP_2XX:
1712 if (px->mode != PR_MODE_HTTP)
1713 goto next_px;
1714 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1715 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1716 break;
1717 case ST_F_HRSP_3XX:
1718 if (px->mode != PR_MODE_HTTP)
1719 goto next_px;
1720 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1721 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1722 break;
1723 case ST_F_HRSP_4XX:
1724 if (px->mode != PR_MODE_HTTP)
1725 goto next_px;
1726 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1727 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1728 break;
1729 case ST_F_HRSP_5XX:
1730 if (px->mode != PR_MODE_HTTP)
1731 goto next_px;
1732 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1733 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1734 break;
1735 case ST_F_HRSP_OTHER:
1736 if (px->mode != PR_MODE_HTTP)
1737 goto next_px;
1738 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1739 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1740 break;
1741 case ST_F_CACHE_LOOKUPS:
1742 if (px->mode != PR_MODE_HTTP)
1743 goto next_px;
1744 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1745 break;
1746 case ST_F_CACHE_HITS:
1747 if (px->mode != PR_MODE_HTTP)
1748 goto next_px;
1749 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1750 break;
1751 case ST_F_COMP_IN:
1752 if (px->mode != PR_MODE_HTTP)
1753 goto next_px;
1754 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1755 break;
1756 case ST_F_COMP_OUT:
1757 if (px->mode != PR_MODE_HTTP)
1758 goto next_px;
1759 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1760 break;
1761 case ST_F_COMP_BYP:
1762 if (px->mode != PR_MODE_HTTP)
1763 goto next_px;
1764 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1765 break;
1766 case ST_F_COMP_RSP:
1767 if (px->mode != PR_MODE_HTTP)
1768 goto next_px;
1769 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1770 break;
1771
1772 default:
1773 goto next_metric;
1774 }
1775
1776 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1777 goto full;
1778 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001779 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001780 }
1781 next_metric:
1782 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001783 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001784 appctx->st2 = promex_back_metrics[appctx->st2];
1785 }
1786
1787 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001788 if (out.len) {
1789 if (!htx_add_data_atonce(htx, out))
1790 return -1; /* Unexpected and unrecoverable error */
1791 channel_add_input(chn, out.len);
1792 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001793 return ret;
1794 full:
1795 ret = 0;
1796 goto end;
1797}
1798
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001799/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001800 * 0 if <htx> is full and -1 in case of any error. */
1801static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1802{
1803 static struct ist prefix = IST("haproxy_server_");
1804 struct proxy *px;
1805 struct server *sv;
1806 struct field metric;
1807 struct channel *chn = si_ic(appctx->owner);
1808 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001809 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001810 int ret = 1;
1811 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001812 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001813
1814 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001815 while (appctx->ctx.stats.obj1) {
1816 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001817
1818 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001819 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001820 goto next_px;
1821
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001822 while (appctx->ctx.stats.obj2) {
1823 sv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001824
Christopher Fauleteba22942019-11-19 14:18:24 +01001825 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1826 goto next_sv;
1827
Christopher Fauletf959d082019-02-07 15:38:42 +01001828 switch (appctx->st2) {
1829 case ST_F_STATUS:
1830 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1831 break;
1832 case ST_F_SCUR:
1833 metric = mkf_u32(0, sv->cur_sess);
1834 break;
1835 case ST_F_SMAX:
1836 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1837 break;
1838 case ST_F_SLIM:
1839 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1840 break;
1841 case ST_F_STOT:
1842 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1843 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001844 case ST_F_RATE_MAX:
1845 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1846 break;
1847 case ST_F_LASTSESS:
1848 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1849 break;
1850 case ST_F_QCUR:
1851 metric = mkf_u32(0, sv->nbpend);
1852 break;
1853 case ST_F_QMAX:
1854 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1855 break;
1856 case ST_F_QLIMIT:
1857 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1858 break;
1859 case ST_F_BIN:
1860 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1861 break;
1862 case ST_F_BOUT:
1863 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1864 break;
1865 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001866 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1867 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001868 break;
1869 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001870 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1871 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001872 break;
1873 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001874 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1875 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001876 break;
1877 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001878 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1879 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001880 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001881 case ST_F_QT_MAX:
1882 secs = (double)sv->counters.qtime_max / 1000.0;
1883 metric = mkf_flt(FN_MAX, secs);
1884 break;
1885 case ST_F_CT_MAX:
1886 secs = (double)sv->counters.ctime_max / 1000.0;
1887 metric = mkf_flt(FN_MAX, secs);
1888 break;
1889 case ST_F_RT_MAX:
1890 secs = (double)sv->counters.dtime_max / 1000.0;
1891 metric = mkf_flt(FN_MAX, secs);
1892 break;
1893 case ST_F_TT_MAX:
1894 secs = (double)sv->counters.ttime_max / 1000.0;
1895 metric = mkf_flt(FN_MAX, secs);
1896 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001897 case ST_F_CONNECT:
1898 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1899 break;
1900 case ST_F_REUSE:
1901 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1902 break;
1903 case ST_F_DRESP:
Christopher Fauleta08546b2019-12-16 16:07:34 +01001904 metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp);
Christopher Fauletf959d082019-02-07 15:38:42 +01001905 break;
1906 case ST_F_ECON:
1907 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1908 break;
1909 case ST_F_ERESP:
1910 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1911 break;
1912 case ST_F_WRETR:
1913 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
1914 break;
1915 case ST_F_WREDIS:
1916 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
1917 break;
1918 case ST_F_WREW:
1919 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
1920 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001921 case ST_F_EINT:
1922 metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors);
1923 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001924 case ST_F_CLI_ABRT:
1925 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1926 break;
1927 case ST_F_SRV_ABRT:
1928 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1929 break;
1930 case ST_F_WEIGHT:
1931 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1932 metric = mkf_u32(FN_AVG, weight);
1933 break;
Christopher Fauletcf403f32019-11-21 14:35:46 +01001934 case ST_F_CHECK_STATUS:
1935 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1936 goto next_sv;
1937 metric = mkf_u32(FN_OUTPUT, sv->check.status);
1938 break;
1939 case ST_F_CHECK_CODE:
1940 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1941 goto next_sv;
1942 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
1943 break;
Christopher Faulet2711e512020-02-27 16:12:07 +01001944 case ST_F_CHECK_DURATION:
1945 if (sv->check.status < HCHK_STATUS_CHECKED)
1946 goto next_sv;
1947 secs = (double)sv->check.duration / 1000.0;
1948 metric = mkf_flt(FN_DURATION, secs);
1949 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001950 case ST_F_CHKFAIL:
1951 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1952 break;
1953 case ST_F_CHKDOWN:
1954 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1955 break;
1956 case ST_F_DOWNTIME:
1957 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
1958 break;
1959 case ST_F_LASTCHG:
1960 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
1961 break;
1962 case ST_F_THROTTLE:
1963 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
1964 break;
1965 case ST_F_LBTOT:
1966 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1967 break;
Marcin Deranek3c27dda2020-05-15 18:32:51 +02001968 case ST_F_REQ_TOT:
1969 if (px->mode != PR_MODE_HTTP)
1970 goto next_px;
1971 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
1972 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001973 case ST_F_HRSP_1XX:
1974 if (px->mode != PR_MODE_HTTP)
1975 goto next_px;
1976 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1977 break;
1978 case ST_F_HRSP_2XX:
1979 if (px->mode != PR_MODE_HTTP)
1980 goto next_px;
1981 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1982 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1983 break;
1984 case ST_F_HRSP_3XX:
1985 if (px->mode != PR_MODE_HTTP)
1986 goto next_px;
1987 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1988 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1989 break;
1990 case ST_F_HRSP_4XX:
1991 if (px->mode != PR_MODE_HTTP)
1992 goto next_px;
1993 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1994 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1995 break;
1996 case ST_F_HRSP_5XX:
1997 if (px->mode != PR_MODE_HTTP)
1998 goto next_px;
1999 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2000 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
2001 break;
2002 case ST_F_HRSP_OTHER:
2003 if (px->mode != PR_MODE_HTTP)
2004 goto next_px;
2005 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2006 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
2007 break;
Christopher Faulet20ab80c2019-11-08 15:24:32 +01002008 case ST_F_SRV_ICUR:
2009 metric = mkf_u32(0, sv->curr_idle_conns);
2010 break;
2011 case ST_F_SRV_ILIM:
2012 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2013 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02002014 case ST_F_IDLE_CONN_CUR:
2015 metric = mkf_u32(0, sv->curr_idle_nb);
2016 break;
2017 case ST_F_SAFE_CONN_CUR:
2018 metric = mkf_u32(0, sv->curr_safe_nb);
2019 break;
2020 case ST_F_USED_CONN_CUR:
2021 metric = mkf_u32(0, sv->curr_used_conns);
2022 break;
2023 case ST_F_NEED_CONN_EST:
2024 metric = mkf_u32(0, sv->est_need_conns);
2025 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002026
2027 default:
2028 goto next_metric;
2029 }
2030
2031 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2032 goto full;
2033
Christopher Fauleteba22942019-11-19 14:18:24 +01002034 next_sv:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002035 appctx->ctx.stats.obj2 = sv->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01002036 }
2037
2038 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002039 appctx->ctx.stats.obj1 = px->next;
2040 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002041 }
2042 next_metric:
2043 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002044 appctx->ctx.stats.obj1 = proxies_list;
2045 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002046 appctx->st2 = promex_srv_metrics[appctx->st2];
2047 }
2048
2049
2050 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02002051 if (out.len) {
2052 if (!htx_add_data_atonce(htx, out))
2053 return -1; /* Unexpected and unrecoverable error */
2054 channel_add_input(chn, out.len);
2055 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002056 return ret;
2057 full:
2058 ret = 0;
2059 goto end;
2060}
2061
2062/* Dump all metrics (global, frontends, backends and servers) depending on the
2063 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002064 * -1 in case of any error.
2065 * Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as
2066 * a pointer to the current server/listener. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002067static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2068{
2069 int ret;
2070
2071 switch (appctx->st1) {
2072 case PROMEX_DUMPER_INIT:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002073 appctx->ctx.stats.obj1 = NULL;
2074 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002075 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002076 appctx->st2 = promex_global_metrics[INF_NAME];
2077 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2078 /* fall through */
2079
2080 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002081 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2082 ret = promex_dump_global_metrics(appctx, htx);
2083 if (ret <= 0) {
2084 if (ret == -1)
2085 goto error;
2086 goto full;
2087 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002088 }
2089
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002090 appctx->ctx.stats.obj1 = proxies_list;
2091 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002092 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
2093 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002094 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2095 appctx->st1 = PROMEX_DUMPER_FRONT;
2096 /* fall through */
2097
2098 case PROMEX_DUMPER_FRONT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002099 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2100 ret = promex_dump_front_metrics(appctx, htx);
2101 if (ret <= 0) {
2102 if (ret == -1)
2103 goto error;
2104 goto full;
2105 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002106 }
2107
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002108 appctx->ctx.stats.obj1 = proxies_list;
2109 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002110 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002111 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2112 appctx->st1 = PROMEX_DUMPER_BACK;
2113 /* fall through */
2114
2115 case PROMEX_DUMPER_BACK:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002116 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2117 ret = promex_dump_back_metrics(appctx, htx);
2118 if (ret <= 0) {
2119 if (ret == -1)
2120 goto error;
2121 goto full;
2122 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002123 }
2124
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002125 appctx->ctx.stats.obj1 = proxies_list;
2126 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletefde9552020-06-05 08:18:56 +02002127 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002128 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2129 appctx->st1 = PROMEX_DUMPER_SRV;
2130 /* fall through */
2131
2132 case PROMEX_DUMPER_SRV:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002133 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2134 ret = promex_dump_srv_metrics(appctx, htx);
2135 if (ret <= 0) {
2136 if (ret == -1)
2137 goto error;
2138 goto full;
2139 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002140 }
2141
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002142 appctx->ctx.stats.obj1 = NULL;
2143 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002144 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002145 appctx->st2 = 0;
2146 appctx->st1 = PROMEX_DUMPER_DONE;
2147 /* fall through */
2148
2149 case PROMEX_DUMPER_DONE:
2150 default:
2151 break;
2152 }
2153
2154 return 1;
2155
2156 full:
2157 si_rx_room_blk(si);
2158 return 0;
2159 error:
2160 /* unrecoverable error */
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002161 appctx->ctx.stats.obj1 = NULL;
2162 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletf959d082019-02-07 15:38:42 +01002163 appctx->ctx.stats.flags = 0;
2164 appctx->st2 = 0;
2165 appctx->st1 = PROMEX_DUMPER_DONE;
2166 return -1;
2167}
2168
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002169/* Parse the query string of request URI to filter the metrics. It returns 1 on
Christopher Faulet78407ce2019-11-18 14:47:08 +01002170 * success and -1 on error. */
2171static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2172{
2173 struct channel *req = si_oc(si);
2174 struct channel *res = si_ic(si);
2175 struct htx *req_htx, *res_htx;
2176 struct htx_sl *sl;
William Dauchyc65f6562019-11-26 12:56:26 +01002177 char *p, *key, *value;
2178 const char *end;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002179 struct buffer *err;
2180 int default_scopes = PROMEX_FL_SCOPE_ALL;
2181 int len;
2182
2183 /* Get the query-string */
2184 req_htx = htxbuf(&req->buf);
2185 sl = http_get_stline(req_htx);
2186 if (!sl)
2187 goto error;
2188 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2189 if (!p)
2190 goto end;
2191 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet78407ce2019-11-18 14:47:08 +01002192
William Dauchyc65f6562019-11-26 12:56:26 +01002193 /* copy the query-string */
2194 len = end - p;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002195 chunk_reset(&trash);
2196 memcpy(trash.area, p, len);
2197 trash.area[len] = 0;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002198 p = trash.area;
William Dauchyc65f6562019-11-26 12:56:26 +01002199 end = trash.area + len;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002200
2201 /* Parse the query-string */
William Dauchyc65f6562019-11-26 12:56:26 +01002202 while (p < end && *p && *p != '#') {
2203 value = NULL;
2204
2205 /* decode parameter name */
2206 key = p;
2207 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002208 ++p;
William Dauchyc65f6562019-11-26 12:56:26 +01002209 /* found a value */
2210 if (*p == '=') {
2211 *(p++) = 0;
2212 value = p;
2213 }
2214 else if (*p == '&')
2215 *(p++) = 0;
2216 else if (*p == '#')
2217 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002218 len = url_decode(key, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002219 if (len == -1)
2220 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002221
William Dauchyc65f6562019-11-26 12:56:26 +01002222 /* decode value */
2223 if (value) {
2224 while (p < end && *p != '=' && *p != '&' && *p != '#')
2225 ++p;
2226 if (*p == '=')
2227 goto error;
2228 if (*p == '&')
2229 *(p++) = 0;
2230 else if (*p == '#')
2231 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002232 len = url_decode(value, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002233 if (len == -1)
2234 goto error;
2235 }
2236
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002237 if (strcmp(key, "scope") == 0) {
William Dauchyc65f6562019-11-26 12:56:26 +01002238 default_scopes = 0; /* at least a scope defined, unset default scopes */
2239 if (!value)
2240 goto error;
2241 else if (*value == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002242 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002243 else if (*value == '*')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002244 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002245 else if (strcmp(value, "global") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002246 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002247 else if (strcmp(value, "server") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002248 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002249 else if (strcmp(value, "backend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002250 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002251 else if (strcmp(value, "frontend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002252 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2253 else
2254 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002255 }
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002256 else if (strcmp(key, "no-maint") == 0)
Christopher Fauleteba22942019-11-19 14:18:24 +01002257 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002258 }
2259
2260 end:
2261 appctx->ctx.stats.flags |= default_scopes;
2262 return 1;
2263
2264 error:
2265 err = &http_err_chunks[HTTP_ERR_400];
2266 channel_erase(res);
2267 res->buf.data = b_data(err);
2268 memcpy(res->buf.area, b_head(err), b_data(err));
2269 res_htx = htx_from_buf(&res->buf);
2270 channel_add_input(res, res_htx->data);
2271 appctx->st0 = PROMEX_ST_END;
2272 return -1;
2273}
2274
Christopher Fauletf959d082019-02-07 15:38:42 +01002275/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2276 * full. */
2277static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2278{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002279 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002280 struct htx_sl *sl;
2281 unsigned int flags;
2282
2283 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);
2284 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2285 if (!sl)
2286 goto full;
2287 sl->info.res.status = 200;
2288 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
Christopher Fauletf959d082019-02-07 15:38:42 +01002289 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2290 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2291 !htx_add_endof(htx, HTX_BLK_EOH))
2292 goto full;
2293
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002294 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002295 return 1;
2296 full:
2297 htx_reset(htx);
2298 si_rx_room_blk(si);
2299 return 0;
2300}
2301
2302/* The function returns 1 if the initialisation is complete, 0 if
2303 * an errors occurs and -1 if more data are required for initializing
2304 * the applet.
2305 */
2306static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2307{
2308 appctx->st0 = PROMEX_ST_INIT;
2309 return 1;
2310}
2311
2312/* The main I/O handler for the promex applet. */
2313static void promex_appctx_handle_io(struct appctx *appctx)
2314{
2315 struct stream_interface *si = appctx->owner;
2316 struct stream *s = si_strm(si);
2317 struct channel *req = si_oc(si);
2318 struct channel *res = si_ic(si);
2319 struct htx *req_htx, *res_htx;
2320 int ret;
2321
2322 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002323 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2324 goto out;
2325
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002326 /* Check if the input buffer is available. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002327 if (!b_size(&res->buf)) {
2328 si_rx_room_blk(si);
2329 goto out;
2330 }
2331
2332 switch (appctx->st0) {
2333 case PROMEX_ST_INIT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002334 ret = promex_parse_uri(appctx, si);
2335 if (ret <= 0) {
2336 if (ret == -1)
2337 goto error;
2338 goto out;
2339 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002340 appctx->st0 = PROMEX_ST_HEAD;
2341 appctx->st1 = PROMEX_DUMPER_INIT;
2342 /* fall through */
2343
2344 case PROMEX_ST_HEAD:
2345 if (!promex_send_headers(appctx, si, res_htx))
2346 goto out;
2347 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2348 /* fall through */
2349
2350 case PROMEX_ST_DUMP:
2351 ret = promex_dump_metrics(appctx, si, res_htx);
2352 if (ret <= 0) {
2353 if (ret == -1)
2354 goto error;
2355 goto out;
2356 }
2357 appctx->st0 = PROMEX_ST_DONE;
2358 /* fall through */
2359
2360 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002361 /* Don't add TLR because mux-h1 will take care of it */
Willy Tarreauf1ea47d2020-07-23 06:53:27 +02002362 res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
Christopher Fauletf959d082019-02-07 15:38:42 +01002363 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2364 si_rx_room_blk(si);
2365 goto out;
2366 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002367 channel_add_input(res, 1);
2368 appctx->st0 = PROMEX_ST_END;
2369 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002370
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002371 case PROMEX_ST_END:
2372 if (!(res->flags & CF_SHUTR)) {
2373 res->flags |= CF_READ_NULL;
2374 si_shutr(si);
2375 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002376 }
2377
Christopher Fauletf959d082019-02-07 15:38:42 +01002378 out:
2379 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002380
2381 /* eat the whole request */
2382 if (co_data(req)) {
2383 req_htx = htx_from_buf(&req->buf);
2384 co_htx_skip(req, req_htx, co_data(req));
2385 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002386 return;
2387
2388 error:
2389 res->flags |= CF_READ_NULL;
2390 si_shutr(si);
2391 si_shutw(si);
2392}
2393
2394struct applet promex_applet = {
2395 .obj_type = OBJ_TYPE_APPLET,
2396 .name = "<PROMEX>", /* used for logging */
2397 .init = promex_appctx_init,
2398 .fct = promex_appctx_handle_io,
2399};
2400
2401static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2402 struct act_rule *rule, char **err)
2403{
2404 /* Prometheus exporter service is only available on "http-request" rulesets */
2405 if (rule->from != ACT_F_HTTP_REQ) {
2406 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2407 return ACT_RET_PRS_ERR;
2408 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002409
2410 /* Add applet pointer in the rule. */
2411 rule->applet = promex_applet;
2412
2413 return ACT_RET_PRS_OK;
2414}
2415static void promex_register_build_options(void)
2416{
2417 char *ptr = NULL;
2418
2419 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2420 hap_register_build_opts(ptr, 1);
2421}
2422
2423
2424static struct action_kw_list service_actions = { ILH, {
2425 { "prometheus-exporter", service_parse_prometheus_exporter },
2426 { /* END */ }
2427}};
2428
2429INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2430INITCALL0(STG_REGISTER, promex_register_build_options);