Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1 | /* |
| 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 Tarreau | 122eba9 | 2020-06-04 10:15:32 +0200 | [diff] [blame] | 16 | #include <haproxy/action-t.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 17 | #include <haproxy/api.h> |
Willy Tarreau | 3f0f82e | 2020-06-04 19:42:41 +0200 | [diff] [blame] | 18 | #include <haproxy/applet.h> |
Willy Tarreau | 4980160 | 2020-06-04 22:50:02 +0200 | [diff] [blame] | 19 | #include <haproxy/backend.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 20 | #include <haproxy/cfgparse.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 21 | #include <haproxy/compression.h> |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 22 | #include <haproxy/dns.h> |
Willy Tarreau | 762d7a5 | 2020-06-04 11:23:07 +0200 | [diff] [blame] | 23 | #include <haproxy/frontend.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 24 | #include <haproxy/global.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 25 | #include <haproxy/http.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 26 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 27 | #include <haproxy/htx.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 28 | #include <haproxy/list.h> |
Willy Tarreau | 213e990 | 2020-06-04 14:58:24 +0200 | [diff] [blame] | 29 | #include <haproxy/listener.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 30 | #include <haproxy/log.h> |
Willy Tarreau | 551271d | 2020-06-04 08:32:23 +0200 | [diff] [blame] | 31 | #include <haproxy/pipe.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 32 | #include <haproxy/pool.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 33 | #include <haproxy/proxy.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 34 | #include <haproxy/sample.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 35 | #include <haproxy/server.h> |
Willy Tarreau | 209108d | 2020-06-04 20:30:20 +0200 | [diff] [blame] | 36 | #include <haproxy/ssl_sock.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 37 | #include <haproxy/stats.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 38 | #include <haproxy/stream.h> |
Willy Tarreau | 5e539c9 | 2020-06-04 20:45:39 +0200 | [diff] [blame] | 39 | #include <haproxy/stream_interface.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 40 | #include <haproxy/task.h> |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 41 | #include <haproxy/version.h> |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 42 | |
| 43 | /* Prometheus exporter applet states (appctx->st0) */ |
| 44 | enum { |
| 45 | PROMEX_ST_INIT = 0, /* initialized */ |
| 46 | PROMEX_ST_HEAD, /* send headers before dump */ |
| 47 | PROMEX_ST_DUMP, /* dumping stats */ |
| 48 | PROMEX_ST_DONE, /* finished */ |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 49 | PROMEX_ST_END, /* treatment terminated */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /* Prometheus exporter dumper states (appctx->st1) */ |
| 53 | enum { |
| 54 | PROMEX_DUMPER_INIT = 0, /* initialized */ |
| 55 | PROMEX_DUMPER_GLOBAL, /* dump metrics of globals */ |
| 56 | PROMEX_DUMPER_FRONT, /* dump metrics of frontend proxies */ |
| 57 | PROMEX_DUMPER_BACK, /* dump metrics of backend proxies */ |
| 58 | PROMEX_DUMPER_LI, /* dump metrics of listeners */ |
| 59 | PROMEX_DUMPER_SRV, /* dump metrics of servers */ |
| 60 | PROMEX_DUMPER_DONE, /* finished */ |
| 61 | }; |
| 62 | |
| 63 | /* Prometheus exporter flags (appctx->ctx.stats.flags) */ |
| 64 | #define PROMEX_FL_METRIC_HDR 0x00000001 |
| 65 | #define PROMEX_FL_INFO_METRIC 0x00000002 |
| 66 | #define PROMEX_FL_STATS_METRIC 0x00000004 |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 67 | #define PROMEX_FL_SCOPE_GLOBAL 0x00000008 |
| 68 | #define PROMEX_FL_SCOPE_FRONT 0x00000010 |
| 69 | #define PROMEX_FL_SCOPE_BACK 0x00000020 |
| 70 | #define PROMEX_FL_SCOPE_SERVER 0x00000040 |
Christopher Faulet | eba2294 | 2019-11-19 14:18:24 +0100 | [diff] [blame] | 71 | #define PROMEX_FL_NO_MAINT_SRV 0x00000080 |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 72 | |
| 73 | #define PROMEX_FL_SCOPE_ALL (PROMEX_FL_SCOPE_GLOBAL|PROMEX_FL_SCOPE_FRONT|PROMEX_FL_SCOPE_BACK|PROMEX_FL_SCOPE_SERVER) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 74 | |
| 75 | /* The max length for metrics name. It is a hard limit but it should be |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 76 | * enough. |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 77 | */ |
| 78 | #define PROMEX_MAX_NAME_LEN 128 |
| 79 | |
| 80 | /* The expected max length for a metric dump, including its header lines. It is |
| 81 | * just a soft limit to avoid extra work. We don't try to dump a metric if less |
| 82 | * than this size is available in the HTX. |
| 83 | */ |
| 84 | #define PROMEX_MAX_METRIC_LENGTH 512 |
| 85 | |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 86 | /* Some labels for build_info */ |
| 87 | #define PROMEX_VERSION_LABEL "version=\"" HAPROXY_VERSION "\"" |
| 88 | #define PROMEX_BUILDINFO_LABEL PROMEX_VERSION_LABEL |
| 89 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 90 | /* Matrix used to dump global metrics. Each metric points to the next one to be |
| 91 | * processed or 0 to stop the dump. */ |
| 92 | const int promex_global_metrics[INF_TOTAL_FIELDS] = { |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 93 | [INF_NAME] = INF_BUILD_INFO, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 94 | [INF_VERSION] = 0, |
| 95 | [INF_RELEASE_DATE] = 0, |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 96 | [INF_BUILD_INFO] = INF_NBTHREAD, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 97 | [INF_NBTHREAD] = INF_NBPROC, |
| 98 | [INF_NBPROC] = INF_PROCESS_NUM, |
| 99 | [INF_PROCESS_NUM] = INF_UPTIME_SEC, |
| 100 | [INF_PID] = 0, |
| 101 | [INF_UPTIME] = 0, |
| 102 | [INF_UPTIME_SEC] = INF_MEMMAX_MB, |
| 103 | [INF_MEMMAX_MB] = INF_POOL_ALLOC_MB, |
| 104 | [INF_POOL_ALLOC_MB] = INF_POOL_USED_MB, |
| 105 | [INF_POOL_USED_MB] = INF_POOL_FAILED, |
| 106 | [INF_POOL_FAILED] = INF_ULIMIT_N, |
| 107 | [INF_ULIMIT_N] = INF_MAXSOCK, |
| 108 | [INF_MAXSOCK] = INF_MAXCONN, |
| 109 | [INF_MAXCONN] = INF_HARD_MAXCONN, |
| 110 | [INF_HARD_MAXCONN] = INF_CURR_CONN, |
| 111 | [INF_CURR_CONN] = INF_CUM_CONN, |
| 112 | [INF_CUM_CONN] = INF_CUM_REQ, |
| 113 | [INF_CUM_REQ] = INF_MAX_SSL_CONNS, |
| 114 | [INF_MAX_SSL_CONNS] = INF_CURR_SSL_CONNS, |
| 115 | [INF_CURR_SSL_CONNS] = INF_CUM_SSL_CONNS, |
| 116 | [INF_CUM_SSL_CONNS] = INF_MAXPIPES, |
| 117 | [INF_MAXPIPES] = INF_PIPES_USED, |
| 118 | [INF_PIPES_USED] = INF_PIPES_FREE, |
| 119 | [INF_PIPES_FREE] = INF_CONN_RATE, |
| 120 | [INF_CONN_RATE] = INF_CONN_RATE_LIMIT, |
| 121 | [INF_CONN_RATE_LIMIT] = INF_MAX_CONN_RATE, |
| 122 | [INF_MAX_CONN_RATE] = INF_SESS_RATE, |
| 123 | [INF_SESS_RATE] = INF_SESS_RATE_LIMIT, |
| 124 | [INF_SESS_RATE_LIMIT] = INF_MAX_SESS_RATE, |
| 125 | [INF_MAX_SESS_RATE] = INF_SSL_RATE, |
| 126 | [INF_SSL_RATE] = INF_SSL_RATE_LIMIT, |
| 127 | [INF_SSL_RATE_LIMIT] = INF_MAX_SSL_RATE, |
| 128 | [INF_MAX_SSL_RATE] = INF_SSL_FRONTEND_KEY_RATE, |
| 129 | [INF_SSL_FRONTEND_KEY_RATE] = INF_SSL_FRONTEND_MAX_KEY_RATE, |
| 130 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = INF_SSL_FRONTEND_SESSION_REUSE_PCT, |
| 131 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = INF_SSL_BACKEND_KEY_RATE, |
| 132 | [INF_SSL_BACKEND_KEY_RATE] = INF_SSL_BACKEND_MAX_KEY_RATE, |
| 133 | [INF_SSL_BACKEND_MAX_KEY_RATE] = INF_SSL_CACHE_LOOKUPS, |
| 134 | [INF_SSL_CACHE_LOOKUPS] = INF_SSL_CACHE_MISSES, |
| 135 | [INF_SSL_CACHE_MISSES] = INF_COMPRESS_BPS_IN, |
| 136 | [INF_COMPRESS_BPS_IN] = INF_COMPRESS_BPS_OUT, |
| 137 | [INF_COMPRESS_BPS_OUT] = INF_COMPRESS_BPS_RATE_LIM, |
| 138 | [INF_COMPRESS_BPS_RATE_LIM] = INF_ZLIB_MEM_USAGE, |
| 139 | [INF_ZLIB_MEM_USAGE] = INF_MAX_ZLIB_MEM_USAGE, |
| 140 | [INF_MAX_ZLIB_MEM_USAGE] = INF_TASKS, |
| 141 | [INF_TASKS] = INF_RUN_QUEUE, |
| 142 | [INF_RUN_QUEUE] = INF_IDLE_PCT, |
| 143 | [INF_IDLE_PCT] = INF_STOPPING, |
| 144 | [INF_NODE] = 0, |
| 145 | [INF_DESCRIPTION] = 0, |
| 146 | [INF_STOPPING] = INF_JOBS, |
| 147 | [INF_JOBS] = INF_UNSTOPPABLE_JOBS, |
| 148 | [INF_UNSTOPPABLE_JOBS] = INF_LISTENERS, |
| 149 | [INF_LISTENERS] = INF_ACTIVE_PEERS, |
| 150 | [INF_ACTIVE_PEERS] = INF_CONNECTED_PEERS, |
| 151 | [INF_CONNECTED_PEERS] = INF_DROPPED_LOGS, |
| 152 | [INF_DROPPED_LOGS] = INF_BUSY_POLLING, |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 153 | [INF_BUSY_POLLING] = INF_FAILED_RESOLUTIONS, |
| 154 | [INF_FAILED_RESOLUTIONS] = INF_TOTAL_BYTES_OUT, |
| 155 | [INF_TOTAL_BYTES_OUT] = INF_TOTAL_SPLICED_BYTES_OUT, |
| 156 | [INF_TOTAL_SPLICED_BYTES_OUT] = INF_BYTES_OUT_RATE, |
| 157 | [INF_BYTES_OUT_RATE] = 0, |
| 158 | [INF_DEBUG_COMMANDS_ISSUED] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | /* Matrix used to dump frontend metrics. Each metric points to the next one to be |
| 162 | * processed or 0 to stop the dump. */ |
| 163 | const int promex_front_metrics[ST_F_TOTAL_FIELDS] = { |
| 164 | [ST_F_PXNAME] = ST_F_STATUS, |
| 165 | [ST_F_SVNAME] = 0, |
| 166 | [ST_F_QCUR] = 0, |
| 167 | [ST_F_QMAX] = 0, |
| 168 | [ST_F_SCUR] = ST_F_SMAX, |
| 169 | [ST_F_SMAX] = ST_F_SLIM, |
| 170 | [ST_F_SLIM] = ST_F_STOT, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 171 | [ST_F_STOT] = ST_F_RATE_LIM, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 172 | [ST_F_BIN] = ST_F_BOUT, |
| 173 | [ST_F_BOUT] = ST_F_DREQ, |
| 174 | [ST_F_DREQ] = ST_F_DRESP, |
| 175 | [ST_F_DRESP] = ST_F_EREQ, |
| 176 | [ST_F_EREQ] = ST_F_DCON, |
| 177 | [ST_F_ECON] = 0, |
| 178 | [ST_F_ERESP] = 0, |
| 179 | [ST_F_WRETR] = 0, |
| 180 | [ST_F_WREDIS] = 0, |
| 181 | [ST_F_STATUS] = ST_F_SCUR, |
| 182 | [ST_F_WEIGHT] = 0, |
| 183 | [ST_F_ACT] = 0, |
| 184 | [ST_F_BCK] = 0, |
| 185 | [ST_F_CHKFAIL] = 0, |
| 186 | [ST_F_CHKDOWN] = 0, |
| 187 | [ST_F_LASTCHG] = 0, |
| 188 | [ST_F_DOWNTIME] = 0, |
| 189 | [ST_F_QLIMIT] = 0, |
| 190 | [ST_F_PID] = 0, |
| 191 | [ST_F_IID] = 0, |
| 192 | [ST_F_SID] = 0, |
| 193 | [ST_F_THROTTLE] = 0, |
| 194 | [ST_F_LBTOT] = 0, |
| 195 | [ST_F_TRACKED] = 0, |
| 196 | [ST_F_TYPE] = 0, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 197 | [ST_F_RATE] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 198 | [ST_F_RATE_LIM] = ST_F_RATE_MAX, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 199 | [ST_F_RATE_MAX] = ST_F_CONN_RATE_MAX, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 200 | [ST_F_CHECK_STATUS] = 0, |
| 201 | [ST_F_CHECK_CODE] = 0, |
| 202 | [ST_F_CHECK_DURATION] = 0, |
| 203 | [ST_F_HRSP_1XX] = ST_F_HRSP_2XX, |
| 204 | [ST_F_HRSP_2XX] = ST_F_HRSP_3XX, |
| 205 | [ST_F_HRSP_3XX] = ST_F_HRSP_4XX, |
| 206 | [ST_F_HRSP_4XX] = ST_F_HRSP_5XX, |
| 207 | [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER, |
| 208 | [ST_F_HRSP_OTHER] = ST_F_INTERCEPTED, |
| 209 | [ST_F_HANAFAIL] = 0, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 210 | [ST_F_REQ_RATE] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 211 | [ST_F_REQ_RATE_MAX] = ST_F_REQ_TOT, |
| 212 | [ST_F_REQ_TOT] = ST_F_HRSP_1XX, |
| 213 | [ST_F_CLI_ABRT] = 0, |
| 214 | [ST_F_SRV_ABRT] = 0, |
| 215 | [ST_F_COMP_IN] = ST_F_COMP_OUT, |
| 216 | [ST_F_COMP_OUT] = ST_F_COMP_BYP, |
| 217 | [ST_F_COMP_BYP] = ST_F_COMP_RSP, |
| 218 | [ST_F_COMP_RSP] = 0, |
| 219 | [ST_F_LASTSESS] = 0, |
| 220 | [ST_F_LAST_CHK] = 0, |
| 221 | [ST_F_LAST_AGT] = 0, |
| 222 | [ST_F_QTIME] = 0, |
| 223 | [ST_F_CTIME] = 0, |
| 224 | [ST_F_RTIME] = 0, |
| 225 | [ST_F_TTIME] = 0, |
| 226 | [ST_F_AGENT_STATUS] = 0, |
| 227 | [ST_F_AGENT_CODE] = 0, |
| 228 | [ST_F_AGENT_DURATION] = 0, |
| 229 | [ST_F_CHECK_DESC] = 0, |
| 230 | [ST_F_AGENT_DESC] = 0, |
| 231 | [ST_F_CHECK_RISE] = 0, |
| 232 | [ST_F_CHECK_FALL] = 0, |
| 233 | [ST_F_CHECK_HEALTH] = 0, |
| 234 | [ST_F_AGENT_RISE] = 0, |
| 235 | [ST_F_AGENT_FALL] = 0, |
| 236 | [ST_F_AGENT_HEALTH] = 0, |
| 237 | [ST_F_ADDR] = 0, |
| 238 | [ST_F_COOKIE] = 0, |
| 239 | [ST_F_MODE] = 0, |
| 240 | [ST_F_ALGO] = 0, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 241 | [ST_F_CONN_RATE] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 242 | [ST_F_CONN_RATE_MAX] = ST_F_CONN_TOT, |
| 243 | [ST_F_CONN_TOT] = ST_F_BIN, |
| 244 | [ST_F_INTERCEPTED] = ST_F_CACHE_LOOKUPS, |
| 245 | [ST_F_DCON] = ST_F_DSES, |
| 246 | [ST_F_DSES] = ST_F_WREW, |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 247 | [ST_F_WREW] = ST_F_EINT, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 248 | [ST_F_CONNECT] = 0, |
| 249 | [ST_F_REUSE] = 0, |
| 250 | [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS, |
| 251 | [ST_F_CACHE_HITS] = ST_F_COMP_IN, |
Christopher Faulet | 20ab80c | 2019-11-08 15:24:32 +0100 | [diff] [blame] | 252 | [ST_F_SRV_ICUR] = 0, |
| 253 | [ST_F_SRV_ILIM] = 0, |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 254 | [ST_F_QT_MAX] = 0, |
| 255 | [ST_F_CT_MAX] = 0, |
| 256 | [ST_F_RT_MAX] = 0, |
| 257 | [ST_F_TT_MAX] = 0, |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 258 | [ST_F_EINT] = ST_F_REQ_RATE_MAX, |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 259 | [ST_F_IDLE_CONN_CUR] = 0, |
| 260 | [ST_F_SAFE_CONN_CUR] = 0, |
| 261 | [ST_F_USED_CONN_CUR] = 0, |
| 262 | [ST_F_NEED_CONN_EST] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | /* Matrix used to dump backend metrics. Each metric points to the next one to be |
| 266 | * processed or 0 to stop the dump. */ |
| 267 | const int promex_back_metrics[ST_F_TOTAL_FIELDS] = { |
| 268 | [ST_F_PXNAME] = ST_F_STATUS, |
| 269 | [ST_F_SVNAME] = 0, |
| 270 | [ST_F_QCUR] = ST_F_QMAX, |
| 271 | [ST_F_QMAX] = ST_F_CONNECT, |
| 272 | [ST_F_SCUR] = ST_F_SMAX, |
| 273 | [ST_F_SMAX] = ST_F_SLIM, |
| 274 | [ST_F_SLIM] = ST_F_STOT, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 275 | [ST_F_STOT] = ST_F_RATE_MAX, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 276 | [ST_F_BIN] = ST_F_BOUT, |
| 277 | [ST_F_BOUT] = ST_F_QTIME, |
| 278 | [ST_F_DREQ] = ST_F_DRESP, |
| 279 | [ST_F_DRESP] = ST_F_ECON, |
| 280 | [ST_F_EREQ] = 0, |
| 281 | [ST_F_ECON] = ST_F_ERESP, |
| 282 | [ST_F_ERESP] = ST_F_WRETR, |
| 283 | [ST_F_WRETR] = ST_F_WREDIS, |
| 284 | [ST_F_WREDIS] = ST_F_WREW, |
| 285 | [ST_F_STATUS] = ST_F_SCUR, |
| 286 | [ST_F_WEIGHT] = ST_F_ACT, |
| 287 | [ST_F_ACT] = ST_F_BCK, |
| 288 | [ST_F_BCK] = ST_F_CHKDOWN, |
| 289 | [ST_F_CHKFAIL] = 0, |
| 290 | [ST_F_CHKDOWN] = ST_F_LASTCHG, |
| 291 | [ST_F_LASTCHG] = ST_F_DOWNTIME, |
| 292 | [ST_F_DOWNTIME] = ST_F_LBTOT, |
| 293 | [ST_F_QLIMIT] = 0, |
| 294 | [ST_F_PID] = 0, |
| 295 | [ST_F_IID] = 0, |
| 296 | [ST_F_SID] = 0, |
| 297 | [ST_F_THROTTLE] = 0, |
| 298 | [ST_F_LBTOT] = ST_F_REQ_TOT, |
| 299 | [ST_F_TRACKED] = 9, |
| 300 | [ST_F_TYPE] = 0, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 301 | [ST_F_RATE] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 302 | [ST_F_RATE_LIM] = 0, |
| 303 | [ST_F_RATE_MAX] = ST_F_LASTSESS, |
| 304 | [ST_F_CHECK_STATUS] = 0, |
| 305 | [ST_F_CHECK_CODE] = 0, |
| 306 | [ST_F_CHECK_DURATION] = 0, |
| 307 | [ST_F_HRSP_1XX] = ST_F_HRSP_2XX, |
| 308 | [ST_F_HRSP_2XX] = ST_F_HRSP_3XX, |
| 309 | [ST_F_HRSP_3XX] = ST_F_HRSP_4XX, |
| 310 | [ST_F_HRSP_4XX] = ST_F_HRSP_5XX, |
| 311 | [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER, |
| 312 | [ST_F_HRSP_OTHER] = ST_F_CACHE_LOOKUPS, |
| 313 | [ST_F_HANAFAIL] = 0, |
| 314 | [ST_F_REQ_RATE] = 0, |
| 315 | [ST_F_REQ_RATE_MAX] = 0, |
| 316 | [ST_F_REQ_TOT] = ST_F_HRSP_1XX, |
| 317 | [ST_F_CLI_ABRT] = ST_F_SRV_ABRT, |
| 318 | [ST_F_SRV_ABRT] = ST_F_WEIGHT, |
| 319 | [ST_F_COMP_IN] = ST_F_COMP_OUT, |
| 320 | [ST_F_COMP_OUT] = ST_F_COMP_BYP, |
| 321 | [ST_F_COMP_BYP] = ST_F_COMP_RSP, |
| 322 | [ST_F_COMP_RSP] = 0, |
| 323 | [ST_F_LASTSESS] = ST_F_QCUR, |
| 324 | [ST_F_LAST_CHK] = 0, |
| 325 | [ST_F_LAST_AGT] = 0, |
| 326 | [ST_F_QTIME] = ST_F_CTIME, |
| 327 | [ST_F_CTIME] = ST_F_RTIME, |
| 328 | [ST_F_RTIME] = ST_F_TTIME, |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 329 | [ST_F_TTIME] = ST_F_QT_MAX, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 330 | [ST_F_AGENT_STATUS] = 0, |
| 331 | [ST_F_AGENT_CODE] = 0, |
| 332 | [ST_F_AGENT_DURATION] = 0, |
| 333 | [ST_F_CHECK_DESC] = 0, |
| 334 | [ST_F_AGENT_DESC] = 0, |
| 335 | [ST_F_CHECK_RISE] = 0, |
| 336 | [ST_F_CHECK_FALL] = 0, |
| 337 | [ST_F_CHECK_HEALTH] = 0, |
| 338 | [ST_F_AGENT_RISE] = 0, |
| 339 | [ST_F_AGENT_FALL] = 0, |
| 340 | [ST_F_AGENT_HEALTH] = 0, |
| 341 | [ST_F_ADDR] = 0, |
| 342 | [ST_F_COOKIE] = 0, |
| 343 | [ST_F_MODE] = 0, |
| 344 | [ST_F_ALGO] = 0, |
| 345 | [ST_F_CONN_RATE] = 0, |
| 346 | [ST_F_CONN_RATE_MAX] = 0, |
| 347 | [ST_F_CONN_TOT] = 0, |
| 348 | [ST_F_INTERCEPTED] = 0, |
| 349 | [ST_F_DCON] = 0, |
| 350 | [ST_F_DSES] = 0, |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 351 | [ST_F_WREW] = ST_F_EINT, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 352 | [ST_F_CONNECT] = ST_F_REUSE, |
| 353 | [ST_F_REUSE] = ST_F_BIN, |
| 354 | [ST_F_CACHE_LOOKUPS] = ST_F_CACHE_HITS, |
| 355 | [ST_F_CACHE_HITS] = ST_F_COMP_IN, |
Christopher Faulet | 20ab80c | 2019-11-08 15:24:32 +0100 | [diff] [blame] | 356 | [ST_F_SRV_ICUR] = 0, |
| 357 | [ST_F_SRV_ILIM] = 0, |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 358 | [ST_F_QT_MAX] = ST_F_CT_MAX, |
| 359 | [ST_F_CT_MAX] = ST_F_RT_MAX, |
| 360 | [ST_F_RT_MAX] = ST_F_TT_MAX, |
| 361 | [ST_F_TT_MAX] = ST_F_DREQ, |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 362 | [ST_F_EINT] = ST_F_CLI_ABRT, |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 363 | [ST_F_IDLE_CONN_CUR] = 0, |
| 364 | [ST_F_SAFE_CONN_CUR] = 0, |
| 365 | [ST_F_USED_CONN_CUR] = 0, |
| 366 | [ST_F_NEED_CONN_EST] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | /* Matrix used to dump server metrics. Each metric points to the next one to be |
| 370 | * processed or 0 to stop the dump. */ |
| 371 | const int promex_srv_metrics[ST_F_TOTAL_FIELDS] = { |
| 372 | [ST_F_PXNAME] = ST_F_STATUS, |
| 373 | [ST_F_SVNAME] = 0, |
| 374 | [ST_F_QCUR] = ST_F_QMAX, |
| 375 | [ST_F_QMAX] = ST_F_QLIMIT, |
| 376 | [ST_F_SCUR] = ST_F_SMAX, |
| 377 | [ST_F_SMAX] = ST_F_SLIM, |
| 378 | [ST_F_SLIM] = ST_F_STOT, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 379 | [ST_F_STOT] = ST_F_RATE_MAX, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 380 | [ST_F_BIN] = ST_F_BOUT, |
| 381 | [ST_F_BOUT] = ST_F_QTIME, |
| 382 | [ST_F_DREQ] = 0, |
| 383 | [ST_F_DRESP] = ST_F_ECON, |
| 384 | [ST_F_EREQ] = 0, |
| 385 | [ST_F_ECON] = ST_F_ERESP, |
| 386 | [ST_F_ERESP] = ST_F_WRETR, |
| 387 | [ST_F_WRETR] = ST_F_WREDIS, |
| 388 | [ST_F_WREDIS] = ST_F_WREW, |
| 389 | [ST_F_STATUS] = ST_F_SCUR, |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 390 | [ST_F_WEIGHT] = ST_F_CHECK_STATUS, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 391 | [ST_F_ACT] = 0, |
| 392 | [ST_F_BCK] = 0, |
| 393 | [ST_F_CHKFAIL] = ST_F_CHKDOWN, |
| 394 | [ST_F_CHKDOWN] = ST_F_DOWNTIME, |
| 395 | [ST_F_LASTCHG] = ST_F_THROTTLE, |
| 396 | [ST_F_DOWNTIME] = ST_F_LASTCHG, |
| 397 | [ST_F_QLIMIT] = ST_F_BIN, |
| 398 | [ST_F_PID] = 0, |
| 399 | [ST_F_IID] = 0, |
| 400 | [ST_F_SID] = 0, |
| 401 | [ST_F_THROTTLE] = ST_F_LBTOT, |
| 402 | [ST_F_LBTOT] = ST_F_HRSP_1XX, |
| 403 | [ST_F_TRACKED] = 0, |
| 404 | [ST_F_TYPE] = 0, |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 405 | [ST_F_RATE] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 406 | [ST_F_RATE_LIM] = 0, |
| 407 | [ST_F_RATE_MAX] = ST_F_LASTSESS, |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 408 | [ST_F_CHECK_STATUS] = ST_F_CHECK_CODE, |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 409 | [ST_F_CHECK_CODE] = ST_F_CHECK_DURATION, |
| 410 | [ST_F_CHECK_DURATION] = ST_F_CHKFAIL, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 411 | [ST_F_HRSP_1XX] = ST_F_HRSP_2XX, |
| 412 | [ST_F_HRSP_2XX] = ST_F_HRSP_3XX, |
| 413 | [ST_F_HRSP_3XX] = ST_F_HRSP_4XX, |
| 414 | [ST_F_HRSP_4XX] = ST_F_HRSP_5XX, |
| 415 | [ST_F_HRSP_5XX] = ST_F_HRSP_OTHER, |
Christopher Faulet | 20ab80c | 2019-11-08 15:24:32 +0100 | [diff] [blame] | 416 | [ST_F_HRSP_OTHER] = ST_F_SRV_ICUR, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 417 | [ST_F_HANAFAIL] = 0, |
| 418 | [ST_F_REQ_RATE] = 0, |
| 419 | [ST_F_REQ_RATE_MAX] = 0, |
| 420 | [ST_F_REQ_TOT] = 0, |
| 421 | [ST_F_CLI_ABRT] = ST_F_SRV_ABRT, |
| 422 | [ST_F_SRV_ABRT] = ST_F_WEIGHT, |
| 423 | [ST_F_COMP_IN] = 0, |
| 424 | [ST_F_COMP_OUT] = 0, |
| 425 | [ST_F_COMP_BYP] = 0, |
| 426 | [ST_F_COMP_RSP] = 0, |
| 427 | [ST_F_LASTSESS] = ST_F_QCUR, |
| 428 | [ST_F_LAST_CHK] = 0, |
| 429 | [ST_F_LAST_AGT] = 0, |
| 430 | [ST_F_QTIME] = ST_F_CTIME, |
| 431 | [ST_F_CTIME] = ST_F_RTIME, |
| 432 | [ST_F_RTIME] = ST_F_TTIME, |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 433 | [ST_F_TTIME] = ST_F_QT_MAX, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 434 | [ST_F_AGENT_STATUS] = 0, |
| 435 | [ST_F_AGENT_CODE] = 0, |
| 436 | [ST_F_AGENT_DURATION] = 0, |
| 437 | [ST_F_CHECK_DESC] = 0, |
| 438 | [ST_F_AGENT_DESC] = 0, |
| 439 | [ST_F_CHECK_RISE] = 0, |
| 440 | [ST_F_CHECK_FALL] = 0, |
| 441 | [ST_F_CHECK_HEALTH] = 0, |
| 442 | [ST_F_AGENT_RISE] = 0, |
| 443 | [ST_F_AGENT_FALL] = 0, |
| 444 | [ST_F_AGENT_HEALTH] = 0, |
| 445 | [ST_F_ADDR] = 0, |
| 446 | [ST_F_COOKIE] = 0, |
| 447 | [ST_F_MODE] = 0, |
| 448 | [ST_F_ALGO] = 0, |
| 449 | [ST_F_CONN_RATE] = 0, |
| 450 | [ST_F_CONN_RATE_MAX] = 0, |
| 451 | [ST_F_CONN_TOT] = 0, |
| 452 | [ST_F_INTERCEPTED] = 0, |
| 453 | [ST_F_DCON] = 0, |
| 454 | [ST_F_DSES] = 0, |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 455 | [ST_F_WREW] = ST_F_EINT, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 456 | [ST_F_CONNECT] = ST_F_REUSE, |
| 457 | [ST_F_REUSE] = ST_F_DRESP, |
| 458 | [ST_F_CACHE_LOOKUPS] = 0, |
| 459 | [ST_F_CACHE_HITS] = 0, |
Christopher Faulet | 20ab80c | 2019-11-08 15:24:32 +0100 | [diff] [blame] | 460 | [ST_F_SRV_ICUR] = ST_F_SRV_ILIM, |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 461 | [ST_F_SRV_ILIM] = ST_F_IDLE_CONN_CUR, |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 462 | [ST_F_QT_MAX] = ST_F_CT_MAX, |
| 463 | [ST_F_CT_MAX] = ST_F_RT_MAX, |
| 464 | [ST_F_RT_MAX] = ST_F_TT_MAX, |
| 465 | [ST_F_TT_MAX] = ST_F_CONNECT, |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 466 | [ST_F_EINT] = ST_F_CLI_ABRT, |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 467 | [ST_F_IDLE_CONN_CUR] = ST_F_SAFE_CONN_CUR, |
| 468 | [ST_F_SAFE_CONN_CUR] = ST_F_USED_CONN_CUR, |
| 469 | [ST_F_USED_CONN_CUR] = ST_F_NEED_CONN_EST, |
| 470 | [ST_F_NEED_CONN_EST] = 0, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 471 | }; |
| 472 | |
| 473 | /* Name of all info fields */ |
| 474 | const struct ist promex_inf_metric_names[INF_TOTAL_FIELDS] = { |
| 475 | [INF_NAME] = IST("name"), |
| 476 | [INF_VERSION] = IST("version"), |
| 477 | [INF_RELEASE_DATE] = IST("release_date"), |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 478 | [INF_BUILD_INFO] = IST("build_info"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 479 | [INF_NBTHREAD] = IST("nbthread"), |
| 480 | [INF_NBPROC] = IST("nbproc"), |
| 481 | [INF_PROCESS_NUM] = IST("relative_process_id"), |
| 482 | [INF_PID] = IST("pid"), |
| 483 | [INF_UPTIME] = IST("uptime"), |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 484 | [INF_UPTIME_SEC] = IST("start_time_seconds"), |
| 485 | [INF_MEMMAX_MB] = IST("max_memory_bytes"), |
| 486 | [INF_POOL_ALLOC_MB] = IST("pool_allocated_bytes"), |
| 487 | [INF_POOL_USED_MB] = IST("pool_used_bytes"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 488 | [INF_POOL_FAILED] = IST("pool_failures_total"), |
| 489 | [INF_ULIMIT_N] = IST("max_fds"), |
| 490 | [INF_MAXSOCK] = IST("max_sockets"), |
| 491 | [INF_MAXCONN] = IST("max_connections"), |
| 492 | [INF_HARD_MAXCONN] = IST("hard_max_connections"), |
| 493 | [INF_CURR_CONN] = IST("current_connections"), |
| 494 | [INF_CUM_CONN] = IST("connections_total"), |
| 495 | [INF_CUM_REQ] = IST("requests_total"), |
| 496 | [INF_MAX_SSL_CONNS] = IST("max_ssl_connections"), |
| 497 | [INF_CURR_SSL_CONNS] = IST("current_ssl_connections"), |
| 498 | [INF_CUM_SSL_CONNS] = IST("ssl_connections_total"), |
| 499 | [INF_MAXPIPES] = IST("max_pipes"), |
| 500 | [INF_PIPES_USED] = IST("pipes_used_total"), |
| 501 | [INF_PIPES_FREE] = IST("pipes_free_total"), |
| 502 | [INF_CONN_RATE] = IST("current_connection_rate"), |
| 503 | [INF_CONN_RATE_LIMIT] = IST("limit_connection_rate"), |
| 504 | [INF_MAX_CONN_RATE] = IST("max_connection_rate"), |
| 505 | [INF_SESS_RATE] = IST("current_session_rate"), |
| 506 | [INF_SESS_RATE_LIMIT] = IST("limit_session_rate"), |
| 507 | [INF_MAX_SESS_RATE] = IST("max_session_rate"), |
| 508 | [INF_SSL_RATE] = IST("current_ssl_rate"), |
| 509 | [INF_SSL_RATE_LIMIT] = IST("limit_ssl_rate"), |
| 510 | [INF_MAX_SSL_RATE] = IST("max_ssl_rate"), |
| 511 | [INF_SSL_FRONTEND_KEY_RATE] = IST("current_frontend_ssl_key_rate"), |
| 512 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("max_frontend_ssl_key_rate"), |
Pierre Cheynier | 1e36976 | 2020-07-07 19:14:08 +0200 | [diff] [blame] | 513 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("frontend_ssl_reuse"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 514 | [INF_SSL_BACKEND_KEY_RATE] = IST("current_backend_ssl_key_rate"), |
| 515 | [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("max_backend_ssl_key_rate"), |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 516 | [INF_SSL_CACHE_LOOKUPS] = IST("ssl_cache_lookups_total"), |
| 517 | [INF_SSL_CACHE_MISSES] = IST("ssl_cache_misses_total"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 518 | [INF_COMPRESS_BPS_IN] = IST("http_comp_bytes_in_total"), |
| 519 | [INF_COMPRESS_BPS_OUT] = IST("http_comp_bytes_out_total"), |
| 520 | [INF_COMPRESS_BPS_RATE_LIM] = IST("limit_http_comp"), |
| 521 | [INF_ZLIB_MEM_USAGE] = IST("current_zlib_memory"), |
| 522 | [INF_MAX_ZLIB_MEM_USAGE] = IST("max_zlib_memory"), |
| 523 | [INF_TASKS] = IST("current_tasks"), |
| 524 | [INF_RUN_QUEUE] = IST("current_run_queue"), |
| 525 | [INF_IDLE_PCT] = IST("idle_time_percent"), |
| 526 | [INF_NODE] = IST("node"), |
| 527 | [INF_DESCRIPTION] = IST("description"), |
| 528 | [INF_STOPPING] = IST("stopping"), |
| 529 | [INF_JOBS] = IST("jobs"), |
| 530 | [INF_UNSTOPPABLE_JOBS] = IST("unstoppable_jobs"), |
| 531 | [INF_LISTENERS] = IST("listeners"), |
| 532 | [INF_ACTIVE_PEERS] = IST("active_peers"), |
| 533 | [INF_CONNECTED_PEERS] = IST("connected_peers"), |
| 534 | [INF_DROPPED_LOGS] = IST("dropped_logs_total"), |
| 535 | [INF_BUSY_POLLING] = IST("busy_polling_enabled"), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 536 | [INF_FAILED_RESOLUTIONS] = IST("failed_resolutions"), |
| 537 | [INF_TOTAL_BYTES_OUT] = IST("bytes_out_total"), |
| 538 | [INF_TOTAL_SPLICED_BYTES_OUT] = IST("spliced_bytes_out_total"), |
| 539 | [INF_BYTES_OUT_RATE] = IST("bytes_out_rate"), |
| 540 | [INF_DEBUG_COMMANDS_ISSUED] = IST("debug_commands_issued"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 541 | }; |
| 542 | |
| 543 | /* Name of all stats fields */ |
| 544 | const struct ist promex_st_metric_names[ST_F_TOTAL_FIELDS] = { |
| 545 | [ST_F_PXNAME] = IST("proxy_name"), |
| 546 | [ST_F_SVNAME] = IST("service_name"), |
| 547 | [ST_F_QCUR] = IST("current_queue"), |
| 548 | [ST_F_QMAX] = IST("max_queue"), |
| 549 | [ST_F_SCUR] = IST("current_sessions"), |
| 550 | [ST_F_SMAX] = IST("max_sessions"), |
| 551 | [ST_F_SLIM] = IST("limit_sessions"), |
| 552 | [ST_F_STOT] = IST("sessions_total"), |
| 553 | [ST_F_BIN] = IST("bytes_in_total"), |
| 554 | [ST_F_BOUT] = IST("bytes_out_total"), |
| 555 | [ST_F_DREQ] = IST("requests_denied_total"), |
| 556 | [ST_F_DRESP] = IST("responses_denied_total"), |
| 557 | [ST_F_EREQ] = IST("request_errors_total"), |
| 558 | [ST_F_ECON] = IST("connection_errors_total"), |
| 559 | [ST_F_ERESP] = IST("response_errors_total"), |
| 560 | [ST_F_WRETR] = IST("retry_warnings_total"), |
| 561 | [ST_F_WREDIS] = IST("redispatch_warnings_total"), |
| 562 | [ST_F_STATUS] = IST("status"), |
| 563 | [ST_F_WEIGHT] = IST("weight"), |
| 564 | [ST_F_ACT] = IST("active_servers"), |
| 565 | [ST_F_BCK] = IST("backup_servers"), |
| 566 | [ST_F_CHKFAIL] = IST("check_failures_total"), |
| 567 | [ST_F_CHKDOWN] = IST("check_up_down_total"), |
| 568 | [ST_F_LASTCHG] = IST("check_last_change_seconds"), |
| 569 | [ST_F_DOWNTIME] = IST("downtime_seconds_total"), |
| 570 | [ST_F_QLIMIT] = IST("queue_limit"), |
| 571 | [ST_F_PID] = IST("pid"), |
| 572 | [ST_F_IID] = IST("proxy_id"), |
| 573 | [ST_F_SID] = IST("server_id"), |
| 574 | [ST_F_THROTTLE] = IST("current_throttle"), |
| 575 | [ST_F_LBTOT] = IST("loadbalanced_total"), |
| 576 | [ST_F_TRACKED] = IST("tracked"), |
| 577 | [ST_F_TYPE] = IST("type"), |
| 578 | [ST_F_RATE] = IST("current_session_rate"), |
| 579 | [ST_F_RATE_LIM] = IST("limit_session_rate"), |
| 580 | [ST_F_RATE_MAX] = IST("max_session_rate"), |
| 581 | [ST_F_CHECK_STATUS] = IST("check_status"), |
| 582 | [ST_F_CHECK_CODE] = IST("check_code"), |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 583 | [ST_F_CHECK_DURATION] = IST("check_duration_seconds"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 584 | [ST_F_HRSP_1XX] = IST("http_responses_total"), |
| 585 | [ST_F_HRSP_2XX] = IST("http_responses_total"), |
| 586 | [ST_F_HRSP_3XX] = IST("http_responses_total"), |
| 587 | [ST_F_HRSP_4XX] = IST("http_responses_total"), |
| 588 | [ST_F_HRSP_5XX] = IST("http_responses_total"), |
| 589 | [ST_F_HRSP_OTHER] = IST("http_responses_total"), |
| 590 | [ST_F_HANAFAIL] = IST("check_analyses_failures_total"), |
| 591 | [ST_F_REQ_RATE] = IST("http_requests_rate_current"), |
| 592 | [ST_F_REQ_RATE_MAX] = IST("http_requests_rate_max"), |
| 593 | [ST_F_REQ_TOT] = IST("http_requests_total"), |
| 594 | [ST_F_CLI_ABRT] = IST("client_aborts_total"), |
| 595 | [ST_F_SRV_ABRT] = IST("server_aborts_total"), |
| 596 | [ST_F_COMP_IN] = IST("http_comp_bytes_in_total"), |
| 597 | [ST_F_COMP_OUT] = IST("http_comp_bytes_out_total"), |
| 598 | [ST_F_COMP_BYP] = IST("http_comp_bytes_bypassed_total"), |
| 599 | [ST_F_COMP_RSP] = IST("http_comp_responses_total"), |
| 600 | [ST_F_LASTSESS] = IST("last_session_seconds"), |
| 601 | [ST_F_LAST_CHK] = IST("check_last_content"), |
| 602 | [ST_F_LAST_AGT] = IST("agentcheck_last_content"), |
Christopher Faulet | 68b6968 | 2019-11-08 15:12:29 +0100 | [diff] [blame] | 603 | [ST_F_QTIME] = IST("queue_time_average_seconds"), |
| 604 | [ST_F_CTIME] = IST("connect_time_average_seconds"), |
| 605 | [ST_F_RTIME] = IST("response_time_average_seconds"), |
| 606 | [ST_F_TTIME] = IST("total_time_average_seconds"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 607 | [ST_F_AGENT_STATUS] = IST("agentcheck_status"), |
| 608 | [ST_F_AGENT_CODE] = IST("agentcheck_code"), |
| 609 | [ST_F_AGENT_DURATION] = IST("agentcheck_duration_milliseconds"), |
| 610 | [ST_F_CHECK_DESC] = IST("check_description"), |
| 611 | [ST_F_AGENT_DESC] = IST("agentcheck_description"), |
| 612 | [ST_F_CHECK_RISE] = IST("check_rise"), |
| 613 | [ST_F_CHECK_FALL] = IST("check_fall"), |
| 614 | [ST_F_CHECK_HEALTH] = IST("check_value"), |
| 615 | [ST_F_AGENT_RISE] = IST("agentcheck_rise"), |
| 616 | [ST_F_AGENT_FALL] = IST("agentcheck_fall"), |
| 617 | [ST_F_AGENT_HEALTH] = IST("agentcheck_value"), |
| 618 | [ST_F_ADDR] = IST("address"), |
| 619 | [ST_F_COOKIE] = IST("cookie"), |
| 620 | [ST_F_MODE] = IST("mode"), |
| 621 | [ST_F_ALGO] = IST("loadbalance_algorithm"), |
| 622 | [ST_F_CONN_RATE] = IST("connections_rate_current"), |
| 623 | [ST_F_CONN_RATE_MAX] = IST("connections_rate_max"), |
| 624 | [ST_F_CONN_TOT] = IST("connections_total"), |
| 625 | [ST_F_INTERCEPTED] = IST("intercepted_requests_total"), |
| 626 | [ST_F_DCON] = IST("denied_connections_total"), |
| 627 | [ST_F_DSES] = IST("denied_sessions_total"), |
| 628 | [ST_F_WREW] = IST("failed_header_rewriting_total"), |
| 629 | [ST_F_CONNECT] = IST("connection_attempts_total"), |
| 630 | [ST_F_REUSE] = IST("connection_reuses_total"), |
| 631 | [ST_F_CACHE_LOOKUPS] = IST("http_cache_lookups_total"), |
| 632 | [ST_F_CACHE_HITS] = IST("http_cache_hits_total"), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 633 | [ST_F_SRV_ICUR] = IST("idle_connections_current"), |
| 634 | [ST_F_SRV_ILIM] = IST("idle_connections_limit"), |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 635 | [ST_F_QT_MAX] = IST("max_queue_time_seconds"), |
| 636 | [ST_F_CT_MAX] = IST("max_connect_time_seconds"), |
| 637 | [ST_F_RT_MAX] = IST("max_response_time_seconds"), |
| 638 | [ST_F_TT_MAX] = IST("max_total_time_seconds"), |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 639 | [ST_F_EINT] = IST("internal_errors_total"), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 640 | [ST_F_IDLE_CONN_CUR] = IST("unsafe_idle_connections_current"), |
| 641 | [ST_F_SAFE_CONN_CUR] = IST("safe_idle_connections_current"), |
| 642 | [ST_F_USED_CONN_CUR] = IST("used_connections_current"), |
| 643 | [ST_F_NEED_CONN_EST] = IST("need_connections_current"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 644 | }; |
| 645 | |
| 646 | /* Description of all info fields */ |
| 647 | const struct ist promex_inf_metric_desc[INF_TOTAL_FIELDS] = { |
| 648 | [INF_NAME] = IST("Product name."), |
| 649 | [INF_VERSION] = IST("HAProxy version."), |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 650 | [INF_RELEASE_DATE] = IST("HAProxy release date."), |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 651 | [INF_BUILD_INFO] = IST("HAProxy build info."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 652 | [INF_NBTHREAD] = IST("Configured number of threads."), |
| 653 | [INF_NBPROC] = IST("Configured number of processes."), |
| 654 | [INF_PROCESS_NUM] = IST("Relative process id, starting at 1."), |
| 655 | [INF_PID] = IST("HAProxy PID."), |
| 656 | [INF_UPTIME] = IST("Uptime in a human readable format."), |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 657 | [INF_UPTIME_SEC] = IST("Start time in seconds."), |
| 658 | [INF_MEMMAX_MB] = IST("Per-process memory limit (in bytes); 0=unset."), |
| 659 | [INF_POOL_ALLOC_MB] = IST("Total amount of memory allocated in pools (in bytes)."), |
| 660 | [INF_POOL_USED_MB] = IST("Total amount of memory used in pools (in bytes)."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 661 | [INF_POOL_FAILED] = IST("Total number of failed pool allocations."), |
| 662 | [INF_ULIMIT_N] = IST("Maximum number of open file descriptors; 0=unset."), |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 663 | [INF_MAXSOCK] = IST("Maximum number of open sockets."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 664 | [INF_MAXCONN] = IST("Maximum number of concurrent connections."), |
| 665 | [INF_HARD_MAXCONN] = IST("Initial Maximum number of concurrent connections."), |
| 666 | [INF_CURR_CONN] = IST("Number of active sessions."), |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 667 | [INF_CUM_CONN] = IST("Total number of created sessions."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 668 | [INF_CUM_REQ] = IST("Total number of requests (TCP or HTTP)."), |
| 669 | [INF_MAX_SSL_CONNS] = IST("Configured maximum number of concurrent SSL connections."), |
| 670 | [INF_CURR_SSL_CONNS] = IST("Number of opened SSL connections."), |
| 671 | [INF_CUM_SSL_CONNS] = IST("Total number of opened SSL connections."), |
| 672 | [INF_MAXPIPES] = IST("Configured maximum number of pipes."), |
| 673 | [INF_PIPES_USED] = IST("Number of pipes in used."), |
| 674 | [INF_PIPES_FREE] = IST("Number of pipes unused."), |
| 675 | [INF_CONN_RATE] = IST("Current number of connections per second over last elapsed second."), |
| 676 | [INF_CONN_RATE_LIMIT] = IST("Configured maximum number of connections per second."), |
| 677 | [INF_MAX_CONN_RATE] = IST("Maximum observed number of connections per second."), |
| 678 | [INF_SESS_RATE] = IST("Current number of sessions per second over last elapsed second."), |
| 679 | [INF_SESS_RATE_LIMIT] = IST("Configured maximum number of sessions per second."), |
| 680 | [INF_MAX_SESS_RATE] = IST("Maximum observed number of sessions per second."), |
| 681 | [INF_SSL_RATE] = IST("Current number of SSL sessions per second over last elapsed second."), |
| 682 | [INF_SSL_RATE_LIMIT] = IST("Configured maximum number of SSL sessions per second."), |
| 683 | [INF_MAX_SSL_RATE] = IST("Maximum observed number of SSL sessions per second."), |
| 684 | [INF_SSL_FRONTEND_KEY_RATE] = IST("Current frontend SSL Key computation per second over last elapsed second."), |
| 685 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("Maximum observed frontend SSL Key computation per second."), |
| 686 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("SSL session reuse ratio (percent)."), |
| 687 | [INF_SSL_BACKEND_KEY_RATE] = IST("Current backend SSL Key computation per second over last elapsed second."), |
| 688 | [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("Maximum observed backend SSL Key computation per second."), |
| 689 | [INF_SSL_CACHE_LOOKUPS] = IST("Total number of SSL session cache lookups."), |
| 690 | [INF_SSL_CACHE_MISSES] = IST("Total number of SSL session cache misses."), |
| 691 | [INF_COMPRESS_BPS_IN] = IST("Number of bytes per second over last elapsed second, before http compression."), |
| 692 | [INF_COMPRESS_BPS_OUT] = IST("Number of bytes per second over last elapsed second, after http compression."), |
| 693 | [INF_COMPRESS_BPS_RATE_LIM] = IST("Configured maximum input compression rate in bytes."), |
| 694 | [INF_ZLIB_MEM_USAGE] = IST("Current memory used for zlib in bytes."), |
| 695 | [INF_MAX_ZLIB_MEM_USAGE] = IST("Configured maximum amount of memory for zlib in bytes."), |
| 696 | [INF_TASKS] = IST("Current number of tasks."), |
| 697 | [INF_RUN_QUEUE] = IST("Current number of tasks in the run-queue."), |
| 698 | [INF_IDLE_PCT] = IST("Idle to total ratio over last sample (percent)."), |
| 699 | [INF_NODE] = IST("Node name."), |
| 700 | [INF_DESCRIPTION] = IST("Node description."), |
| 701 | [INF_STOPPING] = IST("Non zero means stopping in progress."), |
| 702 | [INF_JOBS] = IST("Current number of active jobs (listeners, sessions, open devices)."), |
| 703 | [INF_UNSTOPPABLE_JOBS] = IST("Current number of active jobs that can't be stopped during a soft stop."), |
| 704 | [INF_LISTENERS] = IST("Current number of active listeners."), |
| 705 | [INF_ACTIVE_PEERS] = IST("Current number of active peers."), |
| 706 | [INF_CONNECTED_PEERS] = IST("Current number of connected peers."), |
| 707 | [INF_DROPPED_LOGS] = IST("Total number of dropped logs."), |
| 708 | [INF_BUSY_POLLING] = IST("Non zero if the busy polling is enabled."), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 709 | [INF_FAILED_RESOLUTIONS] = IST("Total number of failed DNS resolutions."), |
| 710 | [INF_TOTAL_BYTES_OUT] = IST("Total number of bytes emitted."), |
| 711 | [INF_TOTAL_SPLICED_BYTES_OUT] = IST("Total number of bytes emitted through a kernel pipe."), |
| 712 | [INF_BYTES_OUT_RATE] = IST("Number of bytes emitted over the last elapsed second."), |
| 713 | [INF_DEBUG_COMMANDS_ISSUED] = IST("Number of debug commands issued on this process (anything > 0 is unsafe)."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 714 | }; |
| 715 | |
| 716 | /* Description of all stats fields */ |
| 717 | const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = { |
| 718 | [ST_F_PXNAME] = IST("The proxy name."), |
| 719 | [ST_F_SVNAME] = IST("The service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener)."), |
| 720 | [ST_F_QCUR] = IST("Current number of queued requests."), |
| 721 | [ST_F_QMAX] = IST("Maximum observed number of queued requests."), |
| 722 | [ST_F_SCUR] = IST("Current number of active sessions."), |
| 723 | [ST_F_SMAX] = IST("Maximum observed number of active sessions."), |
| 724 | [ST_F_SLIM] = IST("Configured session limit."), |
| 725 | [ST_F_STOT] = IST("Total number of sessions."), |
| 726 | [ST_F_BIN] = IST("Current total of incoming bytes."), |
| 727 | [ST_F_BOUT] = IST("Current total of outgoing bytes."), |
| 728 | [ST_F_DREQ] = IST("Total number of denied requests."), |
| 729 | [ST_F_DRESP] = IST("Total number of denied responses."), |
| 730 | [ST_F_EREQ] = IST("Total number of request errors."), |
| 731 | [ST_F_ECON] = IST("Total number of connection errors."), |
| 732 | [ST_F_ERESP] = IST("Total number of response errors."), |
| 733 | [ST_F_WRETR] = IST("Total number of retry warnings."), |
| 734 | [ST_F_WREDIS] = IST("Total number of redispatch warnings."), |
Willy Tarreau | 6b3bf73 | 2020-09-24 07:35:46 +0200 | [diff] [blame] | 735 | [ST_F_STATUS] = IST("Current status of the service (frontend: 0=STOP, 1=UP - backend: 0=DOWN, 1=UP - server: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB)."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 736 | [ST_F_WEIGHT] = IST("Service weight."), |
| 737 | [ST_F_ACT] = IST("Current number of active servers."), |
| 738 | [ST_F_BCK] = IST("Current number of backup servers."), |
| 739 | [ST_F_CHKFAIL] = IST("Total number of failed check (Only counts checks failed when the server is up)."), |
| 740 | [ST_F_CHKDOWN] = IST("Total number of UP->DOWN transitions."), |
| 741 | [ST_F_LASTCHG] = IST("Number of seconds since the last UP<->DOWN transition."), |
| 742 | [ST_F_DOWNTIME] = IST("Total downtime (in seconds) for the service."), |
| 743 | [ST_F_QLIMIT] = IST("Configured maxqueue for the server (0 meaning no limit)."), |
| 744 | [ST_F_PID] = IST("Process id (0 for first instance, 1 for second, ...)"), |
| 745 | [ST_F_IID] = IST("Unique proxy id."), |
| 746 | [ST_F_SID] = IST("Server id (unique inside a proxy)."), |
| 747 | [ST_F_THROTTLE] = IST("Current throttle percentage for the server, when slowstart is active, or no value if not in slowstart."), |
| 748 | [ST_F_LBTOT] = IST("Total number of times a service was selected, either for new sessions, or when redispatching."), |
| 749 | [ST_F_TRACKED] = IST("Id of proxy/server if tracking is enabled."), |
| 750 | [ST_F_TYPE] = IST("Service type (0=frontend, 1=backend, 2=server, 3=socket/listener)."), |
| 751 | [ST_F_RATE] = IST("Current number of sessions per second over last elapsed second."), |
| 752 | [ST_F_RATE_LIM] = IST("Configured limit on new sessions per second."), |
| 753 | [ST_F_RATE_MAX] = IST("Maximum observed number of sessions per second."), |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 754 | [ST_F_CHECK_STATUS] = IST("Status of last health check (HCHK_STATUS_* values)."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 755 | [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."), |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 756 | [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 757 | [ST_F_HRSP_1XX] = IST("Total number of HTTP responses."), |
| 758 | [ST_F_HRSP_2XX] = IST("Total number of HTTP responses."), |
| 759 | [ST_F_HRSP_3XX] = IST("Total number of HTTP responses."), |
| 760 | [ST_F_HRSP_4XX] = IST("Total number of HTTP responses."), |
| 761 | [ST_F_HRSP_5XX] = IST("Total number of HTTP responses."), |
| 762 | [ST_F_HRSP_OTHER] = IST("Total number of HTTP responses."), |
| 763 | [ST_F_HANAFAIL] = IST("Total number of failed health checks."), |
| 764 | [ST_F_REQ_RATE] = IST("Current number of HTTP requests per second over last elapsed second."), |
| 765 | [ST_F_REQ_RATE_MAX] = IST("Maximum observed number of HTTP requests per second."), |
| 766 | [ST_F_REQ_TOT] = IST("Total number of HTTP requests received."), |
| 767 | [ST_F_CLI_ABRT] = IST("Total number of data transfers aborted by the client."), |
| 768 | [ST_F_SRV_ABRT] = IST("Total number of data transfers aborted by the server."), |
| 769 | [ST_F_COMP_IN] = IST("Total number of HTTP response bytes fed to the compressor."), |
| 770 | [ST_F_COMP_OUT] = IST("Total number of HTTP response bytes emitted by the compressor."), |
| 771 | [ST_F_COMP_BYP] = IST("Total number of bytes that bypassed the HTTP compressor (CPU/BW limit)."), |
| 772 | [ST_F_COMP_RSP] = IST("Total number of HTTP responses that were compressed."), |
| 773 | [ST_F_LASTSESS] = IST("Number of seconds since last session assigned to server/backend."), |
| 774 | [ST_F_LAST_CHK] = IST("Last health check contents or textual error"), |
| 775 | [ST_F_LAST_AGT] = IST("Last agent check contents or textual error"), |
| 776 | [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."), |
| 777 | [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."), |
| 778 | [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."), |
| 779 | [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."), |
| 780 | [ST_F_AGENT_STATUS] = IST("Status of last agent check."), |
| 781 | [ST_F_AGENT_CODE] = IST("Numeric code reported by agent if any (unused for now)."), |
| 782 | [ST_F_AGENT_DURATION] = IST("Time in ms taken to finish last agent check."), |
| 783 | [ST_F_CHECK_DESC] = IST("Short human-readable description of the last health status."), |
| 784 | [ST_F_AGENT_DESC] = IST("Short human-readable description of the last agent status."), |
| 785 | [ST_F_CHECK_RISE] = IST("Server's \"rise\" parameter used by health checks"), |
| 786 | [ST_F_CHECK_FALL] = IST("Server's \"fall\" parameter used by health checks"), |
| 787 | [ST_F_CHECK_HEALTH] = IST("Server's health check value between 0 and rise+fall-1"), |
| 788 | [ST_F_AGENT_RISE] = IST("Agent's \"rise\" parameter, normally 1."), |
| 789 | [ST_F_AGENT_FALL] = IST("Agent's \"fall\" parameter, normally 1."), |
| 790 | [ST_F_AGENT_HEALTH] = IST("Agent's health parameter, between 0 and rise+fall-1"), |
| 791 | [ST_F_ADDR] = IST("address:port or \"unix\". IPv6 has brackets around the address."), |
| 792 | [ST_F_COOKIE] = IST("Server's cookie value or backend's cookie name."), |
| 793 | [ST_F_MODE] = IST("Proxy mode (tcp, http, health, unknown)."), |
| 794 | [ST_F_ALGO] = IST("Load balancing algorithm."), |
| 795 | [ST_F_CONN_RATE] = IST("Current number of connections per second over the last elapsed second."), |
| 796 | [ST_F_CONN_RATE_MAX] = IST("Maximum observed number of connections per second."), |
| 797 | [ST_F_CONN_TOT] = IST("Total number of connections."), |
| 798 | [ST_F_INTERCEPTED] = IST("Total number of intercepted HTTP requests."), |
| 799 | [ST_F_DCON] = IST("Total number of requests denied by \"tcp-request connection\" rules."), |
| 800 | [ST_F_DSES] = IST("Total number of requests denied by \"tcp-request session\" rules."), |
| 801 | [ST_F_WREW] = IST("Total number of failed header rewriting warnings."), |
| 802 | [ST_F_CONNECT] = IST("Total number of connection establishment attempts."), |
| 803 | [ST_F_REUSE] = IST("Total number of connection reuses."), |
| 804 | [ST_F_CACHE_LOOKUPS] = IST("Total number of HTTP cache lookups."), |
| 805 | [ST_F_CACHE_HITS] = IST("Total number of HTTP cache hits."), |
Christopher Faulet | 20ab80c | 2019-11-08 15:24:32 +0100 | [diff] [blame] | 806 | [ST_F_SRV_ICUR] = IST("Current number of idle connections available for reuse"), |
| 807 | [ST_F_SRV_ILIM] = IST("Limit on the number of available idle connections"), |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 808 | [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"), |
| 809 | [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"), |
| 810 | [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"), |
| 811 | [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"), |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 812 | [ST_F_EINT] = IST("Total number of internal errors."), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 813 | [ST_F_IDLE_CONN_CUR] = IST("Current number of unsafe idle connections."), |
| 814 | [ST_F_SAFE_CONN_CUR] = IST("Current number of safe idle connections."), |
| 815 | [ST_F_USED_CONN_CUR] = IST("Current number of connections in use."), |
| 816 | [ST_F_NEED_CONN_EST] = IST("Estimated needed number of connections."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 817 | }; |
| 818 | |
| 819 | /* Specific labels for all info fields. Empty by default. */ |
| 820 | const struct ist promex_inf_metric_labels[INF_TOTAL_FIELDS] = { |
| 821 | [INF_NAME] = IST(""), |
| 822 | [INF_VERSION] = IST(""), |
| 823 | [INF_RELEASE_DATE] = IST(""), |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 824 | [INF_BUILD_INFO] = IST(PROMEX_BUILDINFO_LABEL), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 825 | [INF_NBTHREAD] = IST(""), |
| 826 | [INF_NBPROC] = IST(""), |
| 827 | [INF_PROCESS_NUM] = IST(""), |
| 828 | [INF_PID] = IST(""), |
| 829 | [INF_UPTIME] = IST(""), |
| 830 | [INF_UPTIME_SEC] = IST(""), |
| 831 | [INF_MEMMAX_MB] = IST(""), |
| 832 | [INF_POOL_ALLOC_MB] = IST(""), |
| 833 | [INF_POOL_USED_MB] = IST(""), |
| 834 | [INF_POOL_FAILED] = IST(""), |
| 835 | [INF_ULIMIT_N] = IST(""), |
| 836 | [INF_MAXSOCK] = IST(""), |
| 837 | [INF_MAXCONN] = IST(""), |
| 838 | [INF_HARD_MAXCONN] = IST(""), |
| 839 | [INF_CURR_CONN] = IST(""), |
| 840 | [INF_CUM_CONN] = IST(""), |
| 841 | [INF_CUM_REQ] = IST(""), |
| 842 | [INF_MAX_SSL_CONNS] = IST(""), |
| 843 | [INF_CURR_SSL_CONNS] = IST(""), |
| 844 | [INF_CUM_SSL_CONNS] = IST(""), |
| 845 | [INF_MAXPIPES] = IST(""), |
| 846 | [INF_PIPES_USED] = IST(""), |
| 847 | [INF_PIPES_FREE] = IST(""), |
| 848 | [INF_CONN_RATE] = IST(""), |
| 849 | [INF_CONN_RATE_LIMIT] = IST(""), |
| 850 | [INF_MAX_CONN_RATE] = IST(""), |
| 851 | [INF_SESS_RATE] = IST(""), |
| 852 | [INF_SESS_RATE_LIMIT] = IST(""), |
| 853 | [INF_MAX_SESS_RATE] = IST(""), |
| 854 | [INF_SSL_RATE] = IST(""), |
| 855 | [INF_SSL_RATE_LIMIT] = IST(""), |
| 856 | [INF_MAX_SSL_RATE] = IST(""), |
| 857 | [INF_SSL_FRONTEND_KEY_RATE] = IST(""), |
| 858 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST(""), |
| 859 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST(""), |
| 860 | [INF_SSL_BACKEND_KEY_RATE] = IST(""), |
| 861 | [INF_SSL_BACKEND_MAX_KEY_RATE] = IST(""), |
| 862 | [INF_SSL_CACHE_LOOKUPS] = IST(""), |
| 863 | [INF_SSL_CACHE_MISSES] = IST(""), |
| 864 | [INF_COMPRESS_BPS_IN] = IST(""), |
| 865 | [INF_COMPRESS_BPS_OUT] = IST(""), |
| 866 | [INF_COMPRESS_BPS_RATE_LIM] = IST(""), |
| 867 | [INF_ZLIB_MEM_USAGE] = IST(""), |
| 868 | [INF_MAX_ZLIB_MEM_USAGE] = IST(""), |
| 869 | [INF_TASKS] = IST(""), |
| 870 | [INF_RUN_QUEUE] = IST(""), |
| 871 | [INF_IDLE_PCT] = IST(""), |
| 872 | [INF_NODE] = IST(""), |
| 873 | [INF_DESCRIPTION] = IST(""), |
| 874 | [INF_STOPPING] = IST(""), |
| 875 | [INF_JOBS] = IST(""), |
| 876 | [INF_UNSTOPPABLE_JOBS] = IST(""), |
| 877 | [INF_LISTENERS] = IST(""), |
| 878 | [INF_ACTIVE_PEERS] = IST(""), |
| 879 | [INF_CONNECTED_PEERS] = IST(""), |
| 880 | [INF_DROPPED_LOGS] = IST(""), |
| 881 | [INF_BUSY_POLLING] = IST(""), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 882 | [INF_FAILED_RESOLUTIONS] = IST(""), |
| 883 | [INF_TOTAL_BYTES_OUT] = IST(""), |
| 884 | [INF_TOTAL_SPLICED_BYTES_OUT] = IST(""), |
| 885 | [INF_BYTES_OUT_RATE] = IST(""), |
| 886 | [INF_DEBUG_COMMANDS_ISSUED] = IST(""), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 887 | }; |
| 888 | |
| 889 | /* Specific labels for all stats fields. Empty by default. */ |
| 890 | const struct ist promex_st_metric_labels[ST_F_TOTAL_FIELDS] = { |
| 891 | [ST_F_PXNAME] = IST(""), |
| 892 | [ST_F_SVNAME] = IST(""), |
| 893 | [ST_F_QCUR] = IST(""), |
| 894 | [ST_F_QMAX] = IST(""), |
| 895 | [ST_F_SCUR] = IST(""), |
| 896 | [ST_F_SMAX] = IST(""), |
| 897 | [ST_F_SLIM] = IST(""), |
| 898 | [ST_F_STOT] = IST(""), |
| 899 | [ST_F_BIN] = IST(""), |
| 900 | [ST_F_BOUT] = IST(""), |
| 901 | [ST_F_DREQ] = IST(""), |
| 902 | [ST_F_DRESP] = IST(""), |
| 903 | [ST_F_EREQ] = IST(""), |
| 904 | [ST_F_ECON] = IST(""), |
| 905 | [ST_F_ERESP] = IST(""), |
| 906 | [ST_F_WRETR] = IST(""), |
| 907 | [ST_F_WREDIS] = IST(""), |
| 908 | [ST_F_STATUS] = IST(""), |
| 909 | [ST_F_WEIGHT] = IST(""), |
| 910 | [ST_F_ACT] = IST(""), |
| 911 | [ST_F_BCK] = IST(""), |
| 912 | [ST_F_CHKFAIL] = IST(""), |
| 913 | [ST_F_CHKDOWN] = IST(""), |
| 914 | [ST_F_LASTCHG] = IST(""), |
| 915 | [ST_F_DOWNTIME] = IST(""), |
| 916 | [ST_F_QLIMIT] = IST(""), |
| 917 | [ST_F_PID] = IST(""), |
| 918 | [ST_F_IID] = IST(""), |
| 919 | [ST_F_SID] = IST(""), |
| 920 | [ST_F_THROTTLE] = IST(""), |
| 921 | [ST_F_LBTOT] = IST(""), |
| 922 | [ST_F_TRACKED] = IST(""), |
| 923 | [ST_F_TYPE] = IST(""), |
| 924 | [ST_F_RATE] = IST(""), |
| 925 | [ST_F_RATE_LIM] = IST(""), |
| 926 | [ST_F_RATE_MAX] = IST(""), |
| 927 | [ST_F_CHECK_STATUS] = IST(""), |
| 928 | [ST_F_CHECK_CODE] = IST(""), |
| 929 | [ST_F_CHECK_DURATION] = IST(""), |
| 930 | [ST_F_HRSP_1XX] = IST("code=\"1xx\""), |
| 931 | [ST_F_HRSP_2XX] = IST("code=\"2xx\""), |
| 932 | [ST_F_HRSP_3XX] = IST("code=\"3xx\""), |
| 933 | [ST_F_HRSP_4XX] = IST("code=\"4xx\""), |
| 934 | [ST_F_HRSP_5XX] = IST("code=\"5xx\""), |
| 935 | [ST_F_HRSP_OTHER] = IST("code=\"other\""), |
| 936 | [ST_F_HANAFAIL] = IST(""), |
| 937 | [ST_F_REQ_RATE] = IST(""), |
| 938 | [ST_F_REQ_RATE_MAX] = IST(""), |
| 939 | [ST_F_REQ_TOT] = IST(""), |
| 940 | [ST_F_CLI_ABRT] = IST(""), |
| 941 | [ST_F_SRV_ABRT] = IST(""), |
| 942 | [ST_F_COMP_IN] = IST(""), |
| 943 | [ST_F_COMP_OUT] = IST(""), |
| 944 | [ST_F_COMP_BYP] = IST(""), |
| 945 | [ST_F_COMP_RSP] = IST(""), |
| 946 | [ST_F_LASTSESS] = IST(""), |
| 947 | [ST_F_LAST_CHK] = IST(""), |
| 948 | [ST_F_LAST_AGT] = IST(""), |
| 949 | [ST_F_QTIME] = IST(""), |
| 950 | [ST_F_CTIME] = IST(""), |
| 951 | [ST_F_RTIME] = IST(""), |
| 952 | [ST_F_TTIME] = IST(""), |
| 953 | [ST_F_AGENT_STATUS] = IST(""), |
| 954 | [ST_F_AGENT_CODE] = IST(""), |
| 955 | [ST_F_AGENT_DURATION] = IST(""), |
| 956 | [ST_F_CHECK_DESC] = IST(""), |
| 957 | [ST_F_AGENT_DESC] = IST(""), |
| 958 | [ST_F_CHECK_RISE] = IST(""), |
| 959 | [ST_F_CHECK_FALL] = IST(""), |
| 960 | [ST_F_CHECK_HEALTH] = IST(""), |
| 961 | [ST_F_AGENT_RISE] = IST(""), |
| 962 | [ST_F_AGENT_FALL] = IST(""), |
| 963 | [ST_F_AGENT_HEALTH] = IST(""), |
| 964 | [ST_F_ADDR] = IST(""), |
| 965 | [ST_F_COOKIE] = IST(""), |
| 966 | [ST_F_MODE] = IST(""), |
| 967 | [ST_F_ALGO] = IST(""), |
| 968 | [ST_F_CONN_RATE] = IST(""), |
| 969 | [ST_F_CONN_RATE_MAX] = IST(""), |
| 970 | [ST_F_CONN_TOT] = IST(""), |
| 971 | [ST_F_INTERCEPTED] = IST(""), |
| 972 | [ST_F_DCON] = IST(""), |
| 973 | [ST_F_DSES] = IST(""), |
| 974 | [ST_F_WREW] = IST(""), |
| 975 | [ST_F_CONNECT] = IST(""), |
| 976 | [ST_F_REUSE] = IST(""), |
| 977 | [ST_F_CACHE_LOOKUPS] = IST(""), |
| 978 | [ST_F_CACHE_HITS] = IST(""), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 979 | [ST_F_IDLE_CONN_CUR] = IST(""), |
| 980 | [ST_F_SAFE_CONN_CUR] = IST(""), |
| 981 | [ST_F_USED_CONN_CUR] = IST(""), |
| 982 | [ST_F_NEED_CONN_EST] = IST(""), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 983 | }; |
| 984 | |
| 985 | /* Type for all info fields. "untyped" is used for unsupported field. */ |
| 986 | const struct ist promex_inf_metric_types[INF_TOTAL_FIELDS] = { |
| 987 | [INF_NAME] = IST("untyped"), |
| 988 | [INF_VERSION] = IST("untyped"), |
| 989 | [INF_RELEASE_DATE] = IST("untyped"), |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 990 | [INF_BUILD_INFO] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 991 | [INF_NBTHREAD] = IST("gauge"), |
| 992 | [INF_NBPROC] = IST("gauge"), |
| 993 | [INF_PROCESS_NUM] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 994 | [INF_PID] = IST("untyped"), |
| 995 | [INF_UPTIME] = IST("untyped"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 996 | [INF_UPTIME_SEC] = IST("gauge"), |
| 997 | [INF_MEMMAX_MB] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 998 | [INF_POOL_ALLOC_MB] = IST("gauge"), |
| 999 | [INF_POOL_USED_MB] = IST("gauge"), |
| 1000 | [INF_POOL_FAILED] = IST("counter"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1001 | [INF_ULIMIT_N] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1002 | [INF_MAXSOCK] = IST("gauge"), |
| 1003 | [INF_MAXCONN] = IST("gauge"), |
| 1004 | [INF_HARD_MAXCONN] = IST("gauge"), |
| 1005 | [INF_CURR_CONN] = IST("gauge"), |
| 1006 | [INF_CUM_CONN] = IST("counter"), |
| 1007 | [INF_CUM_REQ] = IST("counter"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1008 | [INF_MAX_SSL_CONNS] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1009 | [INF_CURR_SSL_CONNS] = IST("gauge"), |
| 1010 | [INF_CUM_SSL_CONNS] = IST("counter"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1011 | [INF_MAXPIPES] = IST("gauge"), |
| 1012 | [INF_PIPES_USED] = IST("counter"), |
| 1013 | [INF_PIPES_FREE] = IST("counter"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1014 | [INF_CONN_RATE] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1015 | [INF_CONN_RATE_LIMIT] = IST("gauge"), |
| 1016 | [INF_MAX_CONN_RATE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1017 | [INF_SESS_RATE] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1018 | [INF_SESS_RATE_LIMIT] = IST("gauge"), |
| 1019 | [INF_MAX_SESS_RATE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1020 | [INF_SSL_RATE] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1021 | [INF_SSL_RATE_LIMIT] = IST("gauge"), |
| 1022 | [INF_MAX_SSL_RATE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1023 | [INF_SSL_FRONTEND_KEY_RATE] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1024 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1025 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = IST("gauge"), |
| 1026 | [INF_SSL_BACKEND_KEY_RATE] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1027 | [INF_SSL_BACKEND_MAX_KEY_RATE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1028 | [INF_SSL_CACHE_LOOKUPS] = IST("counter"), |
| 1029 | [INF_SSL_CACHE_MISSES] = IST("counter"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1030 | [INF_COMPRESS_BPS_IN] = IST("counter"), |
| 1031 | [INF_COMPRESS_BPS_OUT] = IST("counter"), |
| 1032 | [INF_COMPRESS_BPS_RATE_LIM] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1033 | [INF_ZLIB_MEM_USAGE] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1034 | [INF_MAX_ZLIB_MEM_USAGE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1035 | [INF_TASKS] = IST("gauge"), |
Christopher Faulet | f782c23 | 2019-04-17 16:04:44 +0200 | [diff] [blame] | 1036 | [INF_RUN_QUEUE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1037 | [INF_IDLE_PCT] = IST("gauge"), |
| 1038 | [INF_NODE] = IST("untyped"), |
| 1039 | [INF_DESCRIPTION] = IST("untyped"), |
| 1040 | [INF_STOPPING] = IST("gauge"), |
| 1041 | [INF_JOBS] = IST("gauge"), |
| 1042 | [INF_UNSTOPPABLE_JOBS] = IST("gauge"), |
| 1043 | [INF_LISTENERS] = IST("gauge"), |
| 1044 | [INF_ACTIVE_PEERS] = IST("gauge"), |
| 1045 | [INF_CONNECTED_PEERS] = IST("gauge"), |
| 1046 | [INF_DROPPED_LOGS] = IST("counter"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1047 | [INF_BUSY_POLLING] = IST("gauge"), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 1048 | [INF_FAILED_RESOLUTIONS] = IST("counter"), |
| 1049 | [INF_TOTAL_BYTES_OUT] = IST("counter"), |
| 1050 | [INF_TOTAL_SPLICED_BYTES_OUT] = IST("counter"), |
| 1051 | [INF_BYTES_OUT_RATE] = IST("gauge"), |
| 1052 | [INF_DEBUG_COMMANDS_ISSUED] = IST(""), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1053 | }; |
| 1054 | |
| 1055 | /* Type for all stats fields. "untyped" is used for unsupported field. */ |
| 1056 | const struct ist promex_st_metric_types[ST_F_TOTAL_FIELDS] = { |
| 1057 | [ST_F_PXNAME] = IST("untyped"), |
| 1058 | [ST_F_SVNAME] = IST("untyped"), |
| 1059 | [ST_F_QCUR] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1060 | [ST_F_QMAX] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1061 | [ST_F_SCUR] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1062 | [ST_F_SMAX] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1063 | [ST_F_SLIM] = IST("gauge"), |
| 1064 | [ST_F_STOT] = IST("counter"), |
| 1065 | [ST_F_BIN] = IST("counter"), |
| 1066 | [ST_F_BOUT] = IST("counter"), |
| 1067 | [ST_F_DREQ] = IST("counter"), |
| 1068 | [ST_F_DRESP] = IST("counter"), |
| 1069 | [ST_F_EREQ] = IST("counter"), |
| 1070 | [ST_F_ECON] = IST("counter"), |
| 1071 | [ST_F_ERESP] = IST("counter"), |
| 1072 | [ST_F_WRETR] = IST("counter"), |
| 1073 | [ST_F_WREDIS] = IST("counter"), |
| 1074 | [ST_F_STATUS] = IST("gauge"), |
| 1075 | [ST_F_WEIGHT] = IST("gauge"), |
| 1076 | [ST_F_ACT] = IST("gauge"), |
| 1077 | [ST_F_BCK] = IST("gauge"), |
| 1078 | [ST_F_CHKFAIL] = IST("counter"), |
| 1079 | [ST_F_CHKDOWN] = IST("counter"), |
| 1080 | [ST_F_LASTCHG] = IST("gauge"), |
| 1081 | [ST_F_DOWNTIME] = IST("counter"), |
| 1082 | [ST_F_QLIMIT] = IST("gauge"), |
| 1083 | [ST_F_PID] = IST("untyped"), |
| 1084 | [ST_F_IID] = IST("untyped"), |
| 1085 | [ST_F_SID] = IST("untyped"), |
| 1086 | [ST_F_THROTTLE] = IST("gauge"), |
| 1087 | [ST_F_LBTOT] = IST("counter"), |
| 1088 | [ST_F_TRACKED] = IST("untyped"), |
| 1089 | [ST_F_TYPE] = IST("untyped"), |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 1090 | [ST_F_RATE] = IST("untyped"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1091 | [ST_F_RATE_LIM] = IST("gauge"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1092 | [ST_F_RATE_MAX] = IST("gauge"), |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 1093 | [ST_F_CHECK_STATUS] = IST("gauge"), |
| 1094 | [ST_F_CHECK_CODE] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1095 | [ST_F_CHECK_DURATION] = IST("gauge"), |
| 1096 | [ST_F_HRSP_1XX] = IST("counter"), |
| 1097 | [ST_F_HRSP_2XX] = IST("counter"), |
| 1098 | [ST_F_HRSP_3XX] = IST("counter"), |
| 1099 | [ST_F_HRSP_4XX] = IST("counter"), |
| 1100 | [ST_F_HRSP_5XX] = IST("counter"), |
| 1101 | [ST_F_HRSP_OTHER] = IST("counter"), |
| 1102 | [ST_F_HANAFAIL] = IST("counter"), |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 1103 | [ST_F_REQ_RATE] = IST("untyped"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1104 | [ST_F_REQ_RATE_MAX] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1105 | [ST_F_REQ_TOT] = IST("counter"), |
| 1106 | [ST_F_CLI_ABRT] = IST("counter"), |
| 1107 | [ST_F_SRV_ABRT] = IST("counter"), |
| 1108 | [ST_F_COMP_IN] = IST("counter"), |
| 1109 | [ST_F_COMP_OUT] = IST("counter"), |
| 1110 | [ST_F_COMP_BYP] = IST("counter"), |
| 1111 | [ST_F_COMP_RSP] = IST("counter"), |
| 1112 | [ST_F_LASTSESS] = IST("gauge"), |
| 1113 | [ST_F_LAST_CHK] = IST("untyped"), |
| 1114 | [ST_F_LAST_AGT] = IST("untyped"), |
| 1115 | [ST_F_QTIME] = IST("gauge"), |
| 1116 | [ST_F_CTIME] = IST("gauge"), |
| 1117 | [ST_F_RTIME] = IST("gauge"), |
| 1118 | [ST_F_TTIME] = IST("gauge"), |
| 1119 | [ST_F_AGENT_STATUS] = IST("untyped"), |
| 1120 | [ST_F_AGENT_CODE] = IST("untyped"), |
| 1121 | [ST_F_AGENT_DURATION] = IST("gauge"), |
| 1122 | [ST_F_CHECK_DESC] = IST("untyped"), |
| 1123 | [ST_F_AGENT_DESC] = IST("untyped"), |
| 1124 | [ST_F_CHECK_RISE] = IST("gauge"), |
| 1125 | [ST_F_CHECK_FALL] = IST("gauge"), |
| 1126 | [ST_F_CHECK_HEALTH] = IST("gauge"), |
| 1127 | [ST_F_AGENT_RISE] = IST("gauge"), |
| 1128 | [ST_F_AGENT_FALL] = IST("gauge"), |
| 1129 | [ST_F_AGENT_HEALTH] = IST("gauge"), |
| 1130 | [ST_F_ADDR] = IST("untyped"), |
| 1131 | [ST_F_COOKIE] = IST("untyped"), |
| 1132 | [ST_F_MODE] = IST("untyped"), |
| 1133 | [ST_F_ALGO] = IST("untyped"), |
Christopher Faulet | c58fc0d | 2019-04-18 10:10:49 +0200 | [diff] [blame] | 1134 | [ST_F_CONN_RATE] = IST("untyped"), |
Christopher Faulet | 769a92d | 2019-04-18 10:18:44 +0200 | [diff] [blame] | 1135 | [ST_F_CONN_RATE_MAX] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1136 | [ST_F_CONN_TOT] = IST("counter"), |
| 1137 | [ST_F_INTERCEPTED] = IST("counter"), |
| 1138 | [ST_F_DCON] = IST("counter"), |
| 1139 | [ST_F_DSES] = IST("counter"), |
| 1140 | [ST_F_WREW] = IST("counter"), |
| 1141 | [ST_F_CONNECT] = IST("counter"), |
| 1142 | [ST_F_REUSE] = IST("counter"), |
| 1143 | [ST_F_CACHE_LOOKUPS] = IST("counter"), |
| 1144 | [ST_F_CACHE_HITS] = IST("counter"), |
Christopher Faulet | 20ab80c | 2019-11-08 15:24:32 +0100 | [diff] [blame] | 1145 | [ST_F_SRV_ICUR] = IST("gauge"), |
| 1146 | [ST_F_SRV_ILIM] = IST("gauge"), |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1147 | [ST_F_QT_MAX] = IST("gauge"), |
| 1148 | [ST_F_CT_MAX] = IST("gauge"), |
| 1149 | [ST_F_RT_MAX] = IST("gauge"), |
| 1150 | [ST_F_TT_MAX] = IST("gauge"), |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 1151 | [ST_F_EINT] = IST("counter"), |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 1152 | [ST_F_IDLE_CONN_CUR] = IST("gauge"), |
| 1153 | [ST_F_SAFE_CONN_CUR] = IST("gauge"), |
| 1154 | [ST_F_USED_CONN_CUR] = IST("gauge"), |
| 1155 | [ST_F_NEED_CONN_EST] = IST("gauge"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1156 | }; |
| 1157 | |
Christopher Faulet | d45d105 | 2019-09-06 16:10:19 +0200 | [diff] [blame] | 1158 | /* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1159 | static int promex_srv_status(struct server *sv) |
| 1160 | { |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1161 | int state = 0; |
| 1162 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1163 | if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) { |
| 1164 | state = 1; |
| 1165 | if (sv->cur_admin & SRV_ADMF_DRAIN) |
Christopher Faulet | d45d105 | 2019-09-06 16:10:19 +0200 | [diff] [blame] | 1166 | state = 3; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1167 | } |
Christopher Faulet | d45d105 | 2019-09-06 16:10:19 +0200 | [diff] [blame] | 1168 | else if (sv->cur_state == SRV_ST_STOPPING) |
| 1169 | state = 4; |
| 1170 | |
| 1171 | if (sv->cur_admin & SRV_ADMF_MAINT) |
| 1172 | state = 2; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1173 | |
| 1174 | return state; |
| 1175 | } |
| 1176 | |
| 1177 | /* Convert a field to its string representation and write it in <out>, followed |
| 1178 | * by a newline, if there is enough space. non-numeric value are converted in |
| 1179 | * "Nan" because Prometheus only support numerical values (but it is unexepceted |
| 1180 | * to process this kind of value). It returns 1 on success. Otherwise, it |
| 1181 | * returns 0. The buffer's length must not exceed <max> value. |
| 1182 | */ |
| 1183 | static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max) |
| 1184 | { |
| 1185 | int ret = 0; |
| 1186 | |
| 1187 | switch (field_format(f, 0)) { |
| 1188 | case FF_EMPTY: ret = chunk_strcat(out, "Nan\n"); break; |
| 1189 | case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break; |
| 1190 | case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break; |
| 1191 | case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break; |
| 1192 | case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1193 | case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1194 | case FF_STR: ret = chunk_strcat(out, "Nan\n"); break; |
| 1195 | default: ret = chunk_strcat(out, "Nan\n"); break; |
| 1196 | } |
| 1197 | if (!ret || out->data > max) |
| 1198 | return 0; |
| 1199 | return 1; |
| 1200 | } |
| 1201 | |
| 1202 | /* Concatenate the <prefix> with the field name using the array |
| 1203 | * <promex_st_metric_names> and store it in <name>. The field type is in |
| 1204 | * <appctx->st2>. This function never fails but relies on |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1205 | * <PROMEX_MAX_NAME_LEN>. So by sure the result is small enough to be copied in |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1206 | * <name> |
| 1207 | */ |
| 1208 | static void promex_metric_name(struct appctx *appctx, struct ist *name, const struct ist prefix) |
| 1209 | { |
| 1210 | const struct ist *names; |
| 1211 | |
| 1212 | names = ((appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) |
| 1213 | ? promex_inf_metric_names |
| 1214 | : promex_st_metric_names); |
| 1215 | |
| 1216 | istcat(name, prefix, PROMEX_MAX_NAME_LEN); |
| 1217 | istcat(name, names[appctx->st2], PROMEX_MAX_NAME_LEN); |
| 1218 | } |
| 1219 | |
| 1220 | /* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It |
| 1221 | * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0. |
| 1222 | */ |
| 1223 | static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx, |
| 1224 | const struct ist name, struct ist *out, size_t max) |
| 1225 | { |
| 1226 | const struct ist *desc, *types; |
| 1227 | |
| 1228 | if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) { |
| 1229 | desc = promex_inf_metric_desc; |
| 1230 | types = promex_inf_metric_types; |
| 1231 | } |
| 1232 | else { |
| 1233 | desc = promex_st_metric_desc; |
| 1234 | types = promex_st_metric_types; |
| 1235 | } |
| 1236 | |
Anthonin Bonnefoy | 51c3aa4 | 2019-08-07 17:45:25 +0200 | [diff] [blame] | 1237 | if (istcat(out, ist("# HELP "), max) == -1 || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1238 | istcat(out, name, max) == -1 || |
| 1239 | istcat(out, ist(" "), max) == -1 || |
| 1240 | istcat(out, desc[appctx->st2], max) == -1 || |
Anthonin Bonnefoy | 51c3aa4 | 2019-08-07 17:45:25 +0200 | [diff] [blame] | 1241 | istcat(out, ist("\n# TYPE "), max) == -1 || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1242 | istcat(out, name, max) == -1 || |
| 1243 | istcat(out, ist(" "), max) == -1 || |
| 1244 | istcat(out, types[appctx->st2], max) == -1 || |
| 1245 | istcat(out, ist("\n"), max) == -1) |
| 1246 | goto full; |
| 1247 | |
| 1248 | return 1; |
| 1249 | |
| 1250 | full: |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | /* Dump the line for <metric>. It starts by the metric name followed by its |
| 1255 | * labels (proxy name, server name...) between braces and finally its value. If |
| 1256 | * not already done, the header lines are dumped first. It returns 1 on |
| 1257 | * success. Otherwise if <out> length exceeds <max>, it returns 0. |
| 1258 | */ |
| 1259 | static int promex_dump_metric(struct appctx *appctx, struct htx *htx, |
| 1260 | const struct ist prefix, struct field *metric, |
| 1261 | struct ist *out, size_t max) |
| 1262 | { |
| 1263 | struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 }; |
| 1264 | size_t len = out->len; |
| 1265 | |
| 1266 | if (out->len + PROMEX_MAX_METRIC_LENGTH > max) |
| 1267 | return 0; |
| 1268 | |
| 1269 | promex_metric_name(appctx, &name, prefix); |
| 1270 | if ((appctx->ctx.stats.flags & PROMEX_FL_METRIC_HDR) && |
| 1271 | !promex_dump_metric_header(appctx, htx, name, out, max)) |
| 1272 | goto full; |
| 1273 | |
| 1274 | if (appctx->ctx.stats.flags & PROMEX_FL_INFO_METRIC) { |
| 1275 | const struct ist label = promex_inf_metric_labels[appctx->st2]; |
| 1276 | |
| 1277 | if (istcat(out, name, max) == -1 || |
| 1278 | (label.len && istcat(out, ist("{"), max) == -1) || |
| 1279 | (label.len && istcat(out, label, max) == -1) || |
| 1280 | (label.len && istcat(out, ist("}"), max) == -1) || |
| 1281 | istcat(out, ist(" "), max) == -1) |
| 1282 | goto full; |
| 1283 | } |
| 1284 | else { |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1285 | struct proxy *px = appctx->ctx.stats.obj1; |
| 1286 | struct server *srv = appctx->ctx.stats.obj2; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1287 | const struct ist label = promex_st_metric_labels[appctx->st2]; |
| 1288 | |
| 1289 | if (istcat(out, name, max) == -1 || |
| 1290 | istcat(out, ist("{proxy=\""), max) == -1 || |
| 1291 | istcat(out, ist2(px->id, strlen(px->id)), max) == -1 || |
| 1292 | istcat(out, ist("\""), max) == -1 || |
| 1293 | (srv && istcat(out, ist(",server=\""), max) == -1) || |
| 1294 | (srv && istcat(out, ist2(srv->id, strlen(srv->id)), max) == -1) || |
| 1295 | (srv && istcat(out, ist("\""), max) == -1) || |
| 1296 | (label.len && istcat(out, ist(","), max) == -1) || |
| 1297 | (label.len && istcat(out, label, max) == -1) || |
| 1298 | istcat(out, ist("} "), max) == -1) |
| 1299 | goto full; |
| 1300 | } |
| 1301 | |
| 1302 | trash.data = out->len; |
| 1303 | if (!promex_metric_to_str(&trash, metric, max)) |
| 1304 | goto full; |
| 1305 | out->len = trash.data; |
| 1306 | |
| 1307 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1308 | return 1; |
| 1309 | full: |
| 1310 | // Restore previous length |
| 1311 | out->len = len; |
| 1312 | return 0; |
| 1313 | |
| 1314 | } |
| 1315 | |
| 1316 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1317 | /* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1318 | * 0 if <htx> is full and -1 in case of any error. */ |
| 1319 | static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx) |
| 1320 | { |
| 1321 | static struct ist prefix = IST("haproxy_process_"); |
| 1322 | struct field metric; |
| 1323 | struct channel *chn = si_ic(appctx->owner); |
| 1324 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 1325 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1326 | int ret = 1; |
| 1327 | |
William Dauchy | d40452e | 2021-01-11 20:07:49 +0100 | [diff] [blame] | 1328 | if (!stats_fill_info(info, INF_TOTAL_FIELDS)) |
| 1329 | return -1; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1330 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1331 | while (appctx->st2 && appctx->st2 < INF_TOTAL_FIELDS) { |
| 1332 | switch (appctx->st2) { |
William Dauchy | d97162c | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 1333 | case INF_BUILD_INFO: |
| 1334 | metric = mkf_u32(FN_GAUGE, 1); |
| 1335 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1336 | case INF_UPTIME_SEC: |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 1337 | metric = mkf_u32(FN_DURATION, start_date.tv_sec); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1338 | break; |
| 1339 | case INF_MEMMAX_MB: |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 1340 | metric = mkf_u64(FO_CONFIG|FN_LIMIT, global.rlimit_memmax * 1048576L); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1341 | break; |
| 1342 | case INF_POOL_ALLOC_MB: |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 1343 | metric = mkf_u64(0, pool_total_allocated()); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1344 | break; |
| 1345 | case INF_POOL_USED_MB: |
Christopher Faulet | 8c8e4b1 | 2019-04-18 10:15:15 +0200 | [diff] [blame] | 1346 | metric = mkf_u64(0, pool_total_used()); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1347 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1348 | |
| 1349 | default: |
William Dauchy | d40452e | 2021-01-11 20:07:49 +0100 | [diff] [blame] | 1350 | metric = info[appctx->st2]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max)) |
| 1354 | goto full; |
| 1355 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1356 | appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR; |
| 1357 | appctx->st2 = promex_global_metrics[appctx->st2]; |
| 1358 | } |
| 1359 | |
| 1360 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 1361 | if (out.len) { |
| 1362 | if (!htx_add_data_atonce(htx, out)) |
| 1363 | return -1; /* Unexpected and unrecoverable error */ |
| 1364 | channel_add_input(chn, out.len); |
| 1365 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1366 | return ret; |
| 1367 | full: |
| 1368 | ret = 0; |
| 1369 | goto end; |
| 1370 | } |
| 1371 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1372 | /* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1373 | * 0 if <htx> is full and -1 in case of any error. */ |
| 1374 | static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx) |
| 1375 | { |
| 1376 | static struct ist prefix = IST("haproxy_frontend_"); |
| 1377 | struct proxy *px; |
| 1378 | struct field metric; |
| 1379 | struct channel *chn = si_ic(appctx->owner); |
| 1380 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 1381 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1382 | int ret = 1; |
| 1383 | |
| 1384 | while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) { |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1385 | while (appctx->ctx.stats.obj1) { |
| 1386 | px = appctx->ctx.stats.obj1; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1387 | |
| 1388 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1389 | if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_FE)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1390 | goto next_px; |
| 1391 | |
| 1392 | switch (appctx->st2) { |
| 1393 | case ST_F_STATUS: |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1394 | metric = mkf_u32(FO_STATUS, !px->disabled); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1395 | break; |
| 1396 | case ST_F_SCUR: |
| 1397 | metric = mkf_u32(0, px->feconn); |
| 1398 | break; |
| 1399 | case ST_F_SMAX: |
| 1400 | metric = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 1401 | break; |
| 1402 | case ST_F_SLIM: |
| 1403 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 1404 | break; |
| 1405 | case ST_F_STOT: |
| 1406 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 1407 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1408 | case ST_F_RATE_LIM: |
| 1409 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 1410 | break; |
| 1411 | case ST_F_RATE_MAX: |
| 1412 | metric = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 1413 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1414 | case ST_F_CONN_RATE_MAX: |
| 1415 | metric = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 1416 | break; |
| 1417 | case ST_F_CONN_TOT: |
| 1418 | metric = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 1419 | break; |
| 1420 | case ST_F_BIN: |
| 1421 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 1422 | break; |
| 1423 | case ST_F_BOUT: |
| 1424 | metric = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 1425 | break; |
| 1426 | case ST_F_DREQ: |
| 1427 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 1428 | break; |
| 1429 | case ST_F_DRESP: |
| 1430 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 1431 | break; |
| 1432 | case ST_F_EREQ: |
| 1433 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 1434 | break; |
| 1435 | case ST_F_DCON: |
| 1436 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); |
| 1437 | break; |
| 1438 | case ST_F_DSES: |
| 1439 | metric = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); |
| 1440 | break; |
| 1441 | case ST_F_WREW: |
| 1442 | metric = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites); |
| 1443 | break; |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 1444 | case ST_F_EINT: |
| 1445 | metric = mkf_u64(FN_COUNTER, px->fe_counters.internal_errors); |
| 1446 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1447 | case ST_F_REQ_RATE_MAX: |
| 1448 | if (px->mode != PR_MODE_HTTP) |
| 1449 | goto next_px; |
| 1450 | metric = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 1451 | break; |
| 1452 | case ST_F_REQ_TOT: |
| 1453 | if (px->mode != PR_MODE_HTTP) |
| 1454 | goto next_px; |
| 1455 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 1456 | break; |
| 1457 | case ST_F_HRSP_1XX: |
| 1458 | if (px->mode != PR_MODE_HTTP) |
| 1459 | goto next_px; |
| 1460 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 1461 | break; |
| 1462 | case ST_F_HRSP_2XX: |
| 1463 | if (px->mode != PR_MODE_HTTP) |
| 1464 | goto next_px; |
| 1465 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1466 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 1467 | break; |
| 1468 | case ST_F_HRSP_3XX: |
| 1469 | if (px->mode != PR_MODE_HTTP) |
| 1470 | goto next_px; |
| 1471 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1472 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 1473 | break; |
| 1474 | case ST_F_HRSP_4XX: |
| 1475 | if (px->mode != PR_MODE_HTTP) |
| 1476 | goto next_px; |
| 1477 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1478 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 1479 | break; |
| 1480 | case ST_F_HRSP_5XX: |
| 1481 | if (px->mode != PR_MODE_HTTP) |
| 1482 | goto next_px; |
| 1483 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1484 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 1485 | break; |
| 1486 | case ST_F_HRSP_OTHER: |
| 1487 | if (px->mode != PR_MODE_HTTP) |
| 1488 | goto next_px; |
| 1489 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1490 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
| 1491 | break; |
| 1492 | case ST_F_INTERCEPTED: |
| 1493 | if (px->mode != PR_MODE_HTTP) |
| 1494 | goto next_px; |
| 1495 | metric = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
| 1496 | break; |
| 1497 | case ST_F_CACHE_LOOKUPS: |
| 1498 | if (px->mode != PR_MODE_HTTP) |
| 1499 | goto next_px; |
| 1500 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups); |
| 1501 | break; |
| 1502 | case ST_F_CACHE_HITS: |
| 1503 | if (px->mode != PR_MODE_HTTP) |
| 1504 | goto next_px; |
| 1505 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits); |
| 1506 | break; |
| 1507 | case ST_F_COMP_IN: |
| 1508 | if (px->mode != PR_MODE_HTTP) |
| 1509 | goto next_px; |
| 1510 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 1511 | break; |
| 1512 | case ST_F_COMP_OUT: |
| 1513 | if (px->mode != PR_MODE_HTTP) |
| 1514 | goto next_px; |
| 1515 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 1516 | break; |
| 1517 | case ST_F_COMP_BYP: |
| 1518 | if (px->mode != PR_MODE_HTTP) |
| 1519 | goto next_px; |
| 1520 | metric = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 1521 | break; |
| 1522 | case ST_F_COMP_RSP: |
| 1523 | if (px->mode != PR_MODE_HTTP) |
| 1524 | goto next_px; |
| 1525 | metric = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 1526 | break; |
| 1527 | |
| 1528 | default: |
| 1529 | goto next_metric; |
| 1530 | } |
| 1531 | |
| 1532 | if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max)) |
| 1533 | goto full; |
| 1534 | next_px: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1535 | appctx->ctx.stats.obj1 = px->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1536 | } |
| 1537 | next_metric: |
| 1538 | appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR; |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1539 | appctx->ctx.stats.obj1 = proxies_list; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1540 | appctx->st2 = promex_front_metrics[appctx->st2]; |
| 1541 | } |
| 1542 | |
| 1543 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 1544 | if (out.len) { |
| 1545 | if (!htx_add_data_atonce(htx, out)) |
| 1546 | return -1; /* Unexpected and unrecoverable error */ |
| 1547 | channel_add_input(chn, out.len); |
| 1548 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1549 | return ret; |
| 1550 | full: |
| 1551 | ret = 0; |
| 1552 | goto end; |
| 1553 | } |
| 1554 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1555 | /* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1556 | * 0 if <htx> is full and -1 in case of any error. */ |
| 1557 | static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) |
| 1558 | { |
| 1559 | static struct ist prefix = IST("haproxy_backend_"); |
| 1560 | struct proxy *px; |
| 1561 | struct field metric; |
| 1562 | struct channel *chn = si_ic(appctx->owner); |
| 1563 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 1564 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1565 | int ret = 1; |
| 1566 | uint32_t weight; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1567 | double secs; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1568 | |
| 1569 | while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) { |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1570 | while (appctx->ctx.stats.obj1) { |
| 1571 | px = appctx->ctx.stats.obj1; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1572 | |
| 1573 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1574 | if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1575 | goto next_px; |
| 1576 | |
| 1577 | switch (appctx->st2) { |
| 1578 | case ST_F_STATUS: |
| 1579 | metric = mkf_u32(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0); |
| 1580 | break; |
| 1581 | case ST_F_SCUR: |
| 1582 | metric = mkf_u32(0, px->beconn); |
| 1583 | break; |
| 1584 | case ST_F_SMAX: |
| 1585 | metric = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 1586 | break; |
| 1587 | case ST_F_SLIM: |
| 1588 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 1589 | break; |
| 1590 | case ST_F_STOT: |
| 1591 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 1592 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1593 | case ST_F_RATE_MAX: |
| 1594 | metric = mkf_u32(0, px->be_counters.sps_max); |
| 1595 | break; |
| 1596 | case ST_F_LASTSESS: |
| 1597 | metric = mkf_s32(FN_AGE, be_lastsession(px)); |
| 1598 | break; |
| 1599 | case ST_F_QCUR: |
| 1600 | metric = mkf_u32(0, px->nbpend); |
| 1601 | break; |
| 1602 | case ST_F_QMAX: |
| 1603 | metric = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 1604 | break; |
| 1605 | case ST_F_CONNECT: |
| 1606 | metric = mkf_u64(FN_COUNTER, px->be_counters.connect); |
| 1607 | break; |
| 1608 | case ST_F_REUSE: |
| 1609 | metric = mkf_u64(FN_COUNTER, px->be_counters.reuse); |
| 1610 | break; |
| 1611 | case ST_F_BIN: |
| 1612 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 1613 | break; |
| 1614 | case ST_F_BOUT: |
| 1615 | metric = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 1616 | break; |
| 1617 | case ST_F_QTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1618 | secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1619 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1620 | break; |
| 1621 | case ST_F_CTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1622 | secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1623 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1624 | break; |
| 1625 | case ST_F_RTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1626 | secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1627 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1628 | break; |
| 1629 | case ST_F_TTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1630 | secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1631 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1632 | break; |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1633 | case ST_F_QT_MAX: |
| 1634 | secs = (double)px->be_counters.qtime_max / 1000.0; |
| 1635 | metric = mkf_flt(FN_MAX, secs); |
| 1636 | break; |
| 1637 | case ST_F_CT_MAX: |
| 1638 | secs = (double)px->be_counters.ctime_max / 1000.0; |
| 1639 | metric = mkf_flt(FN_MAX, secs); |
| 1640 | break; |
| 1641 | case ST_F_RT_MAX: |
| 1642 | secs = (double)px->be_counters.dtime_max / 1000.0; |
| 1643 | metric = mkf_flt(FN_MAX, secs); |
| 1644 | break; |
| 1645 | case ST_F_TT_MAX: |
| 1646 | secs = (double)px->be_counters.ttime_max / 1000.0; |
| 1647 | metric = mkf_flt(FN_MAX, secs); |
| 1648 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1649 | case ST_F_DREQ: |
| 1650 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 1651 | break; |
| 1652 | case ST_F_DRESP: |
| 1653 | metric = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 1654 | break; |
| 1655 | case ST_F_ECON: |
| 1656 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 1657 | break; |
| 1658 | case ST_F_ERESP: |
| 1659 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 1660 | break; |
| 1661 | case ST_F_WRETR: |
| 1662 | metric = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 1663 | break; |
| 1664 | case ST_F_WREDIS: |
| 1665 | metric = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 1666 | break; |
| 1667 | case ST_F_WREW: |
| 1668 | metric = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites); |
| 1669 | break; |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 1670 | case ST_F_EINT: |
| 1671 | metric = mkf_u64(FN_COUNTER, px->be_counters.internal_errors); |
| 1672 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1673 | case ST_F_CLI_ABRT: |
| 1674 | metric = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 1675 | break; |
| 1676 | case ST_F_SRV_ABRT: |
| 1677 | metric = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 1678 | break; |
| 1679 | case ST_F_WEIGHT: |
| 1680 | weight = (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv; |
| 1681 | metric = mkf_u32(FN_AVG, weight); |
| 1682 | break; |
| 1683 | case ST_F_ACT: |
| 1684 | metric = mkf_u32(0, px->srv_act); |
| 1685 | break; |
| 1686 | case ST_F_BCK: |
| 1687 | metric = mkf_u32(0, px->srv_bck); |
| 1688 | break; |
| 1689 | case ST_F_CHKDOWN: |
| 1690 | metric = mkf_u64(FN_COUNTER, px->down_trans); |
| 1691 | break; |
| 1692 | case ST_F_LASTCHG: |
| 1693 | metric = mkf_u32(FN_AGE, now.tv_sec - px->last_change); |
| 1694 | break; |
| 1695 | case ST_F_DOWNTIME: |
| 1696 | metric = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 1697 | break; |
| 1698 | case ST_F_LBTOT: |
| 1699 | metric = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 1700 | break; |
| 1701 | case ST_F_REQ_TOT: |
| 1702 | if (px->mode != PR_MODE_HTTP) |
| 1703 | goto next_px; |
| 1704 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 1705 | break; |
| 1706 | case ST_F_HRSP_1XX: |
| 1707 | if (px->mode != PR_MODE_HTTP) |
| 1708 | goto next_px; |
| 1709 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 1710 | break; |
| 1711 | case ST_F_HRSP_2XX: |
| 1712 | if (px->mode != PR_MODE_HTTP) |
| 1713 | goto next_px; |
| 1714 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1715 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 1716 | break; |
| 1717 | case ST_F_HRSP_3XX: |
| 1718 | if (px->mode != PR_MODE_HTTP) |
| 1719 | goto next_px; |
| 1720 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1721 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 1722 | break; |
| 1723 | case ST_F_HRSP_4XX: |
| 1724 | if (px->mode != PR_MODE_HTTP) |
| 1725 | goto next_px; |
| 1726 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1727 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 1728 | break; |
| 1729 | case ST_F_HRSP_5XX: |
| 1730 | if (px->mode != PR_MODE_HTTP) |
| 1731 | goto next_px; |
| 1732 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1733 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 1734 | break; |
| 1735 | case ST_F_HRSP_OTHER: |
| 1736 | if (px->mode != PR_MODE_HTTP) |
| 1737 | goto next_px; |
| 1738 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1739 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
| 1740 | break; |
| 1741 | case ST_F_CACHE_LOOKUPS: |
| 1742 | if (px->mode != PR_MODE_HTTP) |
| 1743 | goto next_px; |
| 1744 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups); |
| 1745 | break; |
| 1746 | case ST_F_CACHE_HITS: |
| 1747 | if (px->mode != PR_MODE_HTTP) |
| 1748 | goto next_px; |
| 1749 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits); |
| 1750 | break; |
| 1751 | case ST_F_COMP_IN: |
| 1752 | if (px->mode != PR_MODE_HTTP) |
| 1753 | goto next_px; |
| 1754 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 1755 | break; |
| 1756 | case ST_F_COMP_OUT: |
| 1757 | if (px->mode != PR_MODE_HTTP) |
| 1758 | goto next_px; |
| 1759 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 1760 | break; |
| 1761 | case ST_F_COMP_BYP: |
| 1762 | if (px->mode != PR_MODE_HTTP) |
| 1763 | goto next_px; |
| 1764 | metric = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 1765 | break; |
| 1766 | case ST_F_COMP_RSP: |
| 1767 | if (px->mode != PR_MODE_HTTP) |
| 1768 | goto next_px; |
| 1769 | metric = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 1770 | break; |
| 1771 | |
| 1772 | default: |
| 1773 | goto next_metric; |
| 1774 | } |
| 1775 | |
| 1776 | if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max)) |
| 1777 | goto full; |
| 1778 | next_px: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1779 | appctx->ctx.stats.obj1 = px->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1780 | } |
| 1781 | next_metric: |
| 1782 | appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR; |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1783 | appctx->ctx.stats.obj1 = proxies_list; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1784 | appctx->st2 = promex_back_metrics[appctx->st2]; |
| 1785 | } |
| 1786 | |
| 1787 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 1788 | if (out.len) { |
| 1789 | if (!htx_add_data_atonce(htx, out)) |
| 1790 | return -1; /* Unexpected and unrecoverable error */ |
| 1791 | channel_add_input(chn, out.len); |
| 1792 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1793 | return ret; |
| 1794 | full: |
| 1795 | ret = 0; |
| 1796 | goto end; |
| 1797 | } |
| 1798 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1799 | /* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1800 | * 0 if <htx> is full and -1 in case of any error. */ |
| 1801 | static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx) |
| 1802 | { |
| 1803 | static struct ist prefix = IST("haproxy_server_"); |
| 1804 | struct proxy *px; |
| 1805 | struct server *sv; |
| 1806 | struct field metric; |
| 1807 | struct channel *chn = si_ic(appctx->owner); |
| 1808 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 1809 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1810 | int ret = 1; |
| 1811 | uint32_t weight; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1812 | double secs; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1813 | |
| 1814 | while (appctx->st2 && appctx->st2 < ST_F_TOTAL_FIELDS) { |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1815 | while (appctx->ctx.stats.obj1) { |
| 1816 | px = appctx->ctx.stats.obj1; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1817 | |
| 1818 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Willy Tarreau | c3914d4 | 2020-09-24 08:39:22 +0200 | [diff] [blame] | 1819 | if (px->disabled || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1820 | goto next_px; |
| 1821 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1822 | while (appctx->ctx.stats.obj2) { |
| 1823 | sv = appctx->ctx.stats.obj2; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1824 | |
Christopher Faulet | eba2294 | 2019-11-19 14:18:24 +0100 | [diff] [blame] | 1825 | if ((appctx->ctx.stats.flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT)) |
| 1826 | goto next_sv; |
| 1827 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1828 | switch (appctx->st2) { |
| 1829 | case ST_F_STATUS: |
| 1830 | metric = mkf_u32(FO_STATUS, promex_srv_status(sv)); |
| 1831 | break; |
| 1832 | case ST_F_SCUR: |
| 1833 | metric = mkf_u32(0, sv->cur_sess); |
| 1834 | break; |
| 1835 | case ST_F_SMAX: |
| 1836 | metric = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 1837 | break; |
| 1838 | case ST_F_SLIM: |
| 1839 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 1840 | break; |
| 1841 | case ST_F_STOT: |
| 1842 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 1843 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1844 | case ST_F_RATE_MAX: |
| 1845 | metric = mkf_u32(FN_MAX, sv->counters.sps_max); |
| 1846 | break; |
| 1847 | case ST_F_LASTSESS: |
| 1848 | metric = mkf_s32(FN_AGE, srv_lastsession(sv)); |
| 1849 | break; |
| 1850 | case ST_F_QCUR: |
| 1851 | metric = mkf_u32(0, sv->nbpend); |
| 1852 | break; |
| 1853 | case ST_F_QMAX: |
| 1854 | metric = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 1855 | break; |
| 1856 | case ST_F_QLIMIT: |
| 1857 | metric = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
| 1858 | break; |
| 1859 | case ST_F_BIN: |
| 1860 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 1861 | break; |
| 1862 | case ST_F_BOUT: |
| 1863 | metric = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 1864 | break; |
| 1865 | case ST_F_QTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1866 | secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1867 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1868 | break; |
| 1869 | case ST_F_CTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1870 | secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1871 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1872 | break; |
| 1873 | case ST_F_RTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1874 | secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1875 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1876 | break; |
| 1877 | case ST_F_TTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1878 | secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0; |
| 1879 | metric = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1880 | break; |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1881 | case ST_F_QT_MAX: |
| 1882 | secs = (double)sv->counters.qtime_max / 1000.0; |
| 1883 | metric = mkf_flt(FN_MAX, secs); |
| 1884 | break; |
| 1885 | case ST_F_CT_MAX: |
| 1886 | secs = (double)sv->counters.ctime_max / 1000.0; |
| 1887 | metric = mkf_flt(FN_MAX, secs); |
| 1888 | break; |
| 1889 | case ST_F_RT_MAX: |
| 1890 | secs = (double)sv->counters.dtime_max / 1000.0; |
| 1891 | metric = mkf_flt(FN_MAX, secs); |
| 1892 | break; |
| 1893 | case ST_F_TT_MAX: |
| 1894 | secs = (double)sv->counters.ttime_max / 1000.0; |
| 1895 | metric = mkf_flt(FN_MAX, secs); |
| 1896 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1897 | case ST_F_CONNECT: |
| 1898 | metric = mkf_u64(FN_COUNTER, sv->counters.connect); |
| 1899 | break; |
| 1900 | case ST_F_REUSE: |
| 1901 | metric = mkf_u64(FN_COUNTER, sv->counters.reuse); |
| 1902 | break; |
| 1903 | case ST_F_DRESP: |
Christopher Faulet | a08546b | 2019-12-16 16:07:34 +0100 | [diff] [blame] | 1904 | metric = mkf_u64(FN_COUNTER, sv->counters.denied_resp); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1905 | break; |
| 1906 | case ST_F_ECON: |
| 1907 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 1908 | break; |
| 1909 | case ST_F_ERESP: |
| 1910 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 1911 | break; |
| 1912 | case ST_F_WRETR: |
| 1913 | metric = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 1914 | break; |
| 1915 | case ST_F_WREDIS: |
| 1916 | metric = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 1917 | break; |
| 1918 | case ST_F_WREW: |
| 1919 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites); |
| 1920 | break; |
Christopher Faulet | e4a2c8d | 2019-12-16 14:44:01 +0100 | [diff] [blame] | 1921 | case ST_F_EINT: |
| 1922 | metric = mkf_u64(FN_COUNTER, sv->counters.internal_errors); |
| 1923 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1924 | case ST_F_CLI_ABRT: |
| 1925 | metric = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 1926 | break; |
| 1927 | case ST_F_SRV_ABRT: |
| 1928 | metric = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 1929 | break; |
| 1930 | case ST_F_WEIGHT: |
| 1931 | weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv; |
| 1932 | metric = mkf_u32(FN_AVG, weight); |
| 1933 | break; |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 1934 | case ST_F_CHECK_STATUS: |
| 1935 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED) |
| 1936 | goto next_sv; |
| 1937 | metric = mkf_u32(FN_OUTPUT, sv->check.status); |
| 1938 | break; |
| 1939 | case ST_F_CHECK_CODE: |
| 1940 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED) |
| 1941 | goto next_sv; |
| 1942 | metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code); |
| 1943 | break; |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 1944 | case ST_F_CHECK_DURATION: |
| 1945 | if (sv->check.status < HCHK_STATUS_CHECKED) |
| 1946 | goto next_sv; |
| 1947 | secs = (double)sv->check.duration / 1000.0; |
| 1948 | metric = mkf_flt(FN_DURATION, secs); |
| 1949 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1950 | case ST_F_CHKFAIL: |
| 1951 | metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 1952 | break; |
| 1953 | case ST_F_CHKDOWN: |
| 1954 | metric = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 1955 | break; |
| 1956 | case ST_F_DOWNTIME: |
| 1957 | metric = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 1958 | break; |
| 1959 | case ST_F_LASTCHG: |
| 1960 | metric = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 1961 | break; |
| 1962 | case ST_F_THROTTLE: |
| 1963 | metric = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
| 1964 | break; |
| 1965 | case ST_F_LBTOT: |
| 1966 | metric = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
| 1967 | break; |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1968 | case ST_F_REQ_TOT: |
| 1969 | if (px->mode != PR_MODE_HTTP) |
| 1970 | goto next_px; |
| 1971 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.cum_req); |
| 1972 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1973 | case ST_F_HRSP_1XX: |
| 1974 | if (px->mode != PR_MODE_HTTP) |
| 1975 | goto next_px; |
| 1976 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 1977 | break; |
| 1978 | case ST_F_HRSP_2XX: |
| 1979 | if (px->mode != PR_MODE_HTTP) |
| 1980 | goto next_px; |
| 1981 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1982 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 1983 | break; |
| 1984 | case ST_F_HRSP_3XX: |
| 1985 | if (px->mode != PR_MODE_HTTP) |
| 1986 | goto next_px; |
| 1987 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1988 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 1989 | break; |
| 1990 | case ST_F_HRSP_4XX: |
| 1991 | if (px->mode != PR_MODE_HTTP) |
| 1992 | goto next_px; |
| 1993 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 1994 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 1995 | break; |
| 1996 | case ST_F_HRSP_5XX: |
| 1997 | if (px->mode != PR_MODE_HTTP) |
| 1998 | goto next_px; |
| 1999 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 2000 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 2001 | break; |
| 2002 | case ST_F_HRSP_OTHER: |
| 2003 | if (px->mode != PR_MODE_HTTP) |
| 2004 | goto next_px; |
| 2005 | appctx->ctx.stats.flags &= ~PROMEX_FL_METRIC_HDR; |
| 2006 | metric = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 2007 | break; |
Christopher Faulet | 20ab80c | 2019-11-08 15:24:32 +0100 | [diff] [blame] | 2008 | case ST_F_SRV_ICUR: |
| 2009 | metric = mkf_u32(0, sv->curr_idle_conns); |
| 2010 | break; |
| 2011 | case ST_F_SRV_ILIM: |
| 2012 | metric = mkf_u32(FO_CONFIG|FN_LIMIT, (sv->max_idle_conns == -1) ? 0 : sv->max_idle_conns); |
| 2013 | break; |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 2014 | case ST_F_IDLE_CONN_CUR: |
| 2015 | metric = mkf_u32(0, sv->curr_idle_nb); |
| 2016 | break; |
| 2017 | case ST_F_SAFE_CONN_CUR: |
| 2018 | metric = mkf_u32(0, sv->curr_safe_nb); |
| 2019 | break; |
| 2020 | case ST_F_USED_CONN_CUR: |
| 2021 | metric = mkf_u32(0, sv->curr_used_conns); |
| 2022 | break; |
| 2023 | case ST_F_NEED_CONN_EST: |
| 2024 | metric = mkf_u32(0, sv->est_need_conns); |
| 2025 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2026 | |
| 2027 | default: |
| 2028 | goto next_metric; |
| 2029 | } |
| 2030 | |
| 2031 | if (!promex_dump_metric(appctx, htx, prefix, &metric, &out, max)) |
| 2032 | goto full; |
| 2033 | |
Christopher Faulet | eba2294 | 2019-11-19 14:18:24 +0100 | [diff] [blame] | 2034 | next_sv: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2035 | appctx->ctx.stats.obj2 = sv->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | next_px: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2039 | appctx->ctx.stats.obj1 = px->next; |
| 2040 | appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2041 | } |
| 2042 | next_metric: |
| 2043 | appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR; |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2044 | appctx->ctx.stats.obj1 = proxies_list; |
| 2045 | appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2046 | appctx->st2 = promex_srv_metrics[appctx->st2]; |
| 2047 | } |
| 2048 | |
| 2049 | |
| 2050 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 2051 | if (out.len) { |
| 2052 | if (!htx_add_data_atonce(htx, out)) |
| 2053 | return -1; /* Unexpected and unrecoverable error */ |
| 2054 | channel_add_input(chn, out.len); |
| 2055 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2056 | return ret; |
| 2057 | full: |
| 2058 | ret = 0; |
| 2059 | goto end; |
| 2060 | } |
| 2061 | |
| 2062 | /* Dump all metrics (global, frontends, backends and servers) depending on the |
| 2063 | * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2064 | * -1 in case of any error. |
| 2065 | * Uses <appctx.ctx.stats.obj1> as a pointer to the current proxy and <obj2> as |
| 2066 | * a pointer to the current server/listener. */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2067 | static int promex_dump_metrics(struct appctx *appctx, struct stream_interface *si, struct htx *htx) |
| 2068 | { |
| 2069 | int ret; |
| 2070 | |
| 2071 | switch (appctx->st1) { |
| 2072 | case PROMEX_DUMPER_INIT: |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2073 | appctx->ctx.stats.obj1 = NULL; |
| 2074 | appctx->ctx.stats.obj2 = NULL; |
Christopher Faulet | efde955 | 2020-06-05 08:18:56 +0200 | [diff] [blame] | 2075 | appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2076 | appctx->st2 = promex_global_metrics[INF_NAME]; |
| 2077 | appctx->st1 = PROMEX_DUMPER_GLOBAL; |
| 2078 | /* fall through */ |
| 2079 | |
| 2080 | case PROMEX_DUMPER_GLOBAL: |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2081 | if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_GLOBAL) { |
| 2082 | ret = promex_dump_global_metrics(appctx, htx); |
| 2083 | if (ret <= 0) { |
| 2084 | if (ret == -1) |
| 2085 | goto error; |
| 2086 | goto full; |
| 2087 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2088 | } |
| 2089 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2090 | appctx->ctx.stats.obj1 = proxies_list; |
| 2091 | appctx->ctx.stats.obj2 = NULL; |
Christopher Faulet | efde955 | 2020-06-05 08:18:56 +0200 | [diff] [blame] | 2092 | appctx->ctx.stats.flags &= ~PROMEX_FL_INFO_METRIC; |
| 2093 | appctx->ctx.stats.flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STATS_METRIC); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2094 | appctx->st2 = promex_front_metrics[ST_F_PXNAME]; |
| 2095 | appctx->st1 = PROMEX_DUMPER_FRONT; |
| 2096 | /* fall through */ |
| 2097 | |
| 2098 | case PROMEX_DUMPER_FRONT: |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2099 | if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_FRONT) { |
| 2100 | ret = promex_dump_front_metrics(appctx, htx); |
| 2101 | if (ret <= 0) { |
| 2102 | if (ret == -1) |
| 2103 | goto error; |
| 2104 | goto full; |
| 2105 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2106 | } |
| 2107 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2108 | appctx->ctx.stats.obj1 = proxies_list; |
| 2109 | appctx->ctx.stats.obj2 = NULL; |
Christopher Faulet | efde955 | 2020-06-05 08:18:56 +0200 | [diff] [blame] | 2110 | appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2111 | appctx->st2 = promex_back_metrics[ST_F_PXNAME]; |
| 2112 | appctx->st1 = PROMEX_DUMPER_BACK; |
| 2113 | /* fall through */ |
| 2114 | |
| 2115 | case PROMEX_DUMPER_BACK: |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2116 | if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_BACK) { |
| 2117 | ret = promex_dump_back_metrics(appctx, htx); |
| 2118 | if (ret <= 0) { |
| 2119 | if (ret == -1) |
| 2120 | goto error; |
| 2121 | goto full; |
| 2122 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2123 | } |
| 2124 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2125 | appctx->ctx.stats.obj1 = proxies_list; |
| 2126 | appctx->ctx.stats.obj2 = (appctx->ctx.stats.obj1 ? ((struct proxy *)appctx->ctx.stats.obj1)->srv : NULL); |
Christopher Faulet | efde955 | 2020-06-05 08:18:56 +0200 | [diff] [blame] | 2127 | appctx->ctx.stats.flags |= PROMEX_FL_METRIC_HDR; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2128 | appctx->st2 = promex_srv_metrics[ST_F_PXNAME]; |
| 2129 | appctx->st1 = PROMEX_DUMPER_SRV; |
| 2130 | /* fall through */ |
| 2131 | |
| 2132 | case PROMEX_DUMPER_SRV: |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2133 | if (appctx->ctx.stats.flags & PROMEX_FL_SCOPE_SERVER) { |
| 2134 | ret = promex_dump_srv_metrics(appctx, htx); |
| 2135 | if (ret <= 0) { |
| 2136 | if (ret == -1) |
| 2137 | goto error; |
| 2138 | goto full; |
| 2139 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2142 | appctx->ctx.stats.obj1 = NULL; |
| 2143 | appctx->ctx.stats.obj2 = NULL; |
Christopher Faulet | efde955 | 2020-06-05 08:18:56 +0200 | [diff] [blame] | 2144 | appctx->ctx.stats.flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC|PROMEX_FL_STATS_METRIC); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2145 | appctx->st2 = 0; |
| 2146 | appctx->st1 = PROMEX_DUMPER_DONE; |
| 2147 | /* fall through */ |
| 2148 | |
| 2149 | case PROMEX_DUMPER_DONE: |
| 2150 | default: |
| 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | return 1; |
| 2155 | |
| 2156 | full: |
| 2157 | si_rx_room_blk(si); |
| 2158 | return 0; |
| 2159 | error: |
| 2160 | /* unrecoverable error */ |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 2161 | appctx->ctx.stats.obj1 = NULL; |
| 2162 | appctx->ctx.stats.obj2 = NULL; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2163 | appctx->ctx.stats.flags = 0; |
| 2164 | appctx->st2 = 0; |
| 2165 | appctx->st1 = PROMEX_DUMPER_DONE; |
| 2166 | return -1; |
| 2167 | } |
| 2168 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 2169 | /* Parse the query string of request URI to filter the metrics. It returns 1 on |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2170 | * success and -1 on error. */ |
| 2171 | static int promex_parse_uri(struct appctx *appctx, struct stream_interface *si) |
| 2172 | { |
| 2173 | struct channel *req = si_oc(si); |
| 2174 | struct channel *res = si_ic(si); |
| 2175 | struct htx *req_htx, *res_htx; |
| 2176 | struct htx_sl *sl; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2177 | char *p, *key, *value; |
| 2178 | const char *end; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2179 | struct buffer *err; |
| 2180 | int default_scopes = PROMEX_FL_SCOPE_ALL; |
| 2181 | int len; |
| 2182 | |
| 2183 | /* Get the query-string */ |
| 2184 | req_htx = htxbuf(&req->buf); |
| 2185 | sl = http_get_stline(req_htx); |
| 2186 | if (!sl) |
| 2187 | goto error; |
| 2188 | p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?'); |
| 2189 | if (!p) |
| 2190 | goto end; |
| 2191 | end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2192 | |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2193 | /* copy the query-string */ |
| 2194 | len = end - p; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2195 | chunk_reset(&trash); |
| 2196 | memcpy(trash.area, p, len); |
| 2197 | trash.area[len] = 0; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2198 | p = trash.area; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2199 | end = trash.area + len; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2200 | |
| 2201 | /* Parse the query-string */ |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2202 | while (p < end && *p && *p != '#') { |
| 2203 | value = NULL; |
| 2204 | |
| 2205 | /* decode parameter name */ |
| 2206 | key = p; |
| 2207 | while (p < end && *p != '=' && *p != '&' && *p != '#') |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2208 | ++p; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2209 | /* found a value */ |
| 2210 | if (*p == '=') { |
| 2211 | *(p++) = 0; |
| 2212 | value = p; |
| 2213 | } |
| 2214 | else if (*p == '&') |
| 2215 | *(p++) = 0; |
| 2216 | else if (*p == '#') |
| 2217 | *p = 0; |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 2218 | len = url_decode(key, 1); |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2219 | if (len == -1) |
| 2220 | goto error; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2221 | |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2222 | /* decode value */ |
| 2223 | if (value) { |
| 2224 | while (p < end && *p != '=' && *p != '&' && *p != '#') |
| 2225 | ++p; |
| 2226 | if (*p == '=') |
| 2227 | goto error; |
| 2228 | if (*p == '&') |
| 2229 | *(p++) = 0; |
| 2230 | else if (*p == '#') |
| 2231 | *p = 0; |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 2232 | len = url_decode(value, 1); |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2233 | if (len == -1) |
| 2234 | goto error; |
| 2235 | } |
| 2236 | |
| 2237 | if (!strcmp(key, "scope")) { |
| 2238 | default_scopes = 0; /* at least a scope defined, unset default scopes */ |
| 2239 | if (!value) |
| 2240 | goto error; |
| 2241 | else if (*value == 0) |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2242 | appctx->ctx.stats.flags &= ~PROMEX_FL_SCOPE_ALL; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2243 | else if (*value == '*') |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2244 | appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_ALL; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2245 | else if (!strcmp(value, "global")) |
| 2246 | appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_GLOBAL; |
| 2247 | else if (!strcmp(value, "server")) |
| 2248 | appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_SERVER; |
| 2249 | else if (!strcmp(value, "backend")) |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2250 | appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_BACK; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2251 | else if (!strcmp(value, "frontend")) |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2252 | appctx->ctx.stats.flags |= PROMEX_FL_SCOPE_FRONT; |
| 2253 | else |
| 2254 | goto error; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2255 | } |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 2256 | else if (!strcmp(key, "no-maint")) |
Christopher Faulet | eba2294 | 2019-11-19 14:18:24 +0100 | [diff] [blame] | 2257 | appctx->ctx.stats.flags |= PROMEX_FL_NO_MAINT_SRV; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | end: |
| 2261 | appctx->ctx.stats.flags |= default_scopes; |
| 2262 | return 1; |
| 2263 | |
| 2264 | error: |
| 2265 | err = &http_err_chunks[HTTP_ERR_400]; |
| 2266 | channel_erase(res); |
| 2267 | res->buf.data = b_data(err); |
| 2268 | memcpy(res->buf.area, b_head(err), b_data(err)); |
| 2269 | res_htx = htx_from_buf(&res->buf); |
| 2270 | channel_add_input(res, res_htx->data); |
| 2271 | appctx->st0 = PROMEX_ST_END; |
| 2272 | return -1; |
| 2273 | } |
| 2274 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2275 | /* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is |
| 2276 | * full. */ |
| 2277 | static int promex_send_headers(struct appctx *appctx, struct stream_interface *si, struct htx *htx) |
| 2278 | { |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 2279 | struct channel *chn = si_ic(appctx->owner); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2280 | struct htx_sl *sl; |
| 2281 | unsigned int flags; |
| 2282 | |
| 2283 | flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_ENC|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK); |
| 2284 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 2285 | if (!sl) |
| 2286 | goto full; |
| 2287 | sl->info.res.status = 200; |
| 2288 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2289 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) || |
| 2290 | !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) || |
| 2291 | !htx_add_endof(htx, HTX_BLK_EOH)) |
| 2292 | goto full; |
| 2293 | |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 2294 | channel_add_input(chn, htx->data); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2295 | return 1; |
| 2296 | full: |
| 2297 | htx_reset(htx); |
| 2298 | si_rx_room_blk(si); |
| 2299 | return 0; |
| 2300 | } |
| 2301 | |
| 2302 | /* The function returns 1 if the initialisation is complete, 0 if |
| 2303 | * an errors occurs and -1 if more data are required for initializing |
| 2304 | * the applet. |
| 2305 | */ |
| 2306 | static int promex_appctx_init(struct appctx *appctx, struct proxy *px, struct stream *strm) |
| 2307 | { |
| 2308 | appctx->st0 = PROMEX_ST_INIT; |
| 2309 | return 1; |
| 2310 | } |
| 2311 | |
| 2312 | /* The main I/O handler for the promex applet. */ |
| 2313 | static void promex_appctx_handle_io(struct appctx *appctx) |
| 2314 | { |
| 2315 | struct stream_interface *si = appctx->owner; |
| 2316 | struct stream *s = si_strm(si); |
| 2317 | struct channel *req = si_oc(si); |
| 2318 | struct channel *res = si_ic(si); |
| 2319 | struct htx *req_htx, *res_htx; |
| 2320 | int ret; |
| 2321 | |
| 2322 | res_htx = htx_from_buf(&res->buf); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2323 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2324 | goto out; |
| 2325 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 2326 | /* Check if the input buffer is available. */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2327 | if (!b_size(&res->buf)) { |
| 2328 | si_rx_room_blk(si); |
| 2329 | goto out; |
| 2330 | } |
| 2331 | |
| 2332 | switch (appctx->st0) { |
| 2333 | case PROMEX_ST_INIT: |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 2334 | ret = promex_parse_uri(appctx, si); |
| 2335 | if (ret <= 0) { |
| 2336 | if (ret == -1) |
| 2337 | goto error; |
| 2338 | goto out; |
| 2339 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2340 | appctx->st0 = PROMEX_ST_HEAD; |
| 2341 | appctx->st1 = PROMEX_DUMPER_INIT; |
| 2342 | /* fall through */ |
| 2343 | |
| 2344 | case PROMEX_ST_HEAD: |
| 2345 | if (!promex_send_headers(appctx, si, res_htx)) |
| 2346 | goto out; |
| 2347 | appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP); |
| 2348 | /* fall through */ |
| 2349 | |
| 2350 | case PROMEX_ST_DUMP: |
| 2351 | ret = promex_dump_metrics(appctx, si, res_htx); |
| 2352 | if (ret <= 0) { |
| 2353 | if (ret == -1) |
| 2354 | goto error; |
| 2355 | goto out; |
| 2356 | } |
| 2357 | appctx->st0 = PROMEX_ST_DONE; |
| 2358 | /* fall through */ |
| 2359 | |
| 2360 | case PROMEX_ST_DONE: |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 2361 | /* Don't add TLR because mux-h1 will take care of it */ |
Willy Tarreau | f1ea47d | 2020-07-23 06:53:27 +0200 | [diff] [blame] | 2362 | res_htx->flags |= HTX_FL_EOI; /* no more data are expected. Only EOM remains to add now */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2363 | if (!htx_add_endof(res_htx, HTX_BLK_EOM)) { |
| 2364 | si_rx_room_blk(si); |
| 2365 | goto out; |
| 2366 | } |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 2367 | channel_add_input(res, 1); |
| 2368 | appctx->st0 = PROMEX_ST_END; |
| 2369 | /* fall through */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2370 | |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 2371 | case PROMEX_ST_END: |
| 2372 | if (!(res->flags & CF_SHUTR)) { |
| 2373 | res->flags |= CF_READ_NULL; |
| 2374 | si_shutr(si); |
| 2375 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2376 | } |
| 2377 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2378 | out: |
| 2379 | htx_to_buf(res_htx, &res->buf); |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 2380 | |
| 2381 | /* eat the whole request */ |
| 2382 | if (co_data(req)) { |
| 2383 | req_htx = htx_from_buf(&req->buf); |
| 2384 | co_htx_skip(req, req_htx, co_data(req)); |
| 2385 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2386 | return; |
| 2387 | |
| 2388 | error: |
| 2389 | res->flags |= CF_READ_NULL; |
| 2390 | si_shutr(si); |
| 2391 | si_shutw(si); |
| 2392 | } |
| 2393 | |
| 2394 | struct applet promex_applet = { |
| 2395 | .obj_type = OBJ_TYPE_APPLET, |
| 2396 | .name = "<PROMEX>", /* used for logging */ |
| 2397 | .init = promex_appctx_init, |
| 2398 | .fct = promex_appctx_handle_io, |
| 2399 | }; |
| 2400 | |
| 2401 | static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px, |
| 2402 | struct act_rule *rule, char **err) |
| 2403 | { |
| 2404 | /* Prometheus exporter service is only available on "http-request" rulesets */ |
| 2405 | if (rule->from != ACT_F_HTTP_REQ) { |
| 2406 | memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets"); |
| 2407 | return ACT_RET_PRS_ERR; |
| 2408 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 2409 | |
| 2410 | /* Add applet pointer in the rule. */ |
| 2411 | rule->applet = promex_applet; |
| 2412 | |
| 2413 | return ACT_RET_PRS_OK; |
| 2414 | } |
| 2415 | static void promex_register_build_options(void) |
| 2416 | { |
| 2417 | char *ptr = NULL; |
| 2418 | |
| 2419 | memprintf(&ptr, "Built with the Prometheus exporter as a service"); |
| 2420 | hap_register_build_opts(ptr, 1); |
| 2421 | } |
| 2422 | |
| 2423 | |
| 2424 | static struct action_kw_list service_actions = { ILH, { |
| 2425 | { "prometheus-exporter", service_parse_prometheus_exporter }, |
| 2426 | { /* END */ } |
| 2427 | }}; |
| 2428 | |
| 2429 | INITCALL1(STG_REGISTER, service_keywords_register, &service_actions); |
| 2430 | INITCALL0(STG_REGISTER, promex_register_build_options); |