Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Promex is a Prometheus exporter for HAProxy |
| 3 | * |
| 4 | * It is highly inspired by the official Prometheus exporter. |
| 5 | * See: https://github.com/prometheus/haproxy_exporter |
| 6 | * |
| 7 | * Copyright 2019 Christopher Faulet <cfaulet@haproxy.com> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | */ |
| 15 | |
Willy Tarreau | 122eba9 | 2020-06-04 10:15:32 +0200 | [diff] [blame] | 16 | #include <haproxy/action-t.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 17 | #include <haproxy/api.h> |
Willy Tarreau | 3f0f82e | 2020-06-04 19:42:41 +0200 | [diff] [blame] | 18 | #include <haproxy/applet.h> |
Willy Tarreau | 4980160 | 2020-06-04 22:50:02 +0200 | [diff] [blame] | 19 | #include <haproxy/backend.h> |
Willy Tarreau | 6be7849 | 2020-06-05 00:00:29 +0200 | [diff] [blame] | 20 | #include <haproxy/cfgparse.h> |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 21 | #include <haproxy/check.h> |
Willy Tarreau | 762d7a5 | 2020-06-04 11:23:07 +0200 | [diff] [blame] | 22 | #include <haproxy/frontend.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 23 | #include <haproxy/global.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 24 | #include <haproxy/http.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 25 | #include <haproxy/http_ana.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 26 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 27 | #include <haproxy/htx.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 28 | #include <haproxy/list.h> |
Willy Tarreau | 213e990 | 2020-06-04 14:58:24 +0200 | [diff] [blame] | 29 | #include <haproxy/listener.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 30 | #include <haproxy/log.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 31 | #include <haproxy/proxy.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 32 | #include <haproxy/sample.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 33 | #include <haproxy/sc_strm.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 34 | #include <haproxy/server.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 35 | #include <haproxy/stats.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 36 | #include <haproxy/stconn.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 37 | #include <haproxy/stream.h> |
Willy Tarreau | cea0e1b | 2020-06-04 17:25:40 +0200 | [diff] [blame] | 38 | #include <haproxy/task.h> |
Willy Tarreau | 0fd04fd | 2021-05-08 12:58:12 +0200 | [diff] [blame] | 39 | #include <haproxy/tools.h> |
William Dauchy | 5a982a7 | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 40 | #include <haproxy/version.h> |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 41 | |
| 42 | /* Prometheus exporter applet states (appctx->st0) */ |
| 43 | enum { |
| 44 | PROMEX_ST_INIT = 0, /* initialized */ |
| 45 | PROMEX_ST_HEAD, /* send headers before dump */ |
| 46 | PROMEX_ST_DUMP, /* dumping stats */ |
| 47 | PROMEX_ST_DONE, /* finished */ |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 48 | PROMEX_ST_END, /* treatment terminated */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | /* Prometheus exporter dumper states (appctx->st1) */ |
| 52 | enum { |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 53 | PROMEX_DUMPER_INIT = 0, /* initialized */ |
| 54 | PROMEX_DUMPER_GLOBAL, /* dump metrics of globals */ |
| 55 | PROMEX_DUMPER_FRONT, /* dump metrics of frontend proxies */ |
| 56 | PROMEX_DUMPER_BACK, /* dump metrics of backend proxies */ |
| 57 | PROMEX_DUMPER_LI, /* dump metrics of listeners */ |
| 58 | PROMEX_DUMPER_SRV, /* dump metrics of servers */ |
| 59 | PROMEX_DUMPER_STICKTABLE, /* dump metrics of stick tables */ |
| 60 | PROMEX_DUMPER_DONE, /* finished */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 63 | /* Prometheus exporter flags (ctx->flags) */ |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 64 | #define PROMEX_FL_METRIC_HDR 0x00000001 |
| 65 | #define PROMEX_FL_INFO_METRIC 0x00000002 |
| 66 | #define PROMEX_FL_FRONT_METRIC 0x00000004 |
| 67 | #define PROMEX_FL_BACK_METRIC 0x00000008 |
| 68 | #define PROMEX_FL_SRV_METRIC 0x00000010 |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 69 | #define PROMEX_FL_LI_METRIC 0x00000020 |
| 70 | #define PROMEX_FL_STICKTABLE_METRIC 0x00000040 |
| 71 | #define PROMEX_FL_SCOPE_GLOBAL 0x00000080 |
| 72 | #define PROMEX_FL_SCOPE_FRONT 0x00000100 |
| 73 | #define PROMEX_FL_SCOPE_BACK 0x00000200 |
| 74 | #define PROMEX_FL_SCOPE_SERVER 0x00000400 |
| 75 | #define PROMEX_FL_SCOPE_LI 0x00000800 |
| 76 | #define PROMEX_FL_SCOPE_STICKTABLE 0x00001000 |
| 77 | #define PROMEX_FL_NO_MAINT_SRV 0x00002000 |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 78 | |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 79 | #define PROMEX_FL_SCOPE_ALL (PROMEX_FL_SCOPE_GLOBAL | PROMEX_FL_SCOPE_FRONT | \ |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 80 | PROMEX_FL_SCOPE_LI | PROMEX_FL_SCOPE_BACK | \ |
| 81 | PROMEX_FL_SCOPE_SERVER | PROMEX_FL_SCOPE_STICKTABLE) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 82 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 83 | /* the context of the applet */ |
| 84 | struct promex_ctx { |
| 85 | struct proxy *px; /* current proxy */ |
| 86 | struct stktable *st; /* current table */ |
| 87 | struct listener *li; /* current listener */ |
| 88 | struct server *sv; /* current server */ |
| 89 | unsigned int flags; /* PROMEX_FL_* */ |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 90 | unsigned field_num; /* current field number (ST_F_* etc) */ |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 91 | int obj_state; /* current state among PROMEX_{FRONT|BACK|SRV|LI}_STATE_* */ |
| 92 | }; |
| 93 | |
Christopher Faulet | 0312c0d | 2021-01-20 15:19:12 +0100 | [diff] [blame] | 94 | /* Promtheus metric type (gauge or counter) */ |
| 95 | enum promex_mt_type { |
| 96 | PROMEX_MT_GAUGE = 1, |
| 97 | PROMEX_MT_COUNTER = 2, |
| 98 | }; |
| 99 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 100 | /* The max length for metrics name. It is a hard limit but it should be |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 101 | * enough. |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 102 | */ |
| 103 | #define PROMEX_MAX_NAME_LEN 128 |
| 104 | |
| 105 | /* The expected max length for a metric dump, including its header lines. It is |
| 106 | * just a soft limit to avoid extra work. We don't try to dump a metric if less |
| 107 | * than this size is available in the HTX. |
| 108 | */ |
| 109 | #define PROMEX_MAX_METRIC_LENGTH 512 |
| 110 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 111 | /* The max number of labels per metric */ |
| 112 | #define PROMEX_MAX_LABELS 8 |
William Dauchy | 5a982a7 | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 113 | |
Christopher Faulet | 0312c0d | 2021-01-20 15:19:12 +0100 | [diff] [blame] | 114 | /* Describe a prometheus metric */ |
| 115 | struct promex_metric { |
| 116 | const struct ist n; /* The metric name */ |
| 117 | enum promex_mt_type type; /* The metric type (gauge or counter) */ |
| 118 | unsigned int flags; /* PROMEX_FL_* flags */ |
| 119 | }; |
| 120 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 121 | /* Describe a prometheus metric label. It is just a key/value pair */ |
| 122 | struct promex_label { |
| 123 | struct ist name; |
| 124 | struct ist value; |
| 125 | }; |
| 126 | |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 127 | /* Global metrics */ |
| 128 | const struct promex_metric promex_global_metrics[INF_TOTAL_FIELDS] = { |
| 129 | //[INF_NAME] ignored |
| 130 | //[INF_VERSION], ignored |
| 131 | //[INF_RELEASE_DATE] ignored |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 132 | [INF_NBTHREAD] = { .n = IST("nbthread"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 133 | [INF_NBPROC] = { .n = IST("nbproc"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 134 | [INF_PROCESS_NUM] = { .n = IST("relative_process_id"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 135 | //[INF_PID] ignored |
| 136 | //[INF_UPTIME] ignored |
| 137 | [INF_UPTIME_SEC] = { .n = IST("uptime_seconds"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 138 | [INF_START_TIME_SEC] = { .n = IST("start_time_seconds"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
William Dauchy | df9a05d | 2021-02-01 13:11:59 +0100 | [diff] [blame] | 139 | //[INF_MEMMAX_MB] ignored |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 140 | [INF_MEMMAX_BYTES] = { .n = IST("max_memory_bytes"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
William Dauchy | df9a05d | 2021-02-01 13:11:59 +0100 | [diff] [blame] | 141 | //[INF_POOL_ALLOC_MB] ignored |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 142 | [INF_POOL_ALLOC_BYTES] = { .n = IST("pool_allocated_bytes"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
William Dauchy | df9a05d | 2021-02-01 13:11:59 +0100 | [diff] [blame] | 143 | //[INF_POOL_USED_MB] ignored |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 144 | [INF_POOL_USED_BYTES] = { .n = IST("pool_used_bytes"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 145 | [INF_POOL_FAILED] = { .n = IST("pool_failures_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 146 | [INF_ULIMIT_N] = { .n = IST("max_fds"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 147 | [INF_MAXSOCK] = { .n = IST("max_sockets"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 148 | [INF_MAXCONN] = { .n = IST("max_connections"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 149 | [INF_HARD_MAXCONN] = { .n = IST("hard_max_connections"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 150 | [INF_CURR_CONN] = { .n = IST("current_connections"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 151 | [INF_CUM_CONN] = { .n = IST("connections_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 152 | [INF_CUM_REQ] = { .n = IST("requests_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 153 | [INF_MAX_SSL_CONNS] = { .n = IST("max_ssl_connections"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 154 | [INF_CURR_SSL_CONNS] = { .n = IST("current_ssl_connections"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 155 | [INF_CUM_SSL_CONNS] = { .n = IST("ssl_connections_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 156 | [INF_MAXPIPES] = { .n = IST("max_pipes"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 157 | [INF_PIPES_USED] = { .n = IST("pipes_used_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 158 | [INF_PIPES_FREE] = { .n = IST("pipes_free_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 159 | [INF_CONN_RATE] = { .n = IST("current_connection_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 160 | [INF_CONN_RATE_LIMIT] = { .n = IST("limit_connection_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 161 | [INF_MAX_CONN_RATE] = { .n = IST("max_connection_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 162 | [INF_SESS_RATE] = { .n = IST("current_session_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 163 | [INF_SESS_RATE_LIMIT] = { .n = IST("limit_session_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 164 | [INF_MAX_SESS_RATE] = { .n = IST("max_session_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 165 | [INF_SSL_RATE] = { .n = IST("current_ssl_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 166 | [INF_SSL_RATE_LIMIT] = { .n = IST("limit_ssl_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 167 | [INF_MAX_SSL_RATE] = { .n = IST("max_ssl_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 168 | [INF_SSL_FRONTEND_KEY_RATE] = { .n = IST("current_frontend_ssl_key_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 169 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = { .n = IST("max_frontend_ssl_key_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 170 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = { .n = IST("frontend_ssl_reuse"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 171 | [INF_SSL_BACKEND_KEY_RATE] = { .n = IST("current_backend_ssl_key_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 172 | [INF_SSL_BACKEND_MAX_KEY_RATE] = { .n = IST("max_backend_ssl_key_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 173 | [INF_SSL_CACHE_LOOKUPS] = { .n = IST("ssl_cache_lookups_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 174 | [INF_SSL_CACHE_MISSES] = { .n = IST("ssl_cache_misses_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 175 | [INF_COMPRESS_BPS_IN] = { .n = IST("http_comp_bytes_in_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 176 | [INF_COMPRESS_BPS_OUT] = { .n = IST("http_comp_bytes_out_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 177 | [INF_COMPRESS_BPS_RATE_LIM] = { .n = IST("limit_http_comp"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 178 | [INF_ZLIB_MEM_USAGE] = { .n = IST("current_zlib_memory"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 179 | [INF_MAX_ZLIB_MEM_USAGE] = { .n = IST("max_zlib_memory"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 180 | [INF_TASKS] = { .n = IST("current_tasks"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 181 | [INF_RUN_QUEUE] = { .n = IST("current_run_queue"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 182 | [INF_IDLE_PCT] = { .n = IST("idle_time_percent"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 183 | //[INF_NODE] ignored |
| 184 | //[INF_DESCRIPTION] ignored |
| 185 | [INF_STOPPING] = { .n = IST("stopping"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 186 | [INF_JOBS] = { .n = IST("jobs"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 187 | [INF_UNSTOPPABLE_JOBS] = { .n = IST("unstoppable_jobs"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 188 | [INF_LISTENERS] = { .n = IST("listeners"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 189 | [INF_ACTIVE_PEERS] = { .n = IST("active_peers"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 190 | [INF_CONNECTED_PEERS] = { .n = IST("connected_peers"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 191 | [INF_DROPPED_LOGS] = { .n = IST("dropped_logs_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 192 | [INF_BUSY_POLLING] = { .n = IST("busy_polling_enabled"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 193 | [INF_FAILED_RESOLUTIONS] = { .n = IST("failed_resolutions"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 194 | [INF_TOTAL_BYTES_OUT] = { .n = IST("bytes_out_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 195 | [INF_TOTAL_SPLICED_BYTES_OUT] = { .n = IST("spliced_bytes_out_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
| 196 | [INF_BYTES_OUT_RATE] = { .n = IST("bytes_out_rate"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
| 197 | //[INF_DEBUG_COMMANDS_ISSUED] ignored |
William Dauchy | 7741c33 | 2021-02-01 13:11:57 +0100 | [diff] [blame] | 198 | [INF_CUM_LOG_MSGS] = { .n = IST("recv_logs_total"), .type = PROMEX_MT_COUNTER, .flags = PROMEX_FL_INFO_METRIC }, |
William Dauchy | df9a05d | 2021-02-01 13:11:59 +0100 | [diff] [blame] | 199 | [INF_BUILD_INFO] = { .n = IST("build_info"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_INFO_METRIC }, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 200 | }; |
| 201 | |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 202 | /* frontend/backend/server fields */ |
| 203 | const struct promex_metric promex_st_metrics[ST_F_TOTAL_FIELDS] = { |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 204 | //[ST_F_PXNAME] ignored |
| 205 | //[ST_F_SVNAME] ignored |
| 206 | [ST_F_QCUR] = { .n = IST("current_queue"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 207 | [ST_F_QMAX] = { .n = IST("max_queue"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 208 | [ST_F_SCUR] = { .n = IST("current_sessions"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 209 | [ST_F_SMAX] = { .n = IST("max_sessions"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 210 | [ST_F_SLIM] = { .n = IST("limit_sessions"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 211 | [ST_F_STOT] = { .n = IST("sessions_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 212 | [ST_F_BIN] = { .n = IST("bytes_in_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 213 | [ST_F_BOUT] = { .n = IST("bytes_out_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 214 | [ST_F_DREQ] = { .n = IST("requests_denied_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 215 | [ST_F_DRESP] = { .n = IST("responses_denied_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 216 | [ST_F_EREQ] = { .n = IST("request_errors_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC ) }, |
| 217 | [ST_F_ECON] = { .n = IST("connection_errors_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 218 | [ST_F_ERESP] = { .n = IST("response_errors_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 219 | [ST_F_WRETR] = { .n = IST("retry_warnings_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 220 | [ST_F_WREDIS] = { .n = IST("redispatch_warnings_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 221 | [ST_F_STATUS] = { .n = IST("status"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 222 | [ST_F_WEIGHT] = { .n = IST("weight"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 223 | [ST_F_ACT] = { .n = IST("active_servers"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC ) }, |
| 224 | [ST_F_BCK] = { .n = IST("backup_servers"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC ) }, |
| 225 | [ST_F_CHKFAIL] = { .n = IST("check_failures_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 226 | [ST_F_CHKDOWN] = { .n = IST("check_up_down_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 227 | [ST_F_LASTCHG] = { .n = IST("check_last_change_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 228 | [ST_F_DOWNTIME] = { .n = IST("downtime_seconds_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 229 | [ST_F_QLIMIT] = { .n = IST("queue_limit"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 230 | //[ST_F_PID] ignored |
| 231 | //[ST_F_IID] ignored |
| 232 | //[ST_F_SID] ignored |
| 233 | [ST_F_THROTTLE] = { .n = IST("current_throttle"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 234 | [ST_F_LBTOT] = { .n = IST("loadbalanced_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 235 | //[ST_F_TRACKED] ignored |
| 236 | //[ST_F_TYPE] ignored |
| 237 | //[ST_F_RATE] ignored |
| 238 | [ST_F_RATE_LIM] = { .n = IST("limit_session_rate"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC ) }, |
| 239 | [ST_F_RATE_MAX] = { .n = IST("max_session_rate"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 240 | [ST_F_CHECK_STATUS] = { .n = IST("check_status"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 241 | [ST_F_CHECK_CODE] = { .n = IST("check_code"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 242 | [ST_F_CHECK_DURATION] = { .n = IST("check_duration_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 243 | [ST_F_HRSP_1XX] = { .n = IST("http_responses_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 244 | [ST_F_HRSP_2XX] = { .n = IST("http_responses_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 245 | [ST_F_HRSP_3XX] = { .n = IST("http_responses_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 246 | [ST_F_HRSP_4XX] = { .n = IST("http_responses_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 247 | [ST_F_HRSP_5XX] = { .n = IST("http_responses_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 248 | [ST_F_HRSP_OTHER] = { .n = IST("http_responses_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 249 | //[ST_F_HANAFAIL] ignored |
| 250 | //[ST_F_REQ_RATE] ignored |
| 251 | [ST_F_REQ_RATE_MAX] = { .n = IST("http_requests_rate_max"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC ) }, |
| 252 | [ST_F_REQ_TOT] = { .n = IST("http_requests_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 253 | [ST_F_CLI_ABRT] = { .n = IST("client_aborts_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 254 | [ST_F_SRV_ABRT] = { .n = IST("server_aborts_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 255 | [ST_F_COMP_IN] = { .n = IST("http_comp_bytes_in_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 256 | [ST_F_COMP_OUT] = { .n = IST("http_comp_bytes_out_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 257 | [ST_F_COMP_BYP] = { .n = IST("http_comp_bytes_bypassed_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 258 | [ST_F_COMP_RSP] = { .n = IST("http_comp_responses_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 259 | [ST_F_LASTSESS] = { .n = IST("last_session_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 260 | //[ST_F_LAST_CHK] ignored |
| 261 | //[ST_F_LAST_AGT] ignored |
| 262 | [ST_F_QTIME] = { .n = IST("queue_time_average_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 263 | [ST_F_CTIME] = { .n = IST("connect_time_average_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 264 | [ST_F_RTIME] = { .n = IST("response_time_average_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 265 | [ST_F_TTIME] = { .n = IST("total_time_average_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 266 | //[ST_F_AGENT_STATUS] ignored |
| 267 | //[ST_F_AGENT_CODE] ignored |
| 268 | //[ST_F_AGENT_DURATION] ignored |
| 269 | //[ST_F_CHECK_DESC] ignored |
| 270 | //[ST_F_AGENT_DESC] ignored |
| 271 | //[ST_F_CHECK_RISE] ignored |
| 272 | //[ST_F_CHECK_FALL] ignored |
| 273 | //[ST_F_CHECK_HEALTH] ignored |
| 274 | //[ST_F_AGENT_RISE] ignored |
| 275 | //[ST_F_AGENT_FALL] ignored |
| 276 | //[ST_F_AGENT_HEALTH] ignored |
| 277 | //[ST_F_ADDR] ignored |
| 278 | //[ST_F_COOKIE] ignored |
| 279 | //[ST_F_MODE] ignored |
| 280 | //[ST_F_ALGO] ignored |
| 281 | //[ST_F_CONN_RATE] ignored |
| 282 | [ST_F_CONN_RATE_MAX] = { .n = IST("connections_rate_max"), .type = PROMEX_MT_GAUGE, .flags = (PROMEX_FL_FRONT_METRIC ) }, |
| 283 | [ST_F_CONN_TOT] = { .n = IST("connections_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC ) }, |
| 284 | [ST_F_INTERCEPTED] = { .n = IST("intercepted_requests_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC ) }, |
| 285 | [ST_F_DCON] = { .n = IST("denied_connections_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC ) }, |
| 286 | [ST_F_DSES] = { .n = IST("denied_sessions_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC ) }, |
| 287 | [ST_F_WREW] = { .n = IST("failed_header_rewriting_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 288 | [ST_F_CONNECT] = { .n = IST("connection_attempts_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 289 | [ST_F_REUSE] = { .n = IST("connection_reuses_total"), .type = PROMEX_MT_COUNTER, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 290 | [ST_F_CACHE_LOOKUPS] = { .n = IST("http_cache_lookups_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 291 | [ST_F_CACHE_HITS] = { .n = IST("http_cache_hits_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_BACK_METRIC ) }, |
| 292 | [ST_F_SRV_ICUR] = { .n = IST("idle_connections_current"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 293 | [ST_F_SRV_ILIM] = { .n = IST("idle_connections_limit"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 294 | [ST_F_QT_MAX] = { .n = IST("max_queue_time_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 295 | [ST_F_CT_MAX] = { .n = IST("max_connect_time_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 296 | [ST_F_RT_MAX] = { .n = IST("max_response_time_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 297 | [ST_F_TT_MAX] = { .n = IST("max_total_time_seconds"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 298 | [ST_F_EINT] = { .n = IST("internal_errors_total"), .type = PROMEX_MT_COUNTER, .flags = (PROMEX_FL_FRONT_METRIC | PROMEX_FL_LI_METRIC | PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 299 | [ST_F_IDLE_CONN_CUR] = { .n = IST("unsafe_idle_connections_current"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 300 | [ST_F_SAFE_CONN_CUR] = { .n = IST("safe_idle_connections_current"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 301 | [ST_F_USED_CONN_CUR] = { .n = IST("used_connections_current"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 302 | [ST_F_NEED_CONN_EST] = { .n = IST("need_connections_current"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_SRV_METRIC) }, |
| 303 | [ST_F_UWEIGHT] = { .n = IST("uweight"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC | PROMEX_FL_SRV_METRIC) }, |
| 304 | [ST_F_AGG_SRV_CHECK_STATUS] = { .n = IST("agg_server_check_status"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC ) }, |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 305 | [ST_F_AGG_SRV_STATUS ] = { .n = IST("agg_server_status"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC ) }, |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame^] | 306 | [ST_F_AGG_CHECK_STATUS] = { .n = IST("agg_check_status"), .type = PROMEX_MT_GAUGE, .flags = ( PROMEX_FL_BACK_METRIC ) }, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 307 | }; |
| 308 | |
Ilya Shipitsin | acf8459 | 2021-02-06 22:29:08 +0500 | [diff] [blame] | 309 | /* Description of overridden stats fields */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 310 | const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = { |
William Dauchy | a1da7ba | 2021-02-01 13:11:52 +0100 | [diff] [blame] | 311 | [ST_F_STATUS] = IST("Current status of the service, per state label value."), |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 312 | [ST_F_CHECK_STATUS] = IST("Status of last health check, per state label value."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 313 | [ST_F_CHECK_CODE] = IST("layer5-7 code, if available of the last health check."), |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 314 | [ST_F_CHECK_DURATION] = IST("Total duration of the latest server health check, in seconds."), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 315 | [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."), |
| 316 | [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."), |
| 317 | [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."), |
| 318 | [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."), |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 319 | [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"), |
| 320 | [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"), |
| 321 | [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"), |
| 322 | [ST_F_TT_MAX] = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 323 | }; |
| 324 | |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 325 | /* stick table base fields */ |
| 326 | enum sticktable_field { |
| 327 | STICKTABLE_SIZE = 0, |
| 328 | STICKTABLE_USED, |
| 329 | /* must always be the last one */ |
| 330 | STICKTABLE_TOTAL_FIELDS |
| 331 | }; |
| 332 | |
| 333 | const struct promex_metric promex_sticktable_metrics[STICKTABLE_TOTAL_FIELDS] = { |
| 334 | [STICKTABLE_SIZE] = { .n = IST("size"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_STICKTABLE_METRIC }, |
| 335 | [STICKTABLE_USED] = { .n = IST("used"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_STICKTABLE_METRIC }, |
| 336 | }; |
| 337 | |
| 338 | /* stick table base description */ |
| 339 | const struct ist promex_sticktable_metric_desc[STICKTABLE_TOTAL_FIELDS] = { |
| 340 | [STICKTABLE_SIZE] = IST("Stick table size."), |
| 341 | [STICKTABLE_USED] = IST("Number of entries used in this stick table."), |
| 342 | }; |
| 343 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 344 | /* Specific labels for all ST_F_HRSP_* fields */ |
| 345 | const struct ist promex_hrsp_code[1 + ST_F_HRSP_OTHER - ST_F_HRSP_1XX] = { |
| 346 | [ST_F_HRSP_1XX - ST_F_HRSP_1XX] = IST("1xx"), |
| 347 | [ST_F_HRSP_2XX - ST_F_HRSP_1XX] = IST("2xx"), |
| 348 | [ST_F_HRSP_3XX - ST_F_HRSP_1XX] = IST("3xx"), |
| 349 | [ST_F_HRSP_4XX - ST_F_HRSP_1XX] = IST("4xx"), |
| 350 | [ST_F_HRSP_5XX - ST_F_HRSP_1XX] = IST("5xx"), |
| 351 | [ST_F_HRSP_OTHER - ST_F_HRSP_1XX] = IST("other"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 352 | }; |
| 353 | |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 354 | enum promex_front_state { |
| 355 | PROMEX_FRONT_STATE_DOWN = 0, |
| 356 | PROMEX_FRONT_STATE_UP, |
| 357 | |
| 358 | PROMEX_FRONT_STATE_COUNT /* must be last */ |
| 359 | }; |
| 360 | |
| 361 | const struct ist promex_front_st[PROMEX_FRONT_STATE_COUNT] = { |
| 362 | [PROMEX_FRONT_STATE_DOWN] = IST("DOWN"), |
| 363 | [PROMEX_FRONT_STATE_UP] = IST("UP"), |
| 364 | }; |
| 365 | |
| 366 | enum promex_back_state { |
| 367 | PROMEX_BACK_STATE_DOWN = 0, |
| 368 | PROMEX_BACK_STATE_UP, |
| 369 | |
| 370 | PROMEX_BACK_STATE_COUNT /* must be last */ |
| 371 | }; |
| 372 | |
| 373 | const struct ist promex_back_st[PROMEX_BACK_STATE_COUNT] = { |
| 374 | [PROMEX_BACK_STATE_DOWN] = IST("DOWN"), |
| 375 | [PROMEX_BACK_STATE_UP] = IST("UP"), |
| 376 | }; |
| 377 | |
| 378 | enum promex_srv_state { |
| 379 | PROMEX_SRV_STATE_DOWN = 0, |
| 380 | PROMEX_SRV_STATE_UP, |
| 381 | PROMEX_SRV_STATE_MAINT, |
| 382 | PROMEX_SRV_STATE_DRAIN, |
| 383 | PROMEX_SRV_STATE_NOLB, |
| 384 | |
| 385 | PROMEX_SRV_STATE_COUNT /* must be last */ |
| 386 | }; |
| 387 | |
| 388 | const struct ist promex_srv_st[PROMEX_SRV_STATE_COUNT] = { |
| 389 | [PROMEX_SRV_STATE_DOWN] = IST("DOWN"), |
| 390 | [PROMEX_SRV_STATE_UP] = IST("UP"), |
| 391 | [PROMEX_SRV_STATE_MAINT] = IST("MAINT"), |
| 392 | [PROMEX_SRV_STATE_DRAIN] = IST("DRAIN"), |
| 393 | [PROMEX_SRV_STATE_NOLB] = IST("NOLB"), |
| 394 | }; |
| 395 | |
| 396 | /* Return the server status. */ |
| 397 | enum promex_srv_state promex_srv_status(struct server *sv) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 398 | { |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 399 | int state = PROMEX_SRV_STATE_DOWN; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 400 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 401 | if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) { |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 402 | state = PROMEX_SRV_STATE_UP; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 403 | if (sv->cur_admin & SRV_ADMF_DRAIN) |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 404 | state = PROMEX_SRV_STATE_DRAIN; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 405 | } |
Christopher Faulet | d45d105 | 2019-09-06 16:10:19 +0200 | [diff] [blame] | 406 | else if (sv->cur_state == SRV_ST_STOPPING) |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 407 | state = PROMEX_SRV_STATE_NOLB; |
Christopher Faulet | d45d105 | 2019-09-06 16:10:19 +0200 | [diff] [blame] | 408 | |
| 409 | if (sv->cur_admin & SRV_ADMF_MAINT) |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 410 | state = PROMEX_SRV_STATE_MAINT; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 411 | |
| 412 | return state; |
| 413 | } |
| 414 | |
| 415 | /* Convert a field to its string representation and write it in <out>, followed |
| 416 | * by a newline, if there is enough space. non-numeric value are converted in |
William Dauchy | 18a2c6e | 2021-01-22 21:09:47 +0100 | [diff] [blame] | 417 | * "NaN" because Prometheus only support numerical values (but it is unexepceted |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 418 | * to process this kind of value). It returns 1 on success. Otherwise, it |
| 419 | * returns 0. The buffer's length must not exceed <max> value. |
| 420 | */ |
| 421 | static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max) |
| 422 | { |
| 423 | int ret = 0; |
| 424 | |
| 425 | switch (field_format(f, 0)) { |
William Dauchy | 18a2c6e | 2021-01-22 21:09:47 +0100 | [diff] [blame] | 426 | case FF_EMPTY: ret = chunk_strcat(out, "NaN\n"); break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 427 | case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break; |
| 428 | case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break; |
| 429 | case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break; |
| 430 | case FF_U64: ret = chunk_appendf(out, "%llu\n", (unsigned long long)f->u.u64); break; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 431 | case FF_FLT: ret = chunk_appendf(out, "%f\n", f->u.flt); break; |
William Dauchy | 18a2c6e | 2021-01-22 21:09:47 +0100 | [diff] [blame] | 432 | case FF_STR: ret = chunk_strcat(out, "NaN\n"); break; |
| 433 | default: ret = chunk_strcat(out, "NaN\n"); break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 434 | } |
| 435 | if (!ret || out->data > max) |
| 436 | return 0; |
| 437 | return 1; |
| 438 | } |
| 439 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 440 | /* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It |
| 441 | * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0. |
| 442 | */ |
| 443 | static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx, |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 444 | const struct promex_metric *metric, const struct ist name, |
| 445 | struct ist *out, size_t max) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 446 | { |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 447 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 448 | struct ist type; |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 449 | struct ist desc; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 450 | |
| 451 | switch (metric->type) { |
| 452 | case PROMEX_MT_COUNTER: |
| 453 | type = ist("counter"); |
| 454 | break; |
| 455 | default: |
| 456 | type = ist("gauge"); |
| 457 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 458 | |
William Dauchy | a191b77 | 2021-01-15 22:41:39 +0100 | [diff] [blame] | 459 | if (istcat(out, ist("# HELP "), max) == -1 || |
| 460 | istcat(out, name, max) == -1 || |
| 461 | istcat(out, ist(" "), max) == -1) |
| 462 | goto full; |
| 463 | |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 464 | if (metric->flags & PROMEX_FL_INFO_METRIC) |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 465 | desc = ist(info_fields[ctx->field_num].desc); |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 466 | else if (metric->flags & PROMEX_FL_STICKTABLE_METRIC) |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 467 | desc = promex_sticktable_metric_desc[ctx->field_num]; |
| 468 | else if (!isttest(promex_st_metric_desc[ctx->field_num])) |
| 469 | desc = ist(stat_fields[ctx->field_num].desc); |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 470 | else |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 471 | desc = promex_st_metric_desc[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 472 | |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 473 | if (istcat(out, desc, max) == -1 || |
| 474 | istcat(out, ist("\n# TYPE "), max) == -1 || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 475 | istcat(out, name, max) == -1 || |
| 476 | istcat(out, ist(" "), max) == -1 || |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 477 | istcat(out, type, max) == -1 || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 478 | istcat(out, ist("\n"), max) == -1) |
| 479 | goto full; |
| 480 | |
| 481 | return 1; |
| 482 | |
| 483 | full: |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | /* Dump the line for <metric>. It starts by the metric name followed by its |
| 488 | * labels (proxy name, server name...) between braces and finally its value. If |
| 489 | * not already done, the header lines are dumped first. It returns 1 on |
| 490 | * success. Otherwise if <out> length exceeds <max>, it returns 0. |
| 491 | */ |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 492 | static int promex_dump_metric(struct appctx *appctx, struct htx *htx, struct ist prefix, |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 493 | const struct promex_metric *metric, struct field *val, |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 494 | struct promex_label *labels, struct ist *out, size_t max) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 495 | { |
| 496 | struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 }; |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 497 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 498 | size_t len = out->len; |
| 499 | |
| 500 | if (out->len + PROMEX_MAX_METRIC_LENGTH > max) |
| 501 | return 0; |
| 502 | |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 503 | /* Fill the metric name */ |
| 504 | istcat(&name, prefix, PROMEX_MAX_NAME_LEN); |
| 505 | istcat(&name, metric->n, PROMEX_MAX_NAME_LEN); |
| 506 | |
| 507 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 508 | if ((ctx->flags & PROMEX_FL_METRIC_HDR) && |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 509 | !promex_dump_metric_header(appctx, htx, metric, name, out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 510 | goto full; |
| 511 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 512 | if (istcat(out, name, max) == -1) |
| 513 | goto full; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 514 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 515 | if (isttest(labels[0].name)) { |
| 516 | int i; |
| 517 | |
| 518 | if (istcat(out, ist("{"), max) == -1) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 519 | goto full; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 520 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 521 | for (i = 0; isttest(labels[i].name); i++) { |
| 522 | if (!isttest(labels[i].value)) |
| 523 | continue; |
| 524 | |
| 525 | if ((i && istcat(out, ist(","), max) == -1) || |
| 526 | istcat(out, labels[i].name, max) == -1 || |
| 527 | istcat(out, ist("=\""), max) == -1 || |
| 528 | istcat(out, labels[i].value, max) == -1 || |
| 529 | istcat(out, ist("\""), max) == -1) |
| 530 | goto full; |
| 531 | } |
| 532 | |
| 533 | if (istcat(out, ist("}"), max) == -1) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 534 | goto full; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 535 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 538 | if (istcat(out, ist(" "), max) == -1) |
| 539 | goto full; |
| 540 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 541 | trash.data = out->len; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 542 | if (!promex_metric_to_str(&trash, val, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 543 | goto full; |
| 544 | out->len = trash.data; |
| 545 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 546 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 547 | return 1; |
| 548 | full: |
| 549 | // Restore previous length |
| 550 | out->len = len; |
| 551 | return 0; |
| 552 | |
| 553 | } |
| 554 | |
| 555 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 556 | /* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 557 | * 0 if <htx> is full and -1 in case of any error. */ |
| 558 | static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx) |
| 559 | { |
| 560 | static struct ist prefix = IST("haproxy_process_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 561 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 562 | struct field val; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 563 | struct channel *chn = sc_ic(appctx_sc(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 564 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 565 | 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] | 566 | int ret = 1; |
| 567 | |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 568 | if (!stats_fill_info(info, INF_TOTAL_FIELDS, 0)) |
William Dauchy | 5d9b8f3 | 2021-01-11 20:07:49 +0100 | [diff] [blame] | 569 | return -1; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 570 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 571 | for (; ctx->field_num < INF_TOTAL_FIELDS; ctx->field_num++) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 572 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 573 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 574 | if (!(promex_global_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 575 | continue; |
| 576 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 577 | switch (ctx->field_num) { |
William Dauchy | 5a982a7 | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 578 | case INF_BUILD_INFO: |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 579 | labels[0].name = ist("version"); |
| 580 | labels[0].value = ist(HAPROXY_VERSION); |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 581 | val = mkf_u32(FN_GAUGE, 1); |
William Dauchy | 5a982a7 | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 582 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 583 | |
| 584 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 585 | val = info[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 588 | if (!promex_dump_metric(appctx, htx, prefix, &promex_global_metrics[ctx->field_num], |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 589 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 590 | goto full; |
| 591 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 592 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 596 | if (out.len) { |
| 597 | if (!htx_add_data_atonce(htx, out)) |
| 598 | return -1; /* Unexpected and unrecoverable error */ |
| 599 | channel_add_input(chn, out.len); |
| 600 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 601 | return ret; |
| 602 | full: |
| 603 | ret = 0; |
| 604 | goto end; |
| 605 | } |
| 606 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 607 | /* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 608 | * 0 if <htx> is full and -1 in case of any error. */ |
| 609 | static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx) |
| 610 | { |
| 611 | static struct ist prefix = IST("haproxy_frontend_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 612 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 613 | struct proxy *px; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 614 | struct field val; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 615 | struct channel *chn = sc_ic(appctx_sc(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 616 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 617 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 618 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 619 | int ret = 1; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 620 | enum promex_front_state state; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 621 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 622 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 623 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 624 | continue; |
| 625 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 626 | while (ctx->px) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 627 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 628 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 629 | px = ctx->px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 630 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 631 | labels[0].name = ist("proxy"); |
| 632 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 633 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 634 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 635 | if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_FE)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 636 | goto next_px; |
| 637 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 638 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS, &(ctx->field_num))) |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 639 | return -1; |
| 640 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 641 | switch (ctx->field_num) { |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 642 | case ST_F_STATUS: |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 643 | state = !(px->flags & PR_FL_STOPPED); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 644 | for (; ctx->obj_state < PROMEX_FRONT_STATE_COUNT; ctx->obj_state++) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 645 | labels[1].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 646 | labels[1].value = promex_front_st[ctx->obj_state]; |
| 647 | val = mkf_u32(FO_STATUS, state == ctx->obj_state); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 648 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 649 | &val, labels, &out, max)) |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 650 | goto full; |
| 651 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 652 | ctx->obj_state = 0; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 653 | goto next_px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 654 | case ST_F_REQ_RATE_MAX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 655 | case ST_F_REQ_TOT: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 656 | case ST_F_INTERCEPTED: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 657 | case ST_F_CACHE_LOOKUPS: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 658 | case ST_F_CACHE_HITS: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 659 | case ST_F_COMP_IN: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 660 | case ST_F_COMP_OUT: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 661 | case ST_F_COMP_BYP: |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 662 | case ST_F_COMP_RSP: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 663 | if (px->mode != PR_MODE_HTTP) |
| 664 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 665 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 666 | break; |
Christopher Faulet | 32ef48e | 2021-02-01 14:55:37 +0100 | [diff] [blame] | 667 | case ST_F_HRSP_1XX: |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 668 | case ST_F_HRSP_2XX: |
| 669 | case ST_F_HRSP_3XX: |
| 670 | case ST_F_HRSP_4XX: |
| 671 | case ST_F_HRSP_5XX: |
| 672 | case ST_F_HRSP_OTHER: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 673 | if (px->mode != PR_MODE_HTTP) |
| 674 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 675 | if (ctx->field_num != ST_F_HRSP_1XX) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 676 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 677 | labels[1].name = ist("code"); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 678 | labels[1].value = promex_hrsp_code[ctx->field_num - ST_F_HRSP_1XX]; |
| 679 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 680 | break; |
| 681 | |
| 682 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 683 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 684 | } |
| 685 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 686 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 687 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 688 | goto full; |
| 689 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 690 | ctx->px = px->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 691 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 692 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 693 | ctx->px = proxies_list; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 697 | if (out.len) { |
| 698 | if (!htx_add_data_atonce(htx, out)) |
| 699 | return -1; /* Unexpected and unrecoverable error */ |
| 700 | channel_add_input(chn, out.len); |
| 701 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 702 | return ret; |
| 703 | full: |
| 704 | ret = 0; |
| 705 | goto end; |
| 706 | } |
| 707 | |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 708 | /* Dump listener metrics (prefixed by "haproxy_listen_"). It returns 1 on |
| 709 | * success, 0 if <htx> is full and -1 in case of any error. */ |
| 710 | static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx) |
| 711 | { |
| 712 | static struct ist prefix = IST("haproxy_listener_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 713 | struct promex_ctx *ctx = appctx->svcctx; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 714 | struct proxy *px; |
| 715 | struct field val; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 716 | struct channel *chn = sc_ic(appctx_sc(appctx)); |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 717 | struct ist out = ist2(trash.area, 0); |
| 718 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
| 719 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 720 | struct listener *li; |
| 721 | int ret = 1; |
| 722 | enum li_status status; |
| 723 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 724 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 725 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 726 | continue; |
| 727 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 728 | while (ctx->px) { |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 729 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 730 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 731 | px = ctx->px; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 732 | |
| 733 | labels[0].name = ist("proxy"); |
| 734 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 735 | |
| 736 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 737 | if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_FE)) |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 738 | goto next_px; |
| 739 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 740 | li = ctx->li; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 741 | list_for_each_entry_from(li, &px->conf.listeners, by_fe) { |
| 742 | |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 743 | if (!li->counters) |
| 744 | continue; |
| 745 | |
William Dauchy | baf2273 | 2021-02-25 00:53:13 +0100 | [diff] [blame] | 746 | labels[1].name = ist("listener"); |
| 747 | labels[1].value = ist2(li->name, strlen(li->name)); |
| 748 | |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 749 | if (!stats_fill_li_stats(px, li, 0, stats, |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 750 | ST_F_TOTAL_FIELDS, &(ctx->field_num))) |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 751 | return -1; |
| 752 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 753 | switch (ctx->field_num) { |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 754 | case ST_F_STATUS: |
| 755 | status = get_li_status(li); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 756 | for (; ctx->obj_state < LI_STATE_COUNT; ctx->obj_state++) { |
| 757 | val = mkf_u32(FO_STATUS, status == ctx->obj_state); |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 758 | labels[2].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 759 | labels[2].value = ist(li_status_st[ctx->obj_state]); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 760 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 761 | &val, labels, &out, max)) |
| 762 | goto full; |
| 763 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 764 | ctx->obj_state = 0; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 765 | continue; |
| 766 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 767 | val = stats[ctx->field_num]; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | if (!promex_dump_metric(appctx, htx, prefix, |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 771 | &promex_st_metrics[ctx->field_num], |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 772 | &val, labels, &out, max)) |
| 773 | goto full; |
| 774 | } |
| 775 | |
| 776 | next_px: |
| 777 | px = px->next; |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 778 | ctx->px = px; |
| 779 | ctx->li = (px ? LIST_NEXT(&px->conf.listeners, struct listener *, by_fe) : NULL); |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 780 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 781 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 782 | ctx->px = proxies_list; |
| 783 | ctx->li = LIST_NEXT(&proxies_list->conf.listeners, struct listener *, by_fe); |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | end: |
| 787 | if (out.len) { |
| 788 | if (!htx_add_data_atonce(htx, out)) |
| 789 | return -1; /* Unexpected and unrecoverable error */ |
| 790 | channel_add_input(chn, out.len); |
| 791 | } |
| 792 | return ret; |
| 793 | full: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 794 | ctx->li = li; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 795 | ret = 0; |
| 796 | goto end; |
| 797 | } |
| 798 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 799 | /* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 800 | * 0 if <htx> is full and -1 in case of any error. */ |
| 801 | static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) |
| 802 | { |
| 803 | static struct ist prefix = IST("haproxy_backend_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 804 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 805 | struct proxy *px; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 806 | struct server *sv; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 807 | struct field val; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 808 | struct channel *chn = sc_ic(appctx_sc(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 809 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 810 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
William Dauchy | 3c6f006 | 2021-01-25 17:29:02 +0100 | [diff] [blame] | 811 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 812 | int ret = 1; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 813 | double secs; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 814 | enum promex_back_state bkd_state; |
| 815 | enum promex_srv_state srv_state; |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame^] | 816 | enum healthcheck_status srv_check_status; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 817 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 818 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 819 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 820 | continue; |
| 821 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 822 | while (ctx->px) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 823 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 824 | unsigned int srv_state_count[PROMEX_SRV_STATE_COUNT] = { 0 }; |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame^] | 825 | unsigned int srv_check_count[HCHK_STATUS_SIZE] = { 0 }; |
| 826 | const char *check_state; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 827 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 828 | px = ctx->px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 829 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 830 | labels[0].name = ist("proxy"); |
| 831 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 832 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 833 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 834 | if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 835 | goto next_px; |
| 836 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 837 | if (!stats_fill_be_stats(px, 0, stats, ST_F_TOTAL_FIELDS, &(ctx->field_num))) |
William Dauchy | 3c6f006 | 2021-01-25 17:29:02 +0100 | [diff] [blame] | 838 | return -1; |
| 839 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 840 | switch (ctx->field_num) { |
Cedric Paillet | 7d6644e | 2022-12-08 09:17:00 +0000 | [diff] [blame] | 841 | case ST_F_AGG_SRV_CHECK_STATUS: // DEPRECATED |
| 842 | case ST_F_AGG_SRV_STATUS: |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 843 | if (!px->srv) |
| 844 | goto next_px; |
| 845 | sv = px->srv; |
| 846 | while (sv) { |
| 847 | srv_state = promex_srv_status(sv); |
| 848 | srv_state_count[srv_state] += 1; |
| 849 | sv = sv->next; |
| 850 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 851 | for (; ctx->obj_state < PROMEX_SRV_STATE_COUNT; ctx->obj_state++) { |
| 852 | val = mkf_u32(FN_GAUGE, srv_state_count[ctx->obj_state]); |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 853 | labels[1].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 854 | labels[1].value = promex_srv_st[ctx->obj_state]; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 855 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 856 | &val, labels, &out, max)) |
| 857 | goto full; |
| 858 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 859 | ctx->obj_state = 0; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 860 | goto next_px; |
Cedric Paillet | e06e31e | 2022-12-08 09:17:01 +0000 | [diff] [blame^] | 861 | case ST_F_AGG_CHECK_STATUS: |
| 862 | if (!px->srv) |
| 863 | goto next_px; |
| 864 | sv = px->srv; |
| 865 | while (sv) { |
| 866 | srv_check_status = sv->check.status; |
| 867 | srv_check_count[srv_check_status] += 1; |
| 868 | sv = sv->next; |
| 869 | } |
| 870 | for (; ctx->obj_state < HCHK_STATUS_SIZE; ctx->obj_state++) { |
| 871 | if (get_check_status_result(ctx->obj_state) < CHK_RES_FAILED) |
| 872 | continue; |
| 873 | val = mkf_u32(FO_STATUS, srv_check_count[ctx->obj_state]); |
| 874 | check_state = get_check_status_info(ctx->obj_state); |
| 875 | labels[1].name = ist("state"); |
| 876 | labels[1].value = ist(check_state); |
| 877 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
| 878 | &val, labels, &out, max)) |
| 879 | goto full; |
| 880 | } |
| 881 | ctx->obj_state = 0; |
| 882 | goto next_px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 883 | case ST_F_STATUS: |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 884 | bkd_state = ((px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 885 | for (; ctx->obj_state < PROMEX_BACK_STATE_COUNT; ctx->obj_state++) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 886 | labels[1].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 887 | labels[1].value = promex_back_st[ctx->obj_state]; |
| 888 | val = mkf_u32(FO_STATUS, bkd_state == ctx->obj_state); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 889 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 890 | &val, labels, &out, max)) |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 891 | goto full; |
| 892 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 893 | ctx->obj_state = 0; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 894 | goto next_px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 895 | case ST_F_QTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 896 | secs = (double)swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 897 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 898 | break; |
| 899 | case ST_F_CTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 900 | secs = (double)swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 901 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 902 | break; |
| 903 | case ST_F_RTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 904 | secs = (double)swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 905 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 906 | break; |
| 907 | case ST_F_TTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 908 | secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 909 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 910 | break; |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 911 | case ST_F_QT_MAX: |
| 912 | secs = (double)px->be_counters.qtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 913 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 914 | break; |
| 915 | case ST_F_CT_MAX: |
| 916 | secs = (double)px->be_counters.ctime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 917 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 918 | break; |
| 919 | case ST_F_RT_MAX: |
| 920 | secs = (double)px->be_counters.dtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 921 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 922 | break; |
| 923 | case ST_F_TT_MAX: |
| 924 | secs = (double)px->be_counters.ttime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 925 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 926 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 927 | case ST_F_REQ_TOT: |
William Dauchy | 3c6f006 | 2021-01-25 17:29:02 +0100 | [diff] [blame] | 928 | case ST_F_CACHE_LOOKUPS: |
| 929 | case ST_F_CACHE_HITS: |
| 930 | case ST_F_COMP_IN: |
| 931 | case ST_F_COMP_OUT: |
| 932 | case ST_F_COMP_BYP: |
| 933 | case ST_F_COMP_RSP: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 934 | if (px->mode != PR_MODE_HTTP) |
| 935 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 936 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 937 | break; |
Christopher Faulet | 32ef48e | 2021-02-01 14:55:37 +0100 | [diff] [blame] | 938 | case ST_F_HRSP_1XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 939 | case ST_F_HRSP_2XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 940 | case ST_F_HRSP_3XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 941 | case ST_F_HRSP_4XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 942 | case ST_F_HRSP_5XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 943 | case ST_F_HRSP_OTHER: |
| 944 | if (px->mode != PR_MODE_HTTP) |
| 945 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 946 | if (ctx->field_num != ST_F_HRSP_1XX) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 947 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 948 | labels[1].name = ist("code"); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 949 | labels[1].value = promex_hrsp_code[ctx->field_num - ST_F_HRSP_1XX]; |
| 950 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 951 | break; |
| 952 | |
| 953 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 954 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 955 | } |
| 956 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 957 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 958 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 959 | goto full; |
| 960 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 961 | ctx->px = px->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 962 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 963 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 964 | ctx->px = proxies_list; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 968 | if (out.len) { |
| 969 | if (!htx_add_data_atonce(htx, out)) |
| 970 | return -1; /* Unexpected and unrecoverable error */ |
| 971 | channel_add_input(chn, out.len); |
| 972 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 973 | return ret; |
| 974 | full: |
| 975 | ret = 0; |
| 976 | goto end; |
| 977 | } |
| 978 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 979 | /* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 980 | * 0 if <htx> is full and -1 in case of any error. */ |
| 981 | static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx) |
| 982 | { |
| 983 | static struct ist prefix = IST("haproxy_server_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 984 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 985 | struct proxy *px; |
| 986 | struct server *sv; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 987 | struct field val; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 988 | struct channel *chn = sc_ic(appctx_sc(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 989 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 990 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
William Dauchy | bde2bf6 | 2021-01-25 17:29:04 +0100 | [diff] [blame] | 991 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 992 | int ret = 1; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 993 | double secs; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 994 | enum promex_srv_state state; |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 995 | const char *check_state; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 996 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 997 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 998 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 999 | continue; |
| 1000 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1001 | while (ctx->px) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1002 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 1003 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1004 | px = ctx->px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1005 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1006 | labels[0].name = ist("proxy"); |
| 1007 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 1008 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1009 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 1010 | if ((px->flags & PR_FL_DISABLED) || px->uuid <= 0 || !(px->cap & PR_CAP_BE)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1011 | goto next_px; |
| 1012 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1013 | while (ctx->sv) { |
| 1014 | sv = ctx->sv; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1015 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1016 | labels[1].name = ist("server"); |
| 1017 | labels[1].value = ist2(sv->id, strlen(sv->id)); |
| 1018 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1019 | if (!stats_fill_sv_stats(px, sv, 0, stats, ST_F_TOTAL_FIELDS, &(ctx->field_num))) |
William Dauchy | bde2bf6 | 2021-01-25 17:29:04 +0100 | [diff] [blame] | 1020 | return -1; |
| 1021 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1022 | if ((ctx->flags & PROMEX_FL_NO_MAINT_SRV) && (sv->cur_admin & SRV_ADMF_MAINT)) |
Christopher Faulet | eba2294 | 2019-11-19 14:18:24 +0100 | [diff] [blame] | 1023 | goto next_sv; |
| 1024 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1025 | switch (ctx->field_num) { |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1026 | case ST_F_STATUS: |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 1027 | state = promex_srv_status(sv); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1028 | for (; ctx->obj_state < PROMEX_SRV_STATE_COUNT; ctx->obj_state++) { |
| 1029 | val = mkf_u32(FO_STATUS, state == ctx->obj_state); |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1030 | labels[2].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1031 | labels[2].value = promex_srv_st[ctx->obj_state]; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1032 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1033 | &val, labels, &out, max)) |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 1034 | goto full; |
| 1035 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1036 | ctx->obj_state = 0; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 1037 | goto next_sv; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1038 | case ST_F_QTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1039 | secs = (double)swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1040 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1041 | break; |
| 1042 | case ST_F_CTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1043 | secs = (double)swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1044 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1045 | break; |
| 1046 | case ST_F_RTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1047 | secs = (double)swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1048 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1049 | break; |
| 1050 | case ST_F_TTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1051 | secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1052 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1053 | break; |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1054 | case ST_F_QT_MAX: |
| 1055 | secs = (double)sv->counters.qtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1056 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1057 | break; |
| 1058 | case ST_F_CT_MAX: |
| 1059 | secs = (double)sv->counters.ctime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1060 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1061 | break; |
| 1062 | case ST_F_RT_MAX: |
| 1063 | secs = (double)sv->counters.dtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1064 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1065 | break; |
| 1066 | case ST_F_TT_MAX: |
| 1067 | secs = (double)sv->counters.ttime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1068 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1069 | break; |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 1070 | case ST_F_CHECK_STATUS: |
| 1071 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED) |
| 1072 | goto next_sv; |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1073 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1074 | for (; ctx->obj_state < HCHK_STATUS_SIZE; ctx->obj_state++) { |
| 1075 | if (get_check_status_result(ctx->obj_state) < CHK_RES_FAILED) |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1076 | continue; |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1077 | val = mkf_u32(FO_STATUS, sv->check.status == ctx->obj_state); |
| 1078 | check_state = get_check_status_info(ctx->obj_state); |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1079 | labels[2].name = ist("state"); |
Tim Duesterhus | b113b5c | 2021-09-15 13:58:44 +0200 | [diff] [blame] | 1080 | labels[2].value = ist(check_state); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1081 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1082 | &val, labels, &out, max)) |
| 1083 | goto full; |
| 1084 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1085 | ctx->obj_state = 0; |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1086 | goto next_sv; |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 1087 | case ST_F_CHECK_CODE: |
| 1088 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED) |
| 1089 | goto next_sv; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1090 | val = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code); |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 1091 | break; |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 1092 | case ST_F_CHECK_DURATION: |
| 1093 | if (sv->check.status < HCHK_STATUS_CHECKED) |
| 1094 | goto next_sv; |
| 1095 | secs = (double)sv->check.duration / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1096 | val = mkf_flt(FN_DURATION, secs); |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 1097 | break; |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1098 | case ST_F_REQ_TOT: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1099 | if (px->mode != PR_MODE_HTTP) |
| 1100 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1101 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1102 | break; |
Christopher Faulet | 32ef48e | 2021-02-01 14:55:37 +0100 | [diff] [blame] | 1103 | case ST_F_HRSP_1XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1104 | case ST_F_HRSP_2XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1105 | case ST_F_HRSP_3XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1106 | case ST_F_HRSP_4XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1107 | case ST_F_HRSP_5XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1108 | case ST_F_HRSP_OTHER: |
| 1109 | if (px->mode != PR_MODE_HTTP) |
| 1110 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1111 | if (ctx->field_num != ST_F_HRSP_1XX) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1112 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1113 | labels[2].name = ist("code"); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1114 | labels[2].value = promex_hrsp_code[ctx->field_num - ST_F_HRSP_1XX]; |
| 1115 | val = stats[ctx->field_num]; |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 1116 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1117 | |
| 1118 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1119 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1120 | } |
| 1121 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1122 | if (!promex_dump_metric(appctx, htx, prefix, &promex_st_metrics[ctx->field_num], |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1123 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1124 | goto full; |
Christopher Faulet | eba2294 | 2019-11-19 14:18:24 +0100 | [diff] [blame] | 1125 | next_sv: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1126 | ctx->sv = sv->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1130 | ctx->px = px->next; |
| 1131 | ctx->sv = (ctx->px ? ctx->px->srv : NULL); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1132 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1133 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 1134 | ctx->px = proxies_list; |
| 1135 | ctx->sv = (ctx->px ? ctx->px->srv : NULL); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 1140 | if (out.len) { |
| 1141 | if (!htx_add_data_atonce(htx, out)) |
| 1142 | return -1; /* Unexpected and unrecoverable error */ |
| 1143 | channel_add_input(chn, out.len); |
| 1144 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1145 | return ret; |
| 1146 | full: |
| 1147 | ret = 0; |
| 1148 | goto end; |
| 1149 | } |
| 1150 | |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1151 | /* Dump stick table metrics (prefixed by "haproxy_sticktable_"). It returns 1 on success, |
| 1152 | * 0 if <htx> is full and -1 in case of any error. */ |
| 1153 | static int promex_dump_sticktable_metrics(struct appctx *appctx, struct htx *htx) |
| 1154 | { |
| 1155 | static struct ist prefix = IST("haproxy_sticktable_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1156 | struct promex_ctx *ctx = appctx->svcctx; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1157 | struct field val; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 1158 | struct channel *chn = sc_ic(appctx_sc(appctx)); |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1159 | struct ist out = ist2(trash.area, 0); |
| 1160 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
| 1161 | int ret = 1; |
| 1162 | struct stktable *t; |
| 1163 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1164 | for (; ctx->field_num < STICKTABLE_TOTAL_FIELDS; ctx->field_num++) { |
| 1165 | if (!(promex_sticktable_metrics[ctx->field_num].flags & ctx->flags)) |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1166 | continue; |
| 1167 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1168 | while (ctx->st) { |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1169 | struct promex_label labels[PROMEX_MAX_LABELS - 1] = {}; |
| 1170 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1171 | t = ctx->st; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1172 | if (!t->size) |
| 1173 | goto next_px; |
| 1174 | |
| 1175 | labels[0].name = ist("name"); |
| 1176 | labels[0].value = ist2(t->id, strlen(t->id)); |
| 1177 | labels[1].name = ist("type"); |
| 1178 | labels[1].value = ist2(stktable_types[t->type].kw, strlen(stktable_types[t->type].kw)); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1179 | switch (ctx->field_num) { |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1180 | case STICKTABLE_SIZE: |
| 1181 | val = mkf_u32(FN_GAUGE, t->size); |
| 1182 | break; |
| 1183 | case STICKTABLE_USED: |
| 1184 | val = mkf_u32(FN_GAUGE, t->current); |
| 1185 | break; |
| 1186 | default: |
| 1187 | goto next_px; |
| 1188 | } |
| 1189 | |
| 1190 | if (!promex_dump_metric(appctx, htx, prefix, |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1191 | &promex_sticktable_metrics[ctx->field_num], |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1192 | &val, labels, &out, max)) |
| 1193 | goto full; |
| 1194 | |
| 1195 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1196 | ctx->st = t->next; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1197 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1198 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 1199 | ctx->st = stktables_list; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | end: |
| 1203 | if (out.len) { |
| 1204 | if (!htx_add_data_atonce(htx, out)) |
| 1205 | return -1; /* Unexpected and unrecoverable error */ |
| 1206 | channel_add_input(chn, out.len); |
| 1207 | } |
| 1208 | return ret; |
| 1209 | full: |
| 1210 | ret = 0; |
| 1211 | goto end; |
| 1212 | } |
| 1213 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1214 | /* Dump all metrics (global, frontends, backends and servers) depending on the |
| 1215 | * dumper state (appctx->st1). It returns 1 on success, 0 if <htx> is full and |
Amaury Denoyelle | da5b6d1 | 2020-10-02 18:32:02 +0200 | [diff] [blame] | 1216 | * -1 in case of any error. |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1217 | * Uses <appctx.ctx.stats.px> as a pointer to the current proxy and <sv>/<li> |
| 1218 | * as pointers to the current server/listener respectively. |
| 1219 | */ |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1220 | static int promex_dump_metrics(struct appctx *appctx, struct stconn *sc, struct htx *htx) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1221 | { |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1222 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1223 | int ret; |
| 1224 | |
| 1225 | switch (appctx->st1) { |
| 1226 | case PROMEX_DUMPER_INIT: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1227 | ctx->px = NULL; |
| 1228 | ctx->st = NULL; |
| 1229 | ctx->li = NULL; |
| 1230 | ctx->sv = NULL; |
| 1231 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC); |
| 1232 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1233 | ctx->field_num = INF_NAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1234 | appctx->st1 = PROMEX_DUMPER_GLOBAL; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1235 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1236 | |
| 1237 | case PROMEX_DUMPER_GLOBAL: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1238 | if (ctx->flags & PROMEX_FL_SCOPE_GLOBAL) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1239 | ret = promex_dump_global_metrics(appctx, htx); |
| 1240 | if (ret <= 0) { |
| 1241 | if (ret == -1) |
| 1242 | goto error; |
| 1243 | goto full; |
| 1244 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1245 | } |
| 1246 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1247 | ctx->px = proxies_list; |
| 1248 | ctx->st = NULL; |
| 1249 | ctx->li = NULL; |
| 1250 | ctx->sv = NULL; |
| 1251 | ctx->flags &= ~PROMEX_FL_INFO_METRIC; |
| 1252 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_FRONT_METRIC); |
| 1253 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1254 | ctx->field_num = ST_F_PXNAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1255 | appctx->st1 = PROMEX_DUMPER_FRONT; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1256 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1257 | |
| 1258 | case PROMEX_DUMPER_FRONT: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1259 | if (ctx->flags & PROMEX_FL_SCOPE_FRONT) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1260 | ret = promex_dump_front_metrics(appctx, htx); |
| 1261 | if (ret <= 0) { |
| 1262 | if (ret == -1) |
| 1263 | goto error; |
| 1264 | goto full; |
| 1265 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1268 | ctx->px = proxies_list; |
| 1269 | ctx->st = NULL; |
| 1270 | ctx->li = LIST_NEXT(&proxies_list->conf.listeners, struct listener *, by_fe); |
| 1271 | ctx->sv = NULL; |
| 1272 | ctx->flags &= ~PROMEX_FL_FRONT_METRIC; |
| 1273 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_LI_METRIC); |
| 1274 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1275 | ctx->field_num = ST_F_PXNAME; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 1276 | appctx->st1 = PROMEX_DUMPER_LI; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1277 | __fallthrough; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 1278 | |
| 1279 | case PROMEX_DUMPER_LI: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1280 | if (ctx->flags & PROMEX_FL_SCOPE_LI) { |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 1281 | ret = promex_dump_listener_metrics(appctx, htx); |
| 1282 | if (ret <= 0) { |
| 1283 | if (ret == -1) |
| 1284 | goto error; |
| 1285 | goto full; |
| 1286 | } |
| 1287 | } |
| 1288 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1289 | ctx->px = proxies_list; |
| 1290 | ctx->st = NULL; |
| 1291 | ctx->li = NULL; |
| 1292 | ctx->sv = NULL; |
| 1293 | ctx->flags &= ~PROMEX_FL_LI_METRIC; |
| 1294 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_BACK_METRIC); |
| 1295 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1296 | ctx->field_num = ST_F_PXNAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1297 | appctx->st1 = PROMEX_DUMPER_BACK; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1298 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1299 | |
| 1300 | case PROMEX_DUMPER_BACK: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1301 | if (ctx->flags & PROMEX_FL_SCOPE_BACK) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1302 | ret = promex_dump_back_metrics(appctx, htx); |
| 1303 | if (ret <= 0) { |
| 1304 | if (ret == -1) |
| 1305 | goto error; |
| 1306 | goto full; |
| 1307 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1308 | } |
| 1309 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1310 | ctx->px = proxies_list; |
| 1311 | ctx->st = NULL; |
| 1312 | ctx->li = NULL; |
| 1313 | ctx->sv = ctx->px ? ctx->px->srv : NULL; |
| 1314 | ctx->flags &= ~PROMEX_FL_BACK_METRIC; |
| 1315 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_SRV_METRIC); |
| 1316 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1317 | ctx->field_num = ST_F_PXNAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1318 | appctx->st1 = PROMEX_DUMPER_SRV; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1319 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1320 | |
| 1321 | case PROMEX_DUMPER_SRV: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1322 | if (ctx->flags & PROMEX_FL_SCOPE_SERVER) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1323 | ret = promex_dump_srv_metrics(appctx, htx); |
| 1324 | if (ret <= 0) { |
| 1325 | if (ret == -1) |
| 1326 | goto error; |
| 1327 | goto full; |
| 1328 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1329 | } |
| 1330 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1331 | ctx->px = NULL; |
| 1332 | ctx->st = stktables_list; |
| 1333 | ctx->li = NULL; |
| 1334 | ctx->sv = NULL; |
| 1335 | ctx->flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_SRV_METRIC); |
| 1336 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STICKTABLE_METRIC); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1337 | ctx->field_num = STICKTABLE_SIZE; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1338 | appctx->st1 = PROMEX_DUMPER_STICKTABLE; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1339 | __fallthrough; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1340 | |
| 1341 | case PROMEX_DUMPER_STICKTABLE: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1342 | if (ctx->flags & PROMEX_FL_SCOPE_STICKTABLE) { |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1343 | ret = promex_dump_sticktable_metrics(appctx, htx); |
| 1344 | if (ret <= 0) { |
| 1345 | if (ret == -1) |
| 1346 | goto error; |
| 1347 | goto full; |
| 1348 | } |
| 1349 | } |
| 1350 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1351 | ctx->px = NULL; |
| 1352 | ctx->st = NULL; |
| 1353 | ctx->li = NULL; |
| 1354 | ctx->sv = NULL; |
| 1355 | ctx->flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_STICKTABLE_METRIC); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1356 | ctx->field_num = 0; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1357 | appctx->st1 = PROMEX_DUMPER_DONE; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1358 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1359 | |
| 1360 | case PROMEX_DUMPER_DONE: |
| 1361 | default: |
| 1362 | break; |
| 1363 | } |
| 1364 | |
| 1365 | return 1; |
| 1366 | |
| 1367 | full: |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1368 | sc_need_room(sc); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1369 | return 0; |
| 1370 | error: |
| 1371 | /* unrecoverable error */ |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1372 | ctx->px = NULL; |
| 1373 | ctx->st = NULL; |
| 1374 | ctx->li = NULL; |
| 1375 | ctx->sv = NULL; |
| 1376 | ctx->flags = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1377 | ctx->field_num = 0; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1378 | appctx->st1 = PROMEX_DUMPER_DONE; |
| 1379 | return -1; |
| 1380 | } |
| 1381 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1382 | /* Parse the query string of request URI to filter the metrics. It returns 1 on |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1383 | * success and -1 on error. */ |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1384 | static int promex_parse_uri(struct appctx *appctx, struct stconn *sc) |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1385 | { |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1386 | struct promex_ctx *ctx = appctx->svcctx; |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1387 | struct channel *req = sc_oc(sc); |
| 1388 | struct channel *res = sc_ic(sc); |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1389 | struct htx *req_htx, *res_htx; |
| 1390 | struct htx_sl *sl; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1391 | char *p, *key, *value; |
| 1392 | const char *end; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1393 | struct buffer *err; |
| 1394 | int default_scopes = PROMEX_FL_SCOPE_ALL; |
| 1395 | int len; |
| 1396 | |
| 1397 | /* Get the query-string */ |
| 1398 | req_htx = htxbuf(&req->buf); |
| 1399 | sl = http_get_stline(req_htx); |
| 1400 | if (!sl) |
| 1401 | goto error; |
| 1402 | p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?'); |
| 1403 | if (!p) |
| 1404 | goto end; |
| 1405 | end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1406 | |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1407 | /* copy the query-string */ |
| 1408 | len = end - p; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1409 | chunk_reset(&trash); |
| 1410 | memcpy(trash.area, p, len); |
| 1411 | trash.area[len] = 0; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1412 | p = trash.area; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1413 | end = trash.area + len; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1414 | |
| 1415 | /* Parse the query-string */ |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1416 | while (p < end && *p && *p != '#') { |
| 1417 | value = NULL; |
| 1418 | |
| 1419 | /* decode parameter name */ |
| 1420 | key = p; |
| 1421 | while (p < end && *p != '=' && *p != '&' && *p != '#') |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1422 | ++p; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1423 | /* found a value */ |
| 1424 | if (*p == '=') { |
| 1425 | *(p++) = 0; |
| 1426 | value = p; |
| 1427 | } |
| 1428 | else if (*p == '&') |
| 1429 | *(p++) = 0; |
| 1430 | else if (*p == '#') |
| 1431 | *p = 0; |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 1432 | len = url_decode(key, 1); |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1433 | if (len == -1) |
| 1434 | goto error; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1435 | |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1436 | /* decode value */ |
| 1437 | if (value) { |
| 1438 | while (p < end && *p != '=' && *p != '&' && *p != '#') |
| 1439 | ++p; |
| 1440 | if (*p == '=') |
| 1441 | goto error; |
| 1442 | if (*p == '&') |
| 1443 | *(p++) = 0; |
| 1444 | else if (*p == '#') |
| 1445 | *p = 0; |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 1446 | len = url_decode(value, 1); |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1447 | if (len == -1) |
| 1448 | goto error; |
| 1449 | } |
| 1450 | |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1451 | if (strcmp(key, "scope") == 0) { |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1452 | default_scopes = 0; /* at least a scope defined, unset default scopes */ |
| 1453 | if (!value) |
| 1454 | goto error; |
| 1455 | else if (*value == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1456 | ctx->flags &= ~PROMEX_FL_SCOPE_ALL; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1457 | else if (*value == '*') |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1458 | ctx->flags |= PROMEX_FL_SCOPE_ALL; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1459 | else if (strcmp(value, "global") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1460 | ctx->flags |= PROMEX_FL_SCOPE_GLOBAL; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1461 | else if (strcmp(value, "server") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1462 | ctx->flags |= PROMEX_FL_SCOPE_SERVER; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1463 | else if (strcmp(value, "backend") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1464 | ctx->flags |= PROMEX_FL_SCOPE_BACK; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1465 | else if (strcmp(value, "frontend") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1466 | ctx->flags |= PROMEX_FL_SCOPE_FRONT; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 1467 | else if (strcmp(value, "listener") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1468 | ctx->flags |= PROMEX_FL_SCOPE_LI; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1469 | else if (strcmp(value, "sticktable") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1470 | ctx->flags |= PROMEX_FL_SCOPE_STICKTABLE; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1471 | else |
| 1472 | goto error; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1473 | } |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1474 | else if (strcmp(key, "no-maint") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1475 | ctx->flags |= PROMEX_FL_NO_MAINT_SRV; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | end: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1479 | ctx->flags |= default_scopes; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1480 | return 1; |
| 1481 | |
| 1482 | error: |
| 1483 | err = &http_err_chunks[HTTP_ERR_400]; |
| 1484 | channel_erase(res); |
| 1485 | res->buf.data = b_data(err); |
| 1486 | memcpy(res->buf.area, b_head(err), b_data(err)); |
| 1487 | res_htx = htx_from_buf(&res->buf); |
| 1488 | channel_add_input(res, res_htx->data); |
| 1489 | appctx->st0 = PROMEX_ST_END; |
| 1490 | return -1; |
| 1491 | } |
| 1492 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1493 | /* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is |
| 1494 | * full. */ |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1495 | static int promex_send_headers(struct appctx *appctx, struct stconn *sc, struct htx *htx) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1496 | { |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1497 | struct channel *chn = sc_ic(sc); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1498 | struct htx_sl *sl; |
| 1499 | unsigned int flags; |
| 1500 | |
| 1501 | 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); |
| 1502 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 1503 | if (!sl) |
| 1504 | goto full; |
| 1505 | sl->info.res.status = 200; |
| 1506 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1507 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) || |
| 1508 | !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) || |
| 1509 | !htx_add_endof(htx, HTX_BLK_EOH)) |
| 1510 | goto full; |
| 1511 | |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1512 | channel_add_input(chn, htx->data); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1513 | return 1; |
| 1514 | full: |
| 1515 | htx_reset(htx); |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1516 | sc_need_room(sc); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | /* The function returns 1 if the initialisation is complete, 0 if |
| 1521 | * an errors occurs and -1 if more data are required for initializing |
| 1522 | * the applet. |
| 1523 | */ |
Christopher Faulet | 4aa1d28 | 2022-01-13 16:01:35 +0100 | [diff] [blame] | 1524 | static int promex_appctx_init(struct appctx *appctx) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1525 | { |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1526 | applet_reserve_svcctx(appctx, sizeof(struct promex_ctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1527 | appctx->st0 = PROMEX_ST_INIT; |
Christopher Faulet | c992938 | 2022-05-12 11:52:27 +0200 | [diff] [blame] | 1528 | return 0; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | /* The main I/O handler for the promex applet. */ |
| 1532 | static void promex_appctx_handle_io(struct appctx *appctx) |
| 1533 | { |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 1534 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1535 | struct stream *s = __sc_strm(sc); |
| 1536 | struct channel *req = sc_oc(sc); |
| 1537 | struct channel *res = sc_ic(sc); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1538 | struct htx *req_htx, *res_htx; |
| 1539 | int ret; |
| 1540 | |
| 1541 | res_htx = htx_from_buf(&res->buf); |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1542 | if (unlikely(sc->state == SC_ST_DIS || sc->state == SC_ST_CLO)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1543 | goto out; |
| 1544 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1545 | /* Check if the input buffer is available. */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1546 | if (!b_size(&res->buf)) { |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1547 | sc_need_room(sc); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1548 | goto out; |
| 1549 | } |
| 1550 | |
| 1551 | switch (appctx->st0) { |
| 1552 | case PROMEX_ST_INIT: |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1553 | ret = promex_parse_uri(appctx, sc); |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1554 | if (ret <= 0) { |
| 1555 | if (ret == -1) |
| 1556 | goto error; |
| 1557 | goto out; |
| 1558 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1559 | appctx->st0 = PROMEX_ST_HEAD; |
| 1560 | appctx->st1 = PROMEX_DUMPER_INIT; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1561 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1562 | |
| 1563 | case PROMEX_ST_HEAD: |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1564 | if (!promex_send_headers(appctx, sc, res_htx)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1565 | goto out; |
| 1566 | appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP); |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1567 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1568 | |
| 1569 | case PROMEX_ST_DUMP: |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1570 | ret = promex_dump_metrics(appctx, sc, res_htx); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1571 | if (ret <= 0) { |
| 1572 | if (ret == -1) |
| 1573 | goto error; |
| 1574 | goto out; |
| 1575 | } |
| 1576 | appctx->st0 = PROMEX_ST_DONE; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1577 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1578 | |
| 1579 | case PROMEX_ST_DONE: |
Christopher Faulet | be69cbd | 2022-04-07 10:19:46 +0200 | [diff] [blame] | 1580 | /* no more data are expected. If the response buffer is |
| 1581 | * empty, be sure to add something (EOT block in this |
| 1582 | * case) to have something to send. It is important to |
| 1583 | * be sure the EOM flags will be handled by the |
| 1584 | * endpoint. |
| 1585 | */ |
| 1586 | if (htx_is_empty(res_htx)) { |
| 1587 | if (!htx_add_endof(res_htx, HTX_BLK_EOT)) { |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1588 | sc_need_room(sc); |
Christopher Faulet | be69cbd | 2022-04-07 10:19:46 +0200 | [diff] [blame] | 1589 | goto out; |
| 1590 | } |
| 1591 | channel_add_input(res, 1); |
| 1592 | } |
| 1593 | res_htx->flags |= HTX_FL_EOM; |
Christopher Faulet | bef64b2 | 2022-03-07 15:56:20 +0100 | [diff] [blame] | 1594 | res->flags |= CF_EOI; |
Willy Tarreau | d869e13 | 2022-05-17 18:05:31 +0200 | [diff] [blame] | 1595 | se_fl_set(appctx->sedesc, SE_FL_EOI); |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1596 | appctx->st0 = PROMEX_ST_END; |
Willy Tarreau | 913bea5 | 2022-11-14 07:37:45 +0100 | [diff] [blame] | 1597 | __fallthrough; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1598 | |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1599 | case PROMEX_ST_END: |
| 1600 | if (!(res->flags & CF_SHUTR)) { |
| 1601 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1602 | sc_shutr(sc); |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1603 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1604 | } |
| 1605 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1606 | out: |
| 1607 | htx_to_buf(res_htx, &res->buf); |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1608 | |
| 1609 | /* eat the whole request */ |
| 1610 | if (co_data(req)) { |
| 1611 | req_htx = htx_from_buf(&req->buf); |
| 1612 | co_htx_skip(req, req_htx, co_data(req)); |
| 1613 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1614 | return; |
| 1615 | |
| 1616 | error: |
| 1617 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 4c218fb | 2022-05-27 10:16:15 +0200 | [diff] [blame] | 1618 | sc_shutr(sc); |
| 1619 | sc_shutw(sc); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | struct applet promex_applet = { |
| 1623 | .obj_type = OBJ_TYPE_APPLET, |
| 1624 | .name = "<PROMEX>", /* used for logging */ |
| 1625 | .init = promex_appctx_init, |
| 1626 | .fct = promex_appctx_handle_io, |
| 1627 | }; |
| 1628 | |
| 1629 | static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px, |
| 1630 | struct act_rule *rule, char **err) |
| 1631 | { |
| 1632 | /* Prometheus exporter service is only available on "http-request" rulesets */ |
| 1633 | if (rule->from != ACT_F_HTTP_REQ) { |
| 1634 | memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets"); |
| 1635 | return ACT_RET_PRS_ERR; |
| 1636 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1637 | |
| 1638 | /* Add applet pointer in the rule. */ |
| 1639 | rule->applet = promex_applet; |
| 1640 | |
| 1641 | return ACT_RET_PRS_OK; |
| 1642 | } |
| 1643 | static void promex_register_build_options(void) |
| 1644 | { |
| 1645 | char *ptr = NULL; |
| 1646 | |
| 1647 | memprintf(&ptr, "Built with the Prometheus exporter as a service"); |
| 1648 | hap_register_build_opts(ptr, 1); |
| 1649 | } |
| 1650 | |
| 1651 | |
| 1652 | static struct action_kw_list service_actions = { ILH, { |
| 1653 | { "prometheus-exporter", service_parse_prometheus_exporter }, |
| 1654 | { /* END */ } |
| 1655 | }}; |
| 1656 | |
| 1657 | INITCALL1(STG_REGISTER, service_keywords_register, &service_actions); |
| 1658 | INITCALL0(STG_REGISTER, promex_register_build_options); |