blob: beca87959de7d209c3d6457fd2af8cda7a21c3b3 [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
1328#ifdef USE_OPENSSL
1329 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
1330 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
1331 int ssl_reuse = 0;
1332
1333 if (ssl_key_rate < ssl_sess_rate) {
1334 /* count the ssl reuse ratio and avoid overflows in both directions */
1335 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
1336 }
1337#endif
Christopher Fauletf959d082019-02-07 15:38:42 +01001338 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1339 switch (appctx->st2) {
William Dauchy5a982a72021-01-08 13:18:06 +01001340 case INF_BUILD_INFO:
1341 metric = mkf_u32(FN_GAUGE, 1);
1342 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001343 case INF_NBTHREAD:
1344 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
1345 break;
1346 case INF_NBPROC:
1347 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
1348 break;
1349 case INF_PROCESS_NUM:
1350 metric = mkf_u32(FO_KEY, relative_pid);
1351 break;
1352 case INF_UPTIME_SEC:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001353 metric = mkf_u32(FN_DURATION, start_date.tv_sec);
Christopher Fauletf959d082019-02-07 15:38:42 +01001354 break;
1355 case INF_MEMMAX_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001356 metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
Christopher Fauletf959d082019-02-07 15:38:42 +01001357 break;
1358 case INF_POOL_ALLOC_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001359 metric = mkf_u64(0, pool_total_allocated());
Christopher Fauletf959d082019-02-07 15:38:42 +01001360 break;
1361 case INF_POOL_USED_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001362 metric = mkf_u64(0, pool_total_used());
Christopher Fauletf959d082019-02-07 15:38:42 +01001363 break;
1364 case INF_POOL_FAILED:
1365 metric = mkf_u32(FN_COUNTER, pool_total_failures());
1366 break;
1367 case INF_ULIMIT_N:
1368 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
1369 break;
1370 case INF_MAXSOCK:
1371 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
1372 break;
1373 case INF_MAXCONN:
1374 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
1375 break;
1376 case INF_HARD_MAXCONN:
1377 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
1378 break;
1379 case INF_CURR_CONN:
1380 metric = mkf_u32(0, actconn);
1381 break;
1382 case INF_CUM_CONN:
1383 metric = mkf_u32(FN_COUNTER, totalconn);
1384 break;
1385 case INF_CUM_REQ:
1386 metric = mkf_u32(FN_COUNTER, global.req_count);
1387 break;
1388#ifdef USE_OPENSSL
1389 case INF_MAX_SSL_CONNS:
1390 metric = mkf_u32(FN_MAX, global.maxsslconn);
1391 break;
1392 case INF_CURR_SSL_CONNS:
1393 metric = mkf_u32(0, sslconns);
1394 break;
1395 case INF_CUM_SSL_CONNS:
1396 metric = mkf_u32(FN_COUNTER, totalsslconns);
1397 break;
1398#endif
1399 case INF_MAXPIPES:
1400 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
1401 break;
1402 case INF_PIPES_USED:
1403 metric = mkf_u32(0, pipes_used);
1404 break;
1405 case INF_PIPES_FREE:
1406 metric = mkf_u32(0, pipes_free);
1407 break;
1408 case INF_CONN_RATE:
1409 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
1410 break;
1411 case INF_CONN_RATE_LIMIT:
1412 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
1413 break;
1414 case INF_MAX_CONN_RATE:
1415 metric = mkf_u32(FN_MAX, global.cps_max);
1416 break;
1417 case INF_SESS_RATE:
1418 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
1419 break;
1420 case INF_SESS_RATE_LIMIT:
1421 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
1422 break;
1423 case INF_MAX_SESS_RATE:
1424 metric = mkf_u32(FN_RATE, global.sps_max);
1425 break;
1426#ifdef USE_OPENSSL
1427 case INF_SSL_RATE:
1428 metric = mkf_u32(FN_RATE, ssl_sess_rate);
1429 break;
1430 case INF_SSL_RATE_LIMIT:
1431 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
1432 break;
1433 case INF_MAX_SSL_RATE:
1434 metric = mkf_u32(FN_MAX, global.ssl_max);
1435 break;
1436 case INF_SSL_FRONTEND_KEY_RATE:
1437 metric = mkf_u32(0, ssl_key_rate);
1438 break;
1439 case INF_SSL_FRONTEND_MAX_KEY_RATE:
1440 metric = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
1441 break;
1442 case INF_SSL_FRONTEND_SESSION_REUSE_PCT:
1443 metric = mkf_u32(0, ssl_reuse);
1444 break;
1445 case INF_SSL_BACKEND_KEY_RATE:
1446 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
1447 break;
1448 case INF_SSL_BACKEND_MAX_KEY_RATE:
1449 metric = mkf_u32(FN_MAX, global.ssl_be_keys_max);
1450 break;
1451 case INF_SSL_CACHE_LOOKUPS:
1452 metric = mkf_u32(FN_COUNTER, global.shctx_lookups);
1453 break;
1454 case INF_SSL_CACHE_MISSES:
1455 metric = mkf_u32(FN_COUNTER, global.shctx_misses);
1456 break;
1457#endif
1458 case INF_COMPRESS_BPS_IN:
1459 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
1460 break;
1461 case INF_COMPRESS_BPS_OUT:
1462 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
1463 break;
1464 case INF_COMPRESS_BPS_RATE_LIM:
1465 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
1466 break;
1467#ifdef USE_ZLIB
1468 case INF_ZLIB_MEM_USAGE:
1469 metric = mkf_u32(0, zlib_used_memory);
1470 break;
1471 case INF_MAX_ZLIB_MEM_USAGE:
1472 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
1473 break;
1474#endif
1475 case INF_TASKS:
1476 metric = mkf_u32(0, nb_tasks_cur);
1477 break;
1478 case INF_RUN_QUEUE:
1479 metric = mkf_u32(0, tasks_run_queue_cur);
1480 break;
1481 case INF_IDLE_PCT:
Willy Tarreau76824a82019-06-02 10:38:48 +02001482 metric = mkf_u32(FN_AVG, ti->idle_pct);
Christopher Fauletf959d082019-02-07 15:38:42 +01001483 break;
1484 case INF_STOPPING:
1485 metric = mkf_u32(0, stopping);
1486 break;
1487 case INF_JOBS:
1488 metric = mkf_u32(0, jobs);
1489 break;
1490 case INF_UNSTOPPABLE_JOBS:
1491 metric = mkf_u32(0, unstoppable_jobs);
1492 break;
1493 case INF_LISTENERS:
1494 metric = mkf_u32(0, listeners);
1495 break;
1496 case INF_ACTIVE_PEERS:
1497 metric = mkf_u32(0, active_peers);
1498 break;
1499 case INF_CONNECTED_PEERS:
1500 metric = mkf_u32(0, connected_peers);
1501 break;
1502 case INF_DROPPED_LOGS:
1503 metric = mkf_u32(0, dropped_logs);
1504 break;
1505 case INF_BUSY_POLLING:
1506 metric = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
1507 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02001508 case INF_FAILED_RESOLUTIONS:
1509 metric = mkf_u32(0, dns_failed_resolutions);
1510 break;
1511 case INF_TOTAL_BYTES_OUT:
1512 metric = mkf_u64(0, global.out_bytes);
1513 break;
1514 case INF_TOTAL_SPLICED_BYTES_OUT:
1515 metric = mkf_u64(0, global.spliced_out_bytes);
1516 break;
1517 case INF_BYTES_OUT_RATE:
1518 metric = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32);
1519 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001520
1521 default:
1522 goto next_metric;
1523 }
1524
1525 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1526 goto full;
1527
1528 next_metric:
1529 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1530 appctx->st2 = promex_global_metrics[appctx->st2];
1531 }
1532
1533 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001534 if (out.len) {
1535 if (!htx_add_data_atonce(htx, out))
1536 return -1; /* Unexpected and unrecoverable error */
1537 channel_add_input(chn, out.len);
1538 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001539 return ret;
1540 full:
1541 ret = 0;
1542 goto end;
1543}
1544
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001545/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001546 * 0 if <htx> is full and -1 in case of any error. */
1547static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1548{
1549 static struct ist prefix = IST("haproxy_frontend_");
1550 struct proxy *px;
1551 struct field metric;
1552 struct channel *chn = si_ic(appctx->owner);
1553 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001554 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001555 int ret = 1;
1556
1557 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001558 while (appctx->ctx.stats.obj1) {
1559 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001560
1561 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001562 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001563 goto next_px;
1564
1565 switch (appctx->st2) {
1566 case ST_F_STATUS:
Willy Tarreauc3914d42020-09-24 08:39:22 +02001567 metric = mkf_u32(FO_STATUS, !px->disabled);
Christopher Fauletf959d082019-02-07 15:38:42 +01001568 break;
1569 case ST_F_SCUR:
1570 metric = mkf_u32(0, px->feconn);
1571 break;
1572 case ST_F_SMAX:
1573 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1574 break;
1575 case ST_F_SLIM:
1576 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1577 break;
1578 case ST_F_STOT:
1579 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1580 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001581 case ST_F_RATE_LIM:
1582 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1583 break;
1584 case ST_F_RATE_MAX:
1585 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1586 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001587 case ST_F_CONN_RATE_MAX:
1588 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1589 break;
1590 case ST_F_CONN_TOT:
1591 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1592 break;
1593 case ST_F_BIN:
1594 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1595 break;
1596 case ST_F_BOUT:
1597 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1598 break;
1599 case ST_F_DREQ:
1600 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1601 break;
1602 case ST_F_DRESP:
1603 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1604 break;
1605 case ST_F_EREQ:
1606 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1607 break;
1608 case ST_F_DCON:
1609 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1610 break;
1611 case ST_F_DSES:
1612 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1613 break;
1614 case ST_F_WREW:
1615 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1616 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001617 case ST_F_EINT:
1618 metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors);
1619 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001620 case ST_F_REQ_RATE_MAX:
1621 if (px->mode != PR_MODE_HTTP)
1622 goto next_px;
1623 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1624 break;
1625 case ST_F_REQ_TOT:
1626 if (px->mode != PR_MODE_HTTP)
1627 goto next_px;
1628 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1629 break;
1630 case ST_F_HRSP_1XX:
1631 if (px->mode != PR_MODE_HTTP)
1632 goto next_px;
1633 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1634 break;
1635 case ST_F_HRSP_2XX:
1636 if (px->mode != PR_MODE_HTTP)
1637 goto next_px;
1638 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1639 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1640 break;
1641 case ST_F_HRSP_3XX:
1642 if (px->mode != PR_MODE_HTTP)
1643 goto next_px;
1644 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1645 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1646 break;
1647 case ST_F_HRSP_4XX:
1648 if (px->mode != PR_MODE_HTTP)
1649 goto next_px;
1650 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1651 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1652 break;
1653 case ST_F_HRSP_5XX:
1654 if (px->mode != PR_MODE_HTTP)
1655 goto next_px;
1656 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1657 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1658 break;
1659 case ST_F_HRSP_OTHER:
1660 if (px->mode != PR_MODE_HTTP)
1661 goto next_px;
1662 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1663 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1664 break;
1665 case ST_F_INTERCEPTED:
1666 if (px->mode != PR_MODE_HTTP)
1667 goto next_px;
1668 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1669 break;
1670 case ST_F_CACHE_LOOKUPS:
1671 if (px->mode != PR_MODE_HTTP)
1672 goto next_px;
1673 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1674 break;
1675 case ST_F_CACHE_HITS:
1676 if (px->mode != PR_MODE_HTTP)
1677 goto next_px;
1678 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1679 break;
1680 case ST_F_COMP_IN:
1681 if (px->mode != PR_MODE_HTTP)
1682 goto next_px;
1683 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1684 break;
1685 case ST_F_COMP_OUT:
1686 if (px->mode != PR_MODE_HTTP)
1687 goto next_px;
1688 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1689 break;
1690 case ST_F_COMP_BYP:
1691 if (px->mode != PR_MODE_HTTP)
1692 goto next_px;
1693 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1694 break;
1695 case ST_F_COMP_RSP:
1696 if (px->mode != PR_MODE_HTTP)
1697 goto next_px;
1698 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1699 break;
1700
1701 default:
1702 goto next_metric;
1703 }
1704
1705 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1706 goto full;
1707 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001708 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001709 }
1710 next_metric:
1711 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001712 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001713 appctx->st2 = promex_front_metrics[appctx->st2];
1714 }
1715
1716 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001717 if (out.len) {
1718 if (!htx_add_data_atonce(htx, out))
1719 return -1; /* Unexpected and unrecoverable error */
1720 channel_add_input(chn, out.len);
1721 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001722 return ret;
1723 full:
1724 ret = 0;
1725 goto end;
1726}
1727
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001728/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001729 * 0 if <htx> is full and -1 in case of any error. */
1730static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1731{
1732 static struct ist prefix = IST("haproxy_backend_");
1733 struct proxy *px;
1734 struct field metric;
1735 struct channel *chn = si_ic(appctx->owner);
1736 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001737 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001738 int ret = 1;
1739 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001740 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001741
1742 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001743 while (appctx->ctx.stats.obj1) {
1744 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001745
1746 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001747 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001748 goto next_px;
1749
1750 switch (appctx->st2) {
1751 case ST_F_STATUS:
1752 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1753 break;
1754 case ST_F_SCUR:
1755 metric = mkf_u32(0, px->beconn);
1756 break;
1757 case ST_F_SMAX:
1758 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1759 break;
1760 case ST_F_SLIM:
1761 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1762 break;
1763 case ST_F_STOT:
1764 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1765 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001766 case ST_F_RATE_MAX:
1767 metric = mkf_u32(0, px->be_counters.sps_max);
1768 break;
1769 case ST_F_LASTSESS:
1770 metric = mkf_s32(FN_AGE, be_lastsession(px));
1771 break;
1772 case ST_F_QCUR:
1773 metric = mkf_u32(0, px->nbpend);
1774 break;
1775 case ST_F_QMAX:
1776 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1777 break;
1778 case ST_F_CONNECT:
1779 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1780 break;
1781 case ST_F_REUSE:
1782 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1783 break;
1784 case ST_F_BIN:
1785 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1786 break;
1787 case ST_F_BOUT:
1788 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1789 break;
1790 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001791 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1792 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001793 break;
1794 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001795 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1796 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001797 break;
1798 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001799 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1800 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001801 break;
1802 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001803 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1804 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001805 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001806 case ST_F_QT_MAX:
1807 secs = (double)px->be_counters.qtime_max / 1000.0;
1808 metric = mkf_flt(FN_MAX, secs);
1809 break;
1810 case ST_F_CT_MAX:
1811 secs = (double)px->be_counters.ctime_max / 1000.0;
1812 metric = mkf_flt(FN_MAX, secs);
1813 break;
1814 case ST_F_RT_MAX:
1815 secs = (double)px->be_counters.dtime_max / 1000.0;
1816 metric = mkf_flt(FN_MAX, secs);
1817 break;
1818 case ST_F_TT_MAX:
1819 secs = (double)px->be_counters.ttime_max / 1000.0;
1820 metric = mkf_flt(FN_MAX, secs);
1821 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001822 case ST_F_DREQ:
1823 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1824 break;
1825 case ST_F_DRESP:
1826 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1827 break;
1828 case ST_F_ECON:
1829 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1830 break;
1831 case ST_F_ERESP:
1832 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1833 break;
1834 case ST_F_WRETR:
1835 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1836 break;
1837 case ST_F_WREDIS:
1838 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1839 break;
1840 case ST_F_WREW:
1841 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1842 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001843 case ST_F_EINT:
1844 metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors);
1845 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001846 case ST_F_CLI_ABRT:
1847 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1848 break;
1849 case ST_F_SRV_ABRT:
1850 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1851 break;
1852 case ST_F_WEIGHT:
1853 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1854 metric = mkf_u32(FN_AVG, weight);
1855 break;
1856 case ST_F_ACT:
1857 metric = mkf_u32(0, px->srv_act);
1858 break;
1859 case ST_F_BCK:
1860 metric = mkf_u32(0, px->srv_bck);
1861 break;
1862 case ST_F_CHKDOWN:
1863 metric = mkf_u64(FN_COUNTER, px->down_trans);
1864 break;
1865 case ST_F_LASTCHG:
1866 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1867 break;
1868 case ST_F_DOWNTIME:
1869 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1870 break;
1871 case ST_F_LBTOT:
1872 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1873 break;
1874 case ST_F_REQ_TOT:
1875 if (px->mode != PR_MODE_HTTP)
1876 goto next_px;
1877 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1878 break;
1879 case ST_F_HRSP_1XX:
1880 if (px->mode != PR_MODE_HTTP)
1881 goto next_px;
1882 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1883 break;
1884 case ST_F_HRSP_2XX:
1885 if (px->mode != PR_MODE_HTTP)
1886 goto next_px;
1887 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1888 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1889 break;
1890 case ST_F_HRSP_3XX:
1891 if (px->mode != PR_MODE_HTTP)
1892 goto next_px;
1893 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1894 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1895 break;
1896 case ST_F_HRSP_4XX:
1897 if (px->mode != PR_MODE_HTTP)
1898 goto next_px;
1899 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1900 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1901 break;
1902 case ST_F_HRSP_5XX:
1903 if (px->mode != PR_MODE_HTTP)
1904 goto next_px;
1905 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1906 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1907 break;
1908 case ST_F_HRSP_OTHER:
1909 if (px->mode != PR_MODE_HTTP)
1910 goto next_px;
1911 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1912 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1913 break;
1914 case ST_F_CACHE_LOOKUPS:
1915 if (px->mode != PR_MODE_HTTP)
1916 goto next_px;
1917 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1918 break;
1919 case ST_F_CACHE_HITS:
1920 if (px->mode != PR_MODE_HTTP)
1921 goto next_px;
1922 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1923 break;
1924 case ST_F_COMP_IN:
1925 if (px->mode != PR_MODE_HTTP)
1926 goto next_px;
1927 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1928 break;
1929 case ST_F_COMP_OUT:
1930 if (px->mode != PR_MODE_HTTP)
1931 goto next_px;
1932 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1933 break;
1934 case ST_F_COMP_BYP:
1935 if (px->mode != PR_MODE_HTTP)
1936 goto next_px;
1937 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1938 break;
1939 case ST_F_COMP_RSP:
1940 if (px->mode != PR_MODE_HTTP)
1941 goto next_px;
1942 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1943 break;
1944
1945 default:
1946 goto next_metric;
1947 }
1948
1949 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1950 goto full;
1951 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001952 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001953 }
1954 next_metric:
1955 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001956 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001957 appctx->st2 = promex_back_metrics[appctx->st2];
1958 }
1959
1960 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001961 if (out.len) {
1962 if (!htx_add_data_atonce(htx, out))
1963 return -1; /* Unexpected and unrecoverable error */
1964 channel_add_input(chn, out.len);
1965 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001966 return ret;
1967 full:
1968 ret = 0;
1969 goto end;
1970}
1971
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001972/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001973 * 0 if <htx> is full and -1 in case of any error. */
1974static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1975{
1976 static struct ist prefix = IST("haproxy_server_");
1977 struct proxy *px;
1978 struct server *sv;
1979 struct field metric;
1980 struct channel *chn = si_ic(appctx->owner);
1981 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001982 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001983 int ret = 1;
1984 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001985 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001986
1987 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001988 while (appctx->ctx.stats.obj1) {
1989 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001990
1991 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001992 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001993 goto next_px;
1994
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001995 while (appctx->ctx.stats.obj2) {
1996 sv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001997
Christopher Fauleteba22942019-11-19 14:18:24 +01001998 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1999 goto next_sv;
2000
Christopher Fauletf959d082019-02-07 15:38:42 +01002001 switch (appctx->st2) {
2002 case ST_F_STATUS:
2003 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
2004 break;
2005 case ST_F_SCUR:
2006 metric = mkf_u32(0, sv->cur_sess);
2007 break;
2008 case ST_F_SMAX:
2009 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
2010 break;
2011 case ST_F_SLIM:
2012 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
2013 break;
2014 case ST_F_STOT:
2015 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
2016 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002017 case ST_F_RATE_MAX:
2018 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
2019 break;
2020 case ST_F_LASTSESS:
2021 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
2022 break;
2023 case ST_F_QCUR:
2024 metric = mkf_u32(0, sv->nbpend);
2025 break;
2026 case ST_F_QMAX:
2027 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
2028 break;
2029 case ST_F_QLIMIT:
2030 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
2031 break;
2032 case ST_F_BIN:
2033 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
2034 break;
2035 case ST_F_BOUT:
2036 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
2037 break;
2038 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002039 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
2040 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002041 break;
2042 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002043 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
2044 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002045 break;
2046 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002047 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
2048 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002049 break;
2050 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002051 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
2052 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002053 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01002054 case ST_F_QT_MAX:
2055 secs = (double)sv->counters.qtime_max / 1000.0;
2056 metric = mkf_flt(FN_MAX, secs);
2057 break;
2058 case ST_F_CT_MAX:
2059 secs = (double)sv->counters.ctime_max / 1000.0;
2060 metric = mkf_flt(FN_MAX, secs);
2061 break;
2062 case ST_F_RT_MAX:
2063 secs = (double)sv->counters.dtime_max / 1000.0;
2064 metric = mkf_flt(FN_MAX, secs);
2065 break;
2066 case ST_F_TT_MAX:
2067 secs = (double)sv->counters.ttime_max / 1000.0;
2068 metric = mkf_flt(FN_MAX, secs);
2069 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002070 case ST_F_CONNECT:
2071 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
2072 break;
2073 case ST_F_REUSE:
2074 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
2075 break;
2076 case ST_F_DRESP:
Christopher Fauleta08546b2019-12-16 16:07:34 +01002077 metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp);
Christopher Fauletf959d082019-02-07 15:38:42 +01002078 break;
2079 case ST_F_ECON:
2080 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
2081 break;
2082 case ST_F_ERESP:
2083 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
2084 break;
2085 case ST_F_WRETR:
2086 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
2087 break;
2088 case ST_F_WREDIS:
2089 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
2090 break;
2091 case ST_F_WREW:
2092 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
2093 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01002094 case ST_F_EINT:
2095 metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors);
2096 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002097 case ST_F_CLI_ABRT:
2098 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
2099 break;
2100 case ST_F_SRV_ABRT:
2101 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
2102 break;
2103 case ST_F_WEIGHT:
2104 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
2105 metric = mkf_u32(FN_AVG, weight);
2106 break;
Christopher Fauletcf403f32019-11-21 14:35:46 +01002107 case ST_F_CHECK_STATUS:
2108 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2109 goto next_sv;
2110 metric = mkf_u32(FN_OUTPUT, sv->check.status);
2111 break;
2112 case ST_F_CHECK_CODE:
2113 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2114 goto next_sv;
2115 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
2116 break;
Christopher Faulet2711e512020-02-27 16:12:07 +01002117 case ST_F_CHECK_DURATION:
2118 if (sv->check.status < HCHK_STATUS_CHECKED)
2119 goto next_sv;
2120 secs = (double)sv->check.duration / 1000.0;
2121 metric = mkf_flt(FN_DURATION, secs);
2122 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002123 case ST_F_CHKFAIL:
2124 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
2125 break;
2126 case ST_F_CHKDOWN:
2127 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
2128 break;
2129 case ST_F_DOWNTIME:
2130 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
2131 break;
2132 case ST_F_LASTCHG:
2133 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
2134 break;
2135 case ST_F_THROTTLE:
2136 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
2137 break;
2138 case ST_F_LBTOT:
2139 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
2140 break;
Marcin Deranek3c27dda2020-05-15 18:32:51 +02002141 case ST_F_REQ_TOT:
2142 if (px->mode != PR_MODE_HTTP)
2143 goto next_px;
2144 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
2145 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002146 case ST_F_HRSP_1XX:
2147 if (px->mode != PR_MODE_HTTP)
2148 goto next_px;
2149 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
2150 break;
2151 case ST_F_HRSP_2XX:
2152 if (px->mode != PR_MODE_HTTP)
2153 goto next_px;
2154 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2155 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
2156 break;
2157 case ST_F_HRSP_3XX:
2158 if (px->mode != PR_MODE_HTTP)
2159 goto next_px;
2160 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2161 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
2162 break;
2163 case ST_F_HRSP_4XX:
2164 if (px->mode != PR_MODE_HTTP)
2165 goto next_px;
2166 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2167 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
2168 break;
2169 case ST_F_HRSP_5XX:
2170 if (px->mode != PR_MODE_HTTP)
2171 goto next_px;
2172 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2173 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
2174 break;
2175 case ST_F_HRSP_OTHER:
2176 if (px->mode != PR_MODE_HTTP)
2177 goto next_px;
2178 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2179 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
2180 break;
Christopher Faulet20ab80c2019-11-08 15:24:32 +01002181 case ST_F_SRV_ICUR:
2182 metric = mkf_u32(0, sv->curr_idle_conns);
2183 break;
2184 case ST_F_SRV_ILIM:
2185 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2186 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02002187 case ST_F_IDLE_CONN_CUR:
2188 metric = mkf_u32(0, sv->curr_idle_nb);
2189 break;
2190 case ST_F_SAFE_CONN_CUR:
2191 metric = mkf_u32(0, sv->curr_safe_nb);
2192 break;
2193 case ST_F_USED_CONN_CUR:
2194 metric = mkf_u32(0, sv->curr_used_conns);
2195 break;
2196 case ST_F_NEED_CONN_EST:
2197 metric = mkf_u32(0, sv->est_need_conns);
2198 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002199
2200 default:
2201 goto next_metric;
2202 }
2203
2204 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2205 goto full;
2206
Christopher Fauleteba22942019-11-19 14:18:24 +01002207 next_sv:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002208 appctx->ctx.stats.obj2 = sv->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01002209 }
2210
2211 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002212 appctx->ctx.stats.obj1 = px->next;
2213 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002214 }
2215 next_metric:
2216 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002217 appctx->ctx.stats.obj1 = proxies_list;
2218 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002219 appctx->st2 = promex_srv_metrics[appctx->st2];
2220 }
2221
2222
2223 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02002224 if (out.len) {
2225 if (!htx_add_data_atonce(htx, out))
2226 return -1; /* Unexpected and unrecoverable error */
2227 channel_add_input(chn, out.len);
2228 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002229 return ret;
2230 full:
2231 ret = 0;
2232 goto end;
2233}
2234
2235/* Dump all metrics (global, frontends, backends and servers) depending on the
2236 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002237 * -1 in case of any error.
2238 * Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as
2239 * a pointer to the current server/listener. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002240static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2241{
2242 int ret;
2243
2244 switch (appctx->st1) {
2245 case PROMEX_DUMPER_INIT:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002246 appctx->ctx.stats.obj1 = NULL;
2247 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002248 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002249 appctx->st2 = promex_global_metrics[INF_NAME];
2250 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2251 /* fall through */
2252
2253 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002254 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2255 ret = promex_dump_global_metrics(appctx, htx);
2256 if (ret <= 0) {
2257 if (ret == -1)
2258 goto error;
2259 goto full;
2260 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002261 }
2262
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002263 appctx->ctx.stats.obj1 = proxies_list;
2264 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002265 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
2266 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002267 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2268 appctx->st1 = PROMEX_DUMPER_FRONT;
2269 /* fall through */
2270
2271 case PROMEX_DUMPER_FRONT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002272 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2273 ret = promex_dump_front_metrics(appctx, htx);
2274 if (ret <= 0) {
2275 if (ret == -1)
2276 goto error;
2277 goto full;
2278 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002279 }
2280
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002281 appctx->ctx.stats.obj1 = proxies_list;
2282 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002283 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002284 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2285 appctx->st1 = PROMEX_DUMPER_BACK;
2286 /* fall through */
2287
2288 case PROMEX_DUMPER_BACK:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002289 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2290 ret = promex_dump_back_metrics(appctx, htx);
2291 if (ret <= 0) {
2292 if (ret == -1)
2293 goto error;
2294 goto full;
2295 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002296 }
2297
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002298 appctx->ctx.stats.obj1 = proxies_list;
2299 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletefde9552020-06-05 08:18:56 +02002300 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002301 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2302 appctx->st1 = PROMEX_DUMPER_SRV;
2303 /* fall through */
2304
2305 case PROMEX_DUMPER_SRV:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002306 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2307 ret = promex_dump_srv_metrics(appctx, htx);
2308 if (ret <= 0) {
2309 if (ret == -1)
2310 goto error;
2311 goto full;
2312 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002313 }
2314
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002315 appctx->ctx.stats.obj1 = NULL;
2316 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002317 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002318 appctx->st2 = 0;
2319 appctx->st1 = PROMEX_DUMPER_DONE;
2320 /* fall through */
2321
2322 case PROMEX_DUMPER_DONE:
2323 default:
2324 break;
2325 }
2326
2327 return 1;
2328
2329 full:
2330 si_rx_room_blk(si);
2331 return 0;
2332 error:
2333 /* unrecoverable error */
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002334 appctx->ctx.stats.obj1 = NULL;
2335 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletf959d082019-02-07 15:38:42 +01002336 appctx->ctx.stats.flags = 0;
2337 appctx->st2 = 0;
2338 appctx->st1 = PROMEX_DUMPER_DONE;
2339 return -1;
2340}
2341
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002342/* Parse the query string of request URI to filter the metrics. It returns 1 on
Christopher Faulet78407ce2019-11-18 14:47:08 +01002343 * success and -1 on error. */
2344static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2345{
2346 struct channel *req = si_oc(si);
2347 struct channel *res = si_ic(si);
2348 struct htx *req_htx, *res_htx;
2349 struct htx_sl *sl;
William Dauchyc65f6562019-11-26 12:56:26 +01002350 char *p, *key, *value;
2351 const char *end;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002352 struct buffer *err;
2353 int default_scopes = PROMEX_FL_SCOPE_ALL;
2354 int len;
2355
2356 /* Get the query-string */
2357 req_htx = htxbuf(&req->buf);
2358 sl = http_get_stline(req_htx);
2359 if (!sl)
2360 goto error;
2361 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2362 if (!p)
2363 goto end;
2364 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet78407ce2019-11-18 14:47:08 +01002365
William Dauchyc65f6562019-11-26 12:56:26 +01002366 /* copy the query-string */
2367 len = end - p;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002368 chunk_reset(&trash);
2369 memcpy(trash.area, p, len);
2370 trash.area[len] = 0;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002371 p = trash.area;
William Dauchyc65f6562019-11-26 12:56:26 +01002372 end = trash.area + len;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002373
2374 /* Parse the query-string */
William Dauchyc65f6562019-11-26 12:56:26 +01002375 while (p < end && *p && *p != '#') {
2376 value = NULL;
2377
2378 /* decode parameter name */
2379 key = p;
2380 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002381 ++p;
William Dauchyc65f6562019-11-26 12:56:26 +01002382 /* found a value */
2383 if (*p == '=') {
2384 *(p++) = 0;
2385 value = p;
2386 }
2387 else if (*p == '&')
2388 *(p++) = 0;
2389 else if (*p == '#')
2390 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002391 len = url_decode(key, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002392 if (len == -1)
2393 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002394
William Dauchyc65f6562019-11-26 12:56:26 +01002395 /* decode value */
2396 if (value) {
2397 while (p < end && *p != '=' && *p != '&' && *p != '#')
2398 ++p;
2399 if (*p == '=')
2400 goto error;
2401 if (*p == '&')
2402 *(p++) = 0;
2403 else if (*p == '#')
2404 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002405 len = url_decode(value, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002406 if (len == -1)
2407 goto error;
2408 }
2409
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002410 if (strcmp(key, "scope") == 0) {
William Dauchyc65f6562019-11-26 12:56:26 +01002411 default_scopes = 0; /* at least a scope defined, unset default scopes */
2412 if (!value)
2413 goto error;
2414 else if (*value == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002415 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002416 else if (*value == '*')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002417 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002418 else if (strcmp(value, "global") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002419 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002420 else if (strcmp(value, "server") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002421 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002422 else if (strcmp(value, "backend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002423 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002424 else if (strcmp(value, "frontend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002425 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2426 else
2427 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002428 }
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002429 else if (strcmp(key, "no-maint") == 0)
Christopher Fauleteba22942019-11-19 14:18:24 +01002430 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002431 }
2432
2433 end:
2434 appctx->ctx.stats.flags |= default_scopes;
2435 return 1;
2436
2437 error:
2438 err = &http_err_chunks[HTTP_ERR_400];
2439 channel_erase(res);
2440 res->buf.data = b_data(err);
2441 memcpy(res->buf.area, b_head(err), b_data(err));
2442 res_htx = htx_from_buf(&res->buf);
2443 channel_add_input(res, res_htx->data);
2444 appctx->st0 = PROMEX_ST_END;
2445 return -1;
2446}
2447
Christopher Fauletf959d082019-02-07 15:38:42 +01002448/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2449 * full. */
2450static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2451{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002452 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002453 struct htx_sl *sl;
2454 unsigned int flags;
2455
2456 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);
2457 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2458 if (!sl)
2459 goto full;
2460 sl->info.res.status = 200;
2461 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
2462 !htx_add_header(htx, ist("Connection"), ist("close")) ||
2463 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2464 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2465 !htx_add_endof(htx, HTX_BLK_EOH))
2466 goto full;
2467
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002468 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002469 return 1;
2470 full:
2471 htx_reset(htx);
2472 si_rx_room_blk(si);
2473 return 0;
2474}
2475
2476/* The function returns 1 if the initialisation is complete, 0 if
2477 * an errors occurs and -1 if more data are required for initializing
2478 * the applet.
2479 */
2480static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2481{
2482 appctx->st0 = PROMEX_ST_INIT;
2483 return 1;
2484}
2485
2486/* The main I/O handler for the promex applet. */
2487static void promex_appctx_handle_io(struct appctx *appctx)
2488{
2489 struct stream_interface *si = appctx->owner;
2490 struct stream *s = si_strm(si);
2491 struct channel *req = si_oc(si);
2492 struct channel *res = si_ic(si);
2493 struct htx *req_htx, *res_htx;
2494 int ret;
2495
2496 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002497 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2498 goto out;
2499
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002500 /* Check if the input buffer is available. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002501 if (!b_size(&res->buf)) {
2502 si_rx_room_blk(si);
2503 goto out;
2504 }
2505
2506 switch (appctx->st0) {
2507 case PROMEX_ST_INIT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002508 ret = promex_parse_uri(appctx, si);
2509 if (ret <= 0) {
2510 if (ret == -1)
2511 goto error;
2512 goto out;
2513 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002514 appctx->st0 = PROMEX_ST_HEAD;
2515 appctx->st1 = PROMEX_DUMPER_INIT;
2516 /* fall through */
2517
2518 case PROMEX_ST_HEAD:
2519 if (!promex_send_headers(appctx, si, res_htx))
2520 goto out;
2521 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2522 /* fall through */
2523
2524 case PROMEX_ST_DUMP:
2525 ret = promex_dump_metrics(appctx, si, res_htx);
2526 if (ret <= 0) {
2527 if (ret == -1)
2528 goto error;
2529 goto out;
2530 }
2531 appctx->st0 = PROMEX_ST_DONE;
2532 /* fall through */
2533
2534 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002535 /* Don't add TLR because mux-h1 will take care of it */
Willy Tarreauf1ea47d2020-07-23 06:53:27 +02002536 res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
Christopher Fauletf959d082019-02-07 15:38:42 +01002537 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2538 si_rx_room_blk(si);
2539 goto out;
2540 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002541 channel_add_input(res, 1);
2542 appctx->st0 = PROMEX_ST_END;
2543 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002544
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002545 case PROMEX_ST_END:
2546 if (!(res->flags & CF_SHUTR)) {
2547 res->flags |= CF_READ_NULL;
2548 si_shutr(si);
2549 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002550 }
2551
Christopher Fauletf959d082019-02-07 15:38:42 +01002552 out:
2553 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002554
2555 /* eat the whole request */
2556 if (co_data(req)) {
2557 req_htx = htx_from_buf(&req->buf);
2558 co_htx_skip(req, req_htx, co_data(req));
2559 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002560 return;
2561
2562 error:
2563 res->flags |= CF_READ_NULL;
2564 si_shutr(si);
2565 si_shutw(si);
2566}
2567
2568struct applet promex_applet = {
2569 .obj_type = OBJ_TYPE_APPLET,
2570 .name = "<PROMEX>", /* used for logging */
2571 .init = promex_appctx_init,
2572 .fct = promex_appctx_handle_io,
2573};
2574
2575static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2576 struct act_rule *rule, char **err)
2577{
2578 /* Prometheus exporter service is only available on "http-request" rulesets */
2579 if (rule->from != ACT_F_HTTP_REQ) {
2580 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2581 return ACT_RET_PRS_ERR;
2582 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002583
2584 /* Add applet pointer in the rule. */
2585 rule->applet = promex_applet;
2586
2587 return ACT_RET_PRS_OK;
2588}
2589static void promex_register_build_options(void)
2590{
2591 char *ptr = NULL;
2592
2593 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2594 hap_register_build_opts(ptr, 1);
2595}
2596
2597
2598static struct action_kw_list service_actions = { ILH, {
2599 { "prometheus-exporter", service_parse_prometheus_exporter },
2600 { /* END */ }
2601}};
2602
2603INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2604INITCALL0(STG_REGISTER, promex_register_build_options);