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