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