blob: 92613e8a9f1e4809862fbaca300c80c495648c70 [file] [log] [blame]
Christopher Fauletf959d082019-02-07 15:38:42 +01001/*
2 * Promex is a Prometheus exporter for HAProxy
3 *
4 * It is highly inspired by the official Prometheus exporter.
5 * See: https://github.com/prometheus/haproxy_exporter
6 *
7 * Copyright 2019 Christopher Faulet <cfaulet@haproxy.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 */
15
Willy Tarreau122eba92020-06-04 10:15:32 +020016#include <haproxy/action-t.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020017#include <haproxy/api.h>
Willy Tarreau3f0f82e2020-06-04 19:42:41 +020018#include <haproxy/applet.h>
Willy Tarreau49801602020-06-04 22:50:02 +020019#include <haproxy/backend.h>
Willy Tarreau6be78492020-06-05 00:00:29 +020020#include <haproxy/cfgparse.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020021#include <haproxy/compression.h>
Christopher Fauletc55a6262020-07-10 15:39:39 +020022#include <haproxy/dns.h>
Willy Tarreau762d7a52020-06-04 11:23:07 +020023#include <haproxy/frontend.h>
Willy Tarreauf268ee82020-06-04 17:05:57 +020024#include <haproxy/global.h>
Willy Tarreaucd72d8c2020-06-02 19:11:26 +020025#include <haproxy/http.h>
Willy Tarreau87735332020-06-04 09:08:41 +020026#include <haproxy/http_htx.h>
Willy Tarreau16f958c2020-06-03 08:44:35 +020027#include <haproxy/htx.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020028#include <haproxy/list.h>
Willy Tarreau213e9902020-06-04 14:58:24 +020029#include <haproxy/listener.h>
Willy Tarreau36979d92020-06-05 17:27:29 +020030#include <haproxy/log.h>
Willy Tarreau551271d2020-06-04 08:32:23 +020031#include <haproxy/pipe.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020032#include <haproxy/pool.h>
Willy Tarreaua264d962020-06-04 22:29:18 +020033#include <haproxy/proxy.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020034#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020035#include <haproxy/server.h>
Willy Tarreau209108d2020-06-04 20:30:20 +020036#include <haproxy/ssl_sock.h>
Willy Tarreau2eec9b52020-06-04 19:58:55 +020037#include <haproxy/stats.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020038#include <haproxy/stream.h>
Willy Tarreau5e539c92020-06-04 20:45:39 +020039#include <haproxy/stream_interface.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020040#include <haproxy/task.h>
William Dauchy5a982a72021-01-08 13:18:06 +010041#include <haproxy/version.h>
Christopher Fauletf959d082019-02-07 15:38:42 +010042
43/* Prometheus exporter applet states (appctx->st0) */
44enum {
45 PROMEX_ST_INIT = 0, /* initialized */
46 PROMEX_ST_HEAD, /* send headers before dump */
47 PROMEX_ST_DUMP, /* dumping stats */
48 PROMEX_ST_DONE, /* finished */
Christopher Faulet9744f7c2019-03-27 15:48:53 +010049 PROMEX_ST_END, /* treatment terminated */
Christopher Fauletf959d082019-02-07 15:38:42 +010050};
51
52/* Prometheus exporter dumper states (appctx->st1) */
53enum {
54 PROMEX_DUMPER_INIT = 0, /* initialized */
55 PROMEX_DUMPER_GLOBAL, /* dump metrics of globals */
56 PROMEX_DUMPER_FRONT, /* dump metrics of frontend proxies */
57 PROMEX_DUMPER_BACK, /* dump metrics of backend proxies */
58 PROMEX_DUMPER_LI, /* dump metrics of listeners */
59 PROMEX_DUMPER_SRV, /* dump metrics of servers */
60 PROMEX_DUMPER_DONE, /* finished */
61};
62
63/* Prometheus exporter flags (appctx->ctx.stats.flags) */
64#define PROMEX_FL_METRIC_HDR 0x00000001
65#define PROMEX_FL_INFO_METRIC 0x00000002
66#define PROMEX_FL_STATS_METRIC 0x00000004
Christopher Faulet78407ce2019-11-18 14:47:08 +010067#define PROMEX_FL_SCOPE_GLOBAL 0x00000008
68#define PROMEX_FL_SCOPE_FRONT 0x00000010
69#define PROMEX_FL_SCOPE_BACK 0x00000020
70#define PROMEX_FL_SCOPE_SERVER 0x00000040
Christopher Fauleteba22942019-11-19 14:18:24 +010071#define PROMEX_FL_NO_MAINT_SRV 0x00000080
Christopher Faulet78407ce2019-11-18 14:47:08 +010072
73#define PROMEX_FL_SCOPE_ALL (PROMEX_FL_SCOPE_GLOBAL|PROMEX_FL_SCOPE_FRONT|PROMEX_FL_SCOPE_BACK|PROMEX_FL_SCOPE_SERVER)
Christopher Fauletf959d082019-02-07 15:38:42 +010074
75/* The max length for metrics name. It is a hard limit but it should be
Ilya Shipitsince7b00f2020-03-23 22:28:40 +050076 * enough.
Christopher Fauletf959d082019-02-07 15:38:42 +010077 */
78#define PROMEX_MAX_NAME_LEN 128
79
80/* The expected max length for a metric dump, including its header lines. It is
81 * just a soft limit to avoid extra work. We don't try to dump a metric if less
82 * than this size is available in the HTX.
83 */
84#define PROMEX_MAX_METRIC_LENGTH 512
85
William Dauchy5a982a72021-01-08 13:18:06 +010086/* Some labels for build_info */
87#define PROMEX_VERSION_LABEL "version=\"" HAPROXY_VERSION "\""
88#define PROMEX_BUILDINFO_LABEL PROMEX_VERSION_LABEL
89
Christopher Fauletf959d082019-02-07 15:38:42 +010090/* Matrix used to dump global metrics. Each metric points to the next one to be
91 * processed or 0 to stop the dump. */
92const int promex_global_metrics[INF_TOTAL_FIELDS] = {
William Dauchy5a982a72021-01-08 13:18:06 +010093 [INF_NAME] = INF_BUILD_INFO,
Christopher Fauletf959d082019-02-07 15:38:42 +010094 [INF_VERSION] = 0,
95 [INF_RELEASE_DATE] = 0,
William Dauchy5a982a72021-01-08 13:18:06 +010096 [INF_BUILD_INFO] = INF_NBTHREAD,
Christopher Fauletf959d082019-02-07 15:38:42 +010097 [INF_NBTHREAD] = INF_NBPROC,
98 [INF_NBPROC] = INF_PROCESS_NUM,
99 [INF_PROCESS_NUM] = INF_UPTIME_SEC,
100 [INF_PID] = 0,
101 [INF_UPTIME] = 0,
William Dauchydefd1562021-01-15 22:41:38 +0100102 [INF_UPTIME_SEC] = INF_START_TIME_SEC,
103 [INF_START_TIME_SEC] = INF_MEMMAX_BYTES,
William Dauchya8766cf2021-01-15 22:41:37 +0100104 [INF_MEMMAX_BYTES] = INF_POOL_ALLOC_BYTES,
105 [INF_POOL_ALLOC_BYTES] = INF_POOL_USED_BYTES,
106 [INF_POOL_USED_BYTES] = INF_POOL_FAILED,
Christopher Fauletf959d082019-02-07 15:38:42 +0100107 [INF_POOL_FAILED] = INF_ULIMIT_N,
108 [INF_ULIMIT_N] = INF_MAXSOCK,
109 [INF_MAXSOCK] = INF_MAXCONN,
110 [INF_MAXCONN] = INF_HARD_MAXCONN,
111 [INF_HARD_MAXCONN] = INF_CURR_CONN,
112 [INF_CURR_CONN] = INF_CUM_CONN,
113 [INF_CUM_CONN] = INF_CUM_REQ,
114 [INF_CUM_REQ] = INF_MAX_SSL_CONNS,
115 [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS,
116 [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS,
117 [INF_CUM_SSL_CONNS] = INF_MAXPIPES,
118 [INF_MAXPIPES] = INF_PIPES_USED,
119 [INF_PIPES_USED] = INF_PIPES_FREE,
120 [INF_PIPES_FREE] = INF_CONN_RATE,
121 [INF_CONN_RATE] = INF_CONN_RATE_LIMIT,
122 [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE,
123 [INF_MAX_CONN_RATE] = INF_SESS_RATE,
124 [INF_SESS_RATE] = INF_SESS_RATE_LIMIT,
125 [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE,
126 [INF_MAX_SESS_RATE] = INF_SSL_RATE,
127 [INF_SSL_RATE] = INF_SSL_RATE_LIMIT,
128 [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE,
129 [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE,
130 [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE,
131 [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT,
132 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE,
133 [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE,
134 [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS,
135 [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES,
136 [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN,
137 [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT,
138 [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM,
139 [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE,
140 [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE,
141 [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS,
142 [INF_TASKS] = INF_RUN_QUEUE,
143 [INF_RUN_QUEUE] = INF_IDLE_PCT,
144 [INF_IDLE_PCT] = INF_STOPPING,
145 [INF_NODE] = 0,
146 [INF_DESCRIPTION] = 0,
147 [INF_STOPPING] = INF_JOBS,
148 [INF_JOBS] = INF_UNSTOPPABLE_JOBS,
149 [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS,
150 [INF_LISTENERS] = INF_ACTIVE_PEERS,
151 [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS,
152 [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS,
153 [INF_DROPPED_LOGS] = INF_BUSY_POLLING,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200154 [INF_BUSY_POLLING] = INF_FAILED_RESOLUTIONS,
155 [INF_FAILED_RESOLUTIONS] = INF_TOTAL_BYTES_OUT,
156 [INF_TOTAL_BYTES_OUT] = INF_TOTAL_SPLICED_BYTES_OUT,
157 [INF_TOTAL_SPLICED_BYTES_OUT] = INF_BYTES_OUT_RATE,
158 [INF_BYTES_OUT_RATE] = 0,
159 [INF_DEBUG_COMMANDS_ISSUED] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100160};
161
162/* Matrix used to dump frontend metrics. Each metric points to the next one to be
163 * processed or 0 to stop the dump. */
164const int promex_front_metrics[ST_F_TOTAL_FIELDS] = {
165 [ST_F_PXNAME] = ST_F_STATUS,
166 [ST_F_SVNAME] = 0,
167 [ST_F_QCUR] = 0,
168 [ST_F_QMAX] = 0,
169 [ST_F_SCUR] = ST_F_SMAX,
170 [ST_F_SMAX] = ST_F_SLIM,
171 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200172 [ST_F_STOT] = ST_F_RATE_LIM,
Christopher Fauletf959d082019-02-07 15:38:42 +0100173 [ST_F_BIN] = ST_F_BOUT,
174 [ST_F_BOUT] = ST_F_DREQ,
175 [ST_F_DREQ] = ST_F_DRESP,
176 [ST_F_DRESP] = ST_F_EREQ,
177 [ST_F_EREQ] = ST_F_DCON,
178 [ST_F_ECON] = 0,
179 [ST_F_ERESP] = 0,
180 [ST_F_WRETR] = 0,
181 [ST_F_WREDIS] = 0,
182 [ST_F_STATUS] = ST_F_SCUR,
183 [ST_F_WEIGHT] = 0,
184 [ST_F_ACT] = 0,
185 [ST_F_BCK] = 0,
186 [ST_F_CHKFAIL] = 0,
187 [ST_F_CHKDOWN] = 0,
188 [ST_F_LASTCHG] = 0,
189 [ST_F_DOWNTIME] = 0,
190 [ST_F_QLIMIT] = 0,
191 [ST_F_PID] = 0,
192 [ST_F_IID] = 0,
193 [ST_F_SID] = 0,
194 [ST_F_THROTTLE] = 0,
195 [ST_F_LBTOT] = 0,
196 [ST_F_TRACKED] = 0,
197 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200198 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100199 [ST_F_RATE_LIM] = ST_F_RATE_MAX,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200200 [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100201 [ST_F_CHECK_STATUS] = 0,
202 [ST_F_CHECK_CODE] = 0,
203 [ST_F_CHECK_DURATION] = 0,
204 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
205 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
206 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
207 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
208 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
209 [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED,
210 [ST_F_HANAFAIL] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200211 [ST_F_REQ_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100212 [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT,
213 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
214 [ST_F_CLI_ABRT] = 0,
215 [ST_F_SRV_ABRT] = 0,
216 [ST_F_COMP_IN] = ST_F_COMP_OUT,
217 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
218 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
219 [ST_F_COMP_RSP] = 0,
220 [ST_F_LASTSESS] = 0,
221 [ST_F_LAST_CHK] = 0,
222 [ST_F_LAST_AGT] = 0,
223 [ST_F_QTIME] = 0,
224 [ST_F_CTIME] = 0,
225 [ST_F_RTIME] = 0,
226 [ST_F_TTIME] = 0,
227 [ST_F_AGENT_STATUS] = 0,
228 [ST_F_AGENT_CODE] = 0,
229 [ST_F_AGENT_DURATION] = 0,
230 [ST_F_CHECK_DESC] = 0,
231 [ST_F_AGENT_DESC] = 0,
232 [ST_F_CHECK_RISE] = 0,
233 [ST_F_CHECK_FALL] = 0,
234 [ST_F_CHECK_HEALTH] = 0,
235 [ST_F_AGENT_RISE] = 0,
236 [ST_F_AGENT_FALL] = 0,
237 [ST_F_AGENT_HEALTH] = 0,
238 [ST_F_ADDR] = 0,
239 [ST_F_COOKIE] = 0,
240 [ST_F_MODE] = 0,
241 [ST_F_ALGO] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200242 [ST_F_CONN_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100243 [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT,
244 [ST_F_CONN_TOT] = ST_F_BIN,
245 [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS,
246 [ST_F_DCON] = ST_F_DSES,
247 [ST_F_DSES] = ST_F_WREW,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100248 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100249 [ST_F_CONNECT] = 0,
250 [ST_F_REUSE] = 0,
251 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
252 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100253 [ST_F_SRV_ICUR] = 0,
254 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100255 [ST_F_QT_MAX] = 0,
256 [ST_F_CT_MAX] = 0,
257 [ST_F_RT_MAX] = 0,
258 [ST_F_TT_MAX] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100259 [ST_F_EINT] = ST_F_REQ_RATE_MAX,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200260 [ST_F_IDLE_CONN_CUR] = 0,
261 [ST_F_SAFE_CONN_CUR] = 0,
262 [ST_F_USED_CONN_CUR] = 0,
263 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100264};
265
266/* Matrix used to dump backend metrics. Each metric points to the next one to be
267 * processed or 0 to stop the dump. */
268const int promex_back_metrics[ST_F_TOTAL_FIELDS] = {
269 [ST_F_PXNAME] = ST_F_STATUS,
270 [ST_F_SVNAME] = 0,
271 [ST_F_QCUR] = ST_F_QMAX,
272 [ST_F_QMAX] = ST_F_CONNECT,
273 [ST_F_SCUR] = ST_F_SMAX,
274 [ST_F_SMAX] = ST_F_SLIM,
275 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200276 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100277 [ST_F_BIN] = ST_F_BOUT,
278 [ST_F_BOUT] = ST_F_QTIME,
279 [ST_F_DREQ] = ST_F_DRESP,
280 [ST_F_DRESP] = ST_F_ECON,
281 [ST_F_EREQ] = 0,
282 [ST_F_ECON] = ST_F_ERESP,
283 [ST_F_ERESP] = ST_F_WRETR,
284 [ST_F_WRETR] = ST_F_WREDIS,
285 [ST_F_WREDIS] = ST_F_WREW,
286 [ST_F_STATUS] = ST_F_SCUR,
287 [ST_F_WEIGHT] = ST_F_ACT,
288 [ST_F_ACT] = ST_F_BCK,
289 [ST_F_BCK] = ST_F_CHKDOWN,
290 [ST_F_CHKFAIL] = 0,
291 [ST_F_CHKDOWN] = ST_F_LASTCHG,
292 [ST_F_LASTCHG] = ST_F_DOWNTIME,
293 [ST_F_DOWNTIME] = ST_F_LBTOT,
294 [ST_F_QLIMIT] = 0,
295 [ST_F_PID] = 0,
296 [ST_F_IID] = 0,
297 [ST_F_SID] = 0,
298 [ST_F_THROTTLE] = 0,
299 [ST_F_LBTOT] = ST_F_REQ_TOT,
300 [ST_F_TRACKED] = 9,
301 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200302 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100303 [ST_F_RATE_LIM] = 0,
304 [ST_F_RATE_MAX] = ST_F_LASTSESS,
305 [ST_F_CHECK_STATUS] = 0,
306 [ST_F_CHECK_CODE] = 0,
307 [ST_F_CHECK_DURATION] = 0,
308 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
309 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
310 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
311 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
312 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
313 [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS,
314 [ST_F_HANAFAIL] = 0,
315 [ST_F_REQ_RATE] = 0,
316 [ST_F_REQ_RATE_MAX] = 0,
317 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
318 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
319 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
320 [ST_F_COMP_IN] = ST_F_COMP_OUT,
321 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
322 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
323 [ST_F_COMP_RSP] = 0,
324 [ST_F_LASTSESS] = ST_F_QCUR,
325 [ST_F_LAST_CHK] = 0,
326 [ST_F_LAST_AGT] = 0,
327 [ST_F_QTIME] = ST_F_CTIME,
328 [ST_F_CTIME] = ST_F_RTIME,
329 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100330 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100331 [ST_F_AGENT_STATUS] = 0,
332 [ST_F_AGENT_CODE] = 0,
333 [ST_F_AGENT_DURATION] = 0,
334 [ST_F_CHECK_DESC] = 0,
335 [ST_F_AGENT_DESC] = 0,
336 [ST_F_CHECK_RISE] = 0,
337 [ST_F_CHECK_FALL] = 0,
338 [ST_F_CHECK_HEALTH] = 0,
339 [ST_F_AGENT_RISE] = 0,
340 [ST_F_AGENT_FALL] = 0,
341 [ST_F_AGENT_HEALTH] = 0,
342 [ST_F_ADDR] = 0,
343 [ST_F_COOKIE] = 0,
344 [ST_F_MODE] = 0,
345 [ST_F_ALGO] = 0,
346 [ST_F_CONN_RATE] = 0,
347 [ST_F_CONN_RATE_MAX] = 0,
348 [ST_F_CONN_TOT] = 0,
349 [ST_F_INTERCEPTED] = 0,
350 [ST_F_DCON] = 0,
351 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100352 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100353 [ST_F_CONNECT] = ST_F_REUSE,
354 [ST_F_REUSE] = ST_F_BIN,
355 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
356 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100357 [ST_F_SRV_ICUR] = 0,
358 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100359 [ST_F_QT_MAX] = ST_F_CT_MAX,
360 [ST_F_CT_MAX] = ST_F_RT_MAX,
361 [ST_F_RT_MAX] = ST_F_TT_MAX,
362 [ST_F_TT_MAX] = ST_F_DREQ,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100363 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200364 [ST_F_IDLE_CONN_CUR] = 0,
365 [ST_F_SAFE_CONN_CUR] = 0,
366 [ST_F_USED_CONN_CUR] = 0,
367 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100368};
369
370/* Matrix used to dump server metrics. Each metric points to the next one to be
371 * processed or 0 to stop the dump. */
372const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = {
373 [ST_F_PXNAME] = ST_F_STATUS,
374 [ST_F_SVNAME] = 0,
375 [ST_F_QCUR] = ST_F_QMAX,
376 [ST_F_QMAX] = ST_F_QLIMIT,
377 [ST_F_SCUR] = ST_F_SMAX,
378 [ST_F_SMAX] = ST_F_SLIM,
379 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200380 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100381 [ST_F_BIN] = ST_F_BOUT,
382 [ST_F_BOUT] = ST_F_QTIME,
383 [ST_F_DREQ] = 0,
384 [ST_F_DRESP] = ST_F_ECON,
385 [ST_F_EREQ] = 0,
386 [ST_F_ECON] = ST_F_ERESP,
387 [ST_F_ERESP] = ST_F_WRETR,
388 [ST_F_WRETR] = ST_F_WREDIS,
389 [ST_F_WREDIS] = ST_F_WREW,
390 [ST_F_STATUS] = ST_F_SCUR,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100391 [ST_F_WEIGHT] = ST_F_CHECK_STATUS,
Christopher Fauletf959d082019-02-07 15:38:42 +0100392 [ST_F_ACT] = 0,
393 [ST_F_BCK] = 0,
394 [ST_F_CHKFAIL] = ST_F_CHKDOWN,
395 [ST_F_CHKDOWN] = ST_F_DOWNTIME,
396 [ST_F_LASTCHG] = ST_F_THROTTLE,
397 [ST_F_DOWNTIME] = ST_F_LASTCHG,
398 [ST_F_QLIMIT] = ST_F_BIN,
399 [ST_F_PID] = 0,
400 [ST_F_IID] = 0,
401 [ST_F_SID] = 0,
402 [ST_F_THROTTLE] = ST_F_LBTOT,
403 [ST_F_LBTOT] = ST_F_HRSP_1XX,
404 [ST_F_TRACKED] = 0,
405 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200406 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100407 [ST_F_RATE_LIM] = 0,
408 [ST_F_RATE_MAX] = ST_F_LASTSESS,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100409 [ST_F_CHECK_STATUS] = ST_F_CHECK_CODE,
Christopher Faulet2711e512020-02-27 16:12:07 +0100410 [ST_F_CHECK_CODE] = ST_F_CHECK_DURATION,
411 [ST_F_CHECK_DURATION] = ST_F_CHKFAIL,
Christopher Fauletf959d082019-02-07 15:38:42 +0100412 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
413 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
414 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
415 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
416 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100417 [ST_F_HRSP_OTHER] = ST_F_SRV_ICUR,
Christopher Fauletf959d082019-02-07 15:38:42 +0100418 [ST_F_HANAFAIL] = 0,
419 [ST_F_REQ_RATE] = 0,
420 [ST_F_REQ_RATE_MAX] = 0,
421 [ST_F_REQ_TOT] = 0,
422 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
423 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
424 [ST_F_COMP_IN] = 0,
425 [ST_F_COMP_OUT] = 0,
426 [ST_F_COMP_BYP] = 0,
427 [ST_F_COMP_RSP] = 0,
428 [ST_F_LASTSESS] = ST_F_QCUR,
429 [ST_F_LAST_CHK] = 0,
430 [ST_F_LAST_AGT] = 0,
431 [ST_F_QTIME] = ST_F_CTIME,
432 [ST_F_CTIME] = ST_F_RTIME,
433 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100434 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100435 [ST_F_AGENT_STATUS] = 0,
436 [ST_F_AGENT_CODE] = 0,
437 [ST_F_AGENT_DURATION] = 0,
438 [ST_F_CHECK_DESC] = 0,
439 [ST_F_AGENT_DESC] = 0,
440 [ST_F_CHECK_RISE] = 0,
441 [ST_F_CHECK_FALL] = 0,
442 [ST_F_CHECK_HEALTH] = 0,
443 [ST_F_AGENT_RISE] = 0,
444 [ST_F_AGENT_FALL] = 0,
445 [ST_F_AGENT_HEALTH] = 0,
446 [ST_F_ADDR] = 0,
447 [ST_F_COOKIE] = 0,
448 [ST_F_MODE] = 0,
449 [ST_F_ALGO] = 0,
450 [ST_F_CONN_RATE] = 0,
451 [ST_F_CONN_RATE_MAX] = 0,
452 [ST_F_CONN_TOT] = 0,
453 [ST_F_INTERCEPTED] = 0,
454 [ST_F_DCON] = 0,
455 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100456 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100457 [ST_F_CONNECT] = ST_F_REUSE,
458 [ST_F_REUSE] = ST_F_DRESP,
459 [ST_F_CACHE_LOOKUPS] = 0,
460 [ST_F_CACHE_HITS] = 0,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100461 [ST_F_SRV_ICUR] = ST_F_SRV_ILIM,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200462 [ST_F_SRV_ILIM] = ST_F_IDLE_CONN_CUR,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100463 [ST_F_QT_MAX] = ST_F_CT_MAX,
464 [ST_F_CT_MAX] = ST_F_RT_MAX,
465 [ST_F_RT_MAX] = ST_F_TT_MAX,
466 [ST_F_TT_MAX] = ST_F_CONNECT,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100467 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200468 [ST_F_IDLE_CONN_CUR] = ST_F_SAFE_CONN_CUR,
469 [ST_F_SAFE_CONN_CUR] = ST_F_USED_CONN_CUR,
470 [ST_F_USED_CONN_CUR] = ST_F_NEED_CONN_EST,
471 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100472};
473
474/* Name of all info fields */
475const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
476 [INF_NAME] = IST("name"),
477 [INF_VERSION] = IST("version"),
478 [INF_RELEASE_DATE] = IST("release_date"),
William Dauchy5a982a72021-01-08 13:18:06 +0100479 [INF_BUILD_INFO] = IST("build_info"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100480 [INF_NBTHREAD] = IST("nbthread"),
481 [INF_NBPROC] = IST("nbproc"),
482 [INF_PROCESS_NUM] = IST("relative_process_id"),
483 [INF_PID] = IST("pid"),
484 [INF_UPTIME] = IST("uptime"),
William Dauchydefd1562021-01-15 22:41:38 +0100485 [INF_UPTIME_SEC] = IST("uptime_seconds"),
486 [INF_START_TIME_SEC] = IST("start_time_seconds"),
William Dauchya8766cf2021-01-15 22:41:37 +0100487 [INF_MEMMAX_BYTES] = IST("max_memory_bytes"),
488 [INF_POOL_ALLOC_BYTES] = IST("pool_allocated_bytes"),
489 [INF_POOL_USED_BYTES] = IST("pool_used_bytes"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100490 [INF_POOL_FAILED] = IST("pool_failures_total"),
491 [INF_ULIMIT_N] = IST("max_fds"),
492 [INF_MAXSOCK] = IST("max_sockets"),
493 [INF_MAXCONN] = IST("max_connections"),
494 [INF_HARD_MAXCONN] = IST("hard_max_connections"),
495 [INF_CURR_CONN] = IST("current_connections"),
496 [INF_CUM_CONN] = IST("connections_total"),
497 [INF_CUM_REQ] = IST("requests_total"),
498 [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"),
499 [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"),
500 [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"),
501 [INF_MAXPIPES] = IST("max_pipes"),
502 [INF_PIPES_USED] = IST("pipes_used_total"),
503 [INF_PIPES_FREE] = IST("pipes_free_total"),
504 [INF_CONN_RATE] = IST("current_connection_rate"),
505 [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"),
506 [INF_MAX_CONN_RATE] = IST("max_connection_rate"),
507 [INF_SESS_RATE] = IST("current_session_rate"),
508 [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"),
509 [INF_MAX_SESS_RATE] = IST("max_session_rate"),
510 [INF_SSL_RATE] = IST("current_ssl_rate"),
511 [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"),
512 [INF_MAX_SSL_RATE] = IST("max_ssl_rate"),
513 [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"),
514 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"),
Pierre Cheynier1e369762020-07-07 19:14:08 +0200515 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontend_ssl_reuse"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100516 [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"),
517 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200518 [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"),
519 [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100520 [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"),
521 [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"),
522 [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"),
523 [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"),
524 [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"),
525 [INF_TASKS] = IST("current_tasks"),
526 [INF_RUN_QUEUE] = IST("current_run_queue"),
527 [INF_IDLE_PCT] = IST("idle_time_percent"),
528 [INF_NODE] = IST("node"),
529 [INF_DESCRIPTION] = IST("description"),
530 [INF_STOPPING] = IST("stopping"),
531 [INF_JOBS] = IST("jobs"),
532 [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"),
533 [INF_LISTENERS] = IST("listeners"),
534 [INF_ACTIVE_PEERS] = IST("active_peers"),
535 [INF_CONNECTED_PEERS] = IST("connected_peers"),
536 [INF_DROPPED_LOGS] = IST("dropped_logs_total"),
537 [INF_BUSY_POLLING] = IST("busy_polling_enabled"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200538 [INF_FAILED_RESOLUTIONS] = IST("failed_resolutions"),
539 [INF_TOTAL_BYTES_OUT] = IST("bytes_out_total"),
540 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("spliced_bytes_out_total"),
541 [INF_BYTES_OUT_RATE] = IST("bytes_out_rate"),
542 [INF_DEBUG_COMMANDS_ISSUED] = IST("debug_commands_issued"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100543};
544
545/* Name of all stats fields */
546const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = {
547 [ST_F_PXNAME] = IST("proxy_name"),
548 [ST_F_SVNAME] = IST("service_name"),
549 [ST_F_QCUR] = IST("current_queue"),
550 [ST_F_QMAX] = IST("max_queue"),
551 [ST_F_SCUR] = IST("current_sessions"),
552 [ST_F_SMAX] = IST("max_sessions"),
553 [ST_F_SLIM] = IST("limit_sessions"),
554 [ST_F_STOT] = IST("sessions_total"),
555 [ST_F_BIN] = IST("bytes_in_total"),
556 [ST_F_BOUT] = IST("bytes_out_total"),
557 [ST_F_DREQ] = IST("requests_denied_total"),
558 [ST_F_DRESP] = IST("responses_denied_total"),
559 [ST_F_EREQ] = IST("request_errors_total"),
560 [ST_F_ECON] = IST("connection_errors_total"),
561 [ST_F_ERESP] = IST("response_errors_total"),
562 [ST_F_WRETR] = IST("retry_warnings_total"),
563 [ST_F_WREDIS] = IST("redispatch_warnings_total"),
564 [ST_F_STATUS] = IST("status"),
565 [ST_F_WEIGHT] = IST("weight"),
566 [ST_F_ACT] = IST("active_servers"),
567 [ST_F_BCK] = IST("backup_servers"),
568 [ST_F_CHKFAIL] = IST("check_failures_total"),
569 [ST_F_CHKDOWN] = IST("check_up_down_total"),
570 [ST_F_LASTCHG] = IST("check_last_change_seconds"),
571 [ST_F_DOWNTIME] = IST("downtime_seconds_total"),
572 [ST_F_QLIMIT] = IST("queue_limit"),
573 [ST_F_PID] = IST("pid"),
574 [ST_F_IID] = IST("proxy_id"),
575 [ST_F_SID] = IST("server_id"),
576 [ST_F_THROTTLE] = IST("current_throttle"),
577 [ST_F_LBTOT] = IST("loadbalanced_total"),
578 [ST_F_TRACKED] = IST("tracked"),
579 [ST_F_TYPE] = IST("type"),
580 [ST_F_RATE] = IST("current_session_rate"),
581 [ST_F_RATE_LIM] = IST("limit_session_rate"),
582 [ST_F_RATE_MAX] = IST("max_session_rate"),
583 [ST_F_CHECK_STATUS] = IST("check_status"),
584 [ST_F_CHECK_CODE] = IST("check_code"),
Christopher Faulet2711e512020-02-27 16:12:07 +0100585 [ST_F_CHECK_DURATION] = IST("check_duration_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100586 [ST_F_HRSP_1XX] = IST("http_responses_total"),
587 [ST_F_HRSP_2XX] = IST("http_responses_total"),
588 [ST_F_HRSP_3XX] = IST("http_responses_total"),
589 [ST_F_HRSP_4XX] = IST("http_responses_total"),
590 [ST_F_HRSP_5XX] = IST("http_responses_total"),
591 [ST_F_HRSP_OTHER] = IST("http_responses_total"),
592 [ST_F_HANAFAIL] = IST("check_analyses_failures_total"),
593 [ST_F_REQ_RATE] = IST("http_requests_rate_current"),
594 [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"),
595 [ST_F_REQ_TOT] = IST("http_requests_total"),
596 [ST_F_CLI_ABRT] = IST("client_aborts_total"),
597 [ST_F_SRV_ABRT] = IST("server_aborts_total"),
598 [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"),
599 [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"),
600 [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"),
601 [ST_F_COMP_RSP] = IST("http_comp_responses_total"),
602 [ST_F_LASTSESS] = IST("last_session_seconds"),
603 [ST_F_LAST_CHK] = IST("check_last_content"),
604 [ST_F_LAST_AGT] = IST("agentcheck_last_content"),
Christopher Faulet68b69682019-11-08 15:12:29 +0100605 [ST_F_QTIME] = IST("queue_time_average_seconds"),
606 [ST_F_CTIME] = IST("connect_time_average_seconds"),
607 [ST_F_RTIME] = IST("response_time_average_seconds"),
608 [ST_F_TTIME] = IST("total_time_average_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100609 [ST_F_AGENT_STATUS] = IST("agentcheck_status"),
610 [ST_F_AGENT_CODE] = IST("agentcheck_code"),
611 [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"),
612 [ST_F_CHECK_DESC] = IST("check_description"),
613 [ST_F_AGENT_DESC] = IST("agentcheck_description"),
614 [ST_F_CHECK_RISE] = IST("check_rise"),
615 [ST_F_CHECK_FALL] = IST("check_fall"),
616 [ST_F_CHECK_HEALTH] = IST("check_value"),
617 [ST_F_AGENT_RISE] = IST("agentcheck_rise"),
618 [ST_F_AGENT_FALL] = IST("agentcheck_fall"),
619 [ST_F_AGENT_HEALTH] = IST("agentcheck_value"),
620 [ST_F_ADDR] = IST("address"),
621 [ST_F_COOKIE] = IST("cookie"),
622 [ST_F_MODE] = IST("mode"),
623 [ST_F_ALGO] = IST("loadbalance_algorithm"),
624 [ST_F_CONN_RATE] = IST("connections_rate_current"),
625 [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"),
626 [ST_F_CONN_TOT] = IST("connections_total"),
627 [ST_F_INTERCEPTED] = IST("intercepted_requests_total"),
628 [ST_F_DCON] = IST("denied_connections_total"),
629 [ST_F_DSES] = IST("denied_sessions_total"),
630 [ST_F_WREW] = IST("failed_header_rewriting_total"),
631 [ST_F_CONNECT] = IST("connection_attempts_total"),
632 [ST_F_REUSE] = IST("connection_reuses_total"),
633 [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"),
634 [ST_F_CACHE_HITS] = IST("http_cache_hits_total"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200635 [ST_F_SRV_ICUR] = IST("idle_connections_current"),
636 [ST_F_SRV_ILIM] = IST("idle_connections_limit"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100637 [ST_F_QT_MAX] = IST("max_queue_time_seconds"),
638 [ST_F_CT_MAX] = IST("max_connect_time_seconds"),
639 [ST_F_RT_MAX] = IST("max_response_time_seconds"),
640 [ST_F_TT_MAX] = IST("max_total_time_seconds"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100641 [ST_F_EINT] = IST("internal_errors_total"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200642 [ST_F_IDLE_CONN_CUR] = IST("unsafe_idle_connections_current"),
643 [ST_F_SAFE_CONN_CUR] = IST("safe_idle_connections_current"),
644 [ST_F_USED_CONN_CUR] = IST("used_connections_current"),
645 [ST_F_NEED_CONN_EST] = IST("need_connections_current"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100646};
647
Christopher Fauletf959d082019-02-07 15:38:42 +0100648/* Description of all stats fields */
649const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
650 [ST_F_PXNAME] = IST("The proxy name."),
651 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
652 [ST_F_QCUR] = IST("Current number of queued requests."),
653 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
654 [ST_F_SCUR] = IST("Current number of active sessions."),
655 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
656 [ST_F_SLIM] = IST("Configured session limit."),
657 [ST_F_STOT] = IST("Total number of sessions."),
658 [ST_F_BIN] = IST("Current total of incoming bytes."),
659 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
660 [ST_F_DREQ] = IST("Total number of denied requests."),
661 [ST_F_DRESP] = IST("Total number of denied responses."),
662 [ST_F_EREQ] = IST("Total number of request errors."),
663 [ST_F_ECON] = IST("Total number of connection errors."),
664 [ST_F_ERESP] = IST("Total number of response errors."),
665 [ST_F_WRETR] = IST("Total number of retry warnings."),
666 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Willy Tarreau6b3bf732020-09-24 07:35:46 +0200667 [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 +0100668 [ST_F_WEIGHT] = IST("Service weight."),
669 [ST_F_ACT] = IST("Current number of active servers."),
670 [ST_F_BCK] = IST("Current number of backup servers."),
671 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
672 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
673 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
674 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
675 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
676 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
677 [ST_F_IID] = IST("Unique proxy id."),
678 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
679 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
680 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
681 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
682 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
683 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
684 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
685 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
Christopher Fauletcf403f32019-11-21 14:35:46 +0100686 [ST_F_CHECK_STATUS] = IST("Status of last health check (HCHK_STATUS_* values)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100687 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
Christopher Faulet2711e512020-02-27 16:12:07 +0100688 [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100689 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
690 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
691 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
692 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
693 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
694 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
695 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
696 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
697 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
698 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
699 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
700 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
701 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
702 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
703 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
704 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
705 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
706 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
707 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
708 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
709 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
710 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
711 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
712 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
713 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
714 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
715 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
716 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
717 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
718 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
719 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
720 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
721 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
722 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
723 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
724 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
725 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
726 [ST_F_ALGO] = IST("Load balancing algorithm."),
727 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
728 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
729 [ST_F_CONN_TOT] = IST("Total number of connections."),
730 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
731 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
732 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
733 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
734 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
735 [ST_F_REUSE] = IST("Total number of connection reuses."),
736 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
737 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100738 [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"),
739 [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100740 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
741 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
742 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
743 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100744 [ST_F_EINT] = IST("Total number of internal errors."),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200745 [ST_F_IDLE_CONN_CUR] = IST("Current number of unsafe idle connections."),
746 [ST_F_SAFE_CONN_CUR] = IST("Current number of safe idle connections."),
747 [ST_F_USED_CONN_CUR] = IST("Current number of connections in use."),
748 [ST_F_NEED_CONN_EST] = IST("Estimated needed number of connections."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100749};
750
751/* Specific labels for all info fields. Empty by default. */
752const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
753 [INF_NAME] = IST(""),
754 [INF_VERSION] = IST(""),
755 [INF_RELEASE_DATE] = IST(""),
William Dauchy5a982a72021-01-08 13:18:06 +0100756 [INF_BUILD_INFO] = IST(PROMEX_BUILDINFO_LABEL),
Christopher Fauletf959d082019-02-07 15:38:42 +0100757 [INF_NBTHREAD] = IST(""),
758 [INF_NBPROC] = IST(""),
759 [INF_PROCESS_NUM] = IST(""),
760 [INF_PID] = IST(""),
761 [INF_UPTIME] = IST(""),
762 [INF_UPTIME_SEC] = IST(""),
William Dauchydefd1562021-01-15 22:41:38 +0100763 [INF_START_TIME_SEC] = IST(""),
William Dauchya8766cf2021-01-15 22:41:37 +0100764 [INF_MEMMAX_BYTES] = IST(""),
765 [INF_POOL_ALLOC_BYTES] = IST(""),
766 [INF_POOL_USED_BYTES] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100767 [INF_POOL_FAILED] = IST(""),
768 [INF_ULIMIT_N] = IST(""),
769 [INF_MAXSOCK] = IST(""),
770 [INF_MAXCONN] = IST(""),
771 [INF_HARD_MAXCONN] = IST(""),
772 [INF_CURR_CONN] = IST(""),
773 [INF_CUM_CONN] = IST(""),
774 [INF_CUM_REQ] = IST(""),
775 [INF_MAX_SSL_CONNS] = IST(""),
776 [INF_CURR_SSL_CONNS] = IST(""),
777 [INF_CUM_SSL_CONNS] = IST(""),
778 [INF_MAXPIPES] = IST(""),
779 [INF_PIPES_USED] = IST(""),
780 [INF_PIPES_FREE] = IST(""),
781 [INF_CONN_RATE] = IST(""),
782 [INF_CONN_RATE_LIMIT] = IST(""),
783 [INF_MAX_CONN_RATE] = IST(""),
784 [INF_SESS_RATE] = IST(""),
785 [INF_SESS_RATE_LIMIT] = IST(""),
786 [INF_MAX_SESS_RATE] = IST(""),
787 [INF_SSL_RATE] = IST(""),
788 [INF_SSL_RATE_LIMIT] = IST(""),
789 [INF_MAX_SSL_RATE] = IST(""),
790 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
791 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
792 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
793 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
794 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
795 [INF_SSL_CACHE_LOOKUPS] = IST(""),
796 [INF_SSL_CACHE_MISSES] = IST(""),
797 [INF_COMPRESS_BPS_IN] = IST(""),
798 [INF_COMPRESS_BPS_OUT] = IST(""),
799 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
800 [INF_ZLIB_MEM_USAGE] = IST(""),
801 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
802 [INF_TASKS] = IST(""),
803 [INF_RUN_QUEUE] = IST(""),
804 [INF_IDLE_PCT] = IST(""),
805 [INF_NODE] = IST(""),
806 [INF_DESCRIPTION] = IST(""),
807 [INF_STOPPING] = IST(""),
808 [INF_JOBS] = IST(""),
809 [INF_UNSTOPPABLE_JOBS] = IST(""),
810 [INF_LISTENERS] = IST(""),
811 [INF_ACTIVE_PEERS] = IST(""),
812 [INF_CONNECTED_PEERS] = IST(""),
813 [INF_DROPPED_LOGS] = IST(""),
814 [INF_BUSY_POLLING] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200815 [INF_FAILED_RESOLUTIONS] = IST(""),
816 [INF_TOTAL_BYTES_OUT] = IST(""),
817 [INF_TOTAL_SPLICED_BYTES_OUT] = IST(""),
818 [INF_BYTES_OUT_RATE] = IST(""),
819 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100820};
821
822/* Specific labels for all stats fields. Empty by default. */
823const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
824 [ST_F_PXNAME] = IST(""),
825 [ST_F_SVNAME] = IST(""),
826 [ST_F_QCUR] = IST(""),
827 [ST_F_QMAX] = IST(""),
828 [ST_F_SCUR] = IST(""),
829 [ST_F_SMAX] = IST(""),
830 [ST_F_SLIM] = IST(""),
831 [ST_F_STOT] = IST(""),
832 [ST_F_BIN] = IST(""),
833 [ST_F_BOUT] = IST(""),
834 [ST_F_DREQ] = IST(""),
835 [ST_F_DRESP] = IST(""),
836 [ST_F_EREQ] = IST(""),
837 [ST_F_ECON] = IST(""),
838 [ST_F_ERESP] = IST(""),
839 [ST_F_WRETR] = IST(""),
840 [ST_F_WREDIS] = IST(""),
841 [ST_F_STATUS] = IST(""),
842 [ST_F_WEIGHT] = IST(""),
843 [ST_F_ACT] = IST(""),
844 [ST_F_BCK] = IST(""),
845 [ST_F_CHKFAIL] = IST(""),
846 [ST_F_CHKDOWN] = IST(""),
847 [ST_F_LASTCHG] = IST(""),
848 [ST_F_DOWNTIME] = IST(""),
849 [ST_F_QLIMIT] = IST(""),
850 [ST_F_PID] = IST(""),
851 [ST_F_IID] = IST(""),
852 [ST_F_SID] = IST(""),
853 [ST_F_THROTTLE] = IST(""),
854 [ST_F_LBTOT] = IST(""),
855 [ST_F_TRACKED] = IST(""),
856 [ST_F_TYPE] = IST(""),
857 [ST_F_RATE] = IST(""),
858 [ST_F_RATE_LIM] = IST(""),
859 [ST_F_RATE_MAX] = IST(""),
860 [ST_F_CHECK_STATUS] = IST(""),
861 [ST_F_CHECK_CODE] = IST(""),
862 [ST_F_CHECK_DURATION] = IST(""),
863 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
864 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
865 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
866 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
867 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
868 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
869 [ST_F_HANAFAIL] = IST(""),
870 [ST_F_REQ_RATE] = IST(""),
871 [ST_F_REQ_RATE_MAX] = IST(""),
872 [ST_F_REQ_TOT] = IST(""),
873 [ST_F_CLI_ABRT] = IST(""),
874 [ST_F_SRV_ABRT] = IST(""),
875 [ST_F_COMP_IN] = IST(""),
876 [ST_F_COMP_OUT] = IST(""),
877 [ST_F_COMP_BYP] = IST(""),
878 [ST_F_COMP_RSP] = IST(""),
879 [ST_F_LASTSESS] = IST(""),
880 [ST_F_LAST_CHK] = IST(""),
881 [ST_F_LAST_AGT] = IST(""),
882 [ST_F_QTIME] = IST(""),
883 [ST_F_CTIME] = IST(""),
884 [ST_F_RTIME] = IST(""),
885 [ST_F_TTIME] = IST(""),
886 [ST_F_AGENT_STATUS] = IST(""),
887 [ST_F_AGENT_CODE] = IST(""),
888 [ST_F_AGENT_DURATION] = IST(""),
889 [ST_F_CHECK_DESC] = IST(""),
890 [ST_F_AGENT_DESC] = IST(""),
891 [ST_F_CHECK_RISE] = IST(""),
892 [ST_F_CHECK_FALL] = IST(""),
893 [ST_F_CHECK_HEALTH] = IST(""),
894 [ST_F_AGENT_RISE] = IST(""),
895 [ST_F_AGENT_FALL] = IST(""),
896 [ST_F_AGENT_HEALTH] = IST(""),
897 [ST_F_ADDR] = IST(""),
898 [ST_F_COOKIE] = IST(""),
899 [ST_F_MODE] = IST(""),
900 [ST_F_ALGO] = IST(""),
901 [ST_F_CONN_RATE] = IST(""),
902 [ST_F_CONN_RATE_MAX] = IST(""),
903 [ST_F_CONN_TOT] = IST(""),
904 [ST_F_INTERCEPTED] = IST(""),
905 [ST_F_DCON] = IST(""),
906 [ST_F_DSES] = IST(""),
907 [ST_F_WREW] = IST(""),
908 [ST_F_CONNECT] = IST(""),
909 [ST_F_REUSE] = IST(""),
910 [ST_F_CACHE_LOOKUPS] = IST(""),
911 [ST_F_CACHE_HITS] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200912 [ST_F_IDLE_CONN_CUR] = IST(""),
913 [ST_F_SAFE_CONN_CUR] = IST(""),
914 [ST_F_USED_CONN_CUR] = IST(""),
915 [ST_F_NEED_CONN_EST] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100916};
917
918/* Type for all info fields. "untyped" is used for unsupported field. */
919const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
920 [INF_NAME] = IST("untyped"),
921 [INF_VERSION] = IST("untyped"),
922 [INF_RELEASE_DATE] = IST("untyped"),
William Dauchy5a982a72021-01-08 13:18:06 +0100923 [INF_BUILD_INFO] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200924 [INF_NBTHREAD] = IST("gauge"),
925 [INF_NBPROC] = IST("gauge"),
926 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100927 [INF_PID] = IST("untyped"),
928 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200929 [INF_UPTIME_SEC] = IST("gauge"),
William Dauchydefd1562021-01-15 22:41:38 +0100930 [INF_START_TIME_SEC] = IST("gauge"),
William Dauchya8766cf2021-01-15 22:41:37 +0100931 [INF_MEMMAX_BYTES] = IST("gauge"),
932 [INF_POOL_ALLOC_BYTES] = IST("gauge"),
933 [INF_POOL_USED_BYTES] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100934 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200935 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100936 [INF_MAXSOCK] = IST("gauge"),
937 [INF_MAXCONN] = IST("gauge"),
938 [INF_HARD_MAXCONN] = IST("gauge"),
939 [INF_CURR_CONN] = IST("gauge"),
940 [INF_CUM_CONN] = IST("counter"),
941 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200942 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100943 [INF_CURR_SSL_CONNS] = IST("gauge"),
944 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200945 [INF_MAXPIPES] = IST("gauge"),
946 [INF_PIPES_USED] = IST("counter"),
947 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100948 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200949 [INF_CONN_RATE_LIMIT] = IST("gauge"),
950 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100951 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200952 [INF_SESS_RATE_LIMIT] = IST("gauge"),
953 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100954 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200955 [INF_SSL_RATE_LIMIT] = IST("gauge"),
956 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100957 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200958 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100959 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
960 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200961 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100962 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
963 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200964 [INF_COMPRESS_BPS_IN] = IST("counter"),
965 [INF_COMPRESS_BPS_OUT] = IST("counter"),
966 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100967 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200968 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100969 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +0200970 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100971 [INF_IDLE_PCT] = IST("gauge"),
972 [INF_NODE] = IST("untyped"),
973 [INF_DESCRIPTION] = IST("untyped"),
974 [INF_STOPPING] = IST("gauge"),
975 [INF_JOBS] = IST("gauge"),
976 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
977 [INF_LISTENERS] = IST("gauge"),
978 [INF_ACTIVE_PEERS] = IST("gauge"),
979 [INF_CONNECTED_PEERS] = IST("gauge"),
980 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200981 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200982 [INF_FAILED_RESOLUTIONS] = IST("counter"),
983 [INF_TOTAL_BYTES_OUT] = IST("counter"),
984 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("counter"),
985 [INF_BYTES_OUT_RATE] = IST("gauge"),
986 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100987};
988
989/* Type for all stats fields. "untyped" is used for unsupported field. */
990const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
991 [ST_F_PXNAME] = IST("untyped"),
992 [ST_F_SVNAME] = IST("untyped"),
993 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200994 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100995 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200996 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100997 [ST_F_SLIM] = IST("gauge"),
998 [ST_F_STOT] = IST("counter"),
999 [ST_F_BIN] = IST("counter"),
1000 [ST_F_BOUT] = IST("counter"),
1001 [ST_F_DREQ] = IST("counter"),
1002 [ST_F_DRESP] = IST("counter"),
1003 [ST_F_EREQ] = IST("counter"),
1004 [ST_F_ECON] = IST("counter"),
1005 [ST_F_ERESP] = IST("counter"),
1006 [ST_F_WRETR] = IST("counter"),
1007 [ST_F_WREDIS] = IST("counter"),
1008 [ST_F_STATUS] = IST("gauge"),
1009 [ST_F_WEIGHT] = IST("gauge"),
1010 [ST_F_ACT] = IST("gauge"),
1011 [ST_F_BCK] = IST("gauge"),
1012 [ST_F_CHKFAIL] = IST("counter"),
1013 [ST_F_CHKDOWN] = IST("counter"),
1014 [ST_F_LASTCHG] = IST("gauge"),
1015 [ST_F_DOWNTIME] = IST("counter"),
1016 [ST_F_QLIMIT] = IST("gauge"),
1017 [ST_F_PID] = IST("untyped"),
1018 [ST_F_IID] = IST("untyped"),
1019 [ST_F_SID] = IST("untyped"),
1020 [ST_F_THROTTLE] = IST("gauge"),
1021 [ST_F_LBTOT] = IST("counter"),
1022 [ST_F_TRACKED] = IST("untyped"),
1023 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001024 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001025 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001026 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Fauletcf403f32019-11-21 14:35:46 +01001027 [ST_F_CHECK_STATUS] = IST("gauge"),
1028 [ST_F_CHECK_CODE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001029 [ST_F_CHECK_DURATION] = IST("gauge"),
1030 [ST_F_HRSP_1XX] = IST("counter"),
1031 [ST_F_HRSP_2XX] = IST("counter"),
1032 [ST_F_HRSP_3XX] = IST("counter"),
1033 [ST_F_HRSP_4XX] = IST("counter"),
1034 [ST_F_HRSP_5XX] = IST("counter"),
1035 [ST_F_HRSP_OTHER] = IST("counter"),
1036 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001037 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001038 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001039 [ST_F_REQ_TOT] = IST("counter"),
1040 [ST_F_CLI_ABRT] = IST("counter"),
1041 [ST_F_SRV_ABRT] = IST("counter"),
1042 [ST_F_COMP_IN] = IST("counter"),
1043 [ST_F_COMP_OUT] = IST("counter"),
1044 [ST_F_COMP_BYP] = IST("counter"),
1045 [ST_F_COMP_RSP] = IST("counter"),
1046 [ST_F_LASTSESS] = IST("gauge"),
1047 [ST_F_LAST_CHK] = IST("untyped"),
1048 [ST_F_LAST_AGT] = IST("untyped"),
1049 [ST_F_QTIME] = IST("gauge"),
1050 [ST_F_CTIME] = IST("gauge"),
1051 [ST_F_RTIME] = IST("gauge"),
1052 [ST_F_TTIME] = IST("gauge"),
1053 [ST_F_AGENT_STATUS] = IST("untyped"),
1054 [ST_F_AGENT_CODE] = IST("untyped"),
1055 [ST_F_AGENT_DURATION] = IST("gauge"),
1056 [ST_F_CHECK_DESC] = IST("untyped"),
1057 [ST_F_AGENT_DESC] = IST("untyped"),
1058 [ST_F_CHECK_RISE] = IST("gauge"),
1059 [ST_F_CHECK_FALL] = IST("gauge"),
1060 [ST_F_CHECK_HEALTH] = IST("gauge"),
1061 [ST_F_AGENT_RISE] = IST("gauge"),
1062 [ST_F_AGENT_FALL] = IST("gauge"),
1063 [ST_F_AGENT_HEALTH] = IST("gauge"),
1064 [ST_F_ADDR] = IST("untyped"),
1065 [ST_F_COOKIE] = IST("untyped"),
1066 [ST_F_MODE] = IST("untyped"),
1067 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001068 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001069 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001070 [ST_F_CONN_TOT] = IST("counter"),
1071 [ST_F_INTERCEPTED] = IST("counter"),
1072 [ST_F_DCON] = IST("counter"),
1073 [ST_F_DSES] = IST("counter"),
1074 [ST_F_WREW] = IST("counter"),
1075 [ST_F_CONNECT] = IST("counter"),
1076 [ST_F_REUSE] = IST("counter"),
1077 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1078 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Faulet20ab80c2019-11-08 15:24:32 +01001079 [ST_F_SRV_ICUR] = IST("gauge"),
1080 [ST_F_SRV_ILIM] = IST("gauge"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001081 [ST_F_QT_MAX] = IST("gauge"),
1082 [ST_F_CT_MAX] = IST("gauge"),
1083 [ST_F_RT_MAX] = IST("gauge"),
1084 [ST_F_TT_MAX] = IST("gauge"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001085 [ST_F_EINT] = IST("counter"),
Christopher Fauletc55a6262020-07-10 15:39:39 +02001086 [ST_F_IDLE_CONN_CUR] = IST("gauge"),
1087 [ST_F_SAFE_CONN_CUR] = IST("gauge"),
1088 [ST_F_USED_CONN_CUR] = IST("gauge"),
1089 [ST_F_NEED_CONN_EST] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001090};
1091
Christopher Fauletd45d1052019-09-06 16:10:19 +02001092/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001093static int promex_srv_status(struct server *sv)
1094{
Christopher Fauletf959d082019-02-07 15:38:42 +01001095 int state = 0;
1096
Christopher Fauletf959d082019-02-07 15:38:42 +01001097 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1098 state = 1;
1099 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Fauletd45d1052019-09-06 16:10:19 +02001100 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001101 }
Christopher Fauletd45d1052019-09-06 16:10:19 +02001102 else if (sv->cur_state == SRV_ST_STOPPING)
1103 state = 4;
1104
1105 if (sv->cur_admin & SRV_ADMF_MAINT)
1106 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001107
1108 return state;
1109}
1110
1111/* Convert a field to its string representation and write it in <out>, followed
1112 * by a newline, if there is enough space. non-numeric value are converted in
1113 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1114 * to process this kind of value). It returns 1 on success. Otherwise, it
1115 * returns 0. The buffer's length must not exceed <max> value.
1116 */
1117static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1118{
1119 int ret = 0;
1120
1121 switch (field_format(f, 0)) {
1122 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1123 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1124 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1125 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1126 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001127 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001128 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1129 default: ret = chunk_strcat(out, "Nan\n"); break;
1130 }
1131 if (!ret || out->data > max)
1132 return 0;
1133 return 1;
1134}
1135
1136/* Concatenate the <prefix> with the field name using the array
1137 * <promex_st_metric_names> and store it in <name>. The field type is in
1138 * <appctx->st2>. This function never fails but relies on
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001139 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enough to be copied in
Christopher Fauletf959d082019-02-07 15:38:42 +01001140 * <name>
1141 */
1142static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1143{
1144 const struct ist *names;
1145
1146 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1147 ? promex_inf_metric_names
1148 : promex_st_metric_names);
1149
1150 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1151 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1152}
1153
1154/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1155 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1156 */
1157static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1158 const struct ist name, struct ist *out, size_t max)
1159{
1160 const struct ist *desc, *types;
1161
William Dauchya191b772021-01-15 22:41:39 +01001162 if (istcat(out, ist("# HELP "), max) == -1 ||
1163 istcat(out, name, max) == -1 ||
1164 istcat(out, ist(" "), max) == -1)
1165 goto full;
1166
Christopher Fauletf959d082019-02-07 15:38:42 +01001167 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
Christopher Fauletf959d082019-02-07 15:38:42 +01001168 types = promex_inf_metric_types;
William Dauchya191b772021-01-15 22:41:39 +01001169
1170 if (istcat(out, ist(info_fields[appctx->st2].desc), max) == -1)
1171 goto full;
Christopher Fauletf959d082019-02-07 15:38:42 +01001172 }
1173 else {
1174 desc = promex_st_metric_desc;
1175 types = promex_st_metric_types;
William Dauchya191b772021-01-15 22:41:39 +01001176
1177 if (istcat(out, desc[appctx->st2], max) == -1)
1178 goto full;
Christopher Fauletf959d082019-02-07 15:38:42 +01001179 }
1180
William Dauchya191b772021-01-15 22:41:39 +01001181 if (istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001182 istcat(out, name, max) == -1 ||
1183 istcat(out, ist(" "), max) == -1 ||
1184 istcat(out, types[appctx->st2], max) == -1 ||
1185 istcat(out, ist("\n"), max) == -1)
1186 goto full;
1187
1188 return 1;
1189
1190 full:
1191 return 0;
1192}
1193
1194/* Dump the line for <metric>. It starts by the metric name followed by its
1195 * labels (proxy name, server name...) between braces and finally its value. If
1196 * not already done, the header lines are dumped first. It returns 1 on
1197 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1198 */
1199static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1200 const struct ist prefix, struct field *metric,
1201 struct ist *out, size_t max)
1202{
1203 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1204 size_t len = out->len;
1205
1206 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1207 return 0;
1208
1209 promex_metric_name(appctx, &name, prefix);
1210 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1211 !promex_dump_metric_header(appctx, htx, name, out, max))
1212 goto full;
1213
1214 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1215 const struct ist label = promex_inf_metric_labels[appctx->st2];
1216
1217 if (istcat(out, name, max) == -1 ||
1218 (label.len && istcat(out, ist("{"), max) == -1) ||
1219 (label.len && istcat(out, label, max) == -1) ||
1220 (label.len && istcat(out, ist("}"), max) == -1) ||
1221 istcat(out, ist(" "), max) == -1)
1222 goto full;
1223 }
1224 else {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001225 struct proxy *px = appctx->ctx.stats.obj1;
1226 struct server *srv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001227 const struct ist label = promex_st_metric_labels[appctx->st2];
1228
1229 if (istcat(out, name, max) == -1 ||
1230 istcat(out, ist("{proxy=\""), max) == -1 ||
1231 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1232 istcat(out, ist("\""), max) == -1 ||
1233 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1234 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1235 (srv && istcat(out, ist("\""), max) == -1) ||
1236 (label.len && istcat(out, ist(","), max) == -1) ||
1237 (label.len && istcat(out, label, max) == -1) ||
1238 istcat(out, ist("} "), max) == -1)
1239 goto full;
1240 }
1241
1242 trash.data = out->len;
1243 if (!promex_metric_to_str(&trash, metric, max))
1244 goto full;
1245 out->len = trash.data;
1246
1247 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1248 return 1;
1249 full:
1250 // Restore previous length
1251 out->len = len;
1252 return 0;
1253
1254}
1255
1256
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001257/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001258 * 0 if <htx> is full and -1 in case of any error. */
1259static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1260{
1261 static struct ist prefix = IST("haproxy_process_");
1262 struct field metric;
1263 struct channel *chn = si_ic(appctx->owner);
1264 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001265 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001266 int ret = 1;
1267
William Dauchy5d9b8f32021-01-11 20:07:49 +01001268 if (!stats_fill_info(info, INF_TOTAL_FIELDS))
1269 return -1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001270
Christopher Fauletf959d082019-02-07 15:38:42 +01001271 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1272 switch (appctx->st2) {
William Dauchy5a982a72021-01-08 13:18:06 +01001273 case INF_BUILD_INFO:
1274 metric = mkf_u32(FN_GAUGE, 1);
1275 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001276
1277 default:
William Dauchy5d9b8f32021-01-11 20:07:49 +01001278 metric = info[appctx->st2];
Christopher Fauletf959d082019-02-07 15:38:42 +01001279 }
1280
1281 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1282 goto full;
1283
Christopher Fauletf959d082019-02-07 15:38:42 +01001284 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1285 appctx->st2 = promex_global_metrics[appctx->st2];
1286 }
1287
1288 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001289 if (out.len) {
1290 if (!htx_add_data_atonce(htx, out))
1291 return -1; /* Unexpected and unrecoverable error */
1292 channel_add_input(chn, out.len);
1293 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001294 return ret;
1295 full:
1296 ret = 0;
1297 goto end;
1298}
1299
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001300/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001301 * 0 if <htx> is full and -1 in case of any error. */
1302static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1303{
1304 static struct ist prefix = IST("haproxy_frontend_");
1305 struct proxy *px;
1306 struct field metric;
1307 struct channel *chn = si_ic(appctx->owner);
1308 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001309 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
William Dauchyb9577452021-01-17 18:27:46 +01001310 struct field *stats = stat_l[STATS_DOMAIN_PROXY];
Christopher Fauletf959d082019-02-07 15:38:42 +01001311 int ret = 1;
1312
1313 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001314 while (appctx->ctx.stats.obj1) {
1315 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001316
1317 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001318 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001319 goto next_px;
1320
William Dauchyb9577452021-01-17 18:27:46 +01001321 if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS, &(appctx->st2)))
1322 return -1;
1323
Christopher Fauletf959d082019-02-07 15:38:42 +01001324 switch (appctx->st2) {
1325 case ST_F_STATUS:
Willy Tarreauc3914d42020-09-24 08:39:22 +02001326 metric = mkf_u32(FO_STATUS, !px->disabled);
Christopher Fauletf959d082019-02-07 15:38:42 +01001327 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001328 case ST_F_REQ_RATE_MAX:
Christopher Fauletf959d082019-02-07 15:38:42 +01001329 case ST_F_REQ_TOT:
Christopher Fauletf959d082019-02-07 15:38:42 +01001330 case ST_F_HRSP_1XX:
Christopher Fauletf959d082019-02-07 15:38:42 +01001331 case ST_F_INTERCEPTED:
Christopher Fauletf959d082019-02-07 15:38:42 +01001332 case ST_F_CACHE_LOOKUPS:
Christopher Fauletf959d082019-02-07 15:38:42 +01001333 case ST_F_CACHE_HITS:
Christopher Fauletf959d082019-02-07 15:38:42 +01001334 case ST_F_COMP_IN:
Christopher Fauletf959d082019-02-07 15:38:42 +01001335 case ST_F_COMP_OUT:
Christopher Fauletf959d082019-02-07 15:38:42 +01001336 case ST_F_COMP_BYP:
William Dauchyb9577452021-01-17 18:27:46 +01001337 case ST_F_COMP_RSP:
Christopher Fauletf959d082019-02-07 15:38:42 +01001338 if (px->mode != PR_MODE_HTTP)
1339 goto next_px;
William Dauchyb9577452021-01-17 18:27:46 +01001340 metric = stats[appctx->st2];
Christopher Fauletf959d082019-02-07 15:38:42 +01001341 break;
William Dauchyb9577452021-01-17 18:27:46 +01001342 case ST_F_HRSP_2XX:
1343 case ST_F_HRSP_3XX:
1344 case ST_F_HRSP_4XX:
1345 case ST_F_HRSP_5XX:
1346 case ST_F_HRSP_OTHER:
Christopher Fauletf959d082019-02-07 15:38:42 +01001347 if (px->mode != PR_MODE_HTTP)
1348 goto next_px;
William Dauchyb9577452021-01-17 18:27:46 +01001349 metric = stats[appctx->st2];
1350 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01001351 break;
1352
1353 default:
William Dauchyb9577452021-01-17 18:27:46 +01001354 metric = stats[appctx->st2];
Christopher Fauletf959d082019-02-07 15:38:42 +01001355 }
1356
1357 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1358 goto full;
1359 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001360 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001361 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001362 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001363 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001364 appctx->st2 = promex_front_metrics[appctx->st2];
1365 }
1366
1367 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001368 if (out.len) {
1369 if (!htx_add_data_atonce(htx, out))
1370 return -1; /* Unexpected and unrecoverable error */
1371 channel_add_input(chn, out.len);
1372 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001373 return ret;
1374 full:
1375 ret = 0;
1376 goto end;
1377}
1378
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001379/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001380 * 0 if <htx> is full and -1 in case of any error. */
1381static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1382{
1383 static struct ist prefix = IST("haproxy_backend_");
1384 struct proxy *px;
1385 struct field metric;
1386 struct channel *chn = si_ic(appctx->owner);
1387 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001388 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001389 int ret = 1;
1390 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001391 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001392
1393 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001394 while (appctx->ctx.stats.obj1) {
1395 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001396
1397 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001398 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001399 goto next_px;
1400
1401 switch (appctx->st2) {
1402 case ST_F_STATUS:
1403 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1404 break;
1405 case ST_F_SCUR:
1406 metric = mkf_u32(0, px->beconn);
1407 break;
1408 case ST_F_SMAX:
1409 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1410 break;
1411 case ST_F_SLIM:
1412 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1413 break;
1414 case ST_F_STOT:
1415 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1416 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001417 case ST_F_RATE_MAX:
1418 metric = mkf_u32(0, px->be_counters.sps_max);
1419 break;
1420 case ST_F_LASTSESS:
1421 metric = mkf_s32(FN_AGE, be_lastsession(px));
1422 break;
1423 case ST_F_QCUR:
1424 metric = mkf_u32(0, px->nbpend);
1425 break;
1426 case ST_F_QMAX:
1427 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1428 break;
1429 case ST_F_CONNECT:
1430 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1431 break;
1432 case ST_F_REUSE:
1433 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1434 break;
1435 case ST_F_BIN:
1436 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1437 break;
1438 case ST_F_BOUT:
1439 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1440 break;
1441 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001442 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1443 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001444 break;
1445 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001446 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1447 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001448 break;
1449 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001450 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1451 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001452 break;
1453 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001454 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1455 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001456 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001457 case ST_F_QT_MAX:
1458 secs = (double)px->be_counters.qtime_max / 1000.0;
1459 metric = mkf_flt(FN_MAX, secs);
1460 break;
1461 case ST_F_CT_MAX:
1462 secs = (double)px->be_counters.ctime_max / 1000.0;
1463 metric = mkf_flt(FN_MAX, secs);
1464 break;
1465 case ST_F_RT_MAX:
1466 secs = (double)px->be_counters.dtime_max / 1000.0;
1467 metric = mkf_flt(FN_MAX, secs);
1468 break;
1469 case ST_F_TT_MAX:
1470 secs = (double)px->be_counters.ttime_max / 1000.0;
1471 metric = mkf_flt(FN_MAX, secs);
1472 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001473 case ST_F_DREQ:
1474 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1475 break;
1476 case ST_F_DRESP:
1477 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1478 break;
1479 case ST_F_ECON:
1480 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1481 break;
1482 case ST_F_ERESP:
1483 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1484 break;
1485 case ST_F_WRETR:
1486 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1487 break;
1488 case ST_F_WREDIS:
1489 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1490 break;
1491 case ST_F_WREW:
1492 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1493 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001494 case ST_F_EINT:
1495 metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors);
1496 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001497 case ST_F_CLI_ABRT:
1498 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1499 break;
1500 case ST_F_SRV_ABRT:
1501 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1502 break;
1503 case ST_F_WEIGHT:
1504 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1505 metric = mkf_u32(FN_AVG, weight);
1506 break;
1507 case ST_F_ACT:
1508 metric = mkf_u32(0, px->srv_act);
1509 break;
1510 case ST_F_BCK:
1511 metric = mkf_u32(0, px->srv_bck);
1512 break;
1513 case ST_F_CHKDOWN:
1514 metric = mkf_u64(FN_COUNTER, px->down_trans);
1515 break;
1516 case ST_F_LASTCHG:
1517 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1518 break;
1519 case ST_F_DOWNTIME:
1520 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1521 break;
1522 case ST_F_LBTOT:
1523 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1524 break;
1525 case ST_F_REQ_TOT:
1526 if (px->mode != PR_MODE_HTTP)
1527 goto next_px;
1528 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1529 break;
1530 case ST_F_HRSP_1XX:
1531 if (px->mode != PR_MODE_HTTP)
1532 goto next_px;
1533 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1534 break;
1535 case ST_F_HRSP_2XX:
1536 if (px->mode != PR_MODE_HTTP)
1537 goto next_px;
1538 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1539 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1540 break;
1541 case ST_F_HRSP_3XX:
1542 if (px->mode != PR_MODE_HTTP)
1543 goto next_px;
1544 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1545 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1546 break;
1547 case ST_F_HRSP_4XX:
1548 if (px->mode != PR_MODE_HTTP)
1549 goto next_px;
1550 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1551 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1552 break;
1553 case ST_F_HRSP_5XX:
1554 if (px->mode != PR_MODE_HTTP)
1555 goto next_px;
1556 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1557 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1558 break;
1559 case ST_F_HRSP_OTHER:
1560 if (px->mode != PR_MODE_HTTP)
1561 goto next_px;
1562 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1563 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1564 break;
1565 case ST_F_CACHE_LOOKUPS:
1566 if (px->mode != PR_MODE_HTTP)
1567 goto next_px;
1568 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1569 break;
1570 case ST_F_CACHE_HITS:
1571 if (px->mode != PR_MODE_HTTP)
1572 goto next_px;
1573 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1574 break;
1575 case ST_F_COMP_IN:
1576 if (px->mode != PR_MODE_HTTP)
1577 goto next_px;
1578 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1579 break;
1580 case ST_F_COMP_OUT:
1581 if (px->mode != PR_MODE_HTTP)
1582 goto next_px;
1583 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1584 break;
1585 case ST_F_COMP_BYP:
1586 if (px->mode != PR_MODE_HTTP)
1587 goto next_px;
1588 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1589 break;
1590 case ST_F_COMP_RSP:
1591 if (px->mode != PR_MODE_HTTP)
1592 goto next_px;
1593 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1594 break;
1595
1596 default:
1597 goto next_metric;
1598 }
1599
1600 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1601 goto full;
1602 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001603 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001604 }
1605 next_metric:
1606 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001607 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001608 appctx->st2 = promex_back_metrics[appctx->st2];
1609 }
1610
1611 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001612 if (out.len) {
1613 if (!htx_add_data_atonce(htx, out))
1614 return -1; /* Unexpected and unrecoverable error */
1615 channel_add_input(chn, out.len);
1616 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001617 return ret;
1618 full:
1619 ret = 0;
1620 goto end;
1621}
1622
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001623/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001624 * 0 if <htx> is full and -1 in case of any error. */
1625static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1626{
1627 static struct ist prefix = IST("haproxy_server_");
1628 struct proxy *px;
1629 struct server *sv;
1630 struct field metric;
1631 struct channel *chn = si_ic(appctx->owner);
1632 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001633 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001634 int ret = 1;
1635 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001636 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001637
1638 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001639 while (appctx->ctx.stats.obj1) {
1640 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001641
1642 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001643 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001644 goto next_px;
1645
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001646 while (appctx->ctx.stats.obj2) {
1647 sv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001648
Christopher Fauleteba22942019-11-19 14:18:24 +01001649 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1650 goto next_sv;
1651
Christopher Fauletf959d082019-02-07 15:38:42 +01001652 switch (appctx->st2) {
1653 case ST_F_STATUS:
1654 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1655 break;
1656 case ST_F_SCUR:
1657 metric = mkf_u32(0, sv->cur_sess);
1658 break;
1659 case ST_F_SMAX:
1660 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1661 break;
1662 case ST_F_SLIM:
1663 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1664 break;
1665 case ST_F_STOT:
1666 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1667 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001668 case ST_F_RATE_MAX:
1669 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1670 break;
1671 case ST_F_LASTSESS:
1672 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1673 break;
1674 case ST_F_QCUR:
1675 metric = mkf_u32(0, sv->nbpend);
1676 break;
1677 case ST_F_QMAX:
1678 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1679 break;
1680 case ST_F_QLIMIT:
1681 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1682 break;
1683 case ST_F_BIN:
1684 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1685 break;
1686 case ST_F_BOUT:
1687 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1688 break;
1689 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001690 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1691 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001692 break;
1693 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001694 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1695 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001696 break;
1697 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001698 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1699 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001700 break;
1701 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001702 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1703 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001704 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001705 case ST_F_QT_MAX:
1706 secs = (double)sv->counters.qtime_max / 1000.0;
1707 metric = mkf_flt(FN_MAX, secs);
1708 break;
1709 case ST_F_CT_MAX:
1710 secs = (double)sv->counters.ctime_max / 1000.0;
1711 metric = mkf_flt(FN_MAX, secs);
1712 break;
1713 case ST_F_RT_MAX:
1714 secs = (double)sv->counters.dtime_max / 1000.0;
1715 metric = mkf_flt(FN_MAX, secs);
1716 break;
1717 case ST_F_TT_MAX:
1718 secs = (double)sv->counters.ttime_max / 1000.0;
1719 metric = mkf_flt(FN_MAX, secs);
1720 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001721 case ST_F_CONNECT:
1722 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1723 break;
1724 case ST_F_REUSE:
1725 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1726 break;
1727 case ST_F_DRESP:
Christopher Fauleta08546b2019-12-16 16:07:34 +01001728 metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp);
Christopher Fauletf959d082019-02-07 15:38:42 +01001729 break;
1730 case ST_F_ECON:
1731 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1732 break;
1733 case ST_F_ERESP:
1734 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1735 break;
1736 case ST_F_WRETR:
1737 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
1738 break;
1739 case ST_F_WREDIS:
1740 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
1741 break;
1742 case ST_F_WREW:
1743 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
1744 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001745 case ST_F_EINT:
1746 metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors);
1747 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001748 case ST_F_CLI_ABRT:
1749 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1750 break;
1751 case ST_F_SRV_ABRT:
1752 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1753 break;
1754 case ST_F_WEIGHT:
1755 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1756 metric = mkf_u32(FN_AVG, weight);
1757 break;
Christopher Fauletcf403f32019-11-21 14:35:46 +01001758 case ST_F_CHECK_STATUS:
1759 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1760 goto next_sv;
1761 metric = mkf_u32(FN_OUTPUT, sv->check.status);
1762 break;
1763 case ST_F_CHECK_CODE:
1764 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1765 goto next_sv;
1766 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
1767 break;
Christopher Faulet2711e512020-02-27 16:12:07 +01001768 case ST_F_CHECK_DURATION:
1769 if (sv->check.status < HCHK_STATUS_CHECKED)
1770 goto next_sv;
1771 secs = (double)sv->check.duration / 1000.0;
1772 metric = mkf_flt(FN_DURATION, secs);
1773 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001774 case ST_F_CHKFAIL:
1775 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1776 break;
1777 case ST_F_CHKDOWN:
1778 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1779 break;
1780 case ST_F_DOWNTIME:
1781 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
1782 break;
1783 case ST_F_LASTCHG:
1784 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
1785 break;
1786 case ST_F_THROTTLE:
1787 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
1788 break;
1789 case ST_F_LBTOT:
1790 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1791 break;
Marcin Deranek3c27dda2020-05-15 18:32:51 +02001792 case ST_F_REQ_TOT:
1793 if (px->mode != PR_MODE_HTTP)
1794 goto next_px;
1795 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
1796 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001797 case ST_F_HRSP_1XX:
1798 if (px->mode != PR_MODE_HTTP)
1799 goto next_px;
1800 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1801 break;
1802 case ST_F_HRSP_2XX:
1803 if (px->mode != PR_MODE_HTTP)
1804 goto next_px;
1805 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1806 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1807 break;
1808 case ST_F_HRSP_3XX:
1809 if (px->mode != PR_MODE_HTTP)
1810 goto next_px;
1811 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1812 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1813 break;
1814 case ST_F_HRSP_4XX:
1815 if (px->mode != PR_MODE_HTTP)
1816 goto next_px;
1817 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1818 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1819 break;
1820 case ST_F_HRSP_5XX:
1821 if (px->mode != PR_MODE_HTTP)
1822 goto next_px;
1823 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1824 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
1825 break;
1826 case ST_F_HRSP_OTHER:
1827 if (px->mode != PR_MODE_HTTP)
1828 goto next_px;
1829 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1830 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
1831 break;
Christopher Faulet20ab80c2019-11-08 15:24:32 +01001832 case ST_F_SRV_ICUR:
1833 metric = mkf_u32(0, sv->curr_idle_conns);
1834 break;
1835 case ST_F_SRV_ILIM:
1836 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
1837 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02001838 case ST_F_IDLE_CONN_CUR:
1839 metric = mkf_u32(0, sv->curr_idle_nb);
1840 break;
1841 case ST_F_SAFE_CONN_CUR:
1842 metric = mkf_u32(0, sv->curr_safe_nb);
1843 break;
1844 case ST_F_USED_CONN_CUR:
1845 metric = mkf_u32(0, sv->curr_used_conns);
1846 break;
1847 case ST_F_NEED_CONN_EST:
1848 metric = mkf_u32(0, sv->est_need_conns);
1849 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001850
1851 default:
1852 goto next_metric;
1853 }
1854
1855 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1856 goto full;
1857
Christopher Fauleteba22942019-11-19 14:18:24 +01001858 next_sv:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001859 appctx->ctx.stats.obj2 = sv->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001860 }
1861
1862 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001863 appctx->ctx.stats.obj1 = px->next;
1864 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01001865 }
1866 next_metric:
1867 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001868 appctx->ctx.stats.obj1 = proxies_list;
1869 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01001870 appctx->st2 = promex_srv_metrics[appctx->st2];
1871 }
1872
1873
1874 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001875 if (out.len) {
1876 if (!htx_add_data_atonce(htx, out))
1877 return -1; /* Unexpected and unrecoverable error */
1878 channel_add_input(chn, out.len);
1879 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001880 return ret;
1881 full:
1882 ret = 0;
1883 goto end;
1884}
1885
1886/* Dump all metrics (global, frontends, backends and servers) depending on the
1887 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001888 * -1 in case of any error.
1889 * Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as
1890 * a pointer to the current server/listener. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001891static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
1892{
1893 int ret;
1894
1895 switch (appctx->st1) {
1896 case PROMEX_DUMPER_INIT:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001897 appctx->ctx.stats.obj1 = NULL;
1898 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02001899 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01001900 appctx->st2 = promex_global_metrics[INF_NAME];
1901 appctx->st1 = PROMEX_DUMPER_GLOBAL;
1902 /* fall through */
1903
1904 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet78407ce2019-11-18 14:47:08 +01001905 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
1906 ret = promex_dump_global_metrics(appctx, htx);
1907 if (ret <= 0) {
1908 if (ret == -1)
1909 goto error;
1910 goto full;
1911 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001912 }
1913
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001914 appctx->ctx.stats.obj1 = proxies_list;
1915 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02001916 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
1917 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01001918 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
1919 appctx->st1 = PROMEX_DUMPER_FRONT;
1920 /* fall through */
1921
1922 case PROMEX_DUMPER_FRONT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01001923 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
1924 ret = promex_dump_front_metrics(appctx, htx);
1925 if (ret <= 0) {
1926 if (ret == -1)
1927 goto error;
1928 goto full;
1929 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001930 }
1931
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001932 appctx->ctx.stats.obj1 = proxies_list;
1933 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02001934 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01001935 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
1936 appctx->st1 = PROMEX_DUMPER_BACK;
1937 /* fall through */
1938
1939 case PROMEX_DUMPER_BACK:
Christopher Faulet78407ce2019-11-18 14:47:08 +01001940 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
1941 ret = promex_dump_back_metrics(appctx, htx);
1942 if (ret <= 0) {
1943 if (ret == -1)
1944 goto error;
1945 goto full;
1946 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001947 }
1948
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001949 appctx->ctx.stats.obj1 = proxies_list;
1950 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletefde9552020-06-05 08:18:56 +02001951 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01001952 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
1953 appctx->st1 = PROMEX_DUMPER_SRV;
1954 /* fall through */
1955
1956 case PROMEX_DUMPER_SRV:
Christopher Faulet78407ce2019-11-18 14:47:08 +01001957 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
1958 ret = promex_dump_srv_metrics(appctx, htx);
1959 if (ret <= 0) {
1960 if (ret == -1)
1961 goto error;
1962 goto full;
1963 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001964 }
1965
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001966 appctx->ctx.stats.obj1 = NULL;
1967 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02001968 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01001969 appctx->st2 = 0;
1970 appctx->st1 = PROMEX_DUMPER_DONE;
1971 /* fall through */
1972
1973 case PROMEX_DUMPER_DONE:
1974 default:
1975 break;
1976 }
1977
1978 return 1;
1979
1980 full:
1981 si_rx_room_blk(si);
1982 return 0;
1983 error:
1984 /* unrecoverable error */
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001985 appctx->ctx.stats.obj1 = NULL;
1986 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletf959d082019-02-07 15:38:42 +01001987 appctx->ctx.stats.flags = 0;
1988 appctx->st2 = 0;
1989 appctx->st1 = PROMEX_DUMPER_DONE;
1990 return -1;
1991}
1992
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001993/* Parse the query string of request URI to filter the metrics. It returns 1 on
Christopher Faulet78407ce2019-11-18 14:47:08 +01001994 * success and -1 on error. */
1995static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
1996{
1997 struct channel *req = si_oc(si);
1998 struct channel *res = si_ic(si);
1999 struct htx *req_htx, *res_htx;
2000 struct htx_sl *sl;
William Dauchyc65f6562019-11-26 12:56:26 +01002001 char *p, *key, *value;
2002 const char *end;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002003 struct buffer *err;
2004 int default_scopes = PROMEX_FL_SCOPE_ALL;
2005 int len;
2006
2007 /* Get the query-string */
2008 req_htx = htxbuf(&req->buf);
2009 sl = http_get_stline(req_htx);
2010 if (!sl)
2011 goto error;
2012 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2013 if (!p)
2014 goto end;
2015 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet78407ce2019-11-18 14:47:08 +01002016
William Dauchyc65f6562019-11-26 12:56:26 +01002017 /* copy the query-string */
2018 len = end - p;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002019 chunk_reset(&trash);
2020 memcpy(trash.area, p, len);
2021 trash.area[len] = 0;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002022 p = trash.area;
William Dauchyc65f6562019-11-26 12:56:26 +01002023 end = trash.area + len;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002024
2025 /* Parse the query-string */
William Dauchyc65f6562019-11-26 12:56:26 +01002026 while (p < end && *p && *p != '#') {
2027 value = NULL;
2028
2029 /* decode parameter name */
2030 key = p;
2031 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002032 ++p;
William Dauchyc65f6562019-11-26 12:56:26 +01002033 /* found a value */
2034 if (*p == '=') {
2035 *(p++) = 0;
2036 value = p;
2037 }
2038 else if (*p == '&')
2039 *(p++) = 0;
2040 else if (*p == '#')
2041 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002042 len = url_decode(key, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002043 if (len == -1)
2044 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002045
William Dauchyc65f6562019-11-26 12:56:26 +01002046 /* decode value */
2047 if (value) {
2048 while (p < end && *p != '=' && *p != '&' && *p != '#')
2049 ++p;
2050 if (*p == '=')
2051 goto error;
2052 if (*p == '&')
2053 *(p++) = 0;
2054 else if (*p == '#')
2055 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002056 len = url_decode(value, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002057 if (len == -1)
2058 goto error;
2059 }
2060
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002061 if (strcmp(key, "scope") == 0) {
William Dauchyc65f6562019-11-26 12:56:26 +01002062 default_scopes = 0; /* at least a scope defined, unset default scopes */
2063 if (!value)
2064 goto error;
2065 else if (*value == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002066 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002067 else if (*value == '*')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002068 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002069 else if (strcmp(value, "global") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002070 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002071 else if (strcmp(value, "server") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002072 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002073 else if (strcmp(value, "backend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002074 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002075 else if (strcmp(value, "frontend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002076 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2077 else
2078 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002079 }
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002080 else if (strcmp(key, "no-maint") == 0)
Christopher Fauleteba22942019-11-19 14:18:24 +01002081 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002082 }
2083
2084 end:
2085 appctx->ctx.stats.flags |= default_scopes;
2086 return 1;
2087
2088 error:
2089 err = &http_err_chunks[HTTP_ERR_400];
2090 channel_erase(res);
2091 res->buf.data = b_data(err);
2092 memcpy(res->buf.area, b_head(err), b_data(err));
2093 res_htx = htx_from_buf(&res->buf);
2094 channel_add_input(res, res_htx->data);
2095 appctx->st0 = PROMEX_ST_END;
2096 return -1;
2097}
2098
Christopher Fauletf959d082019-02-07 15:38:42 +01002099/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2100 * full. */
2101static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2102{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002103 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002104 struct htx_sl *sl;
2105 unsigned int flags;
2106
2107 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);
2108 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2109 if (!sl)
2110 goto full;
2111 sl->info.res.status = 200;
2112 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
Christopher Fauletf959d082019-02-07 15:38:42 +01002113 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2114 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2115 !htx_add_endof(htx, HTX_BLK_EOH))
2116 goto full;
2117
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002118 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002119 return 1;
2120 full:
2121 htx_reset(htx);
2122 si_rx_room_blk(si);
2123 return 0;
2124}
2125
2126/* The function returns 1 if the initialisation is complete, 0 if
2127 * an errors occurs and -1 if more data are required for initializing
2128 * the applet.
2129 */
2130static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2131{
2132 appctx->st0 = PROMEX_ST_INIT;
2133 return 1;
2134}
2135
2136/* The main I/O handler for the promex applet. */
2137static void promex_appctx_handle_io(struct appctx *appctx)
2138{
2139 struct stream_interface *si = appctx->owner;
2140 struct stream *s = si_strm(si);
2141 struct channel *req = si_oc(si);
2142 struct channel *res = si_ic(si);
2143 struct htx *req_htx, *res_htx;
2144 int ret;
2145
2146 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002147 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2148 goto out;
2149
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002150 /* Check if the input buffer is available. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002151 if (!b_size(&res->buf)) {
2152 si_rx_room_blk(si);
2153 goto out;
2154 }
2155
2156 switch (appctx->st0) {
2157 case PROMEX_ST_INIT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002158 ret = promex_parse_uri(appctx, si);
2159 if (ret <= 0) {
2160 if (ret == -1)
2161 goto error;
2162 goto out;
2163 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002164 appctx->st0 = PROMEX_ST_HEAD;
2165 appctx->st1 = PROMEX_DUMPER_INIT;
2166 /* fall through */
2167
2168 case PROMEX_ST_HEAD:
2169 if (!promex_send_headers(appctx, si, res_htx))
2170 goto out;
2171 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2172 /* fall through */
2173
2174 case PROMEX_ST_DUMP:
2175 ret = promex_dump_metrics(appctx, si, res_htx);
2176 if (ret <= 0) {
2177 if (ret == -1)
2178 goto error;
2179 goto out;
2180 }
2181 appctx->st0 = PROMEX_ST_DONE;
2182 /* fall through */
2183
2184 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002185 /* Don't add TLR because mux-h1 will take care of it */
Willy Tarreauf1ea47d2020-07-23 06:53:27 +02002186 res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
Christopher Fauletf959d082019-02-07 15:38:42 +01002187 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2188 si_rx_room_blk(si);
2189 goto out;
2190 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002191 channel_add_input(res, 1);
2192 appctx->st0 = PROMEX_ST_END;
2193 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002194
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002195 case PROMEX_ST_END:
2196 if (!(res->flags & CF_SHUTR)) {
2197 res->flags |= CF_READ_NULL;
2198 si_shutr(si);
2199 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002200 }
2201
Christopher Fauletf959d082019-02-07 15:38:42 +01002202 out:
2203 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002204
2205 /* eat the whole request */
2206 if (co_data(req)) {
2207 req_htx = htx_from_buf(&req->buf);
2208 co_htx_skip(req, req_htx, co_data(req));
2209 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002210 return;
2211
2212 error:
2213 res->flags |= CF_READ_NULL;
2214 si_shutr(si);
2215 si_shutw(si);
2216}
2217
2218struct applet promex_applet = {
2219 .obj_type = OBJ_TYPE_APPLET,
2220 .name = "<PROMEX>", /* used for logging */
2221 .init = promex_appctx_init,
2222 .fct = promex_appctx_handle_io,
2223};
2224
2225static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2226 struct act_rule *rule, char **err)
2227{
2228 /* Prometheus exporter service is only available on "http-request" rulesets */
2229 if (rule->from != ACT_F_HTTP_REQ) {
2230 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2231 return ACT_RET_PRS_ERR;
2232 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002233
2234 /* Add applet pointer in the rule. */
2235 rule->applet = promex_applet;
2236
2237 return ACT_RET_PRS_OK;
2238}
2239static void promex_register_build_options(void)
2240{
2241 char *ptr = NULL;
2242
2243 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2244 hap_register_build_opts(ptr, 1);
2245}
2246
2247
2248static struct action_kw_list service_actions = { ILH, {
2249 { "prometheus-exporter", service_parse_prometheus_exporter },
2250 { /* END */ }
2251}};
2252
2253INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2254INITCALL0(STG_REGISTER, promex_register_build_options);