blob: 027626dd3fb46cc454192bbfcc3020f9e59c7e14 [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>
Christopher Fauletf959d082019-02-07 15:38:42 +010041
42/* Prometheus exporter applet states (appctx->st0) */
43enum {
44 PROMEX_ST_INIT = 0, /* initialized */
45 PROMEX_ST_HEAD, /* send headers before dump */
46 PROMEX_ST_DUMP, /* dumping stats */
47 PROMEX_ST_DONE, /* finished */
Christopher Faulet9744f7c2019-03-27 15:48:53 +010048 PROMEX_ST_END, /* treatment terminated */
Christopher Fauletf959d082019-02-07 15:38:42 +010049};
50
51/* Prometheus exporter dumper states (appctx->st1) */
52enum {
53 PROMEX_DUMPER_INIT = 0, /* initialized */
54 PROMEX_DUMPER_GLOBAL, /* dump metrics of globals */
55 PROMEX_DUMPER_FRONT, /* dump metrics of frontend proxies */
56 PROMEX_DUMPER_BACK, /* dump metrics of backend proxies */
57 PROMEX_DUMPER_LI, /* dump metrics of listeners */
58 PROMEX_DUMPER_SRV, /* dump metrics of servers */
59 PROMEX_DUMPER_DONE, /* finished */
60};
61
62/* Prometheus exporter flags (appctx->ctx.stats.flags) */
63#define PROMEX_FL_METRIC_HDR 0x00000001
64#define PROMEX_FL_INFO_METRIC 0x00000002
65#define PROMEX_FL_STATS_METRIC 0x00000004
Christopher Faulet78407ce2019-11-18 14:47:08 +010066#define PROMEX_FL_SCOPE_GLOBAL 0x00000008
67#define PROMEX_FL_SCOPE_FRONT 0x00000010
68#define PROMEX_FL_SCOPE_BACK 0x00000020
69#define PROMEX_FL_SCOPE_SERVER 0x00000040
Christopher Fauleteba22942019-11-19 14:18:24 +010070#define PROMEX_FL_NO_MAINT_SRV 0x00000080
Christopher Faulet78407ce2019-11-18 14:47:08 +010071
72#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 +010073
74/* The max length for metrics name. It is a hard limit but it should be
Ilya Shipitsince7b00f2020-03-23 22:28:40 +050075 * enough.
Christopher Fauletf959d082019-02-07 15:38:42 +010076 */
77#define PROMEX_MAX_NAME_LEN 128
78
79/* The expected max length for a metric dump, including its header lines. It is
80 * just a soft limit to avoid extra work. We don't try to dump a metric if less
81 * than this size is available in the HTX.
82 */
83#define PROMEX_MAX_METRIC_LENGTH 512
84
85/* Matrix used to dump global metrics. Each metric points to the next one to be
86 * processed or 0 to stop the dump. */
87const int promex_global_metrics[INF_TOTAL_FIELDS] = {
88 [INF_NAME] = INF_NBTHREAD,
89 [INF_VERSION] = 0,
90 [INF_RELEASE_DATE] = 0,
91 [INF_NBTHREAD] = INF_NBPROC,
92 [INF_NBPROC] = INF_PROCESS_NUM,
93 [INF_PROCESS_NUM] = INF_UPTIME_SEC,
94 [INF_PID] = 0,
95 [INF_UPTIME] = 0,
96 [INF_UPTIME_SEC] = INF_MEMMAX_MB,
97 [INF_MEMMAX_MB] = INF_POOL_ALLOC_MB,
98 [INF_POOL_ALLOC_MB] = INF_POOL_USED_MB,
99 [INF_POOL_USED_MB] = INF_POOL_FAILED,
100 [INF_POOL_FAILED] = INF_ULIMIT_N,
101 [INF_ULIMIT_N] = INF_MAXSOCK,
102 [INF_MAXSOCK] = INF_MAXCONN,
103 [INF_MAXCONN] = INF_HARD_MAXCONN,
104 [INF_HARD_MAXCONN] = INF_CURR_CONN,
105 [INF_CURR_CONN] = INF_CUM_CONN,
106 [INF_CUM_CONN] = INF_CUM_REQ,
107 [INF_CUM_REQ] = INF_MAX_SSL_CONNS,
108 [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS,
109 [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS,
110 [INF_CUM_SSL_CONNS] = INF_MAXPIPES,
111 [INF_MAXPIPES] = INF_PIPES_USED,
112 [INF_PIPES_USED] = INF_PIPES_FREE,
113 [INF_PIPES_FREE] = INF_CONN_RATE,
114 [INF_CONN_RATE] = INF_CONN_RATE_LIMIT,
115 [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE,
116 [INF_MAX_CONN_RATE] = INF_SESS_RATE,
117 [INF_SESS_RATE] = INF_SESS_RATE_LIMIT,
118 [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE,
119 [INF_MAX_SESS_RATE] = INF_SSL_RATE,
120 [INF_SSL_RATE] = INF_SSL_RATE_LIMIT,
121 [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE,
122 [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE,
123 [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE,
124 [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT,
125 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE,
126 [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE,
127 [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS,
128 [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES,
129 [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN,
130 [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT,
131 [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM,
132 [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE,
133 [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE,
134 [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS,
135 [INF_TASKS] = INF_RUN_QUEUE,
136 [INF_RUN_QUEUE] = INF_IDLE_PCT,
137 [INF_IDLE_PCT] = INF_STOPPING,
138 [INF_NODE] = 0,
139 [INF_DESCRIPTION] = 0,
140 [INF_STOPPING] = INF_JOBS,
141 [INF_JOBS] = INF_UNSTOPPABLE_JOBS,
142 [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS,
143 [INF_LISTENERS] = INF_ACTIVE_PEERS,
144 [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS,
145 [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS,
146 [INF_DROPPED_LOGS] = INF_BUSY_POLLING,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200147 [INF_BUSY_POLLING] = INF_FAILED_RESOLUTIONS,
148 [INF_FAILED_RESOLUTIONS] = INF_TOTAL_BYTES_OUT,
149 [INF_TOTAL_BYTES_OUT] = INF_TOTAL_SPLICED_BYTES_OUT,
150 [INF_TOTAL_SPLICED_BYTES_OUT] = INF_BYTES_OUT_RATE,
151 [INF_BYTES_OUT_RATE] = 0,
152 [INF_DEBUG_COMMANDS_ISSUED] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100153};
154
155/* Matrix used to dump frontend metrics. Each metric points to the next one to be
156 * processed or 0 to stop the dump. */
157const int promex_front_metrics[ST_F_TOTAL_FIELDS] = {
158 [ST_F_PXNAME] = ST_F_STATUS,
159 [ST_F_SVNAME] = 0,
160 [ST_F_QCUR] = 0,
161 [ST_F_QMAX] = 0,
162 [ST_F_SCUR] = ST_F_SMAX,
163 [ST_F_SMAX] = ST_F_SLIM,
164 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200165 [ST_F_STOT] = ST_F_RATE_LIM,
Christopher Fauletf959d082019-02-07 15:38:42 +0100166 [ST_F_BIN] = ST_F_BOUT,
167 [ST_F_BOUT] = ST_F_DREQ,
168 [ST_F_DREQ] = ST_F_DRESP,
169 [ST_F_DRESP] = ST_F_EREQ,
170 [ST_F_EREQ] = ST_F_DCON,
171 [ST_F_ECON] = 0,
172 [ST_F_ERESP] = 0,
173 [ST_F_WRETR] = 0,
174 [ST_F_WREDIS] = 0,
175 [ST_F_STATUS] = ST_F_SCUR,
176 [ST_F_WEIGHT] = 0,
177 [ST_F_ACT] = 0,
178 [ST_F_BCK] = 0,
179 [ST_F_CHKFAIL] = 0,
180 [ST_F_CHKDOWN] = 0,
181 [ST_F_LASTCHG] = 0,
182 [ST_F_DOWNTIME] = 0,
183 [ST_F_QLIMIT] = 0,
184 [ST_F_PID] = 0,
185 [ST_F_IID] = 0,
186 [ST_F_SID] = 0,
187 [ST_F_THROTTLE] = 0,
188 [ST_F_LBTOT] = 0,
189 [ST_F_TRACKED] = 0,
190 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200191 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100192 [ST_F_RATE_LIM] = ST_F_RATE_MAX,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200193 [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100194 [ST_F_CHECK_STATUS] = 0,
195 [ST_F_CHECK_CODE] = 0,
196 [ST_F_CHECK_DURATION] = 0,
197 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
198 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
199 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
200 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
201 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
202 [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED,
203 [ST_F_HANAFAIL] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200204 [ST_F_REQ_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100205 [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT,
206 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
207 [ST_F_CLI_ABRT] = 0,
208 [ST_F_SRV_ABRT] = 0,
209 [ST_F_COMP_IN] = ST_F_COMP_OUT,
210 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
211 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
212 [ST_F_COMP_RSP] = 0,
213 [ST_F_LASTSESS] = 0,
214 [ST_F_LAST_CHK] = 0,
215 [ST_F_LAST_AGT] = 0,
216 [ST_F_QTIME] = 0,
217 [ST_F_CTIME] = 0,
218 [ST_F_RTIME] = 0,
219 [ST_F_TTIME] = 0,
220 [ST_F_AGENT_STATUS] = 0,
221 [ST_F_AGENT_CODE] = 0,
222 [ST_F_AGENT_DURATION] = 0,
223 [ST_F_CHECK_DESC] = 0,
224 [ST_F_AGENT_DESC] = 0,
225 [ST_F_CHECK_RISE] = 0,
226 [ST_F_CHECK_FALL] = 0,
227 [ST_F_CHECK_HEALTH] = 0,
228 [ST_F_AGENT_RISE] = 0,
229 [ST_F_AGENT_FALL] = 0,
230 [ST_F_AGENT_HEALTH] = 0,
231 [ST_F_ADDR] = 0,
232 [ST_F_COOKIE] = 0,
233 [ST_F_MODE] = 0,
234 [ST_F_ALGO] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200235 [ST_F_CONN_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100236 [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT,
237 [ST_F_CONN_TOT] = ST_F_BIN,
238 [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS,
239 [ST_F_DCON] = ST_F_DSES,
240 [ST_F_DSES] = ST_F_WREW,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100241 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100242 [ST_F_CONNECT] = 0,
243 [ST_F_REUSE] = 0,
244 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
245 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100246 [ST_F_SRV_ICUR] = 0,
247 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100248 [ST_F_QT_MAX] = 0,
249 [ST_F_CT_MAX] = 0,
250 [ST_F_RT_MAX] = 0,
251 [ST_F_TT_MAX] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100252 [ST_F_EINT] = ST_F_REQ_RATE_MAX,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200253 [ST_F_IDLE_CONN_CUR] = 0,
254 [ST_F_SAFE_CONN_CUR] = 0,
255 [ST_F_USED_CONN_CUR] = 0,
256 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100257};
258
259/* Matrix used to dump backend metrics. Each metric points to the next one to be
260 * processed or 0 to stop the dump. */
261const int promex_back_metrics[ST_F_TOTAL_FIELDS] = {
262 [ST_F_PXNAME] = ST_F_STATUS,
263 [ST_F_SVNAME] = 0,
264 [ST_F_QCUR] = ST_F_QMAX,
265 [ST_F_QMAX] = ST_F_CONNECT,
266 [ST_F_SCUR] = ST_F_SMAX,
267 [ST_F_SMAX] = ST_F_SLIM,
268 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200269 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100270 [ST_F_BIN] = ST_F_BOUT,
271 [ST_F_BOUT] = ST_F_QTIME,
272 [ST_F_DREQ] = ST_F_DRESP,
273 [ST_F_DRESP] = ST_F_ECON,
274 [ST_F_EREQ] = 0,
275 [ST_F_ECON] = ST_F_ERESP,
276 [ST_F_ERESP] = ST_F_WRETR,
277 [ST_F_WRETR] = ST_F_WREDIS,
278 [ST_F_WREDIS] = ST_F_WREW,
279 [ST_F_STATUS] = ST_F_SCUR,
280 [ST_F_WEIGHT] = ST_F_ACT,
281 [ST_F_ACT] = ST_F_BCK,
282 [ST_F_BCK] = ST_F_CHKDOWN,
283 [ST_F_CHKFAIL] = 0,
284 [ST_F_CHKDOWN] = ST_F_LASTCHG,
285 [ST_F_LASTCHG] = ST_F_DOWNTIME,
286 [ST_F_DOWNTIME] = ST_F_LBTOT,
287 [ST_F_QLIMIT] = 0,
288 [ST_F_PID] = 0,
289 [ST_F_IID] = 0,
290 [ST_F_SID] = 0,
291 [ST_F_THROTTLE] = 0,
292 [ST_F_LBTOT] = ST_F_REQ_TOT,
293 [ST_F_TRACKED] = 9,
294 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200295 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100296 [ST_F_RATE_LIM] = 0,
297 [ST_F_RATE_MAX] = ST_F_LASTSESS,
298 [ST_F_CHECK_STATUS] = 0,
299 [ST_F_CHECK_CODE] = 0,
300 [ST_F_CHECK_DURATION] = 0,
301 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
302 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
303 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
304 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
305 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
306 [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS,
307 [ST_F_HANAFAIL] = 0,
308 [ST_F_REQ_RATE] = 0,
309 [ST_F_REQ_RATE_MAX] = 0,
310 [ST_F_REQ_TOT] = ST_F_HRSP_1XX,
311 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
312 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
313 [ST_F_COMP_IN] = ST_F_COMP_OUT,
314 [ST_F_COMP_OUT] = ST_F_COMP_BYP,
315 [ST_F_COMP_BYP] = ST_F_COMP_RSP,
316 [ST_F_COMP_RSP] = 0,
317 [ST_F_LASTSESS] = ST_F_QCUR,
318 [ST_F_LAST_CHK] = 0,
319 [ST_F_LAST_AGT] = 0,
320 [ST_F_QTIME] = ST_F_CTIME,
321 [ST_F_CTIME] = ST_F_RTIME,
322 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100323 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100324 [ST_F_AGENT_STATUS] = 0,
325 [ST_F_AGENT_CODE] = 0,
326 [ST_F_AGENT_DURATION] = 0,
327 [ST_F_CHECK_DESC] = 0,
328 [ST_F_AGENT_DESC] = 0,
329 [ST_F_CHECK_RISE] = 0,
330 [ST_F_CHECK_FALL] = 0,
331 [ST_F_CHECK_HEALTH] = 0,
332 [ST_F_AGENT_RISE] = 0,
333 [ST_F_AGENT_FALL] = 0,
334 [ST_F_AGENT_HEALTH] = 0,
335 [ST_F_ADDR] = 0,
336 [ST_F_COOKIE] = 0,
337 [ST_F_MODE] = 0,
338 [ST_F_ALGO] = 0,
339 [ST_F_CONN_RATE] = 0,
340 [ST_F_CONN_RATE_MAX] = 0,
341 [ST_F_CONN_TOT] = 0,
342 [ST_F_INTERCEPTED] = 0,
343 [ST_F_DCON] = 0,
344 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100345 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100346 [ST_F_CONNECT] = ST_F_REUSE,
347 [ST_F_REUSE] = ST_F_BIN,
348 [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS,
349 [ST_F_CACHE_HITS] = ST_F_COMP_IN,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100350 [ST_F_SRV_ICUR] = 0,
351 [ST_F_SRV_ILIM] = 0,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100352 [ST_F_QT_MAX] = ST_F_CT_MAX,
353 [ST_F_CT_MAX] = ST_F_RT_MAX,
354 [ST_F_RT_MAX] = ST_F_TT_MAX,
355 [ST_F_TT_MAX] = ST_F_DREQ,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100356 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200357 [ST_F_IDLE_CONN_CUR] = 0,
358 [ST_F_SAFE_CONN_CUR] = 0,
359 [ST_F_USED_CONN_CUR] = 0,
360 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100361};
362
363/* Matrix used to dump server metrics. Each metric points to the next one to be
364 * processed or 0 to stop the dump. */
365const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = {
366 [ST_F_PXNAME] = ST_F_STATUS,
367 [ST_F_SVNAME] = 0,
368 [ST_F_QCUR] = ST_F_QMAX,
369 [ST_F_QMAX] = ST_F_QLIMIT,
370 [ST_F_SCUR] = ST_F_SMAX,
371 [ST_F_SMAX] = ST_F_SLIM,
372 [ST_F_SLIM] = ST_F_STOT,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200373 [ST_F_STOT] = ST_F_RATE_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100374 [ST_F_BIN] = ST_F_BOUT,
375 [ST_F_BOUT] = ST_F_QTIME,
376 [ST_F_DREQ] = 0,
377 [ST_F_DRESP] = ST_F_ECON,
378 [ST_F_EREQ] = 0,
379 [ST_F_ECON] = ST_F_ERESP,
380 [ST_F_ERESP] = ST_F_WRETR,
381 [ST_F_WRETR] = ST_F_WREDIS,
382 [ST_F_WREDIS] = ST_F_WREW,
383 [ST_F_STATUS] = ST_F_SCUR,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100384 [ST_F_WEIGHT] = ST_F_CHECK_STATUS,
Christopher Fauletf959d082019-02-07 15:38:42 +0100385 [ST_F_ACT] = 0,
386 [ST_F_BCK] = 0,
387 [ST_F_CHKFAIL] = ST_F_CHKDOWN,
388 [ST_F_CHKDOWN] = ST_F_DOWNTIME,
389 [ST_F_LASTCHG] = ST_F_THROTTLE,
390 [ST_F_DOWNTIME] = ST_F_LASTCHG,
391 [ST_F_QLIMIT] = ST_F_BIN,
392 [ST_F_PID] = 0,
393 [ST_F_IID] = 0,
394 [ST_F_SID] = 0,
395 [ST_F_THROTTLE] = ST_F_LBTOT,
396 [ST_F_LBTOT] = ST_F_HRSP_1XX,
397 [ST_F_TRACKED] = 0,
398 [ST_F_TYPE] = 0,
Christopher Fauletc58fc0d2019-04-18 10:10:49 +0200399 [ST_F_RATE] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100400 [ST_F_RATE_LIM] = 0,
401 [ST_F_RATE_MAX] = ST_F_LASTSESS,
Christopher Fauletcf403f32019-11-21 14:35:46 +0100402 [ST_F_CHECK_STATUS] = ST_F_CHECK_CODE,
Christopher Faulet2711e512020-02-27 16:12:07 +0100403 [ST_F_CHECK_CODE] = ST_F_CHECK_DURATION,
404 [ST_F_CHECK_DURATION] = ST_F_CHKFAIL,
Christopher Fauletf959d082019-02-07 15:38:42 +0100405 [ST_F_HRSP_1XX] = ST_F_HRSP_2XX,
406 [ST_F_HRSP_2XX] = ST_F_HRSP_3XX,
407 [ST_F_HRSP_3XX] = ST_F_HRSP_4XX,
408 [ST_F_HRSP_4XX] = ST_F_HRSP_5XX,
409 [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100410 [ST_F_HRSP_OTHER] = ST_F_SRV_ICUR,
Christopher Fauletf959d082019-02-07 15:38:42 +0100411 [ST_F_HANAFAIL] = 0,
412 [ST_F_REQ_RATE] = 0,
413 [ST_F_REQ_RATE_MAX] = 0,
414 [ST_F_REQ_TOT] = 0,
415 [ST_F_CLI_ABRT] = ST_F_SRV_ABRT,
416 [ST_F_SRV_ABRT] = ST_F_WEIGHT,
417 [ST_F_COMP_IN] = 0,
418 [ST_F_COMP_OUT] = 0,
419 [ST_F_COMP_BYP] = 0,
420 [ST_F_COMP_RSP] = 0,
421 [ST_F_LASTSESS] = ST_F_QCUR,
422 [ST_F_LAST_CHK] = 0,
423 [ST_F_LAST_AGT] = 0,
424 [ST_F_QTIME] = ST_F_CTIME,
425 [ST_F_CTIME] = ST_F_RTIME,
426 [ST_F_RTIME] = ST_F_TTIME,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100427 [ST_F_TTIME] = ST_F_QT_MAX,
Christopher Fauletf959d082019-02-07 15:38:42 +0100428 [ST_F_AGENT_STATUS] = 0,
429 [ST_F_AGENT_CODE] = 0,
430 [ST_F_AGENT_DURATION] = 0,
431 [ST_F_CHECK_DESC] = 0,
432 [ST_F_AGENT_DESC] = 0,
433 [ST_F_CHECK_RISE] = 0,
434 [ST_F_CHECK_FALL] = 0,
435 [ST_F_CHECK_HEALTH] = 0,
436 [ST_F_AGENT_RISE] = 0,
437 [ST_F_AGENT_FALL] = 0,
438 [ST_F_AGENT_HEALTH] = 0,
439 [ST_F_ADDR] = 0,
440 [ST_F_COOKIE] = 0,
441 [ST_F_MODE] = 0,
442 [ST_F_ALGO] = 0,
443 [ST_F_CONN_RATE] = 0,
444 [ST_F_CONN_RATE_MAX] = 0,
445 [ST_F_CONN_TOT] = 0,
446 [ST_F_INTERCEPTED] = 0,
447 [ST_F_DCON] = 0,
448 [ST_F_DSES] = 0,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100449 [ST_F_WREW] = ST_F_EINT,
Christopher Fauletf959d082019-02-07 15:38:42 +0100450 [ST_F_CONNECT] = ST_F_REUSE,
451 [ST_F_REUSE] = ST_F_DRESP,
452 [ST_F_CACHE_LOOKUPS] = 0,
453 [ST_F_CACHE_HITS] = 0,
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100454 [ST_F_SRV_ICUR] = ST_F_SRV_ILIM,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200455 [ST_F_SRV_ILIM] = ST_F_IDLE_CONN_CUR,
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100456 [ST_F_QT_MAX] = ST_F_CT_MAX,
457 [ST_F_CT_MAX] = ST_F_RT_MAX,
458 [ST_F_RT_MAX] = ST_F_TT_MAX,
459 [ST_F_TT_MAX] = ST_F_CONNECT,
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100460 [ST_F_EINT] = ST_F_CLI_ABRT,
Christopher Fauletc55a6262020-07-10 15:39:39 +0200461 [ST_F_IDLE_CONN_CUR] = ST_F_SAFE_CONN_CUR,
462 [ST_F_SAFE_CONN_CUR] = ST_F_USED_CONN_CUR,
463 [ST_F_USED_CONN_CUR] = ST_F_NEED_CONN_EST,
464 [ST_F_NEED_CONN_EST] = 0,
Christopher Fauletf959d082019-02-07 15:38:42 +0100465};
466
467/* Name of all info fields */
468const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = {
469 [INF_NAME] = IST("name"),
470 [INF_VERSION] = IST("version"),
471 [INF_RELEASE_DATE] = IST("release_date"),
472 [INF_NBTHREAD] = IST("nbthread"),
473 [INF_NBPROC] = IST("nbproc"),
474 [INF_PROCESS_NUM] = IST("relative_process_id"),
475 [INF_PID] = IST("pid"),
476 [INF_UPTIME] = IST("uptime"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200477 [INF_UPTIME_SEC] = IST("start_time_seconds"),
478 [INF_MEMMAX_MB] = IST("max_memory_bytes"),
479 [INF_POOL_ALLOC_MB] = IST("pool_allocated_bytes"),
480 [INF_POOL_USED_MB] = IST("pool_used_bytes"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100481 [INF_POOL_FAILED] = IST("pool_failures_total"),
482 [INF_ULIMIT_N] = IST("max_fds"),
483 [INF_MAXSOCK] = IST("max_sockets"),
484 [INF_MAXCONN] = IST("max_connections"),
485 [INF_HARD_MAXCONN] = IST("hard_max_connections"),
486 [INF_CURR_CONN] = IST("current_connections"),
487 [INF_CUM_CONN] = IST("connections_total"),
488 [INF_CUM_REQ] = IST("requests_total"),
489 [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"),
490 [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"),
491 [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"),
492 [INF_MAXPIPES] = IST("max_pipes"),
493 [INF_PIPES_USED] = IST("pipes_used_total"),
494 [INF_PIPES_FREE] = IST("pipes_free_total"),
495 [INF_CONN_RATE] = IST("current_connection_rate"),
496 [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"),
497 [INF_MAX_CONN_RATE] = IST("max_connection_rate"),
498 [INF_SESS_RATE] = IST("current_session_rate"),
499 [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"),
500 [INF_MAX_SESS_RATE] = IST("max_session_rate"),
501 [INF_SSL_RATE] = IST("current_ssl_rate"),
502 [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"),
503 [INF_MAX_SSL_RATE] = IST("max_ssl_rate"),
504 [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"),
505 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"),
Pierre Cheynier1e369762020-07-07 19:14:08 +0200506 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontend_ssl_reuse"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100507 [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"),
508 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200509 [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"),
510 [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100511 [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"),
512 [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"),
513 [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"),
514 [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"),
515 [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"),
516 [INF_TASKS] = IST("current_tasks"),
517 [INF_RUN_QUEUE] = IST("current_run_queue"),
518 [INF_IDLE_PCT] = IST("idle_time_percent"),
519 [INF_NODE] = IST("node"),
520 [INF_DESCRIPTION] = IST("description"),
521 [INF_STOPPING] = IST("stopping"),
522 [INF_JOBS] = IST("jobs"),
523 [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"),
524 [INF_LISTENERS] = IST("listeners"),
525 [INF_ACTIVE_PEERS] = IST("active_peers"),
526 [INF_CONNECTED_PEERS] = IST("connected_peers"),
527 [INF_DROPPED_LOGS] = IST("dropped_logs_total"),
528 [INF_BUSY_POLLING] = IST("busy_polling_enabled"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200529 [INF_FAILED_RESOLUTIONS] = IST("failed_resolutions"),
530 [INF_TOTAL_BYTES_OUT] = IST("bytes_out_total"),
531 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("spliced_bytes_out_total"),
532 [INF_BYTES_OUT_RATE] = IST("bytes_out_rate"),
533 [INF_DEBUG_COMMANDS_ISSUED] = IST("debug_commands_issued"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100534};
535
536/* Name of all stats fields */
537const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = {
538 [ST_F_PXNAME] = IST("proxy_name"),
539 [ST_F_SVNAME] = IST("service_name"),
540 [ST_F_QCUR] = IST("current_queue"),
541 [ST_F_QMAX] = IST("max_queue"),
542 [ST_F_SCUR] = IST("current_sessions"),
543 [ST_F_SMAX] = IST("max_sessions"),
544 [ST_F_SLIM] = IST("limit_sessions"),
545 [ST_F_STOT] = IST("sessions_total"),
546 [ST_F_BIN] = IST("bytes_in_total"),
547 [ST_F_BOUT] = IST("bytes_out_total"),
548 [ST_F_DREQ] = IST("requests_denied_total"),
549 [ST_F_DRESP] = IST("responses_denied_total"),
550 [ST_F_EREQ] = IST("request_errors_total"),
551 [ST_F_ECON] = IST("connection_errors_total"),
552 [ST_F_ERESP] = IST("response_errors_total"),
553 [ST_F_WRETR] = IST("retry_warnings_total"),
554 [ST_F_WREDIS] = IST("redispatch_warnings_total"),
555 [ST_F_STATUS] = IST("status"),
556 [ST_F_WEIGHT] = IST("weight"),
557 [ST_F_ACT] = IST("active_servers"),
558 [ST_F_BCK] = IST("backup_servers"),
559 [ST_F_CHKFAIL] = IST("check_failures_total"),
560 [ST_F_CHKDOWN] = IST("check_up_down_total"),
561 [ST_F_LASTCHG] = IST("check_last_change_seconds"),
562 [ST_F_DOWNTIME] = IST("downtime_seconds_total"),
563 [ST_F_QLIMIT] = IST("queue_limit"),
564 [ST_F_PID] = IST("pid"),
565 [ST_F_IID] = IST("proxy_id"),
566 [ST_F_SID] = IST("server_id"),
567 [ST_F_THROTTLE] = IST("current_throttle"),
568 [ST_F_LBTOT] = IST("loadbalanced_total"),
569 [ST_F_TRACKED] = IST("tracked"),
570 [ST_F_TYPE] = IST("type"),
571 [ST_F_RATE] = IST("current_session_rate"),
572 [ST_F_RATE_LIM] = IST("limit_session_rate"),
573 [ST_F_RATE_MAX] = IST("max_session_rate"),
574 [ST_F_CHECK_STATUS] = IST("check_status"),
575 [ST_F_CHECK_CODE] = IST("check_code"),
Christopher Faulet2711e512020-02-27 16:12:07 +0100576 [ST_F_CHECK_DURATION] = IST("check_duration_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100577 [ST_F_HRSP_1XX] = IST("http_responses_total"),
578 [ST_F_HRSP_2XX] = IST("http_responses_total"),
579 [ST_F_HRSP_3XX] = IST("http_responses_total"),
580 [ST_F_HRSP_4XX] = IST("http_responses_total"),
581 [ST_F_HRSP_5XX] = IST("http_responses_total"),
582 [ST_F_HRSP_OTHER] = IST("http_responses_total"),
583 [ST_F_HANAFAIL] = IST("check_analyses_failures_total"),
584 [ST_F_REQ_RATE] = IST("http_requests_rate_current"),
585 [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"),
586 [ST_F_REQ_TOT] = IST("http_requests_total"),
587 [ST_F_CLI_ABRT] = IST("client_aborts_total"),
588 [ST_F_SRV_ABRT] = IST("server_aborts_total"),
589 [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"),
590 [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"),
591 [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"),
592 [ST_F_COMP_RSP] = IST("http_comp_responses_total"),
593 [ST_F_LASTSESS] = IST("last_session_seconds"),
594 [ST_F_LAST_CHK] = IST("check_last_content"),
595 [ST_F_LAST_AGT] = IST("agentcheck_last_content"),
Christopher Faulet68b69682019-11-08 15:12:29 +0100596 [ST_F_QTIME] = IST("queue_time_average_seconds"),
597 [ST_F_CTIME] = IST("connect_time_average_seconds"),
598 [ST_F_RTIME] = IST("response_time_average_seconds"),
599 [ST_F_TTIME] = IST("total_time_average_seconds"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100600 [ST_F_AGENT_STATUS] = IST("agentcheck_status"),
601 [ST_F_AGENT_CODE] = IST("agentcheck_code"),
602 [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"),
603 [ST_F_CHECK_DESC] = IST("check_description"),
604 [ST_F_AGENT_DESC] = IST("agentcheck_description"),
605 [ST_F_CHECK_RISE] = IST("check_rise"),
606 [ST_F_CHECK_FALL] = IST("check_fall"),
607 [ST_F_CHECK_HEALTH] = IST("check_value"),
608 [ST_F_AGENT_RISE] = IST("agentcheck_rise"),
609 [ST_F_AGENT_FALL] = IST("agentcheck_fall"),
610 [ST_F_AGENT_HEALTH] = IST("agentcheck_value"),
611 [ST_F_ADDR] = IST("address"),
612 [ST_F_COOKIE] = IST("cookie"),
613 [ST_F_MODE] = IST("mode"),
614 [ST_F_ALGO] = IST("loadbalance_algorithm"),
615 [ST_F_CONN_RATE] = IST("connections_rate_current"),
616 [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"),
617 [ST_F_CONN_TOT] = IST("connections_total"),
618 [ST_F_INTERCEPTED] = IST("intercepted_requests_total"),
619 [ST_F_DCON] = IST("denied_connections_total"),
620 [ST_F_DSES] = IST("denied_sessions_total"),
621 [ST_F_WREW] = IST("failed_header_rewriting_total"),
622 [ST_F_CONNECT] = IST("connection_attempts_total"),
623 [ST_F_REUSE] = IST("connection_reuses_total"),
624 [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"),
625 [ST_F_CACHE_HITS] = IST("http_cache_hits_total"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200626 [ST_F_SRV_ICUR] = IST("idle_connections_current"),
627 [ST_F_SRV_ILIM] = IST("idle_connections_limit"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100628 [ST_F_QT_MAX] = IST("max_queue_time_seconds"),
629 [ST_F_CT_MAX] = IST("max_connect_time_seconds"),
630 [ST_F_RT_MAX] = IST("max_response_time_seconds"),
631 [ST_F_TT_MAX] = IST("max_total_time_seconds"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100632 [ST_F_EINT] = IST("internal_errors_total"),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200633 [ST_F_IDLE_CONN_CUR] = IST("unsafe_idle_connections_current"),
634 [ST_F_SAFE_CONN_CUR] = IST("safe_idle_connections_current"),
635 [ST_F_USED_CONN_CUR] = IST("used_connections_current"),
636 [ST_F_NEED_CONN_EST] = IST("need_connections_current"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100637};
638
639/* Description of all info fields */
640const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = {
641 [INF_NAME] = IST("Product name."),
642 [INF_VERSION] = IST("HAProxy version."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500643 [INF_RELEASE_DATE] = IST("HAProxy release date."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100644 [INF_NBTHREAD] = IST("Configured number of threads."),
645 [INF_NBPROC] = IST("Configured number of processes."),
646 [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."),
647 [INF_PID] = IST("HAProxy PID."),
648 [INF_UPTIME] = IST("Uptime in a human readable format."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200649 [INF_UPTIME_SEC] = IST("Start time in seconds."),
650 [INF_MEMMAX_MB] = IST("Per-process memory limit (in bytes); 0=unset."),
651 [INF_POOL_ALLOC_MB] = IST("Total amount of memory allocated in pools (in bytes)."),
652 [INF_POOL_USED_MB] = IST("Total amount of memory used in pools (in bytes)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100653 [INF_POOL_FAILED] = IST("Total number of failed pool allocations."),
654 [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."),
Ilya Shipitsince7b00f2020-03-23 22:28:40 +0500655 [INF_MAXSOCK] = IST("Maximum number of open sockets."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100656 [INF_MAXCONN] = IST("Maximum number of concurrent connections."),
657 [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."),
658 [INF_CURR_CONN] = IST("Number of active sessions."),
Christopher Faulet8c8e4b12019-04-18 10:15:15 +0200659 [INF_CUM_CONN] = IST("Total number of created sessions."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100660 [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."),
661 [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."),
662 [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."),
663 [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."),
664 [INF_MAXPIPES] = IST("Configured maximum number of pipes."),
665 [INF_PIPES_USED] = IST("Number of pipes in used."),
666 [INF_PIPES_FREE] = IST("Number of pipes unused."),
667 [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."),
668 [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."),
669 [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."),
670 [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."),
671 [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."),
672 [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."),
673 [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."),
674 [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."),
675 [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."),
676 [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."),
677 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."),
678 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."),
679 [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."),
680 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."),
681 [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."),
682 [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."),
683 [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."),
684 [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."),
685 [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."),
686 [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."),
687 [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."),
688 [INF_TASKS] = IST("Current number of tasks."),
689 [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."),
690 [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."),
691 [INF_NODE] = IST("Node name."),
692 [INF_DESCRIPTION] = IST("Node description."),
693 [INF_STOPPING] = IST("Non zero means stopping in progress."),
694 [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."),
695 [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."),
696 [INF_LISTENERS] = IST("Current number of active listeners."),
697 [INF_ACTIVE_PEERS] = IST("Current number of active peers."),
698 [INF_CONNECTED_PEERS] = IST("Current number of connected peers."),
699 [INF_DROPPED_LOGS] = IST("Total number of dropped logs."),
700 [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200701 [INF_FAILED_RESOLUTIONS] = IST("Total number of failed DNS resolutions."),
702 [INF_TOTAL_BYTES_OUT] = IST("Total number of bytes emitted."),
703 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("Total number of bytes emitted through a kernel pipe."),
704 [INF_BYTES_OUT_RATE] = IST("Number of bytes emitted over the last elapsed second."),
705 [INF_DEBUG_COMMANDS_ISSUED] = IST("Number of debug commands issued on this process (anything > 0 is unsafe)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100706};
707
708/* Description of all stats fields */
709const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = {
710 [ST_F_PXNAME] = IST("The proxy name."),
711 [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."),
712 [ST_F_QCUR] = IST("Current number of queued requests."),
713 [ST_F_QMAX] = IST("Maximum observed number of queued requests."),
714 [ST_F_SCUR] = IST("Current number of active sessions."),
715 [ST_F_SMAX] = IST("Maximum observed number of active sessions."),
716 [ST_F_SLIM] = IST("Configured session limit."),
717 [ST_F_STOT] = IST("Total number of sessions."),
718 [ST_F_BIN] = IST("Current total of incoming bytes."),
719 [ST_F_BOUT] = IST("Current total of outgoing bytes."),
720 [ST_F_DREQ] = IST("Total number of denied requests."),
721 [ST_F_DRESP] = IST("Total number of denied responses."),
722 [ST_F_EREQ] = IST("Total number of request errors."),
723 [ST_F_ECON] = IST("Total number of connection errors."),
724 [ST_F_ERESP] = IST("Total number of response errors."),
725 [ST_F_WRETR] = IST("Total number of retry warnings."),
726 [ST_F_WREDIS] = IST("Total number of redispatch warnings."),
Christopher Fauletd45d1052019-09-06 16:10:19 +0200727 [ST_F_STATUS] = IST("Current status of the service (frontend: 0=STOP, 1=UP, 2=FULL - backend: 0=DOWN, 1=UP - server: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100728 [ST_F_WEIGHT] = IST("Service weight."),
729 [ST_F_ACT] = IST("Current number of active servers."),
730 [ST_F_BCK] = IST("Current number of backup servers."),
731 [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."),
732 [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."),
733 [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."),
734 [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."),
735 [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."),
736 [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"),
737 [ST_F_IID] = IST("Unique proxy id."),
738 [ST_F_SID] = IST("Server id (unique inside a proxy)."),
739 [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."),
740 [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."),
741 [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."),
742 [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."),
743 [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."),
744 [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."),
745 [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."),
Christopher Fauletcf403f32019-11-21 14:35:46 +0100746 [ST_F_CHECK_STATUS] = IST("Status of last health check (HCHK_STATUS_* values)."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100747 [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."),
Christopher Faulet2711e512020-02-27 16:12:07 +0100748 [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100749 [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."),
750 [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."),
751 [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."),
752 [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."),
753 [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."),
754 [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."),
755 [ST_F_HANAFAIL] = IST("Total number of failed health checks."),
756 [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."),
757 [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."),
758 [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."),
759 [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."),
760 [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."),
761 [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."),
762 [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."),
763 [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."),
764 [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."),
765 [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."),
766 [ST_F_LAST_CHK] = IST("Last health check contents or textual error"),
767 [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"),
768 [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."),
769 [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."),
770 [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."),
771 [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."),
772 [ST_F_AGENT_STATUS] = IST("Status of last agent check."),
773 [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."),
774 [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."),
775 [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."),
776 [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."),
777 [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"),
778 [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"),
779 [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"),
780 [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."),
781 [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."),
782 [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"),
783 [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."),
784 [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."),
785 [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."),
786 [ST_F_ALGO] = IST("Load balancing algorithm."),
787 [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."),
788 [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."),
789 [ST_F_CONN_TOT] = IST("Total number of connections."),
790 [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."),
791 [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."),
792 [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."),
793 [ST_F_WREW] = IST("Total number of failed header rewriting warnings."),
794 [ST_F_CONNECT] = IST("Total number of connection establishment attempts."),
795 [ST_F_REUSE] = IST("Total number of connection reuses."),
796 [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."),
797 [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."),
Christopher Faulet20ab80c2019-11-08 15:24:32 +0100798 [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"),
799 [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +0100800 [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"),
801 [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"),
802 [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"),
803 [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +0100804 [ST_F_EINT] = IST("Total number of internal errors."),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200805 [ST_F_IDLE_CONN_CUR] = IST("Current number of unsafe idle connections."),
806 [ST_F_SAFE_CONN_CUR] = IST("Current number of safe idle connections."),
807 [ST_F_USED_CONN_CUR] = IST("Current number of connections in use."),
808 [ST_F_NEED_CONN_EST] = IST("Estimated needed number of connections."),
Christopher Fauletf959d082019-02-07 15:38:42 +0100809};
810
811/* Specific labels for all info fields. Empty by default. */
812const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = {
813 [INF_NAME] = IST(""),
814 [INF_VERSION] = IST(""),
815 [INF_RELEASE_DATE] = IST(""),
816 [INF_NBTHREAD] = IST(""),
817 [INF_NBPROC] = IST(""),
818 [INF_PROCESS_NUM] = IST(""),
819 [INF_PID] = IST(""),
820 [INF_UPTIME] = IST(""),
821 [INF_UPTIME_SEC] = IST(""),
822 [INF_MEMMAX_MB] = IST(""),
823 [INF_POOL_ALLOC_MB] = IST(""),
824 [INF_POOL_USED_MB] = IST(""),
825 [INF_POOL_FAILED] = IST(""),
826 [INF_ULIMIT_N] = IST(""),
827 [INF_MAXSOCK] = IST(""),
828 [INF_MAXCONN] = IST(""),
829 [INF_HARD_MAXCONN] = IST(""),
830 [INF_CURR_CONN] = IST(""),
831 [INF_CUM_CONN] = IST(""),
832 [INF_CUM_REQ] = IST(""),
833 [INF_MAX_SSL_CONNS] = IST(""),
834 [INF_CURR_SSL_CONNS] = IST(""),
835 [INF_CUM_SSL_CONNS] = IST(""),
836 [INF_MAXPIPES] = IST(""),
837 [INF_PIPES_USED] = IST(""),
838 [INF_PIPES_FREE] = IST(""),
839 [INF_CONN_RATE] = IST(""),
840 [INF_CONN_RATE_LIMIT] = IST(""),
841 [INF_MAX_CONN_RATE] = IST(""),
842 [INF_SESS_RATE] = IST(""),
843 [INF_SESS_RATE_LIMIT] = IST(""),
844 [INF_MAX_SESS_RATE] = IST(""),
845 [INF_SSL_RATE] = IST(""),
846 [INF_SSL_RATE_LIMIT] = IST(""),
847 [INF_MAX_SSL_RATE] = IST(""),
848 [INF_SSL_FRONTEND_KEY_RATE] = IST(""),
849 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""),
850 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""),
851 [INF_SSL_BACKEND_KEY_RATE] = IST(""),
852 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""),
853 [INF_SSL_CACHE_LOOKUPS] = IST(""),
854 [INF_SSL_CACHE_MISSES] = IST(""),
855 [INF_COMPRESS_BPS_IN] = IST(""),
856 [INF_COMPRESS_BPS_OUT] = IST(""),
857 [INF_COMPRESS_BPS_RATE_LIM] = IST(""),
858 [INF_ZLIB_MEM_USAGE] = IST(""),
859 [INF_MAX_ZLIB_MEM_USAGE] = IST(""),
860 [INF_TASKS] = IST(""),
861 [INF_RUN_QUEUE] = IST(""),
862 [INF_IDLE_PCT] = IST(""),
863 [INF_NODE] = IST(""),
864 [INF_DESCRIPTION] = IST(""),
865 [INF_STOPPING] = IST(""),
866 [INF_JOBS] = IST(""),
867 [INF_UNSTOPPABLE_JOBS] = IST(""),
868 [INF_LISTENERS] = IST(""),
869 [INF_ACTIVE_PEERS] = IST(""),
870 [INF_CONNECTED_PEERS] = IST(""),
871 [INF_DROPPED_LOGS] = IST(""),
872 [INF_BUSY_POLLING] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200873 [INF_FAILED_RESOLUTIONS] = IST(""),
874 [INF_TOTAL_BYTES_OUT] = IST(""),
875 [INF_TOTAL_SPLICED_BYTES_OUT] = IST(""),
876 [INF_BYTES_OUT_RATE] = IST(""),
877 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100878};
879
880/* Specific labels for all stats fields. Empty by default. */
881const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = {
882 [ST_F_PXNAME] = IST(""),
883 [ST_F_SVNAME] = IST(""),
884 [ST_F_QCUR] = IST(""),
885 [ST_F_QMAX] = IST(""),
886 [ST_F_SCUR] = IST(""),
887 [ST_F_SMAX] = IST(""),
888 [ST_F_SLIM] = IST(""),
889 [ST_F_STOT] = IST(""),
890 [ST_F_BIN] = IST(""),
891 [ST_F_BOUT] = IST(""),
892 [ST_F_DREQ] = IST(""),
893 [ST_F_DRESP] = IST(""),
894 [ST_F_EREQ] = IST(""),
895 [ST_F_ECON] = IST(""),
896 [ST_F_ERESP] = IST(""),
897 [ST_F_WRETR] = IST(""),
898 [ST_F_WREDIS] = IST(""),
899 [ST_F_STATUS] = IST(""),
900 [ST_F_WEIGHT] = IST(""),
901 [ST_F_ACT] = IST(""),
902 [ST_F_BCK] = IST(""),
903 [ST_F_CHKFAIL] = IST(""),
904 [ST_F_CHKDOWN] = IST(""),
905 [ST_F_LASTCHG] = IST(""),
906 [ST_F_DOWNTIME] = IST(""),
907 [ST_F_QLIMIT] = IST(""),
908 [ST_F_PID] = IST(""),
909 [ST_F_IID] = IST(""),
910 [ST_F_SID] = IST(""),
911 [ST_F_THROTTLE] = IST(""),
912 [ST_F_LBTOT] = IST(""),
913 [ST_F_TRACKED] = IST(""),
914 [ST_F_TYPE] = IST(""),
915 [ST_F_RATE] = IST(""),
916 [ST_F_RATE_LIM] = IST(""),
917 [ST_F_RATE_MAX] = IST(""),
918 [ST_F_CHECK_STATUS] = IST(""),
919 [ST_F_CHECK_CODE] = IST(""),
920 [ST_F_CHECK_DURATION] = IST(""),
921 [ST_F_HRSP_1XX] = IST("code=\"1xx\""),
922 [ST_F_HRSP_2XX] = IST("code=\"2xx\""),
923 [ST_F_HRSP_3XX] = IST("code=\"3xx\""),
924 [ST_F_HRSP_4XX] = IST("code=\"4xx\""),
925 [ST_F_HRSP_5XX] = IST("code=\"5xx\""),
926 [ST_F_HRSP_OTHER] = IST("code=\"other\""),
927 [ST_F_HANAFAIL] = IST(""),
928 [ST_F_REQ_RATE] = IST(""),
929 [ST_F_REQ_RATE_MAX] = IST(""),
930 [ST_F_REQ_TOT] = IST(""),
931 [ST_F_CLI_ABRT] = IST(""),
932 [ST_F_SRV_ABRT] = IST(""),
933 [ST_F_COMP_IN] = IST(""),
934 [ST_F_COMP_OUT] = IST(""),
935 [ST_F_COMP_BYP] = IST(""),
936 [ST_F_COMP_RSP] = IST(""),
937 [ST_F_LASTSESS] = IST(""),
938 [ST_F_LAST_CHK] = IST(""),
939 [ST_F_LAST_AGT] = IST(""),
940 [ST_F_QTIME] = IST(""),
941 [ST_F_CTIME] = IST(""),
942 [ST_F_RTIME] = IST(""),
943 [ST_F_TTIME] = IST(""),
944 [ST_F_AGENT_STATUS] = IST(""),
945 [ST_F_AGENT_CODE] = IST(""),
946 [ST_F_AGENT_DURATION] = IST(""),
947 [ST_F_CHECK_DESC] = IST(""),
948 [ST_F_AGENT_DESC] = IST(""),
949 [ST_F_CHECK_RISE] = IST(""),
950 [ST_F_CHECK_FALL] = IST(""),
951 [ST_F_CHECK_HEALTH] = IST(""),
952 [ST_F_AGENT_RISE] = IST(""),
953 [ST_F_AGENT_FALL] = IST(""),
954 [ST_F_AGENT_HEALTH] = IST(""),
955 [ST_F_ADDR] = IST(""),
956 [ST_F_COOKIE] = IST(""),
957 [ST_F_MODE] = IST(""),
958 [ST_F_ALGO] = IST(""),
959 [ST_F_CONN_RATE] = IST(""),
960 [ST_F_CONN_RATE_MAX] = IST(""),
961 [ST_F_CONN_TOT] = IST(""),
962 [ST_F_INTERCEPTED] = IST(""),
963 [ST_F_DCON] = IST(""),
964 [ST_F_DSES] = IST(""),
965 [ST_F_WREW] = IST(""),
966 [ST_F_CONNECT] = IST(""),
967 [ST_F_REUSE] = IST(""),
968 [ST_F_CACHE_LOOKUPS] = IST(""),
969 [ST_F_CACHE_HITS] = IST(""),
Christopher Fauletc55a6262020-07-10 15:39:39 +0200970 [ST_F_IDLE_CONN_CUR] = IST(""),
971 [ST_F_SAFE_CONN_CUR] = IST(""),
972 [ST_F_USED_CONN_CUR] = IST(""),
973 [ST_F_NEED_CONN_EST] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +0100974};
975
976/* Type for all info fields. "untyped" is used for unsupported field. */
977const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = {
978 [INF_NAME] = IST("untyped"),
979 [INF_VERSION] = IST("untyped"),
980 [INF_RELEASE_DATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200981 [INF_NBTHREAD] = IST("gauge"),
982 [INF_NBPROC] = IST("gauge"),
983 [INF_PROCESS_NUM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100984 [INF_PID] = IST("untyped"),
985 [INF_UPTIME] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200986 [INF_UPTIME_SEC] = IST("gauge"),
987 [INF_MEMMAX_MB] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100988 [INF_POOL_ALLOC_MB] = IST("gauge"),
989 [INF_POOL_USED_MB] = IST("gauge"),
990 [INF_POOL_FAILED] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200991 [INF_ULIMIT_N] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100992 [INF_MAXSOCK] = IST("gauge"),
993 [INF_MAXCONN] = IST("gauge"),
994 [INF_HARD_MAXCONN] = IST("gauge"),
995 [INF_CURR_CONN] = IST("gauge"),
996 [INF_CUM_CONN] = IST("counter"),
997 [INF_CUM_REQ] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +0200998 [INF_MAX_SSL_CONNS] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +0100999 [INF_CURR_SSL_CONNS] = IST("gauge"),
1000 [INF_CUM_SSL_CONNS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001001 [INF_MAXPIPES] = IST("gauge"),
1002 [INF_PIPES_USED] = IST("counter"),
1003 [INF_PIPES_FREE] = IST("counter"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001004 [INF_CONN_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001005 [INF_CONN_RATE_LIMIT] = IST("gauge"),
1006 [INF_MAX_CONN_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001007 [INF_SESS_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001008 [INF_SESS_RATE_LIMIT] = IST("gauge"),
1009 [INF_MAX_SESS_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001010 [INF_SSL_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001011 [INF_SSL_RATE_LIMIT] = IST("gauge"),
1012 [INF_MAX_SSL_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001013 [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001014 [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001015 [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"),
1016 [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001017 [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001018 [INF_SSL_CACHE_LOOKUPS] = IST("counter"),
1019 [INF_SSL_CACHE_MISSES] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001020 [INF_COMPRESS_BPS_IN] = IST("counter"),
1021 [INF_COMPRESS_BPS_OUT] = IST("counter"),
1022 [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001023 [INF_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001024 [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001025 [INF_TASKS] = IST("gauge"),
Christopher Fauletf782c232019-04-17 16:04:44 +02001026 [INF_RUN_QUEUE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001027 [INF_IDLE_PCT] = IST("gauge"),
1028 [INF_NODE] = IST("untyped"),
1029 [INF_DESCRIPTION] = IST("untyped"),
1030 [INF_STOPPING] = IST("gauge"),
1031 [INF_JOBS] = IST("gauge"),
1032 [INF_UNSTOPPABLE_JOBS] = IST("gauge"),
1033 [INF_LISTENERS] = IST("gauge"),
1034 [INF_ACTIVE_PEERS] = IST("gauge"),
1035 [INF_CONNECTED_PEERS] = IST("gauge"),
1036 [INF_DROPPED_LOGS] = IST("counter"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001037 [INF_BUSY_POLLING] = IST("gauge"),
Christopher Fauletc55a6262020-07-10 15:39:39 +02001038 [INF_FAILED_RESOLUTIONS] = IST("counter"),
1039 [INF_TOTAL_BYTES_OUT] = IST("counter"),
1040 [INF_TOTAL_SPLICED_BYTES_OUT] = IST("counter"),
1041 [INF_BYTES_OUT_RATE] = IST("gauge"),
1042 [INF_DEBUG_COMMANDS_ISSUED] = IST(""),
Christopher Fauletf959d082019-02-07 15:38:42 +01001043};
1044
1045/* Type for all stats fields. "untyped" is used for unsupported field. */
1046const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = {
1047 [ST_F_PXNAME] = IST("untyped"),
1048 [ST_F_SVNAME] = IST("untyped"),
1049 [ST_F_QCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001050 [ST_F_QMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001051 [ST_F_SCUR] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001052 [ST_F_SMAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001053 [ST_F_SLIM] = IST("gauge"),
1054 [ST_F_STOT] = IST("counter"),
1055 [ST_F_BIN] = IST("counter"),
1056 [ST_F_BOUT] = IST("counter"),
1057 [ST_F_DREQ] = IST("counter"),
1058 [ST_F_DRESP] = IST("counter"),
1059 [ST_F_EREQ] = IST("counter"),
1060 [ST_F_ECON] = IST("counter"),
1061 [ST_F_ERESP] = IST("counter"),
1062 [ST_F_WRETR] = IST("counter"),
1063 [ST_F_WREDIS] = IST("counter"),
1064 [ST_F_STATUS] = IST("gauge"),
1065 [ST_F_WEIGHT] = IST("gauge"),
1066 [ST_F_ACT] = IST("gauge"),
1067 [ST_F_BCK] = IST("gauge"),
1068 [ST_F_CHKFAIL] = IST("counter"),
1069 [ST_F_CHKDOWN] = IST("counter"),
1070 [ST_F_LASTCHG] = IST("gauge"),
1071 [ST_F_DOWNTIME] = IST("counter"),
1072 [ST_F_QLIMIT] = IST("gauge"),
1073 [ST_F_PID] = IST("untyped"),
1074 [ST_F_IID] = IST("untyped"),
1075 [ST_F_SID] = IST("untyped"),
1076 [ST_F_THROTTLE] = IST("gauge"),
1077 [ST_F_LBTOT] = IST("counter"),
1078 [ST_F_TRACKED] = IST("untyped"),
1079 [ST_F_TYPE] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001080 [ST_F_RATE] = IST("untyped"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001081 [ST_F_RATE_LIM] = IST("gauge"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001082 [ST_F_RATE_MAX] = IST("gauge"),
Christopher Fauletcf403f32019-11-21 14:35:46 +01001083 [ST_F_CHECK_STATUS] = IST("gauge"),
1084 [ST_F_CHECK_CODE] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001085 [ST_F_CHECK_DURATION] = IST("gauge"),
1086 [ST_F_HRSP_1XX] = IST("counter"),
1087 [ST_F_HRSP_2XX] = IST("counter"),
1088 [ST_F_HRSP_3XX] = IST("counter"),
1089 [ST_F_HRSP_4XX] = IST("counter"),
1090 [ST_F_HRSP_5XX] = IST("counter"),
1091 [ST_F_HRSP_OTHER] = IST("counter"),
1092 [ST_F_HANAFAIL] = IST("counter"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001093 [ST_F_REQ_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001094 [ST_F_REQ_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001095 [ST_F_REQ_TOT] = IST("counter"),
1096 [ST_F_CLI_ABRT] = IST("counter"),
1097 [ST_F_SRV_ABRT] = IST("counter"),
1098 [ST_F_COMP_IN] = IST("counter"),
1099 [ST_F_COMP_OUT] = IST("counter"),
1100 [ST_F_COMP_BYP] = IST("counter"),
1101 [ST_F_COMP_RSP] = IST("counter"),
1102 [ST_F_LASTSESS] = IST("gauge"),
1103 [ST_F_LAST_CHK] = IST("untyped"),
1104 [ST_F_LAST_AGT] = IST("untyped"),
1105 [ST_F_QTIME] = IST("gauge"),
1106 [ST_F_CTIME] = IST("gauge"),
1107 [ST_F_RTIME] = IST("gauge"),
1108 [ST_F_TTIME] = IST("gauge"),
1109 [ST_F_AGENT_STATUS] = IST("untyped"),
1110 [ST_F_AGENT_CODE] = IST("untyped"),
1111 [ST_F_AGENT_DURATION] = IST("gauge"),
1112 [ST_F_CHECK_DESC] = IST("untyped"),
1113 [ST_F_AGENT_DESC] = IST("untyped"),
1114 [ST_F_CHECK_RISE] = IST("gauge"),
1115 [ST_F_CHECK_FALL] = IST("gauge"),
1116 [ST_F_CHECK_HEALTH] = IST("gauge"),
1117 [ST_F_AGENT_RISE] = IST("gauge"),
1118 [ST_F_AGENT_FALL] = IST("gauge"),
1119 [ST_F_AGENT_HEALTH] = IST("gauge"),
1120 [ST_F_ADDR] = IST("untyped"),
1121 [ST_F_COOKIE] = IST("untyped"),
1122 [ST_F_MODE] = IST("untyped"),
1123 [ST_F_ALGO] = IST("untyped"),
Christopher Fauletc58fc0d2019-04-18 10:10:49 +02001124 [ST_F_CONN_RATE] = IST("untyped"),
Christopher Faulet769a92d2019-04-18 10:18:44 +02001125 [ST_F_CONN_RATE_MAX] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001126 [ST_F_CONN_TOT] = IST("counter"),
1127 [ST_F_INTERCEPTED] = IST("counter"),
1128 [ST_F_DCON] = IST("counter"),
1129 [ST_F_DSES] = IST("counter"),
1130 [ST_F_WREW] = IST("counter"),
1131 [ST_F_CONNECT] = IST("counter"),
1132 [ST_F_REUSE] = IST("counter"),
1133 [ST_F_CACHE_LOOKUPS] = IST("counter"),
1134 [ST_F_CACHE_HITS] = IST("counter"),
Christopher Faulet20ab80c2019-11-08 15:24:32 +01001135 [ST_F_SRV_ICUR] = IST("gauge"),
1136 [ST_F_SRV_ILIM] = IST("gauge"),
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001137 [ST_F_QT_MAX] = IST("gauge"),
1138 [ST_F_CT_MAX] = IST("gauge"),
1139 [ST_F_RT_MAX] = IST("gauge"),
1140 [ST_F_TT_MAX] = IST("gauge"),
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001141 [ST_F_EINT] = IST("counter"),
Christopher Fauletc55a6262020-07-10 15:39:39 +02001142 [ST_F_IDLE_CONN_CUR] = IST("gauge"),
1143 [ST_F_SAFE_CONN_CUR] = IST("gauge"),
1144 [ST_F_USED_CONN_CUR] = IST("gauge"),
1145 [ST_F_NEED_CONN_EST] = IST("gauge"),
Christopher Fauletf959d082019-02-07 15:38:42 +01001146};
1147
Christopher Fauletd45d1052019-09-06 16:10:19 +02001148/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
Christopher Fauletf959d082019-02-07 15:38:42 +01001149static int promex_srv_status(struct server *sv)
1150{
Christopher Fauletf959d082019-02-07 15:38:42 +01001151 int state = 0;
1152
Christopher Fauletf959d082019-02-07 15:38:42 +01001153 if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
1154 state = 1;
1155 if (sv->cur_admin & SRV_ADMF_DRAIN)
Christopher Fauletd45d1052019-09-06 16:10:19 +02001156 state = 3;
Christopher Fauletf959d082019-02-07 15:38:42 +01001157 }
Christopher Fauletd45d1052019-09-06 16:10:19 +02001158 else if (sv->cur_state == SRV_ST_STOPPING)
1159 state = 4;
1160
1161 if (sv->cur_admin & SRV_ADMF_MAINT)
1162 state = 2;
Christopher Fauletf959d082019-02-07 15:38:42 +01001163
1164 return state;
1165}
1166
1167/* Convert a field to its string representation and write it in <out>, followed
1168 * by a newline, if there is enough space. non-numeric value are converted in
1169 * "Nan" because Prometheus only support numerical values (but it is unexepceted
1170 * to process this kind of value). It returns 1 on success. Otherwise, it
1171 * returns 0. The buffer's length must not exceed <max> value.
1172 */
1173static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max)
1174{
1175 int ret = 0;
1176
1177 switch (field_format(f, 0)) {
1178 case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break;
1179 case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break;
1180 case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break;
1181 case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break;
1182 case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001183 case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001184 case FF_STR: ret = chunk_strcat(out, "Nan\n"); break;
1185 default: ret = chunk_strcat(out, "Nan\n"); break;
1186 }
1187 if (!ret || out->data > max)
1188 return 0;
1189 return 1;
1190}
1191
1192/* Concatenate the <prefix> with the field name using the array
1193 * <promex_st_metric_names> and store it in <name>. The field type is in
1194 * <appctx->st2>. This function never fails but relies on
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001195 * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enough to be copied in
Christopher Fauletf959d082019-02-07 15:38:42 +01001196 * <name>
1197 */
1198static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix)
1199{
1200 const struct ist *names;
1201
1202 names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC)
1203 ? promex_inf_metric_names
1204 : promex_st_metric_names);
1205
1206 istcat(name, prefix, PROMEX_MAX_NAME_LEN);
1207 istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN);
1208}
1209
1210/* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It
1211 * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0.
1212 */
1213static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx,
1214 const struct ist name, struct ist *out, size_t max)
1215{
1216 const struct ist *desc, *types;
1217
1218 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1219 desc = promex_inf_metric_desc;
1220 types = promex_inf_metric_types;
1221 }
1222 else {
1223 desc = promex_st_metric_desc;
1224 types = promex_st_metric_types;
1225 }
1226
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001227 if (istcat(out, ist("# HELP "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001228 istcat(out, name, max) == -1 ||
1229 istcat(out, ist(" "), max) == -1 ||
1230 istcat(out, desc[appctx->st2], max) == -1 ||
Anthonin Bonnefoy51c3aa42019-08-07 17:45:25 +02001231 istcat(out, ist("\n# TYPE "), max) == -1 ||
Christopher Fauletf959d082019-02-07 15:38:42 +01001232 istcat(out, name, max) == -1 ||
1233 istcat(out, ist(" "), max) == -1 ||
1234 istcat(out, types[appctx->st2], max) == -1 ||
1235 istcat(out, ist("\n"), max) == -1)
1236 goto full;
1237
1238 return 1;
1239
1240 full:
1241 return 0;
1242}
1243
1244/* Dump the line for <metric>. It starts by the metric name followed by its
1245 * labels (proxy name, server name...) between braces and finally its value. If
1246 * not already done, the header lines are dumped first. It returns 1 on
1247 * success. Otherwise if <out> length exceeds <max>, it returns 0.
1248 */
1249static int promex_dump_metric(struct appctx *appctx, struct htx *htx,
1250 const struct ist prefix, struct field *metric,
1251 struct ist *out, size_t max)
1252{
1253 struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 };
1254 size_t len = out->len;
1255
1256 if (out->len + PROMEX_MAX_METRIC_LENGTH > max)
1257 return 0;
1258
1259 promex_metric_name(appctx, &name, prefix);
1260 if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) &&
1261 !promex_dump_metric_header(appctx, htx, name, out, max))
1262 goto full;
1263
1264 if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) {
1265 const struct ist label = promex_inf_metric_labels[appctx->st2];
1266
1267 if (istcat(out, name, max) == -1 ||
1268 (label.len && istcat(out, ist("{"), max) == -1) ||
1269 (label.len && istcat(out, label, max) == -1) ||
1270 (label.len && istcat(out, ist("}"), max) == -1) ||
1271 istcat(out, ist(" "), max) == -1)
1272 goto full;
1273 }
1274 else {
1275 struct proxy *px = appctx->ctx.stats.px;
1276 struct server *srv = appctx->ctx.stats.sv;
1277 const struct ist label = promex_st_metric_labels[appctx->st2];
1278
1279 if (istcat(out, name, max) == -1 ||
1280 istcat(out, ist("{proxy=\""), max) == -1 ||
1281 istcat(out, ist2(px->id, strlen(px->id)), max) == -1 ||
1282 istcat(out, ist("\""), max) == -1 ||
1283 (srv && istcat(out, ist(",server=\""), max) == -1) ||
1284 (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) ||
1285 (srv && istcat(out, ist("\""), max) == -1) ||
1286 (label.len && istcat(out, ist(","), max) == -1) ||
1287 (label.len && istcat(out, label, max) == -1) ||
1288 istcat(out, ist("} "), max) == -1)
1289 goto full;
1290 }
1291
1292 trash.data = out->len;
1293 if (!promex_metric_to_str(&trash, metric, max))
1294 goto full;
1295 out->len = trash.data;
1296
1297 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1298 return 1;
1299 full:
1300 // Restore previous length
1301 out->len = len;
1302 return 0;
1303
1304}
1305
1306
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001307/* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001308 * 0 if <htx> is full and -1 in case of any error. */
1309static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
1310{
1311 static struct ist prefix = IST("haproxy_process_");
1312 struct field metric;
1313 struct channel *chn = si_ic(appctx->owner);
1314 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001315 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001316 int ret = 1;
1317
1318#ifdef USE_OPENSSL
1319 int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec);
1320 int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec);
1321 int ssl_reuse = 0;
1322
1323 if (ssl_key_rate < ssl_sess_rate) {
1324 /* count the ssl reuse ratio and avoid overflows in both directions */
1325 ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate;
1326 }
1327#endif
Christopher Fauletf959d082019-02-07 15:38:42 +01001328 while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) {
1329 switch (appctx->st2) {
1330 case INF_NBTHREAD:
1331 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread);
1332 break;
1333 case INF_NBPROC:
1334 metric = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc);
1335 break;
1336 case INF_PROCESS_NUM:
1337 metric = mkf_u32(FO_KEY, relative_pid);
1338 break;
1339 case INF_UPTIME_SEC:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001340 metric = mkf_u32(FN_DURATION, start_date.tv_sec);
Christopher Fauletf959d082019-02-07 15:38:42 +01001341 break;
1342 case INF_MEMMAX_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001343 metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L);
Christopher Fauletf959d082019-02-07 15:38:42 +01001344 break;
1345 case INF_POOL_ALLOC_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001346 metric = mkf_u64(0, pool_total_allocated());
Christopher Fauletf959d082019-02-07 15:38:42 +01001347 break;
1348 case INF_POOL_USED_MB:
Christopher Faulet8c8e4b12019-04-18 10:15:15 +02001349 metric = mkf_u64(0, pool_total_used());
Christopher Fauletf959d082019-02-07 15:38:42 +01001350 break;
1351 case INF_POOL_FAILED:
1352 metric = mkf_u32(FN_COUNTER, pool_total_failures());
1353 break;
1354 case INF_ULIMIT_N:
1355 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile);
1356 break;
1357 case INF_MAXSOCK:
1358 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock);
1359 break;
1360 case INF_MAXCONN:
1361 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn);
1362 break;
1363 case INF_HARD_MAXCONN:
1364 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn);
1365 break;
1366 case INF_CURR_CONN:
1367 metric = mkf_u32(0, actconn);
1368 break;
1369 case INF_CUM_CONN:
1370 metric = mkf_u32(FN_COUNTER, totalconn);
1371 break;
1372 case INF_CUM_REQ:
1373 metric = mkf_u32(FN_COUNTER, global.req_count);
1374 break;
1375#ifdef USE_OPENSSL
1376 case INF_MAX_SSL_CONNS:
1377 metric = mkf_u32(FN_MAX, global.maxsslconn);
1378 break;
1379 case INF_CURR_SSL_CONNS:
1380 metric = mkf_u32(0, sslconns);
1381 break;
1382 case INF_CUM_SSL_CONNS:
1383 metric = mkf_u32(FN_COUNTER, totalsslconns);
1384 break;
1385#endif
1386 case INF_MAXPIPES:
1387 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes);
1388 break;
1389 case INF_PIPES_USED:
1390 metric = mkf_u32(0, pipes_used);
1391 break;
1392 case INF_PIPES_FREE:
1393 metric = mkf_u32(0, pipes_free);
1394 break;
1395 case INF_CONN_RATE:
1396 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec));
1397 break;
1398 case INF_CONN_RATE_LIMIT:
1399 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim);
1400 break;
1401 case INF_MAX_CONN_RATE:
1402 metric = mkf_u32(FN_MAX, global.cps_max);
1403 break;
1404 case INF_SESS_RATE:
1405 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec));
1406 break;
1407 case INF_SESS_RATE_LIMIT:
1408 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim);
1409 break;
1410 case INF_MAX_SESS_RATE:
1411 metric = mkf_u32(FN_RATE, global.sps_max);
1412 break;
1413#ifdef USE_OPENSSL
1414 case INF_SSL_RATE:
1415 metric = mkf_u32(FN_RATE, ssl_sess_rate);
1416 break;
1417 case INF_SSL_RATE_LIMIT:
1418 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim);
1419 break;
1420 case INF_MAX_SSL_RATE:
1421 metric = mkf_u32(FN_MAX, global.ssl_max);
1422 break;
1423 case INF_SSL_FRONTEND_KEY_RATE:
1424 metric = mkf_u32(0, ssl_key_rate);
1425 break;
1426 case INF_SSL_FRONTEND_MAX_KEY_RATE:
1427 metric = mkf_u32(FN_MAX, global.ssl_fe_keys_max);
1428 break;
1429 case INF_SSL_FRONTEND_SESSION_REUSE_PCT:
1430 metric = mkf_u32(0, ssl_reuse);
1431 break;
1432 case INF_SSL_BACKEND_KEY_RATE:
1433 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec));
1434 break;
1435 case INF_SSL_BACKEND_MAX_KEY_RATE:
1436 metric = mkf_u32(FN_MAX, global.ssl_be_keys_max);
1437 break;
1438 case INF_SSL_CACHE_LOOKUPS:
1439 metric = mkf_u32(FN_COUNTER, global.shctx_lookups);
1440 break;
1441 case INF_SSL_CACHE_MISSES:
1442 metric = mkf_u32(FN_COUNTER, global.shctx_misses);
1443 break;
1444#endif
1445 case INF_COMPRESS_BPS_IN:
1446 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in));
1447 break;
1448 case INF_COMPRESS_BPS_OUT:
1449 metric = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out));
1450 break;
1451 case INF_COMPRESS_BPS_RATE_LIM:
1452 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim);
1453 break;
1454#ifdef USE_ZLIB
1455 case INF_ZLIB_MEM_USAGE:
1456 metric = mkf_u32(0, zlib_used_memory);
1457 break;
1458 case INF_MAX_ZLIB_MEM_USAGE:
1459 metric = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem);
1460 break;
1461#endif
1462 case INF_TASKS:
1463 metric = mkf_u32(0, nb_tasks_cur);
1464 break;
1465 case INF_RUN_QUEUE:
1466 metric = mkf_u32(0, tasks_run_queue_cur);
1467 break;
1468 case INF_IDLE_PCT:
Willy Tarreau76824a82019-06-02 10:38:48 +02001469 metric = mkf_u32(FN_AVG, ti->idle_pct);
Christopher Fauletf959d082019-02-07 15:38:42 +01001470 break;
1471 case INF_STOPPING:
1472 metric = mkf_u32(0, stopping);
1473 break;
1474 case INF_JOBS:
1475 metric = mkf_u32(0, jobs);
1476 break;
1477 case INF_UNSTOPPABLE_JOBS:
1478 metric = mkf_u32(0, unstoppable_jobs);
1479 break;
1480 case INF_LISTENERS:
1481 metric = mkf_u32(0, listeners);
1482 break;
1483 case INF_ACTIVE_PEERS:
1484 metric = mkf_u32(0, active_peers);
1485 break;
1486 case INF_CONNECTED_PEERS:
1487 metric = mkf_u32(0, connected_peers);
1488 break;
1489 case INF_DROPPED_LOGS:
1490 metric = mkf_u32(0, dropped_logs);
1491 break;
1492 case INF_BUSY_POLLING:
1493 metric = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING));
1494 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02001495 case INF_FAILED_RESOLUTIONS:
1496 metric = mkf_u32(0, dns_failed_resolutions);
1497 break;
1498 case INF_TOTAL_BYTES_OUT:
1499 metric = mkf_u64(0, global.out_bytes);
1500 break;
1501 case INF_TOTAL_SPLICED_BYTES_OUT:
1502 metric = mkf_u64(0, global.spliced_out_bytes);
1503 break;
1504 case INF_BYTES_OUT_RATE:
1505 metric = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32);
1506 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001507
1508 default:
1509 goto next_metric;
1510 }
1511
1512 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1513 goto full;
1514
1515 next_metric:
1516 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1517 appctx->st2 = promex_global_metrics[appctx->st2];
1518 }
1519
1520 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001521 if (out.len) {
1522 if (!htx_add_data_atonce(htx, out))
1523 return -1; /* Unexpected and unrecoverable error */
1524 channel_add_input(chn, out.len);
1525 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001526 return ret;
1527 full:
1528 ret = 0;
1529 goto end;
1530}
1531
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001532/* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001533 * 0 if <htx> is full and -1 in case of any error. */
1534static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
1535{
1536 static struct ist prefix = IST("haproxy_frontend_");
1537 struct proxy *px;
1538 struct field metric;
1539 struct channel *chn = si_ic(appctx->owner);
1540 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001541 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001542 int ret = 1;
1543
1544 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1545 while (appctx->ctx.stats.px) {
1546 px = appctx->ctx.stats.px;
1547
1548 /* skip the disabled proxies, global frontend and non-networked ones */
1549 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_FE))
1550 goto next_px;
1551
1552 switch (appctx->st2) {
1553 case ST_F_STATUS:
1554 metric = mkf_u32(FO_STATUS, px->state == PR_STREADY ? 1 : px->state == PR_STFULL ? 2 : 0);
1555 break;
1556 case ST_F_SCUR:
1557 metric = mkf_u32(0, px->feconn);
1558 break;
1559 case ST_F_SMAX:
1560 metric = mkf_u32(FN_MAX, px->fe_counters.conn_max);
1561 break;
1562 case ST_F_SLIM:
1563 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn);
1564 break;
1565 case ST_F_STOT:
1566 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess);
1567 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001568 case ST_F_RATE_LIM:
1569 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim);
1570 break;
1571 case ST_F_RATE_MAX:
1572 metric = mkf_u32(FN_MAX, px->fe_counters.sps_max);
1573 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001574 case ST_F_CONN_RATE_MAX:
1575 metric = mkf_u32(FN_MAX, px->fe_counters.cps_max);
1576 break;
1577 case ST_F_CONN_TOT:
1578 metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn);
1579 break;
1580 case ST_F_BIN:
1581 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in);
1582 break;
1583 case ST_F_BOUT:
1584 metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out);
1585 break;
1586 case ST_F_DREQ:
1587 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req);
1588 break;
1589 case ST_F_DRESP:
1590 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp);
1591 break;
1592 case ST_F_EREQ:
1593 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req);
1594 break;
1595 case ST_F_DCON:
1596 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn);
1597 break;
1598 case ST_F_DSES:
1599 metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess);
1600 break;
1601 case ST_F_WREW:
1602 metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites);
1603 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001604 case ST_F_EINT:
1605 metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors);
1606 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001607 case ST_F_REQ_RATE_MAX:
1608 if (px->mode != PR_MODE_HTTP)
1609 goto next_px;
1610 metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max);
1611 break;
1612 case ST_F_REQ_TOT:
1613 if (px->mode != PR_MODE_HTTP)
1614 goto next_px;
1615 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req);
1616 break;
1617 case ST_F_HRSP_1XX:
1618 if (px->mode != PR_MODE_HTTP)
1619 goto next_px;
1620 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]);
1621 break;
1622 case ST_F_HRSP_2XX:
1623 if (px->mode != PR_MODE_HTTP)
1624 goto next_px;
1625 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1626 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]);
1627 break;
1628 case ST_F_HRSP_3XX:
1629 if (px->mode != PR_MODE_HTTP)
1630 goto next_px;
1631 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1632 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]);
1633 break;
1634 case ST_F_HRSP_4XX:
1635 if (px->mode != PR_MODE_HTTP)
1636 goto next_px;
1637 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1638 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]);
1639 break;
1640 case ST_F_HRSP_5XX:
1641 if (px->mode != PR_MODE_HTTP)
1642 goto next_px;
1643 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1644 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]);
1645 break;
1646 case ST_F_HRSP_OTHER:
1647 if (px->mode != PR_MODE_HTTP)
1648 goto next_px;
1649 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1650 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]);
1651 break;
1652 case ST_F_INTERCEPTED:
1653 if (px->mode != PR_MODE_HTTP)
1654 goto next_px;
1655 metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req);
1656 break;
1657 case ST_F_CACHE_LOOKUPS:
1658 if (px->mode != PR_MODE_HTTP)
1659 goto next_px;
1660 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups);
1661 break;
1662 case ST_F_CACHE_HITS:
1663 if (px->mode != PR_MODE_HTTP)
1664 goto next_px;
1665 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits);
1666 break;
1667 case ST_F_COMP_IN:
1668 if (px->mode != PR_MODE_HTTP)
1669 goto next_px;
1670 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in);
1671 break;
1672 case ST_F_COMP_OUT:
1673 if (px->mode != PR_MODE_HTTP)
1674 goto next_px;
1675 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out);
1676 break;
1677 case ST_F_COMP_BYP:
1678 if (px->mode != PR_MODE_HTTP)
1679 goto next_px;
1680 metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp);
1681 break;
1682 case ST_F_COMP_RSP:
1683 if (px->mode != PR_MODE_HTTP)
1684 goto next_px;
1685 metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp);
1686 break;
1687
1688 default:
1689 goto next_metric;
1690 }
1691
1692 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1693 goto full;
1694 next_px:
1695 appctx->ctx.stats.px = px->next;
1696 }
1697 next_metric:
1698 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1699 appctx->ctx.stats.px = proxies_list;
1700 appctx->st2 = promex_front_metrics[appctx->st2];
1701 }
1702
1703 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001704 if (out.len) {
1705 if (!htx_add_data_atonce(htx, out))
1706 return -1; /* Unexpected and unrecoverable error */
1707 channel_add_input(chn, out.len);
1708 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001709 return ret;
1710 full:
1711 ret = 0;
1712 goto end;
1713}
1714
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001715/* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001716 * 0 if <htx> is full and -1 in case of any error. */
1717static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
1718{
1719 static struct ist prefix = IST("haproxy_backend_");
1720 struct proxy *px;
1721 struct field metric;
1722 struct channel *chn = si_ic(appctx->owner);
1723 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001724 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001725 int ret = 1;
1726 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001727 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001728
1729 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1730 while (appctx->ctx.stats.px) {
1731 px = appctx->ctx.stats.px;
1732
1733 /* skip the disabled proxies, global frontend and non-networked ones */
1734 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1735 goto next_px;
1736
1737 switch (appctx->st2) {
1738 case ST_F_STATUS:
1739 metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0);
1740 break;
1741 case ST_F_SCUR:
1742 metric = mkf_u32(0, px->beconn);
1743 break;
1744 case ST_F_SMAX:
1745 metric = mkf_u32(FN_MAX, px->be_counters.conn_max);
1746 break;
1747 case ST_F_SLIM:
1748 metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn);
1749 break;
1750 case ST_F_STOT:
1751 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn);
1752 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001753 case ST_F_RATE_MAX:
1754 metric = mkf_u32(0, px->be_counters.sps_max);
1755 break;
1756 case ST_F_LASTSESS:
1757 metric = mkf_s32(FN_AGE, be_lastsession(px));
1758 break;
1759 case ST_F_QCUR:
1760 metric = mkf_u32(0, px->nbpend);
1761 break;
1762 case ST_F_QMAX:
1763 metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max);
1764 break;
1765 case ST_F_CONNECT:
1766 metric = mkf_u64(FN_COUNTER, px->be_counters.connect);
1767 break;
1768 case ST_F_REUSE:
1769 metric = mkf_u64(FN_COUNTER, px->be_counters.reuse);
1770 break;
1771 case ST_F_BIN:
1772 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in);
1773 break;
1774 case ST_F_BOUT:
1775 metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out);
1776 break;
1777 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001778 secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
1779 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001780 break;
1781 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001782 secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
1783 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001784 break;
1785 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001786 secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
1787 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001788 break;
1789 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001790 secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
1791 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01001792 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01001793 case ST_F_QT_MAX:
1794 secs = (double)px->be_counters.qtime_max / 1000.0;
1795 metric = mkf_flt(FN_MAX, secs);
1796 break;
1797 case ST_F_CT_MAX:
1798 secs = (double)px->be_counters.ctime_max / 1000.0;
1799 metric = mkf_flt(FN_MAX, secs);
1800 break;
1801 case ST_F_RT_MAX:
1802 secs = (double)px->be_counters.dtime_max / 1000.0;
1803 metric = mkf_flt(FN_MAX, secs);
1804 break;
1805 case ST_F_TT_MAX:
1806 secs = (double)px->be_counters.ttime_max / 1000.0;
1807 metric = mkf_flt(FN_MAX, secs);
1808 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001809 case ST_F_DREQ:
1810 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
1811 break;
1812 case ST_F_DRESP:
1813 metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp);
1814 break;
1815 case ST_F_ECON:
1816 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns);
1817 break;
1818 case ST_F_ERESP:
1819 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp);
1820 break;
1821 case ST_F_WRETR:
1822 metric = mkf_u64(FN_COUNTER, px->be_counters.retries);
1823 break;
1824 case ST_F_WREDIS:
1825 metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches);
1826 break;
1827 case ST_F_WREW:
1828 metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites);
1829 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01001830 case ST_F_EINT:
1831 metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors);
1832 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01001833 case ST_F_CLI_ABRT:
1834 metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts);
1835 break;
1836 case ST_F_SRV_ABRT:
1837 metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts);
1838 break;
1839 case ST_F_WEIGHT:
1840 weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
1841 metric = mkf_u32(FN_AVG, weight);
1842 break;
1843 case ST_F_ACT:
1844 metric = mkf_u32(0, px->srv_act);
1845 break;
1846 case ST_F_BCK:
1847 metric = mkf_u32(0, px->srv_bck);
1848 break;
1849 case ST_F_CHKDOWN:
1850 metric = mkf_u64(FN_COUNTER, px->down_trans);
1851 break;
1852 case ST_F_LASTCHG:
1853 metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change);
1854 break;
1855 case ST_F_DOWNTIME:
1856 metric = mkf_u32(FN_COUNTER, be_downtime(px));
1857 break;
1858 case ST_F_LBTOT:
1859 metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn);
1860 break;
1861 case ST_F_REQ_TOT:
1862 if (px->mode != PR_MODE_HTTP)
1863 goto next_px;
1864 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req);
1865 break;
1866 case ST_F_HRSP_1XX:
1867 if (px->mode != PR_MODE_HTTP)
1868 goto next_px;
1869 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]);
1870 break;
1871 case ST_F_HRSP_2XX:
1872 if (px->mode != PR_MODE_HTTP)
1873 goto next_px;
1874 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1875 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]);
1876 break;
1877 case ST_F_HRSP_3XX:
1878 if (px->mode != PR_MODE_HTTP)
1879 goto next_px;
1880 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1881 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]);
1882 break;
1883 case ST_F_HRSP_4XX:
1884 if (px->mode != PR_MODE_HTTP)
1885 goto next_px;
1886 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1887 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]);
1888 break;
1889 case ST_F_HRSP_5XX:
1890 if (px->mode != PR_MODE_HTTP)
1891 goto next_px;
1892 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1893 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]);
1894 break;
1895 case ST_F_HRSP_OTHER:
1896 if (px->mode != PR_MODE_HTTP)
1897 goto next_px;
1898 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
1899 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]);
1900 break;
1901 case ST_F_CACHE_LOOKUPS:
1902 if (px->mode != PR_MODE_HTTP)
1903 goto next_px;
1904 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups);
1905 break;
1906 case ST_F_CACHE_HITS:
1907 if (px->mode != PR_MODE_HTTP)
1908 goto next_px;
1909 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits);
1910 break;
1911 case ST_F_COMP_IN:
1912 if (px->mode != PR_MODE_HTTP)
1913 goto next_px;
1914 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in);
1915 break;
1916 case ST_F_COMP_OUT:
1917 if (px->mode != PR_MODE_HTTP)
1918 goto next_px;
1919 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out);
1920 break;
1921 case ST_F_COMP_BYP:
1922 if (px->mode != PR_MODE_HTTP)
1923 goto next_px;
1924 metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp);
1925 break;
1926 case ST_F_COMP_RSP:
1927 if (px->mode != PR_MODE_HTTP)
1928 goto next_px;
1929 metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp);
1930 break;
1931
1932 default:
1933 goto next_metric;
1934 }
1935
1936 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
1937 goto full;
1938 next_px:
1939 appctx->ctx.stats.px = px->next;
1940 }
1941 next_metric:
1942 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
1943 appctx->ctx.stats.px = proxies_list;
1944 appctx->st2 = promex_back_metrics[appctx->st2];
1945 }
1946
1947 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02001948 if (out.len) {
1949 if (!htx_add_data_atonce(htx, out))
1950 return -1; /* Unexpected and unrecoverable error */
1951 channel_add_input(chn, out.len);
1952 }
Christopher Fauletf959d082019-02-07 15:38:42 +01001953 return ret;
1954 full:
1955 ret = 0;
1956 goto end;
1957}
1958
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05001959/* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success,
Christopher Fauletf959d082019-02-07 15:38:42 +01001960 * 0 if <htx> is full and -1 in case of any error. */
1961static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
1962{
1963 static struct ist prefix = IST("haproxy_server_");
1964 struct proxy *px;
1965 struct server *sv;
1966 struct field metric;
1967 struct channel *chn = si_ic(appctx->owner);
1968 struct ist out = ist2(trash.area, 0);
Christopher Faulet11921e62019-07-03 11:43:17 +02001969 size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx));
Christopher Fauletf959d082019-02-07 15:38:42 +01001970 int ret = 1;
1971 uint32_t weight;
Christopher Fauletaf4bf142019-09-24 16:35:19 +02001972 double secs;
Christopher Fauletf959d082019-02-07 15:38:42 +01001973
1974 while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) {
1975 while (appctx->ctx.stats.px) {
1976 px = appctx->ctx.stats.px;
1977
1978 /* skip the disabled proxies, global frontend and non-networked ones */
1979 if (px->state == PR_STSTOPPED || px->uuid <= 0 || !(px->cap & PR_CAP_BE))
1980 goto next_px;
1981
1982 while (appctx->ctx.stats.sv) {
1983 sv = appctx->ctx.stats.sv;
1984
Christopher Fauleteba22942019-11-19 14:18:24 +01001985 if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT))
1986 goto next_sv;
1987
Christopher Fauletf959d082019-02-07 15:38:42 +01001988 switch (appctx->st2) {
1989 case ST_F_STATUS:
1990 metric = mkf_u32(FO_STATUS, promex_srv_status(sv));
1991 break;
1992 case ST_F_SCUR:
1993 metric = mkf_u32(0, sv->cur_sess);
1994 break;
1995 case ST_F_SMAX:
1996 metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max);
1997 break;
1998 case ST_F_SLIM:
1999 metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn);
2000 break;
2001 case ST_F_STOT:
2002 metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess);
2003 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002004 case ST_F_RATE_MAX:
2005 metric = mkf_u32(FN_MAX, sv->counters.sps_max);
2006 break;
2007 case ST_F_LASTSESS:
2008 metric = mkf_s32(FN_AGE, srv_lastsession(sv));
2009 break;
2010 case ST_F_QCUR:
2011 metric = mkf_u32(0, sv->nbpend);
2012 break;
2013 case ST_F_QMAX:
2014 metric = mkf_u32(FN_MAX, sv->counters.nbpend_max);
2015 break;
2016 case ST_F_QLIMIT:
2017 metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue);
2018 break;
2019 case ST_F_BIN:
2020 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in);
2021 break;
2022 case ST_F_BOUT:
2023 metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out);
2024 break;
2025 case ST_F_QTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002026 secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0;
2027 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002028 break;
2029 case ST_F_CTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002030 secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0;
2031 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002032 break;
2033 case ST_F_RTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002034 secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0;
2035 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002036 break;
2037 case ST_F_TTIME:
Christopher Fauletaf4bf142019-09-24 16:35:19 +02002038 secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
2039 metric = mkf_flt(FN_AVG, secs);
Christopher Fauletf959d082019-02-07 15:38:42 +01002040 break;
Christopher Faulet8fc027d2019-11-08 15:05:31 +01002041 case ST_F_QT_MAX:
2042 secs = (double)sv->counters.qtime_max / 1000.0;
2043 metric = mkf_flt(FN_MAX, secs);
2044 break;
2045 case ST_F_CT_MAX:
2046 secs = (double)sv->counters.ctime_max / 1000.0;
2047 metric = mkf_flt(FN_MAX, secs);
2048 break;
2049 case ST_F_RT_MAX:
2050 secs = (double)sv->counters.dtime_max / 1000.0;
2051 metric = mkf_flt(FN_MAX, secs);
2052 break;
2053 case ST_F_TT_MAX:
2054 secs = (double)sv->counters.ttime_max / 1000.0;
2055 metric = mkf_flt(FN_MAX, secs);
2056 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002057 case ST_F_CONNECT:
2058 metric = mkf_u64(FN_COUNTER, sv->counters.connect);
2059 break;
2060 case ST_F_REUSE:
2061 metric = mkf_u64(FN_COUNTER, sv->counters.reuse);
2062 break;
2063 case ST_F_DRESP:
Christopher Fauleta08546b2019-12-16 16:07:34 +01002064 metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp);
Christopher Fauletf959d082019-02-07 15:38:42 +01002065 break;
2066 case ST_F_ECON:
2067 metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns);
2068 break;
2069 case ST_F_ERESP:
2070 metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp);
2071 break;
2072 case ST_F_WRETR:
2073 metric = mkf_u64(FN_COUNTER, sv->counters.retries);
2074 break;
2075 case ST_F_WREDIS:
2076 metric = mkf_u64(FN_COUNTER, sv->counters.redispatches);
2077 break;
2078 case ST_F_WREW:
2079 metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites);
2080 break;
Christopher Faulete4a2c8d2019-12-16 14:44:01 +01002081 case ST_F_EINT:
2082 metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors);
2083 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002084 case ST_F_CLI_ABRT:
2085 metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts);
2086 break;
2087 case ST_F_SRV_ABRT:
2088 metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts);
2089 break;
2090 case ST_F_WEIGHT:
2091 weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
2092 metric = mkf_u32(FN_AVG, weight);
2093 break;
Christopher Fauletcf403f32019-11-21 14:35:46 +01002094 case ST_F_CHECK_STATUS:
2095 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2096 goto next_sv;
2097 metric = mkf_u32(FN_OUTPUT, sv->check.status);
2098 break;
2099 case ST_F_CHECK_CODE:
2100 if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
2101 goto next_sv;
2102 metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
2103 break;
Christopher Faulet2711e512020-02-27 16:12:07 +01002104 case ST_F_CHECK_DURATION:
2105 if (sv->check.status < HCHK_STATUS_CHECKED)
2106 goto next_sv;
2107 secs = (double)sv->check.duration / 1000.0;
2108 metric = mkf_flt(FN_DURATION, secs);
2109 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002110 case ST_F_CHKFAIL:
2111 metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
2112 break;
2113 case ST_F_CHKDOWN:
2114 metric = mkf_u64(FN_COUNTER, sv->counters.down_trans);
2115 break;
2116 case ST_F_DOWNTIME:
2117 metric = mkf_u32(FN_COUNTER, srv_downtime(sv));
2118 break;
2119 case ST_F_LASTCHG:
2120 metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change);
2121 break;
2122 case ST_F_THROTTLE:
2123 metric = mkf_u32(FN_AVG, server_throttle_rate(sv));
2124 break;
2125 case ST_F_LBTOT:
2126 metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn);
2127 break;
Marcin Deranek3c27dda2020-05-15 18:32:51 +02002128 case ST_F_REQ_TOT:
2129 if (px->mode != PR_MODE_HTTP)
2130 goto next_px;
2131 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req);
2132 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002133 case ST_F_HRSP_1XX:
2134 if (px->mode != PR_MODE_HTTP)
2135 goto next_px;
2136 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]);
2137 break;
2138 case ST_F_HRSP_2XX:
2139 if (px->mode != PR_MODE_HTTP)
2140 goto next_px;
2141 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2142 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]);
2143 break;
2144 case ST_F_HRSP_3XX:
2145 if (px->mode != PR_MODE_HTTP)
2146 goto next_px;
2147 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2148 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]);
2149 break;
2150 case ST_F_HRSP_4XX:
2151 if (px->mode != PR_MODE_HTTP)
2152 goto next_px;
2153 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2154 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]);
2155 break;
2156 case ST_F_HRSP_5XX:
2157 if (px->mode != PR_MODE_HTTP)
2158 goto next_px;
2159 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2160 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]);
2161 break;
2162 case ST_F_HRSP_OTHER:
2163 if (px->mode != PR_MODE_HTTP)
2164 goto next_px;
2165 appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR;
2166 metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]);
2167 break;
Christopher Faulet20ab80c2019-11-08 15:24:32 +01002168 case ST_F_SRV_ICUR:
2169 metric = mkf_u32(0, sv->curr_idle_conns);
2170 break;
2171 case ST_F_SRV_ILIM:
2172 metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns);
2173 break;
Christopher Fauletc55a6262020-07-10 15:39:39 +02002174 case ST_F_IDLE_CONN_CUR:
2175 metric = mkf_u32(0, sv->curr_idle_nb);
2176 break;
2177 case ST_F_SAFE_CONN_CUR:
2178 metric = mkf_u32(0, sv->curr_safe_nb);
2179 break;
2180 case ST_F_USED_CONN_CUR:
2181 metric = mkf_u32(0, sv->curr_used_conns);
2182 break;
2183 case ST_F_NEED_CONN_EST:
2184 metric = mkf_u32(0, sv->est_need_conns);
2185 break;
Christopher Fauletf959d082019-02-07 15:38:42 +01002186
2187 default:
2188 goto next_metric;
2189 }
2190
2191 if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max))
2192 goto full;
2193
Christopher Fauleteba22942019-11-19 14:18:24 +01002194 next_sv:
Christopher Fauletf959d082019-02-07 15:38:42 +01002195 appctx->ctx.stats.sv = sv->next;
2196 }
2197
2198 next_px:
2199 appctx->ctx.stats.px = px->next;
2200 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2201 }
2202 next_metric:
2203 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
2204 appctx->ctx.stats.px = proxies_list;
2205 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
2206 appctx->st2 = promex_srv_metrics[appctx->st2];
2207 }
2208
2209
2210 end:
Christopher Faulet0c55a152019-07-04 10:03:28 +02002211 if (out.len) {
2212 if (!htx_add_data_atonce(htx, out))
2213 return -1; /* Unexpected and unrecoverable error */
2214 channel_add_input(chn, out.len);
2215 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002216 return ret;
2217 full:
2218 ret = 0;
2219 goto end;
2220}
2221
2222/* Dump all metrics (global, frontends, backends and servers) depending on the
2223 * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and
2224 * -1 in case of any error. */
2225static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2226{
2227 int ret;
2228
2229 switch (appctx->st1) {
2230 case PROMEX_DUMPER_INIT:
2231 appctx->ctx.stats.px = NULL;
2232 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002233 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002234 appctx->st2 = promex_global_metrics[INF_NAME];
2235 appctx->st1 = PROMEX_DUMPER_GLOBAL;
2236 /* fall through */
2237
2238 case PROMEX_DUMPER_GLOBAL:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002239 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) {
2240 ret = promex_dump_global_metrics(appctx, htx);
2241 if (ret <= 0) {
2242 if (ret == -1)
2243 goto error;
2244 goto full;
2245 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002246 }
2247
2248 appctx->ctx.stats.px = proxies_list;
2249 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002250 appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC;
2251 appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002252 appctx->st2 = promex_front_metrics[ST_F_PXNAME];
2253 appctx->st1 = PROMEX_DUMPER_FRONT;
2254 /* fall through */
2255
2256 case PROMEX_DUMPER_FRONT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002257 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) {
2258 ret = promex_dump_front_metrics(appctx, htx);
2259 if (ret <= 0) {
2260 if (ret == -1)
2261 goto error;
2262 goto full;
2263 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002264 }
2265
2266 appctx->ctx.stats.px = proxies_list;
2267 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002268 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002269 appctx->st2 = promex_back_metrics[ST_F_PXNAME];
2270 appctx->st1 = PROMEX_DUMPER_BACK;
2271 /* fall through */
2272
2273 case PROMEX_DUMPER_BACK:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002274 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) {
2275 ret = promex_dump_back_metrics(appctx, htx);
2276 if (ret <= 0) {
2277 if (ret == -1)
2278 goto error;
2279 goto full;
2280 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002281 }
2282
2283 appctx->ctx.stats.px = proxies_list;
2284 appctx->ctx.stats.sv = (appctx->ctx.stats.px ? appctx->ctx.stats.px->srv : NULL);
Christopher Fauletefde9552020-06-05 08:18:56 +02002285 appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR;
Christopher Fauletf959d082019-02-07 15:38:42 +01002286 appctx->st2 = promex_srv_metrics[ST_F_PXNAME];
2287 appctx->st1 = PROMEX_DUMPER_SRV;
2288 /* fall through */
2289
2290 case PROMEX_DUMPER_SRV:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002291 if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) {
2292 ret = promex_dump_srv_metrics(appctx, htx);
2293 if (ret <= 0) {
2294 if (ret == -1)
2295 goto error;
2296 goto full;
2297 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002298 }
2299
2300 appctx->ctx.stats.px = NULL;
2301 appctx->ctx.stats.sv = NULL;
Christopher Fauletefde9552020-06-05 08:18:56 +02002302 appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC);
Christopher Fauletf959d082019-02-07 15:38:42 +01002303 appctx->st2 = 0;
2304 appctx->st1 = PROMEX_DUMPER_DONE;
2305 /* fall through */
2306
2307 case PROMEX_DUMPER_DONE:
2308 default:
2309 break;
2310 }
2311
2312 return 1;
2313
2314 full:
2315 si_rx_room_blk(si);
2316 return 0;
2317 error:
2318 /* unrecoverable error */
2319 appctx->ctx.stats.px = NULL;
2320 appctx->ctx.stats.sv = NULL;
2321 appctx->ctx.stats.flags = 0;
2322 appctx->st2 = 0;
2323 appctx->st1 = PROMEX_DUMPER_DONE;
2324 return -1;
2325}
2326
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002327/* Parse the query string of request URI to filter the metrics. It returns 1 on
Christopher Faulet78407ce2019-11-18 14:47:08 +01002328 * success and -1 on error. */
2329static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si)
2330{
2331 struct channel *req = si_oc(si);
2332 struct channel *res = si_ic(si);
2333 struct htx *req_htx, *res_htx;
2334 struct htx_sl *sl;
William Dauchyc65f6562019-11-26 12:56:26 +01002335 char *p, *key, *value;
2336 const char *end;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002337 struct buffer *err;
2338 int default_scopes = PROMEX_FL_SCOPE_ALL;
2339 int len;
2340
2341 /* Get the query-string */
2342 req_htx = htxbuf(&req->buf);
2343 sl = http_get_stline(req_htx);
2344 if (!sl)
2345 goto error;
2346 p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?');
2347 if (!p)
2348 goto end;
2349 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Christopher Faulet78407ce2019-11-18 14:47:08 +01002350
William Dauchyc65f6562019-11-26 12:56:26 +01002351 /* copy the query-string */
2352 len = end - p;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002353 chunk_reset(&trash);
2354 memcpy(trash.area, p, len);
2355 trash.area[len] = 0;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002356 p = trash.area;
William Dauchyc65f6562019-11-26 12:56:26 +01002357 end = trash.area + len;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002358
2359 /* Parse the query-string */
William Dauchyc65f6562019-11-26 12:56:26 +01002360 while (p < end && *p && *p != '#') {
2361 value = NULL;
2362
2363 /* decode parameter name */
2364 key = p;
2365 while (p < end && *p != '=' && *p != '&' && *p != '#')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002366 ++p;
William Dauchyc65f6562019-11-26 12:56:26 +01002367 /* found a value */
2368 if (*p == '=') {
2369 *(p++) = 0;
2370 value = p;
2371 }
2372 else if (*p == '&')
2373 *(p++) = 0;
2374 else if (*p == '#')
2375 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002376 len = url_decode(key, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002377 if (len == -1)
2378 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002379
William Dauchyc65f6562019-11-26 12:56:26 +01002380 /* decode value */
2381 if (value) {
2382 while (p < end && *p != '=' && *p != '&' && *p != '#')
2383 ++p;
2384 if (*p == '=')
2385 goto error;
2386 if (*p == '&')
2387 *(p++) = 0;
2388 else if (*p == '#')
2389 *p = 0;
Willy Tarreau62ba9ba2020-04-23 17:54:47 +02002390 len = url_decode(value, 1);
William Dauchyc65f6562019-11-26 12:56:26 +01002391 if (len == -1)
2392 goto error;
2393 }
2394
2395 if (!strcmp(key, "scope")) {
2396 default_scopes = 0; /* at least a scope defined, unset default scopes */
2397 if (!value)
2398 goto error;
2399 else if (*value == 0)
Christopher Faulet78407ce2019-11-18 14:47:08 +01002400 appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002401 else if (*value == '*')
Christopher Faulet78407ce2019-11-18 14:47:08 +01002402 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL;
William Dauchyc65f6562019-11-26 12:56:26 +01002403 else if (!strcmp(value, "global"))
2404 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL;
2405 else if (!strcmp(value, "server"))
2406 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER;
2407 else if (!strcmp(value, "backend"))
Christopher Faulet78407ce2019-11-18 14:47:08 +01002408 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK;
William Dauchyc65f6562019-11-26 12:56:26 +01002409 else if (!strcmp(value, "frontend"))
Christopher Faulet78407ce2019-11-18 14:47:08 +01002410 appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT;
2411 else
2412 goto error;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002413 }
William Dauchyc65f6562019-11-26 12:56:26 +01002414 else if (!strcmp(key, "no-maint"))
Christopher Fauleteba22942019-11-19 14:18:24 +01002415 appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV;
Christopher Faulet78407ce2019-11-18 14:47:08 +01002416 }
2417
2418 end:
2419 appctx->ctx.stats.flags |= default_scopes;
2420 return 1;
2421
2422 error:
2423 err = &http_err_chunks[HTTP_ERR_400];
2424 channel_erase(res);
2425 res->buf.data = b_data(err);
2426 memcpy(res->buf.area, b_head(err), b_data(err));
2427 res_htx = htx_from_buf(&res->buf);
2428 channel_add_input(res, res_htx->data);
2429 appctx->st0 = PROMEX_ST_END;
2430 return -1;
2431}
2432
Christopher Fauletf959d082019-02-07 15:38:42 +01002433/* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is
2434 * full. */
2435static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx)
2436{
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002437 struct channel *chn = si_ic(appctx->owner);
Christopher Fauletf959d082019-02-07 15:38:42 +01002438 struct htx_sl *sl;
2439 unsigned int flags;
2440
2441 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);
2442 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK"));
2443 if (!sl)
2444 goto full;
2445 sl->info.res.status = 200;
2446 if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) ||
2447 !htx_add_header(htx, ist("Connection"), ist("close")) ||
2448 !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) ||
2449 !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) ||
2450 !htx_add_endof(htx, HTX_BLK_EOH))
2451 goto full;
2452
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002453 channel_add_input(chn, htx->data);
Christopher Fauletf959d082019-02-07 15:38:42 +01002454 return 1;
2455 full:
2456 htx_reset(htx);
2457 si_rx_room_blk(si);
2458 return 0;
2459}
2460
2461/* The function returns 1 if the initialisation is complete, 0 if
2462 * an errors occurs and -1 if more data are required for initializing
2463 * the applet.
2464 */
2465static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm)
2466{
2467 appctx->st0 = PROMEX_ST_INIT;
2468 return 1;
2469}
2470
2471/* The main I/O handler for the promex applet. */
2472static void promex_appctx_handle_io(struct appctx *appctx)
2473{
2474 struct stream_interface *si = appctx->owner;
2475 struct stream *s = si_strm(si);
2476 struct channel *req = si_oc(si);
2477 struct channel *res = si_ic(si);
2478 struct htx *req_htx, *res_htx;
2479 int ret;
2480
2481 res_htx = htx_from_buf(&res->buf);
Christopher Fauletf959d082019-02-07 15:38:42 +01002482 if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO))
2483 goto out;
2484
Ilya Shipitsince7b00f2020-03-23 22:28:40 +05002485 /* Check if the input buffer is available. */
Christopher Fauletf959d082019-02-07 15:38:42 +01002486 if (!b_size(&res->buf)) {
2487 si_rx_room_blk(si);
2488 goto out;
2489 }
2490
2491 switch (appctx->st0) {
2492 case PROMEX_ST_INIT:
Christopher Faulet78407ce2019-11-18 14:47:08 +01002493 ret = promex_parse_uri(appctx, si);
2494 if (ret <= 0) {
2495 if (ret == -1)
2496 goto error;
2497 goto out;
2498 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002499 appctx->st0 = PROMEX_ST_HEAD;
2500 appctx->st1 = PROMEX_DUMPER_INIT;
2501 /* fall through */
2502
2503 case PROMEX_ST_HEAD:
2504 if (!promex_send_headers(appctx, si, res_htx))
2505 goto out;
2506 appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP);
2507 /* fall through */
2508
2509 case PROMEX_ST_DUMP:
2510 ret = promex_dump_metrics(appctx, si, res_htx);
2511 if (ret <= 0) {
2512 if (ret == -1)
2513 goto error;
2514 goto out;
2515 }
2516 appctx->st0 = PROMEX_ST_DONE;
2517 /* fall through */
2518
2519 case PROMEX_ST_DONE:
Christopher Faulet54b5e212019-06-04 10:08:28 +02002520 /* Don't add TLR because mux-h1 will take care of it */
Willy Tarreauf1ea47d2020-07-23 06:53:27 +02002521 res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */
Christopher Fauletf959d082019-02-07 15:38:42 +01002522 if (!htx_add_endof(res_htx, HTX_BLK_EOM)) {
2523 si_rx_room_blk(si);
2524 goto out;
2525 }
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002526 channel_add_input(res, 1);
2527 appctx->st0 = PROMEX_ST_END;
2528 /* fall through */
Christopher Fauletf959d082019-02-07 15:38:42 +01002529
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002530 case PROMEX_ST_END:
2531 if (!(res->flags & CF_SHUTR)) {
2532 res->flags |= CF_READ_NULL;
2533 si_shutr(si);
2534 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002535 }
2536
Christopher Fauletf959d082019-02-07 15:38:42 +01002537 out:
2538 htx_to_buf(res_htx, &res->buf);
Christopher Faulet9744f7c2019-03-27 15:48:53 +01002539
2540 /* eat the whole request */
2541 if (co_data(req)) {
2542 req_htx = htx_from_buf(&req->buf);
2543 co_htx_skip(req, req_htx, co_data(req));
2544 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002545 return;
2546
2547 error:
2548 res->flags |= CF_READ_NULL;
2549 si_shutr(si);
2550 si_shutw(si);
2551}
2552
2553struct applet promex_applet = {
2554 .obj_type = OBJ_TYPE_APPLET,
2555 .name = "<PROMEX>", /* used for logging */
2556 .init = promex_appctx_init,
2557 .fct = promex_appctx_handle_io,
2558};
2559
2560static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px,
2561 struct act_rule *rule, char **err)
2562{
2563 /* Prometheus exporter service is only available on "http-request" rulesets */
2564 if (rule->from != ACT_F_HTTP_REQ) {
2565 memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets");
2566 return ACT_RET_PRS_ERR;
2567 }
Christopher Fauletf959d082019-02-07 15:38:42 +01002568
2569 /* Add applet pointer in the rule. */
2570 rule->applet = promex_applet;
2571
2572 return ACT_RET_PRS_OK;
2573}
2574static void promex_register_build_options(void)
2575{
2576 char *ptr = NULL;
2577
2578 memprintf(&ptr, "Built with the Prometheus exporter as a service");
2579 hap_register_build_opts(ptr, 1);
2580}
2581
2582
2583static struct action_kw_list service_actions = { ILH, {
2584 { "prometheus-exporter", service_parse_prometheus_exporter },
2585 { /* END */ }
2586}};
2587
2588INITCALL1(STG_REGISTER, service_keywords_register, &service_actions);
2589INITCALL0(STG_REGISTER, promex_register_build_options);