blob: 3c5663a9460a819ee9562c882958524689fecf3b [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
648/* Description of all info fields */
649const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
650 [INF_NAME] = IST("Product name."),
651 [INF_VERSION] = IST("HAProxy version."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500652 [INF_RELEASE_DATE] = IST("HAProxy release date."),
William Dauchy5a982a72021-01-08 13:18:06 +0100653 [INF_BUILD_INFO] = IST("HAProxy build info."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100654 [INF_NBTHREAD] = IST("Configured number of threads."),
655 [INF_NBPROC] = IST("Configured number of processes."),
656 [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
657 [INF_PID] = IST("HAProxy PID."),
658 [INF_UPTIME] = IST("Uptime in a human readable format."),
William Dauchydefd1562021-01-15 22:41:38 +0100659 [INF_UPTIME_SEC] = IST("Uptime in seconds."),
660 [INF_START_TIME_SEC] = IST("Start time in seconds."),
William Dauchya8766cf2021-01-15 22:41:37 +0100661 [INF_MEMMAX_BYTES] = IST("Per-process memory limit (in bytes); 0=unset."),
662 [INF_POOL_ALLOC_BYTES] = IST("Total amount of memory allocated in pools (in bytes)."),
663 [INF_POOL_USED_BYTES] = IST("Total amount of memory used in pools (in bytes)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100664 [INF_POOL_FAILED] = IST("Total number of failed pool allocations."),
665 [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500666 [INF_MAXSOCK] = IST("Maximum number of open sockets."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100667 [INF_MAXCONN] = IST("Maximum number of concurrent connections."),
668 [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."),
669 [INF_CURR_CONN] = IST("Number of active sessions."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200670 [INF_CUM_CONN] = IST("Total number of created sessions."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100671 [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."),
672 [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."),
673 [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."),
674 [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."),
675 [INF_MAXPIPES] = IST("Configured maximum number of pipes."),
676 [INF_PIPES_USED] = IST("Number of pipes in used."),
677 [INF_PIPES_FREE] = IST("Number of pipes unused."),
678 [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."),
679 [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."),
680 [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."),
681 [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."),
682 [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."),
683 [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."),
684 [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."),
685 [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."),
686 [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."),
687 [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."),
688 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."),
689 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."),
690 [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."),
691 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."),
692 [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."),
693 [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."),
694 [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."),
695 [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."),
696 [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."),
697 [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."),
698 [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."),
699 [INF_TASKS] = IST("Current number of tasks."),
700 [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."),
701 [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."),
702 [INF_NODE] = IST("Node name."),
703 [INF_DESCRIPTION] = IST("Node description."),
704 [INF_STOPPING] = IST("Non zero means stopping in progress."),
705 [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."),
706 [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."),
707 [INF_LISTENERS] = IST("Current number of active listeners."),
708 [INF_ACTIVE_PEERS] = IST("Current number of active peers."),
709 [INF_CONNECTED_PEERS] = IST("Current number of connected peers."),
710 [INF_DROPPED_LOGS] = IST("Total number of dropped logs."),
711 [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200712 [INF_FAILED_RESOLUTIONS] = IST("Total number of failed DNS resolutions."),
713 [INF_TOTAL_BYTES_OUT] = IST("Total number of bytes emitted."),
714 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("Total number of bytes emitted through a kernel pipe."),
715 [INF_BYTES_OUT_RATE] = IST("Number of bytes emitted over the last elapsed second."),
716 [INF_DEBUG_COMMANDS_ISSUED] = IST("Number of debug commands issued on this process (anything > 0 is unsafe)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100717};
718
719/* Description of all stats fields */
720const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
721 [ST_F_PXNAME] = IST("The proxy name."),
722 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
723 [ST_F_QCUR] = IST("Current number of queued requests."),
724 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
725 [ST_F_SCUR] = IST("Current number of active sessions."),
726 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
727 [ST_F_SLIM] = IST("Configured session limit."),
728 [ST_F_STOT] = IST("Total number of sessions."),
729 [ST_F_BIN] = IST("Current total of incoming bytes."),
730 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
731 [ST_F_DREQ] = IST("Total number of denied requests."),
732 [ST_F_DRESP] = IST("Total number of denied responses."),
733 [ST_F_EREQ] = IST("Total number of request errors."),
734 [ST_F_ECON] = IST("Total number of connection errors."),
735 [ST_F_ERESP] = IST("Total number of response errors."),
736 [ST_F_WRETR] = IST("Total number of retry warnings."),
737 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Willy Tarreau6b3bf732020-09-24 07:35:46 +0200738 [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 +0100739 [ST_F_WEIGHT] = IST("Service weight."),
740 [ST_F_ACT] = IST("Current number of active servers."),
741 [ST_F_BCK] = IST("Current number of backup servers."),
742 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
743 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
744 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
745 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
746 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
747 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
748 [ST_F_IID] = IST("Unique proxy id."),
749 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
750 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
751 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
752 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
753 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
754 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
755 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
756 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
Christopher Fauletcf403f32019-11-21 14:35:46 +0100757 [ST_F_CHECK_STATUS] = IST("Status of last health check (HCHK_STATUS_* values)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100758 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
Christopher Faulet2711e512020-02-27 16:12:07 +0100759 [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100760 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
761 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
762 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
763 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
764 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
765 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
766 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
767 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
768 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
769 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
770 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
771 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
772 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
773 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
774 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
775 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
776 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
777 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
778 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
779 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
780 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
781 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
782 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
783 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
784 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
785 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
786 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
787 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
788 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
789 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
790 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
791 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
792 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
793 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
794 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
795 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
796 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
797 [ST_F_ALGO] = IST("Load balancing algorithm."),
798 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
799 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
800 [ST_F_CONN_TOT] = IST("Total number of connections."),
801 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
802 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
803 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
804 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
805 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
806 [ST_F_REUSE] = IST("Total number of connection reuses."),
807 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
808 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100809 [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"),
810 [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100811 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
812 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
813 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
814 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100815 [ST_F_EINT] = IST("Total number of internal errors."),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200816 [ST_F_IDLE_CONN_CUR] = IST("Current number of unsafe idle connections."),
817 [ST_F_SAFE_CONN_CUR] = IST("Current number of safe idle connections."),
818 [ST_F_USED_CONN_CUR] = IST("Current number of connections in use."),
819 [ST_F_NEED_CONN_EST] = IST("Estimated needed number of connections."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100820};
821
822/* Specific labels for all info fields. Empty by default. */
823const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
824 [INF_NAME] = IST(""),
825 [INF_VERSION] = IST(""),
826 [INF_RELEASE_DATE] = IST(""),
William Dauchy5a982a72021-01-08 13:18:06 +0100827 [INF_BUILD_INFO] = IST(PROMEX_BUILDINFO_LABEL),
Christopher Fauletf959d082019-02-07 15:38:42 +0100828 [INF_NBTHREAD] = IST(""),
829 [INF_NBPROC] = IST(""),
830 [INF_PROCESS_NUM] = IST(""),
831 [INF_PID] = IST(""),
832 [INF_UPTIME] = IST(""),
833 [INF_UPTIME_SEC] = IST(""),
William Dauchydefd1562021-01-15 22:41:38 +0100834 [INF_START_TIME_SEC] = IST(""),
William Dauchya8766cf2021-01-15 22:41:37 +0100835 [INF_MEMMAX_BYTES] = IST(""),
836 [INF_POOL_ALLOC_BYTES] = IST(""),
837 [INF_POOL_USED_BYTES] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100838 [INF_POOL_FAILED] = IST(""),
839 [INF_ULIMIT_N] = IST(""),
840 [INF_MAXSOCK] = IST(""),
841 [INF_MAXCONN] = IST(""),
842 [INF_HARD_MAXCONN] = IST(""),
843 [INF_CURR_CONN] = IST(""),
844 [INF_CUM_CONN] = IST(""),
845 [INF_CUM_REQ] = IST(""),
846 [INF_MAX_SSL_CONNS] = IST(""),
847 [INF_CURR_SSL_CONNS] = IST(""),
848 [INF_CUM_SSL_CONNS] = IST(""),
849 [INF_MAXPIPES] = IST(""),
850 [INF_PIPES_USED] = IST(""),
851 [INF_PIPES_FREE] = IST(""),
852 [INF_CONN_RATE] = IST(""),
853 [INF_CONN_RATE_LIMIT] = IST(""),
854 [INF_MAX_CONN_RATE] = IST(""),
855 [INF_SESS_RATE] = IST(""),
856 [INF_SESS_RATE_LIMIT] = IST(""),
857 [INF_MAX_SESS_RATE] = IST(""),
858 [INF_SSL_RATE] = IST(""),
859 [INF_SSL_RATE_LIMIT] = IST(""),
860 [INF_MAX_SSL_RATE] = IST(""),
861 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
862 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
863 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
864 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
865 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
866 [INF_SSL_CACHE_LOOKUPS] = IST(""),
867 [INF_SSL_CACHE_MISSES] = IST(""),
868 [INF_COMPRESS_BPS_IN] = IST(""),
869 [INF_COMPRESS_BPS_OUT] = IST(""),
870 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
871 [INF_ZLIB_MEM_USAGE] = IST(""),
872 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
873 [INF_TASKS] = IST(""),
874 [INF_RUN_QUEUE] = IST(""),
875 [INF_IDLE_PCT] = IST(""),
876 [INF_NODE] = IST(""),
877 [INF_DESCRIPTION] = IST(""),
878 [INF_STOPPING] = IST(""),
879 [INF_JOBS] = IST(""),
880 [INF_UNSTOPPABLE_JOBS] = IST(""),
881 [INF_LISTENERS] = IST(""),
882 [INF_ACTIVE_PEERS] = IST(""),
883 [INF_CONNECTED_PEERS] = IST(""),
884 [INF_DROPPED_LOGS] = IST(""),
885 [INF_BUSY_POLLING] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200886 [INF_FAILED_RESOLUTIONS] = IST(""),
887 [INF_TOTAL_BYTES_OUT] = IST(""),
888 [INF_TOTAL_SPLICED_BYTES_OUT] = IST(""),
889 [INF_BYTES_OUT_RATE] = IST(""),
890 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100891};
892
893/* Specific labels for all stats fields. Empty by default. */
894const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
895 [ST_F_PXNAME] = IST(""),
896 [ST_F_SVNAME] = IST(""),
897 [ST_F_QCUR] = IST(""),
898 [ST_F_QMAX] = IST(""),
899 [ST_F_SCUR] = IST(""),
900 [ST_F_SMAX] = IST(""),
901 [ST_F_SLIM] = IST(""),
902 [ST_F_STOT] = IST(""),
903 [ST_F_BIN] = IST(""),
904 [ST_F_BOUT] = IST(""),
905 [ST_F_DREQ] = IST(""),
906 [ST_F_DRESP] = IST(""),
907 [ST_F_EREQ] = IST(""),
908 [ST_F_ECON] = IST(""),
909 [ST_F_ERESP] = IST(""),
910 [ST_F_WRETR] = IST(""),
911 [ST_F_WREDIS] = IST(""),
912 [ST_F_STATUS] = IST(""),
913 [ST_F_WEIGHT] = IST(""),
914 [ST_F_ACT] = IST(""),
915 [ST_F_BCK] = IST(""),
916 [ST_F_CHKFAIL] = IST(""),
917 [ST_F_CHKDOWN] = IST(""),
918 [ST_F_LASTCHG] = IST(""),
919 [ST_F_DOWNTIME] = IST(""),
920 [ST_F_QLIMIT] = IST(""),
921 [ST_F_PID] = IST(""),
922 [ST_F_IID] = IST(""),
923 [ST_F_SID] = IST(""),
924 [ST_F_THROTTLE] = IST(""),
925 [ST_F_LBTOT] = IST(""),
926 [ST_F_TRACKED] = IST(""),
927 [ST_F_TYPE] = IST(""),
928 [ST_F_RATE] = IST(""),
929 [ST_F_RATE_LIM] = IST(""),
930 [ST_F_RATE_MAX] = IST(""),
931 [ST_F_CHECK_STATUS] = IST(""),
932 [ST_F_CHECK_CODE] = IST(""),
933 [ST_F_CHECK_DURATION] = IST(""),
934 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
935 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
936 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
937 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
938 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
939 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
940 [ST_F_HANAFAIL] = IST(""),
941 [ST_F_REQ_RATE] = IST(""),
942 [ST_F_REQ_RATE_MAX] = IST(""),
943 [ST_F_REQ_TOT] = IST(""),
944 [ST_F_CLI_ABRT] = IST(""),
945 [ST_F_SRV_ABRT] = IST(""),
946 [ST_F_COMP_IN] = IST(""),
947 [ST_F_COMP_OUT] = IST(""),
948 [ST_F_COMP_BYP] = IST(""),
949 [ST_F_COMP_RSP] = IST(""),
950 [ST_F_LASTSESS] = IST(""),
951 [ST_F_LAST_CHK] = IST(""),
952 [ST_F_LAST_AGT] = IST(""),
953 [ST_F_QTIME] = IST(""),
954 [ST_F_CTIME] = IST(""),
955 [ST_F_RTIME] = IST(""),
956 [ST_F_TTIME] = IST(""),
957 [ST_F_AGENT_STATUS] = IST(""),
958 [ST_F_AGENT_CODE] = IST(""),
959 [ST_F_AGENT_DURATION] = IST(""),
960 [ST_F_CHECK_DESC] = IST(""),
961 [ST_F_AGENT_DESC] = IST(""),
962 [ST_F_CHECK_RISE] = IST(""),
963 [ST_F_CHECK_FALL] = IST(""),
964 [ST_F_CHECK_HEALTH] = IST(""),
965 [ST_F_AGENT_RISE] = IST(""),
966 [ST_F_AGENT_FALL] = IST(""),
967 [ST_F_AGENT_HEALTH] = IST(""),
968 [ST_F_ADDR] = IST(""),
969 [ST_F_COOKIE] = IST(""),
970 [ST_F_MODE] = IST(""),
971 [ST_F_ALGO] = IST(""),
972 [ST_F_CONN_RATE] = IST(""),
973 [ST_F_CONN_RATE_MAX] = IST(""),
974 [ST_F_CONN_TOT] = IST(""),
975 [ST_F_INTERCEPTED] = IST(""),
976 [ST_F_DCON] = IST(""),
977 [ST_F_DSES] = IST(""),
978 [ST_F_WREW] = IST(""),
979 [ST_F_CONNECT] = IST(""),
980 [ST_F_REUSE] = IST(""),
981 [ST_F_CACHE_LOOKUPS] = IST(""),
982 [ST_F_CACHE_HITS] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200983 [ST_F_IDLE_CONN_CUR] = IST(""),
984 [ST_F_SAFE_CONN_CUR] = IST(""),
985 [ST_F_USED_CONN_CUR] = IST(""),
986 [ST_F_NEED_CONN_EST] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100987};
988
989/* Type for all info fields. "untyped" is used for unsupported field. */
990const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
991 [INF_NAME] = IST("untyped"),
992 [INF_VERSION] = IST("untyped"),
993 [INF_RELEASE_DATE] = IST("untyped"),
William Dauchy5a982a72021-01-08 13:18:06 +0100994 [INF_BUILD_INFO] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200995 [INF_NBTHREAD] = IST("gauge"),
996 [INF_NBPROC] = IST("gauge"),
997 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100998 [INF_PID] = IST("untyped"),
999 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001000 [INF_UPTIME_SEC] = IST("gauge"),
William Dauchydefd1562021-01-15 22:41:38 +01001001 [INF_START_TIME_SEC] = IST("gauge"),
William Dauchya8766cf2021-01-15 22:41:37 +01001002 [INF_MEMMAX_BYTES] = IST("gauge"),
1003 [INF_POOL_ALLOC_BYTES] = IST("gauge"),
1004 [INF_POOL_USED_BYTES] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001005 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001006 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001007 [INF_MAXSOCK] = IST("gauge"),
1008 [INF_MAXCONN] = IST("gauge"),
1009 [INF_HARD_MAXCONN] = IST("gauge"),
1010 [INF_CURR_CONN] = IST("gauge"),
1011 [INF_CUM_CONN] = IST("counter"),
1012 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001013 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001014 [INF_CURR_SSL_CONNS] = IST("gauge"),
1015 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001016 [INF_MAXPIPES] = IST("gauge"),
1017 [INF_PIPES_USED] = IST("counter"),
1018 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001019 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001020 [INF_CONN_RATE_LIMIT] = IST("gauge"),
1021 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001022 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001023 [INF_SESS_RATE_LIMIT] = IST("gauge"),
1024 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001025 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001026 [INF_SSL_RATE_LIMIT] = IST("gauge"),
1027 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001028 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001029 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001030 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
1031 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001032 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001033 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
1034 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001035 [INF_COMPRESS_BPS_IN] = IST("counter"),
1036 [INF_COMPRESS_BPS_OUT] = IST("counter"),
1037 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001038 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001039 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001040 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +02001041 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001042 [INF_IDLE_PCT] = IST("gauge"),
1043 [INF_NODE] = IST("untyped"),
1044 [INF_DESCRIPTION] = IST("untyped"),
1045 [INF_STOPPING] = IST("gauge"),
1046 [INF_JOBS] = IST("gauge"),
1047 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
1048 [INF_LISTENERS] = IST("gauge"),
1049 [INF_ACTIVE_PEERS] = IST("gauge"),
1050 [INF_CONNECTED_PEERS] = IST("gauge"),
1051 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001052 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletc55a6262020-07-10 15:39:39 +02001053 [INF_FAILED_RESOLUTIONS] = IST("counter"),
1054 [INF_TOTAL_BYTES_OUT] = IST("counter"),
1055 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("counter"),
1056 [INF_BYTES_OUT_RATE] = IST("gauge"),
1057 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +01001058};
1059
1060/* Type for all stats fields. "untyped" is used for unsupported field. */
1061const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
1062 [ST_F_PXNAME] = IST("untyped"),
1063 [ST_F_SVNAME] = IST("untyped"),
1064 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001065 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001066 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001067 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001068 [ST_F_SLIM] = IST("gauge"),
1069 [ST_F_STOT] = IST("counter"),
1070 [ST_F_BIN] = IST("counter"),
1071 [ST_F_BOUT] = IST("counter"),
1072 [ST_F_DREQ] = IST("counter"),
1073 [ST_F_DRESP] = IST("counter"),
1074 [ST_F_EREQ] = IST("counter"),
1075 [ST_F_ECON] = IST("counter"),
1076 [ST_F_ERESP] = IST("counter"),
1077 [ST_F_WRETR] = IST("counter"),
1078 [ST_F_WREDIS] = IST("counter"),
1079 [ST_F_STATUS] = IST("gauge"),
1080 [ST_F_WEIGHT] = IST("gauge"),
1081 [ST_F_ACT] = IST("gauge"),
1082 [ST_F_BCK] = IST("gauge"),
1083 [ST_F_CHKFAIL] = IST("counter"),
1084 [ST_F_CHKDOWN] = IST("counter"),
1085 [ST_F_LASTCHG] = IST("gauge"),
1086 [ST_F_DOWNTIME] = IST("counter"),
1087 [ST_F_QLIMIT] = IST("gauge"),
1088 [ST_F_PID] = IST("untyped"),
1089 [ST_F_IID] = IST("untyped"),
1090 [ST_F_SID] = IST("untyped"),
1091 [ST_F_THROTTLE] = IST("gauge"),
1092 [ST_F_LBTOT] = IST("counter"),
1093 [ST_F_TRACKED] = IST("untyped"),
1094 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001095 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001096 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001097 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Fauletcf403f32019-11-21 14:35:46 +01001098 [ST_F_CHECK_STATUS] = IST("gauge"),
1099 [ST_F_CHECK_CODE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001100 [ST_F_CHECK_DURATION] = IST("gauge"),
1101 [ST_F_HRSP_1XX] = IST("counter"),
1102 [ST_F_HRSP_2XX] = IST("counter"),
1103 [ST_F_HRSP_3XX] = IST("counter"),
1104 [ST_F_HRSP_4XX] = IST("counter"),
1105 [ST_F_HRSP_5XX] = IST("counter"),
1106 [ST_F_HRSP_OTHER] = IST("counter"),
1107 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001108 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001109 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001110 [ST_F_REQ_TOT] = IST("counter"),
1111 [ST_F_CLI_ABRT] = IST("counter"),
1112 [ST_F_SRV_ABRT] = IST("counter"),
1113 [ST_F_COMP_IN] = IST("counter"),
1114 [ST_F_COMP_OUT] = IST("counter"),
1115 [ST_F_COMP_BYP] = IST("counter"),
1116 [ST_F_COMP_RSP] = IST("counter"),
1117 [ST_F_LASTSESS] = IST("gauge"),
1118 [ST_F_LAST_CHK] = IST("untyped"),
1119 [ST_F_LAST_AGT] = IST("untyped"),
1120 [ST_F_QTIME] = IST("gauge"),
1121 [ST_F_CTIME] = IST("gauge"),
1122 [ST_F_RTIME] = IST("gauge"),
1123 [ST_F_TTIME] = IST("gauge"),
1124 [ST_F_AGENT_STATUS] = IST("untyped"),
1125 [ST_F_AGENT_CODE] = IST("untyped"),
1126 [ST_F_AGENT_DURATION] = IST("gauge"),
1127 [ST_F_CHECK_DESC] = IST("untyped"),
1128 [ST_F_AGENT_DESC] = IST("untyped"),
1129 [ST_F_CHECK_RISE] = IST("gauge"),
1130 [ST_F_CHECK_FALL] = IST("gauge"),
1131 [ST_F_CHECK_HEALTH] = IST("gauge"),
1132 [ST_F_AGENT_RISE] = IST("gauge"),
1133 [ST_F_AGENT_FALL] = IST("gauge"),
1134 [ST_F_AGENT_HEALTH] = IST("gauge"),
1135 [ST_F_ADDR] = IST("untyped"),
1136 [ST_F_COOKIE] = IST("untyped"),
1137 [ST_F_MODE] = IST("untyped"),
1138 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001139 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001140 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001141 [ST_F_CONN_TOT] = IST("counter"),
1142 [ST_F_INTERCEPTED] = IST("counter"),
1143 [ST_F_DCON] = IST("counter"),
1144 [ST_F_DSES] = IST("counter"),
1145 [ST_F_WREW] = IST("counter"),
1146 [ST_F_CONNECT] = IST("counter"),
1147 [ST_F_REUSE] = IST("counter"),
1148 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1149 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Faulet20ab80c2019-11-08 15:24:32 +01001150 [ST_F_SRV_ICUR] = IST("gauge"),
1151 [ST_F_SRV_ILIM] = IST("gauge"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001152 [ST_F_QT_MAX] = IST("gauge"),
1153 [ST_F_CT_MAX] = IST("gauge"),
1154 [ST_F_RT_MAX] = IST("gauge"),
1155 [ST_F_TT_MAX] = IST("gauge"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001156 [ST_F_EINT] = IST("counter"),
Christopher Fauletc55a6262020-07-10 15:39:39 +02001157 [ST_F_IDLE_CONN_CUR] = IST("gauge"),
1158 [ST_F_SAFE_CONN_CUR] = IST("gauge"),
1159 [ST_F_USED_CONN_CUR] = IST("gauge"),
1160 [ST_F_NEED_CONN_EST] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001161};
1162
Christopher Fauletd45d1052019-09-06 16:10:19 +02001163/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001164static int promex_srv_status(struct server *sv)
1165{
Christopher Fauletf959d082019-02-07 15:38:42 +01001166 int state = 0;
1167
Christopher Fauletf959d082019-02-07 15:38:42 +01001168 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1169 state = 1;
1170 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Fauletd45d1052019-09-06 16:10:19 +02001171 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001172 }
Christopher Fauletd45d1052019-09-06 16:10:19 +02001173 else if (sv->cur_state == SRV_ST_STOPPING)
1174 state = 4;
1175
1176 if (sv->cur_admin & SRV_ADMF_MAINT)
1177 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001178
1179 return state;
1180}
1181
1182/* Convert a field to its string representation and write it in <out>, followed
1183 * by a newline, if there is enough space. non-numeric value are converted in
1184 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1185 * to process this kind of value). It returns 1 on success. Otherwise, it
1186 * returns 0. The buffer's length must not exceed <max> value.
1187 */
1188static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1189{
1190 int ret = 0;
1191
1192 switch (field_format(f, 0)) {
1193 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1194 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1195 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1196 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1197 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001198 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001199 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1200 default: ret = chunk_strcat(out, "Nan\n"); break;
1201 }
1202 if (!ret || out->data > max)
1203 return 0;
1204 return 1;
1205}
1206
1207/* Concatenate the <prefix> with the field name using the array
1208 * <promex_st_metric_names> and store it in <name>. The field type is in
1209 * <appctx->st2>. This function never fails but relies on
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001210 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enough to be copied in
Christopher Fauletf959d082019-02-07 15:38:42 +01001211 * <name>
1212 */
1213static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1214{
1215 const struct ist *names;
1216
1217 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1218 ? promex_inf_metric_names
1219 : promex_st_metric_names);
1220
1221 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1222 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1223}
1224
1225/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1226 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1227 */
1228static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1229 const struct ist name, struct ist *out, size_t max)
1230{
1231 const struct ist *desc, *types;
1232
1233 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1234 desc = promex_inf_metric_desc;
1235 types = promex_inf_metric_types;
1236 }
1237 else {
1238 desc = promex_st_metric_desc;
1239 types = promex_st_metric_types;
1240 }
1241
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001242 if (istcat(out, ist("# HELP "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001243 istcat(out, name, max) == -1 ||
1244 istcat(out, ist(" "), max) == -1 ||
1245 istcat(out, desc[appctx->st2], max) == -1 ||
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001246 istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001247 istcat(out, name, max) == -1 ||
1248 istcat(out, ist(" "), max) == -1 ||
1249 istcat(out, types[appctx->st2], max) == -1 ||
1250 istcat(out, ist("\n"), max) == -1)
1251 goto full;
1252
1253 return 1;
1254
1255 full:
1256 return 0;
1257}
1258
1259/* Dump the line for <metric>. It starts by the metric name followed by its
1260 * labels (proxy name, server name...) between braces and finally its value. If
1261 * not already done, the header lines are dumped first. It returns 1 on
1262 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1263 */
1264static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1265 const struct ist prefix, struct field *metric,
1266 struct ist *out, size_t max)
1267{
1268 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1269 size_t len = out->len;
1270
1271 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1272 return 0;
1273
1274 promex_metric_name(appctx, &name, prefix);
1275 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1276 !promex_dump_metric_header(appctx, htx, name, out, max))
1277 goto full;
1278
1279 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1280 const struct ist label = promex_inf_metric_labels[appctx->st2];
1281
1282 if (istcat(out, name, max) == -1 ||
1283 (label.len && istcat(out, ist("{"), max) == -1) ||
1284 (label.len && istcat(out, label, max) == -1) ||
1285 (label.len && istcat(out, ist("}"), max) == -1) ||
1286 istcat(out, ist(" "), max) == -1)
1287 goto full;
1288 }
1289 else {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001290 struct proxy *px = appctx->ctx.stats.obj1;
1291 struct server *srv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001292 const struct ist label = promex_st_metric_labels[appctx->st2];
1293
1294 if (istcat(out, name, max) == -1 ||
1295 istcat(out, ist("{proxy=\""), max) == -1 ||
1296 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1297 istcat(out, ist("\""), max) == -1 ||
1298 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1299 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1300 (srv && istcat(out, ist("\""), max) == -1) ||
1301 (label.len && istcat(out, ist(","), max) == -1) ||
1302 (label.len && istcat(out, label, max) == -1) ||
1303 istcat(out, ist("} "), max) == -1)
1304 goto full;
1305 }
1306
1307 trash.data = out->len;
1308 if (!promex_metric_to_str(&trash, metric, max))
1309 goto full;
1310 out->len = trash.data;
1311
1312 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1313 return 1;
1314 full:
1315 // Restore previous length
1316 out->len = len;
1317 return 0;
1318
1319}
1320
1321
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001322/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001323 * 0 if <htx> is full and -1 in case of any error. */
1324static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1325{
1326 static struct ist prefix = IST("haproxy_process_");
1327 struct field metric;
1328 struct channel *chn = si_ic(appctx->owner);
1329 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001330 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001331 int ret = 1;
1332
William Dauchy5d9b8f32021-01-11 20:07:49 +01001333 if (!stats_fill_info(info, INF_TOTAL_FIELDS))
1334 return -1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001335
Christopher Fauletf959d082019-02-07 15:38:42 +01001336 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1337 switch (appctx->st2) {
William Dauchy5a982a72021-01-08 13:18:06 +01001338 case INF_BUILD_INFO:
1339 metric = mkf_u32(FN_GAUGE, 1);
1340 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001341
1342 default:
William Dauchy5d9b8f32021-01-11 20:07:49 +01001343 metric = info[appctx->st2];
Christopher Fauletf959d082019-02-07 15:38:42 +01001344 }
1345
1346 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1347 goto full;
1348
Christopher Fauletf959d082019-02-07 15:38:42 +01001349 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1350 appctx->st2 = promex_global_metrics[appctx->st2];
1351 }
1352
1353 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001354 if (out.len) {
1355 if (!htx_add_data_atonce(htx, out))
1356 return -1; /* Unexpected and unrecoverable error */
1357 channel_add_input(chn, out.len);
1358 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001359 return ret;
1360 full:
1361 ret = 0;
1362 goto end;
1363}
1364
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001365/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001366 * 0 if <htx> is full and -1 in case of any error. */
1367static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1368{
1369 static struct ist prefix = IST("haproxy_frontend_");
1370 struct proxy *px;
1371 struct field metric;
1372 struct channel *chn = si_ic(appctx->owner);
1373 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001374 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001375 int ret = 1;
1376
1377 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001378 while (appctx->ctx.stats.obj1) {
1379 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001380
1381 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001382 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001383 goto next_px;
1384
1385 switch (appctx->st2) {
1386 case ST_F_STATUS:
Willy Tarreauc3914d42020-09-24 08:39:22 +02001387 metric = mkf_u32(FO_STATUS, !px->disabled);
Christopher Fauletf959d082019-02-07 15:38:42 +01001388 break;
1389 case ST_F_SCUR:
1390 metric = mkf_u32(0, px->feconn);
1391 break;
1392 case ST_F_SMAX:
1393 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1394 break;
1395 case ST_F_SLIM:
1396 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1397 break;
1398 case ST_F_STOT:
1399 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1400 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001401 case ST_F_RATE_LIM:
1402 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1403 break;
1404 case ST_F_RATE_MAX:
1405 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1406 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001407 case ST_F_CONN_RATE_MAX:
1408 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1409 break;
1410 case ST_F_CONN_TOT:
1411 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1412 break;
1413 case ST_F_BIN:
1414 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1415 break;
1416 case ST_F_BOUT:
1417 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1418 break;
1419 case ST_F_DREQ:
1420 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1421 break;
1422 case ST_F_DRESP:
1423 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1424 break;
1425 case ST_F_EREQ:
1426 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1427 break;
1428 case ST_F_DCON:
1429 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1430 break;
1431 case ST_F_DSES:
1432 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1433 break;
1434 case ST_F_WREW:
1435 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1436 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001437 case ST_F_EINT:
1438 metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors);
1439 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001440 case ST_F_REQ_RATE_MAX:
1441 if (px->mode != PR_MODE_HTTP)
1442 goto next_px;
1443 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1444 break;
1445 case ST_F_REQ_TOT:
1446 if (px->mode != PR_MODE_HTTP)
1447 goto next_px;
1448 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1449 break;
1450 case ST_F_HRSP_1XX:
1451 if (px->mode != PR_MODE_HTTP)
1452 goto next_px;
1453 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1454 break;
1455 case ST_F_HRSP_2XX:
1456 if (px->mode != PR_MODE_HTTP)
1457 goto next_px;
1458 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1459 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1460 break;
1461 case ST_F_HRSP_3XX:
1462 if (px->mode != PR_MODE_HTTP)
1463 goto next_px;
1464 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1465 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1466 break;
1467 case ST_F_HRSP_4XX:
1468 if (px->mode != PR_MODE_HTTP)
1469 goto next_px;
1470 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1471 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1472 break;
1473 case ST_F_HRSP_5XX:
1474 if (px->mode != PR_MODE_HTTP)
1475 goto next_px;
1476 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1477 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1478 break;
1479 case ST_F_HRSP_OTHER:
1480 if (px->mode != PR_MODE_HTTP)
1481 goto next_px;
1482 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1483 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1484 break;
1485 case ST_F_INTERCEPTED:
1486 if (px->mode != PR_MODE_HTTP)
1487 goto next_px;
1488 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1489 break;
1490 case ST_F_CACHE_LOOKUPS:
1491 if (px->mode != PR_MODE_HTTP)
1492 goto next_px;
1493 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1494 break;
1495 case ST_F_CACHE_HITS:
1496 if (px->mode != PR_MODE_HTTP)
1497 goto next_px;
1498 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1499 break;
1500 case ST_F_COMP_IN:
1501 if (px->mode != PR_MODE_HTTP)
1502 goto next_px;
1503 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1504 break;
1505 case ST_F_COMP_OUT:
1506 if (px->mode != PR_MODE_HTTP)
1507 goto next_px;
1508 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1509 break;
1510 case ST_F_COMP_BYP:
1511 if (px->mode != PR_MODE_HTTP)
1512 goto next_px;
1513 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1514 break;
1515 case ST_F_COMP_RSP:
1516 if (px->mode != PR_MODE_HTTP)
1517 goto next_px;
1518 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1519 break;
1520
1521 default:
1522 goto next_metric;
1523 }
1524
1525 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1526 goto full;
1527 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001528 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001529 }
1530 next_metric:
1531 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001532 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001533 appctx->st2 = promex_front_metrics[appctx->st2];
1534 }
1535
1536 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001537 if (out.len) {
1538 if (!htx_add_data_atonce(htx, out))
1539 return -1; /* Unexpected and unrecoverable error */
1540 channel_add_input(chn, out.len);
1541 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001542 return ret;
1543 full:
1544 ret = 0;
1545 goto end;
1546}
1547
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001548/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001549 * 0 if <htx> is full and -1 in case of any error. */
1550static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1551{
1552 static struct ist prefix = IST("haproxy_backend_");
1553 struct proxy *px;
1554 struct field metric;
1555 struct channel *chn = si_ic(appctx->owner);
1556 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001557 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001558 int ret = 1;
1559 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001560 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001561
1562 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001563 while (appctx->ctx.stats.obj1) {
1564 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001565
1566 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001567 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001568 goto next_px;
1569
1570 switch (appctx->st2) {
1571 case ST_F_STATUS:
1572 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1573 break;
1574 case ST_F_SCUR:
1575 metric = mkf_u32(0, px->beconn);
1576 break;
1577 case ST_F_SMAX:
1578 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1579 break;
1580 case ST_F_SLIM:
1581 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1582 break;
1583 case ST_F_STOT:
1584 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1585 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001586 case ST_F_RATE_MAX:
1587 metric = mkf_u32(0, px->be_counters.sps_max);
1588 break;
1589 case ST_F_LASTSESS:
1590 metric = mkf_s32(FN_AGE, be_lastsession(px));
1591 break;
1592 case ST_F_QCUR:
1593 metric = mkf_u32(0, px->nbpend);
1594 break;
1595 case ST_F_QMAX:
1596 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1597 break;
1598 case ST_F_CONNECT:
1599 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1600 break;
1601 case ST_F_REUSE:
1602 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1603 break;
1604 case ST_F_BIN:
1605 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1606 break;
1607 case ST_F_BOUT:
1608 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1609 break;
1610 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001611 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1612 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001613 break;
1614 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001615 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1616 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001617 break;
1618 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001619 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1620 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001621 break;
1622 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001623 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1624 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001625 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001626 case ST_F_QT_MAX:
1627 secs = (double)px->be_counters.qtime_max / 1000.0;
1628 metric = mkf_flt(FN_MAX, secs);
1629 break;
1630 case ST_F_CT_MAX:
1631 secs = (double)px->be_counters.ctime_max / 1000.0;
1632 metric = mkf_flt(FN_MAX, secs);
1633 break;
1634 case ST_F_RT_MAX:
1635 secs = (double)px->be_counters.dtime_max / 1000.0;
1636 metric = mkf_flt(FN_MAX, secs);
1637 break;
1638 case ST_F_TT_MAX:
1639 secs = (double)px->be_counters.ttime_max / 1000.0;
1640 metric = mkf_flt(FN_MAX, secs);
1641 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001642 case ST_F_DREQ:
1643 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1644 break;
1645 case ST_F_DRESP:
1646 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1647 break;
1648 case ST_F_ECON:
1649 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1650 break;
1651 case ST_F_ERESP:
1652 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1653 break;
1654 case ST_F_WRETR:
1655 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1656 break;
1657 case ST_F_WREDIS:
1658 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1659 break;
1660 case ST_F_WREW:
1661 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1662 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001663 case ST_F_EINT:
1664 metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors);
1665 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001666 case ST_F_CLI_ABRT:
1667 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1668 break;
1669 case ST_F_SRV_ABRT:
1670 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1671 break;
1672 case ST_F_WEIGHT:
1673 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1674 metric = mkf_u32(FN_AVG, weight);
1675 break;
1676 case ST_F_ACT:
1677 metric = mkf_u32(0, px->srv_act);
1678 break;
1679 case ST_F_BCK:
1680 metric = mkf_u32(0, px->srv_bck);
1681 break;
1682 case ST_F_CHKDOWN:
1683 metric = mkf_u64(FN_COUNTER, px->down_trans);
1684 break;
1685 case ST_F_LASTCHG:
1686 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1687 break;
1688 case ST_F_DOWNTIME:
1689 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1690 break;
1691 case ST_F_LBTOT:
1692 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1693 break;
1694 case ST_F_REQ_TOT:
1695 if (px->mode != PR_MODE_HTTP)
1696 goto next_px;
1697 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1698 break;
1699 case ST_F_HRSP_1XX:
1700 if (px->mode != PR_MODE_HTTP)
1701 goto next_px;
1702 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1703 break;
1704 case ST_F_HRSP_2XX:
1705 if (px->mode != PR_MODE_HTTP)
1706 goto next_px;
1707 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1708 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1709 break;
1710 case ST_F_HRSP_3XX:
1711 if (px->mode != PR_MODE_HTTP)
1712 goto next_px;
1713 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1714 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1715 break;
1716 case ST_F_HRSP_4XX:
1717 if (px->mode != PR_MODE_HTTP)
1718 goto next_px;
1719 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1720 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1721 break;
1722 case ST_F_HRSP_5XX:
1723 if (px->mode != PR_MODE_HTTP)
1724 goto next_px;
1725 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1726 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1727 break;
1728 case ST_F_HRSP_OTHER:
1729 if (px->mode != PR_MODE_HTTP)
1730 goto next_px;
1731 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1732 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1733 break;
1734 case ST_F_CACHE_LOOKUPS:
1735 if (px->mode != PR_MODE_HTTP)
1736 goto next_px;
1737 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1738 break;
1739 case ST_F_CACHE_HITS:
1740 if (px->mode != PR_MODE_HTTP)
1741 goto next_px;
1742 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1743 break;
1744 case ST_F_COMP_IN:
1745 if (px->mode != PR_MODE_HTTP)
1746 goto next_px;
1747 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1748 break;
1749 case ST_F_COMP_OUT:
1750 if (px->mode != PR_MODE_HTTP)
1751 goto next_px;
1752 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1753 break;
1754 case ST_F_COMP_BYP:
1755 if (px->mode != PR_MODE_HTTP)
1756 goto next_px;
1757 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1758 break;
1759 case ST_F_COMP_RSP:
1760 if (px->mode != PR_MODE_HTTP)
1761 goto next_px;
1762 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1763 break;
1764
1765 default:
1766 goto next_metric;
1767 }
1768
1769 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1770 goto full;
1771 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001772 appctx->ctx.stats.obj1 = px->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01001773 }
1774 next_metric:
1775 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001776 appctx->ctx.stats.obj1 = proxies_list;
Christopher Fauletf959d082019-02-07 15:38:42 +01001777 appctx->st2 = promex_back_metrics[appctx->st2];
1778 }
1779
1780 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001781 if (out.len) {
1782 if (!htx_add_data_atonce(htx, out))
1783 return -1; /* Unexpected and unrecoverable error */
1784 channel_add_input(chn, out.len);
1785 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001786 return ret;
1787 full:
1788 ret = 0;
1789 goto end;
1790}
1791
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001792/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001793 * 0 if <htx> is full and -1 in case of any error. */
1794static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1795{
1796 static struct ist prefix = IST("haproxy_server_");
1797 struct proxy *px;
1798 struct server *sv;
1799 struct field metric;
1800 struct channel *chn = si_ic(appctx->owner);
1801 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001802 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001803 int ret = 1;
1804 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001805 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001806
1807 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001808 while (appctx->ctx.stats.obj1) {
1809 px = appctx->ctx.stats.obj1;
Christopher Fauletf959d082019-02-07 15:38:42 +01001810
1811 /* skip the disabled proxies, global frontend and non-networked ones */
Willy Tarreauc3914d42020-09-24 08:39:22 +02001812 if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
Christopher Fauletf959d082019-02-07 15:38:42 +01001813 goto next_px;
1814
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02001815 while (appctx->ctx.stats.obj2) {
1816 sv = appctx->ctx.stats.obj2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001817
Christopher Fauleteba22942019-11-19 14:18:24 +01001818 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1819 goto next_sv;
1820
Christopher Fauletf959d082019-02-07 15:38:42 +01001821 switch (appctx->st2) {
1822 case ST_F_STATUS:
1823 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1824 break;
1825 case ST_F_SCUR:
1826 metric = mkf_u32(0, sv->cur_sess);
1827 break;
1828 case ST_F_SMAX:
1829 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1830 break;
1831 case ST_F_SLIM:
1832 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
1833 break;
1834 case ST_F_STOT:
1835 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
1836 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001837 case ST_F_RATE_MAX:
1838 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
1839 break;
1840 case ST_F_LASTSESS:
1841 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
1842 break;
1843 case ST_F_QCUR:
1844 metric = mkf_u32(0, sv->nbpend);
1845 break;
1846 case ST_F_QMAX:
1847 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
1848 break;
1849 case ST_F_QLIMIT:
1850 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
1851 break;
1852 case ST_F_BIN:
1853 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
1854 break;
1855 case ST_F_BOUT:
1856 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
1857 break;
1858 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001859 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1860 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001861 break;
1862 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001863 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1864 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001865 break;
1866 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001867 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1868 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001869 break;
1870 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001871 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1872 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001873 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001874 case ST_F_QT_MAX:
1875 secs = (double)sv->counters.qtime_max / 1000.0;
1876 metric = mkf_flt(FN_MAX, secs);
1877 break;
1878 case ST_F_CT_MAX:
1879 secs = (double)sv->counters.ctime_max / 1000.0;
1880 metric = mkf_flt(FN_MAX, secs);
1881 break;
1882 case ST_F_RT_MAX:
1883 secs = (double)sv->counters.dtime_max / 1000.0;
1884 metric = mkf_flt(FN_MAX, secs);
1885 break;
1886 case ST_F_TT_MAX:
1887 secs = (double)sv->counters.ttime_max / 1000.0;
1888 metric = mkf_flt(FN_MAX, secs);
1889 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001890 case ST_F_CONNECT:
1891 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
1892 break;
1893 case ST_F_REUSE:
1894 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
1895 break;
1896 case ST_F_DRESP:
Christopher Fauleta08546b2019-12-16 16:07:34 +01001897 metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp);
Christopher Fauletf959d082019-02-07 15:38:42 +01001898 break;
1899 case ST_F_ECON:
1900 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
1901 break;
1902 case ST_F_ERESP:
1903 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
1904 break;
1905 case ST_F_WRETR:
1906 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
1907 break;
1908 case ST_F_WREDIS:
1909 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
1910 break;
1911 case ST_F_WREW:
1912 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
1913 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001914 case ST_F_EINT:
1915 metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors);
1916 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001917 case ST_F_CLI_ABRT:
1918 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
1919 break;
1920 case ST_F_SRV_ABRT:
1921 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
1922 break;
1923 case ST_F_WEIGHT:
1924 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1925 metric = mkf_u32(FN_AVG, weight);
1926 break;
Christopher Fauletcf403f32019-11-21 14:35:46 +01001927 case ST_F_CHECK_STATUS:
1928 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1929 goto next_sv;
1930 metric = mkf_u32(FN_OUTPUT, sv->check.status);
1931 break;
1932 case ST_F_CHECK_CODE:
1933 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
1934 goto next_sv;
1935 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
1936 break;
Christopher Faulet2711e512020-02-27 16:12:07 +01001937 case ST_F_CHECK_DURATION:
1938 if (sv->check.status < HCHK_STATUS_CHECKED)
1939 goto next_sv;
1940 secs = (double)sv->check.duration / 1000.0;
1941 metric = mkf_flt(FN_DURATION, secs);
1942 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001943 case ST_F_CHKFAIL:
1944 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
1945 break;
1946 case ST_F_CHKDOWN:
1947 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
1948 break;
1949 case ST_F_DOWNTIME:
1950 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
1951 break;
1952 case ST_F_LASTCHG:
1953 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
1954 break;
1955 case ST_F_THROTTLE:
1956 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
1957 break;
1958 case ST_F_LBTOT:
1959 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
1960 break;
Marcin Deranek3c27dda2020-05-15 18:32:51 +02001961 case ST_F_REQ_TOT:
1962 if (px->mode != PR_MODE_HTTP)
1963 goto next_px;
1964 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
1965 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001966 case ST_F_HRSP_1XX:
1967 if (px->mode != PR_MODE_HTTP)
1968 goto next_px;
1969 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
1970 break;
1971 case ST_F_HRSP_2XX:
1972 if (px->mode != PR_MODE_HTTP)
1973 goto next_px;
1974 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1975 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
1976 break;
1977 case ST_F_HRSP_3XX:
1978 if (px->mode != PR_MODE_HTTP)
1979 goto next_px;
1980 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1981 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
1982 break;
1983 case ST_F_HRSP_4XX:
1984 if (px->mode != PR_MODE_HTTP)
1985 goto next_px;
1986 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1987 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
1988 break;
1989 case ST_F_HRSP_5XX:
1990 if (px->mode != PR_MODE_HTTP)
1991 goto next_px;
1992 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1993 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
1994 break;
1995 case ST_F_HRSP_OTHER:
1996 if (px->mode != PR_MODE_HTTP)
1997 goto next_px;
1998 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1999 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
2000 break;
Christopher Faulet20ab80c2019-11-08 15:24:32 +01002001 case ST_F_SRV_ICUR:
2002 metric = mkf_u32(0, sv->curr_idle_conns);
2003 break;
2004 case ST_F_SRV_ILIM:
2005 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2006 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02002007 case ST_F_IDLE_CONN_CUR:
2008 metric = mkf_u32(0, sv->curr_idle_nb);
2009 break;
2010 case ST_F_SAFE_CONN_CUR:
2011 metric = mkf_u32(0, sv->curr_safe_nb);
2012 break;
2013 case ST_F_USED_CONN_CUR:
2014 metric = mkf_u32(0, sv->curr_used_conns);
2015 break;
2016 case ST_F_NEED_CONN_EST:
2017 metric = mkf_u32(0, sv->est_need_conns);
2018 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002019
2020 default:
2021 goto next_metric;
2022 }
2023
2024 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2025 goto full;
2026
Christopher Fauleteba22942019-11-19 14:18:24 +01002027 next_sv:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002028 appctx->ctx.stats.obj2 = sv->next;
Christopher Fauletf959d082019-02-07 15:38:42 +01002029 }
2030
2031 next_px:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002032 appctx->ctx.stats.obj1 = px->next;
2033 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002034 }
2035 next_metric:
2036 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002037 appctx->ctx.stats.obj1 = proxies_list;
2038 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletf959d082019-02-07 15:38:42 +01002039 appctx->st2 = promex_srv_metrics[appctx->st2];
2040 }
2041
2042
2043 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02002044 if (out.len) {
2045 if (!htx_add_data_atonce(htx, out))
2046 return -1; /* Unexpected and unrecoverable error */
2047 channel_add_input(chn, out.len);
2048 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002049 return ret;
2050 full:
2051 ret = 0;
2052 goto end;
2053}
2054
2055/* Dump all metrics (global, frontends, backends and servers) depending on the
2056 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002057 * -1 in case of any error.
2058 * Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as
2059 * a pointer to the current server/listener. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002060static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2061{
2062 int ret;
2063
2064 switch (appctx->st1) {
2065 case PROMEX_DUMPER_INIT:
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002066 appctx->ctx.stats.obj1 = NULL;
2067 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002068 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002069 appctx->st2 = promex_global_metrics[INF_NAME];
2070 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2071 /* fall through */
2072
2073 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002074 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2075 ret = promex_dump_global_metrics(appctx, htx);
2076 if (ret <= 0) {
2077 if (ret == -1)
2078 goto error;
2079 goto full;
2080 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002081 }
2082
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002083 appctx->ctx.stats.obj1 = proxies_list;
2084 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002085 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
2086 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002087 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2088 appctx->st1 = PROMEX_DUMPER_FRONT;
2089 /* fall through */
2090
2091 case PROMEX_DUMPER_FRONT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002092 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2093 ret = promex_dump_front_metrics(appctx, htx);
2094 if (ret <= 0) {
2095 if (ret == -1)
2096 goto error;
2097 goto full;
2098 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002099 }
2100
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002101 appctx->ctx.stats.obj1 = proxies_list;
2102 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002103 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002104 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2105 appctx->st1 = PROMEX_DUMPER_BACK;
2106 /* fall through */
2107
2108 case PROMEX_DUMPER_BACK:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002109 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2110 ret = promex_dump_back_metrics(appctx, htx);
2111 if (ret <= 0) {
2112 if (ret == -1)
2113 goto error;
2114 goto full;
2115 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002116 }
2117
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002118 appctx->ctx.stats.obj1 = proxies_list;
2119 appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL);
Christopher Fauletefde9552020-06-05 08:18:56 +02002120 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002121 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2122 appctx->st1 = PROMEX_DUMPER_SRV;
2123 /* fall through */
2124
2125 case PROMEX_DUMPER_SRV:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002126 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2127 ret = promex_dump_srv_metrics(appctx, htx);
2128 if (ret <= 0) {
2129 if (ret == -1)
2130 goto error;
2131 goto full;
2132 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002133 }
2134
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002135 appctx->ctx.stats.obj1 = NULL;
2136 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002137 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002138 appctx->st2 = 0;
2139 appctx->st1 = PROMEX_DUMPER_DONE;
2140 /* fall through */
2141
2142 case PROMEX_DUMPER_DONE:
2143 default:
2144 break;
2145 }
2146
2147 return 1;
2148
2149 full:
2150 si_rx_room_blk(si);
2151 return 0;
2152 error:
2153 /* unrecoverable error */
Amaury Denoyelleda5b6d12020-10-02 18:32:02 +02002154 appctx->ctx.stats.obj1 = NULL;
2155 appctx->ctx.stats.obj2 = NULL;
Christopher Fauletf959d082019-02-07 15:38:42 +01002156 appctx->ctx.stats.flags = 0;
2157 appctx->st2 = 0;
2158 appctx->st1 = PROMEX_DUMPER_DONE;
2159 return -1;
2160}
2161
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002162/* Parse the query string of request URI to filter the metrics. It returns 1 on
Christopher Faulet78407ce2019-11-18 14:47:08 +01002163 * success and -1 on error. */
2164static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2165{
2166 struct channel *req = si_oc(si);
2167 struct channel *res = si_ic(si);
2168 struct htx *req_htx, *res_htx;
2169 struct htx_sl *sl;
William Dauchyc65f6562019-11-26 12:56:26 +01002170 char *p, *key, *value;
2171 const char *end;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002172 struct buffer *err;
2173 int default_scopes = PROMEX_FL_SCOPE_ALL;
2174 int len;
2175
2176 /* Get the query-string */
2177 req_htx = htxbuf(&req->buf);
2178 sl = http_get_stline(req_htx);
2179 if (!sl)
2180 goto error;
2181 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2182 if (!p)
2183 goto end;
2184 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet78407ce2019-11-18 14:47:08 +01002185
William Dauchyc65f6562019-11-26 12:56:26 +01002186 /* copy the query-string */
2187 len = end - p;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002188 chunk_reset(&trash);
2189 memcpy(trash.area, p, len);
2190 trash.area[len] = 0;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002191 p = trash.area;
William Dauchyc65f6562019-11-26 12:56:26 +01002192 end = trash.area + len;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002193
2194 /* Parse the query-string */
William Dauchyc65f6562019-11-26 12:56:26 +01002195 while (p < end && *p && *p != '#') {
2196 value = NULL;
2197
2198 /* decode parameter name */
2199 key = p;
2200 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002201 ++p;
William Dauchyc65f6562019-11-26 12:56:26 +01002202 /* found a value */
2203 if (*p == '=') {
2204 *(p++) = 0;
2205 value = p;
2206 }
2207 else if (*p == '&')
2208 *(p++) = 0;
2209 else if (*p == '#')
2210 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002211 len = url_decode(key, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002212 if (len == -1)
2213 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002214
William Dauchyc65f6562019-11-26 12:56:26 +01002215 /* decode value */
2216 if (value) {
2217 while (p < end && *p != '=' && *p != '&' && *p != '#')
2218 ++p;
2219 if (*p == '=')
2220 goto error;
2221 if (*p == '&')
2222 *(p++) = 0;
2223 else if (*p == '#')
2224 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002225 len = url_decode(value, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002226 if (len == -1)
2227 goto error;
2228 }
2229
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002230 if (strcmp(key, "scope") == 0) {
William Dauchyc65f6562019-11-26 12:56:26 +01002231 default_scopes = 0; /* at least a scope defined, unset default scopes */
2232 if (!value)
2233 goto error;
2234 else if (*value == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002235 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002236 else if (*value == '*')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002237 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002238 else if (strcmp(value, "global") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002239 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002240 else if (strcmp(value, "server") == 0)
William Dauchyc65f6562019-11-26 12:56:26 +01002241 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002242 else if (strcmp(value, "backend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002243 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002244 else if (strcmp(value, "frontend") == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002245 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2246 else
2247 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002248 }
Tim Duesterhus8cb12a82021-01-02 22:31:55 +01002249 else if (strcmp(key, "no-maint") == 0)
Christopher Fauleteba22942019-11-19 14:18:24 +01002250 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002251 }
2252
2253 end:
2254 appctx->ctx.stats.flags |= default_scopes;
2255 return 1;
2256
2257 error:
2258 err = &http_err_chunks[HTTP_ERR_400];
2259 channel_erase(res);
2260 res->buf.data = b_data(err);
2261 memcpy(res->buf.area, b_head(err), b_data(err));
2262 res_htx = htx_from_buf(&res->buf);
2263 channel_add_input(res, res_htx->data);
2264 appctx->st0 = PROMEX_ST_END;
2265 return -1;
2266}
2267
Christopher Fauletf959d082019-02-07 15:38:42 +01002268/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2269 * full. */
2270static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2271{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002272 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002273 struct htx_sl *sl;
2274 unsigned int flags;
2275
2276 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);
2277 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2278 if (!sl)
2279 goto full;
2280 sl->info.res.status = 200;
2281 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
Christopher Fauletf959d082019-02-07 15:38:42 +01002282 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2283 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2284 !htx_add_endof(htx, HTX_BLK_EOH))
2285 goto full;
2286
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002287 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002288 return 1;
2289 full:
2290 htx_reset(htx);
2291 si_rx_room_blk(si);
2292 return 0;
2293}
2294
2295/* The function returns 1 if the initialisation is complete, 0 if
2296 * an errors occurs and -1 if more data are required for initializing
2297 * the applet.
2298 */
2299static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2300{
2301 appctx->st0 = PROMEX_ST_INIT;
2302 return 1;
2303}
2304
2305/* The main I/O handler for the promex applet. */
2306static void promex_appctx_handle_io(struct appctx *appctx)
2307{
2308 struct stream_interface *si = appctx->owner;
2309 struct stream *s = si_strm(si);
2310 struct channel *req = si_oc(si);
2311 struct channel *res = si_ic(si);
2312 struct htx *req_htx, *res_htx;
2313 int ret;
2314
2315 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002316 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2317 goto out;
2318
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002319 /* Check if the input buffer is available. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002320 if (!b_size(&res->buf)) {
2321 si_rx_room_blk(si);
2322 goto out;
2323 }
2324
2325 switch (appctx->st0) {
2326 case PROMEX_ST_INIT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002327 ret = promex_parse_uri(appctx, si);
2328 if (ret <= 0) {
2329 if (ret == -1)
2330 goto error;
2331 goto out;
2332 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002333 appctx->st0 = PROMEX_ST_HEAD;
2334 appctx->st1 = PROMEX_DUMPER_INIT;
2335 /* fall through */
2336
2337 case PROMEX_ST_HEAD:
2338 if (!promex_send_headers(appctx, si, res_htx))
2339 goto out;
2340 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2341 /* fall through */
2342
2343 case PROMEX_ST_DUMP:
2344 ret = promex_dump_metrics(appctx, si, res_htx);
2345 if (ret <= 0) {
2346 if (ret == -1)
2347 goto error;
2348 goto out;
2349 }
2350 appctx->st0 = PROMEX_ST_DONE;
2351 /* fall through */
2352
2353 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002354 /* Don't add TLR because mux-h1 will take care of it */
Willy Tarreauf1ea47d2020-07-23 06:53:27 +02002355 res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
Christopher Fauletf959d082019-02-07 15:38:42 +01002356 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2357 si_rx_room_blk(si);
2358 goto out;
2359 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002360 channel_add_input(res, 1);
2361 appctx->st0 = PROMEX_ST_END;
2362 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002363
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002364 case PROMEX_ST_END:
2365 if (!(res->flags & CF_SHUTR)) {
2366 res->flags |= CF_READ_NULL;
2367 si_shutr(si);
2368 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002369 }
2370
Christopher Fauletf959d082019-02-07 15:38:42 +01002371 out:
2372 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002373
2374 /* eat the whole request */
2375 if (co_data(req)) {
2376 req_htx = htx_from_buf(&req->buf);
2377 co_htx_skip(req, req_htx, co_data(req));
2378 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002379 return;
2380
2381 error:
2382 res->flags |= CF_READ_NULL;
2383 si_shutr(si);
2384 si_shutw(si);
2385}
2386
2387struct applet promex_applet = {
2388 .obj_type = OBJ_TYPE_APPLET,
2389 .name = "<PROMEX>", /* used for logging */
2390 .init = promex_appctx_init,
2391 .fct = promex_appctx_handle_io,
2392};
2393
2394static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2395 struct act_rule *rule, char **err)
2396{
2397 /* Prometheus exporter service is only available on "http-request" rulesets */
2398 if (rule->from != ACT_F_HTTP_REQ) {
2399 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2400 return ACT_RET_PRS_ERR;
2401 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002402
2403 /* Add applet pointer in the rule. */
2404 rule->applet = promex_applet;
2405
2406 return ACT_RET_PRS_OK;
2407}
2408static void promex_register_build_options(void)
2409{
2410 char *ptr = NULL;
2411
2412 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2413 hap_register_build_opts(ptr, 1);
2414}
2415
2416
2417static struct action_kw_list service_actions = { ILH, {
2418 { "prometheus-exporter", service_parse_prometheus_exporter },
2419 { /* END */ }
2420}};
2421
2422INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2423INITCALL0(STG_REGISTER, promex_register_build_options);