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> |
Christopher Faulet | 908628c | 2022-03-25 16:43:49 +0100 | [diff] [blame] | 22 | #include <haproxy/conn_stream.h> |
| 23 | #include <haproxy/cs_utils.h> |
Willy Tarreau | 762d7a5 | 2020-06-04 11:23:07 +0200 | [diff] [blame] | 24 | #include <haproxy/frontend.h> |
Willy Tarreau | f268ee8 | 2020-06-04 17:05:57 +0200 | [diff] [blame] | 25 | #include <haproxy/global.h> |
Willy Tarreau | cd72d8c | 2020-06-02 19:11:26 +0200 | [diff] [blame] | 26 | #include <haproxy/http.h> |
Willy Tarreau | b7fc4c4 | 2021-10-06 18:56:42 +0200 | [diff] [blame] | 27 | #include <haproxy/http_ana.h> |
Willy Tarreau | 8773533 | 2020-06-04 09:08:41 +0200 | [diff] [blame] | 28 | #include <haproxy/http_htx.h> |
Willy Tarreau | 16f958c | 2020-06-03 08:44:35 +0200 | [diff] [blame] | 29 | #include <haproxy/htx.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 30 | #include <haproxy/list.h> |
Willy Tarreau | 213e990 | 2020-06-04 14:58:24 +0200 | [diff] [blame] | 31 | #include <haproxy/listener.h> |
Willy Tarreau | 36979d9 | 2020-06-05 17:27:29 +0200 | [diff] [blame] | 32 | #include <haproxy/log.h> |
Willy Tarreau | a264d96 | 2020-06-04 22:29:18 +0200 | [diff] [blame] | 33 | #include <haproxy/proxy.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 34 | #include <haproxy/sample.h> |
Willy Tarreau | 1e56f92 | 2020-06-04 23:20:13 +0200 | [diff] [blame] | 35 | #include <haproxy/server.h> |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 36 | #include <haproxy/stats.h> |
Willy Tarreau | dfd3de8 | 2020-06-04 23:46:14 +0200 | [diff] [blame] | 37 | #include <haproxy/stream.h> |
Willy Tarreau | 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 ) }, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 305 | }; |
| 306 | |
Ilya Shipitsin | acf8459 | 2021-02-06 22:29:08 +0500 | [diff] [blame] | 307 | /* Description of overridden stats fields */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 308 | const struct ist promex_st_metric_desc[ST_F_TOTAL_FIELDS] = { |
William Dauchy | a1da7ba | 2021-02-01 13:11:52 +0100 | [diff] [blame] | 309 | [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] | 310 | [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] | 311 | [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] | 312 | [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] | 313 | [ST_F_QTIME] = IST("Avg. queue time for last 1024 successful connections."), |
| 314 | [ST_F_CTIME] = IST("Avg. connect time for last 1024 successful connections."), |
| 315 | [ST_F_RTIME] = IST("Avg. response time for last 1024 successful connections."), |
| 316 | [ST_F_TTIME] = IST("Avg. total time for last 1024 successful connections."), |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 317 | [ST_F_QT_MAX] = IST("Maximum observed time spent in the queue"), |
| 318 | [ST_F_CT_MAX] = IST("Maximum observed time spent waiting for a connection to complete"), |
| 319 | [ST_F_RT_MAX] = IST("Maximum observed time spent waiting for a server response"), |
| 320 | [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] | 321 | }; |
| 322 | |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 323 | /* stick table base fields */ |
| 324 | enum sticktable_field { |
| 325 | STICKTABLE_SIZE = 0, |
| 326 | STICKTABLE_USED, |
| 327 | /* must always be the last one */ |
| 328 | STICKTABLE_TOTAL_FIELDS |
| 329 | }; |
| 330 | |
| 331 | const struct promex_metric promex_sticktable_metrics[STICKTABLE_TOTAL_FIELDS] = { |
| 332 | [STICKTABLE_SIZE] = { .n = IST("size"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_STICKTABLE_METRIC }, |
| 333 | [STICKTABLE_USED] = { .n = IST("used"), .type = PROMEX_MT_GAUGE, .flags = PROMEX_FL_STICKTABLE_METRIC }, |
| 334 | }; |
| 335 | |
| 336 | /* stick table base description */ |
| 337 | const struct ist promex_sticktable_metric_desc[STICKTABLE_TOTAL_FIELDS] = { |
| 338 | [STICKTABLE_SIZE] = IST("Stick table size."), |
| 339 | [STICKTABLE_USED] = IST("Number of entries used in this stick table."), |
| 340 | }; |
| 341 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 342 | /* Specific labels for all ST_F_HRSP_* fields */ |
| 343 | const struct ist promex_hrsp_code[1 + ST_F_HRSP_OTHER - ST_F_HRSP_1XX] = { |
| 344 | [ST_F_HRSP_1XX - ST_F_HRSP_1XX] = IST("1xx"), |
| 345 | [ST_F_HRSP_2XX - ST_F_HRSP_1XX] = IST("2xx"), |
| 346 | [ST_F_HRSP_3XX - ST_F_HRSP_1XX] = IST("3xx"), |
| 347 | [ST_F_HRSP_4XX - ST_F_HRSP_1XX] = IST("4xx"), |
| 348 | [ST_F_HRSP_5XX - ST_F_HRSP_1XX] = IST("5xx"), |
| 349 | [ST_F_HRSP_OTHER - ST_F_HRSP_1XX] = IST("other"), |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 350 | }; |
| 351 | |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 352 | enum promex_front_state { |
| 353 | PROMEX_FRONT_STATE_DOWN = 0, |
| 354 | PROMEX_FRONT_STATE_UP, |
| 355 | |
| 356 | PROMEX_FRONT_STATE_COUNT /* must be last */ |
| 357 | }; |
| 358 | |
| 359 | const struct ist promex_front_st[PROMEX_FRONT_STATE_COUNT] = { |
| 360 | [PROMEX_FRONT_STATE_DOWN] = IST("DOWN"), |
| 361 | [PROMEX_FRONT_STATE_UP] = IST("UP"), |
| 362 | }; |
| 363 | |
| 364 | enum promex_back_state { |
| 365 | PROMEX_BACK_STATE_DOWN = 0, |
| 366 | PROMEX_BACK_STATE_UP, |
| 367 | |
| 368 | PROMEX_BACK_STATE_COUNT /* must be last */ |
| 369 | }; |
| 370 | |
| 371 | const struct ist promex_back_st[PROMEX_BACK_STATE_COUNT] = { |
| 372 | [PROMEX_BACK_STATE_DOWN] = IST("DOWN"), |
| 373 | [PROMEX_BACK_STATE_UP] = IST("UP"), |
| 374 | }; |
| 375 | |
| 376 | enum promex_srv_state { |
| 377 | PROMEX_SRV_STATE_DOWN = 0, |
| 378 | PROMEX_SRV_STATE_UP, |
| 379 | PROMEX_SRV_STATE_MAINT, |
| 380 | PROMEX_SRV_STATE_DRAIN, |
| 381 | PROMEX_SRV_STATE_NOLB, |
| 382 | |
| 383 | PROMEX_SRV_STATE_COUNT /* must be last */ |
| 384 | }; |
| 385 | |
| 386 | const struct ist promex_srv_st[PROMEX_SRV_STATE_COUNT] = { |
| 387 | [PROMEX_SRV_STATE_DOWN] = IST("DOWN"), |
| 388 | [PROMEX_SRV_STATE_UP] = IST("UP"), |
| 389 | [PROMEX_SRV_STATE_MAINT] = IST("MAINT"), |
| 390 | [PROMEX_SRV_STATE_DRAIN] = IST("DRAIN"), |
| 391 | [PROMEX_SRV_STATE_NOLB] = IST("NOLB"), |
| 392 | }; |
| 393 | |
| 394 | /* Return the server status. */ |
| 395 | enum promex_srv_state promex_srv_status(struct server *sv) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 396 | { |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 397 | int state = PROMEX_SRV_STATE_DOWN; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 398 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 399 | 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] | 400 | state = PROMEX_SRV_STATE_UP; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 401 | if (sv->cur_admin & SRV_ADMF_DRAIN) |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 402 | state = PROMEX_SRV_STATE_DRAIN; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 403 | } |
Christopher Faulet | d45d105 | 2019-09-06 16:10:19 +0200 | [diff] [blame] | 404 | else if (sv->cur_state == SRV_ST_STOPPING) |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 405 | state = PROMEX_SRV_STATE_NOLB; |
Christopher Faulet | d45d105 | 2019-09-06 16:10:19 +0200 | [diff] [blame] | 406 | |
| 407 | if (sv->cur_admin & SRV_ADMF_MAINT) |
William Dauchy | 5493821 | 2021-01-27 22:40:16 +0100 | [diff] [blame] | 408 | state = PROMEX_SRV_STATE_MAINT; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 409 | |
| 410 | return state; |
| 411 | } |
| 412 | |
| 413 | /* Convert a field to its string representation and write it in <out>, followed |
| 414 | * 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] | 415 | * "NaN" because Prometheus only support numerical values (but it is unexepceted |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 416 | * to process this kind of value). It returns 1 on success. Otherwise, it |
| 417 | * returns 0. The buffer's length must not exceed <max> value. |
| 418 | */ |
| 419 | static int promex_metric_to_str(struct buffer *out, struct field *f, size_t max) |
| 420 | { |
| 421 | int ret = 0; |
| 422 | |
| 423 | switch (field_format(f, 0)) { |
William Dauchy | 18a2c6e | 2021-01-22 21:09:47 +0100 | [diff] [blame] | 424 | case FF_EMPTY: ret = chunk_strcat(out, "NaN\n"); break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 425 | case FF_S32: ret = chunk_appendf(out, "%d\n", f->u.s32); break; |
| 426 | case FF_U32: ret = chunk_appendf(out, "%u\n", f->u.u32); break; |
| 427 | case FF_S64: ret = chunk_appendf(out, "%lld\n", (long long)f->u.s64); break; |
| 428 | 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] | 429 | 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] | 430 | case FF_STR: ret = chunk_strcat(out, "NaN\n"); break; |
| 431 | default: ret = chunk_strcat(out, "NaN\n"); break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 432 | } |
| 433 | if (!ret || out->data > max) |
| 434 | return 0; |
| 435 | return 1; |
| 436 | } |
| 437 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 438 | /* Dump the header lines for <metric>. It is its #HELP and #TYPE strings. It |
| 439 | * returns 1 on success. Otherwise, if <out> length exceeds <max>, it returns 0. |
| 440 | */ |
| 441 | static int promex_dump_metric_header(struct appctx *appctx, struct htx *htx, |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 442 | const struct promex_metric *metric, const struct ist name, |
| 443 | struct ist *out, size_t max) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 444 | { |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 445 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 446 | struct ist type; |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 447 | struct ist desc; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 448 | |
| 449 | switch (metric->type) { |
| 450 | case PROMEX_MT_COUNTER: |
| 451 | type = ist("counter"); |
| 452 | break; |
| 453 | default: |
| 454 | type = ist("gauge"); |
| 455 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 456 | |
William Dauchy | a191b77 | 2021-01-15 22:41:39 +0100 | [diff] [blame] | 457 | if (istcat(out, ist("# HELP "), max) == -1 || |
| 458 | istcat(out, name, max) == -1 || |
| 459 | istcat(out, ist(" "), max) == -1) |
| 460 | goto full; |
| 461 | |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 462 | if (metric->flags & PROMEX_FL_INFO_METRIC) |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 463 | desc = ist(info_fields[ctx->field_num].desc); |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 464 | else if (metric->flags & PROMEX_FL_STICKTABLE_METRIC) |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 465 | desc = promex_sticktable_metric_desc[ctx->field_num]; |
| 466 | else if (!isttest(promex_st_metric_desc[ctx->field_num])) |
| 467 | desc = ist(stat_fields[ctx->field_num].desc); |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 468 | else |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 469 | desc = promex_st_metric_desc[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 470 | |
William Dauchy | 82b2ce2 | 2021-02-01 13:11:55 +0100 | [diff] [blame] | 471 | if (istcat(out, desc, max) == -1 || |
| 472 | istcat(out, ist("\n# TYPE "), max) == -1 || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 473 | istcat(out, name, max) == -1 || |
| 474 | istcat(out, ist(" "), max) == -1 || |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 475 | istcat(out, type, max) == -1 || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 476 | istcat(out, ist("\n"), max) == -1) |
| 477 | goto full; |
| 478 | |
| 479 | return 1; |
| 480 | |
| 481 | full: |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | /* Dump the line for <metric>. It starts by the metric name followed by its |
| 486 | * labels (proxy name, server name...) between braces and finally its value. If |
| 487 | * not already done, the header lines are dumped first. It returns 1 on |
| 488 | * success. Otherwise if <out> length exceeds <max>, it returns 0. |
| 489 | */ |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 490 | 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] | 491 | const struct promex_metric *metric, struct field *val, |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 492 | struct promex_label *labels, struct ist *out, size_t max) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 493 | { |
| 494 | struct ist name = { .ptr = (char[PROMEX_MAX_NAME_LEN]){ 0 }, .len = 0 }; |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 495 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 496 | size_t len = out->len; |
| 497 | |
| 498 | if (out->len + PROMEX_MAX_METRIC_LENGTH > max) |
| 499 | return 0; |
| 500 | |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 501 | /* Fill the metric name */ |
| 502 | istcat(&name, prefix, PROMEX_MAX_NAME_LEN); |
| 503 | istcat(&name, metric->n, PROMEX_MAX_NAME_LEN); |
| 504 | |
| 505 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 506 | if ((ctx->flags & PROMEX_FL_METRIC_HDR) && |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 507 | !promex_dump_metric_header(appctx, htx, metric, name, out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 508 | goto full; |
| 509 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 510 | if (istcat(out, name, max) == -1) |
| 511 | goto full; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 512 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 513 | if (isttest(labels[0].name)) { |
| 514 | int i; |
| 515 | |
| 516 | if (istcat(out, ist("{"), max) == -1) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 517 | goto full; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 518 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 519 | for (i = 0; isttest(labels[i].name); i++) { |
| 520 | if (!isttest(labels[i].value)) |
| 521 | continue; |
| 522 | |
| 523 | if ((i && istcat(out, ist(","), max) == -1) || |
| 524 | istcat(out, labels[i].name, max) == -1 || |
| 525 | istcat(out, ist("=\""), max) == -1 || |
| 526 | istcat(out, labels[i].value, max) == -1 || |
| 527 | istcat(out, ist("\""), max) == -1) |
| 528 | goto full; |
| 529 | } |
| 530 | |
| 531 | if (istcat(out, ist("}"), max) == -1) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 532 | goto full; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 533 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 534 | } |
| 535 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 536 | if (istcat(out, ist(" "), max) == -1) |
| 537 | goto full; |
| 538 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 539 | trash.data = out->len; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 540 | if (!promex_metric_to_str(&trash, val, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 541 | goto full; |
| 542 | out->len = trash.data; |
| 543 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 544 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 545 | return 1; |
| 546 | full: |
| 547 | // Restore previous length |
| 548 | out->len = len; |
| 549 | return 0; |
| 550 | |
| 551 | } |
| 552 | |
| 553 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 554 | /* Dump global metrics (prefixed by "haproxy_process_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 555 | * 0 if <htx> is full and -1 in case of any error. */ |
| 556 | static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx) |
| 557 | { |
| 558 | static struct ist prefix = IST("haproxy_process_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 559 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 560 | struct field val; |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 561 | struct channel *chn = sc_ic(appctx_cs(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 562 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 563 | 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] | 564 | int ret = 1; |
| 565 | |
Willy Tarreau | 0b26b38 | 2021-05-08 07:43:53 +0200 | [diff] [blame] | 566 | if (!stats_fill_info(info, INF_TOTAL_FIELDS, 0)) |
William Dauchy | 5d9b8f3 | 2021-01-11 20:07:49 +0100 | [diff] [blame] | 567 | return -1; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 568 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 569 | for (; ctx->field_num < INF_TOTAL_FIELDS; ctx->field_num++) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 570 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 571 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 572 | if (!(promex_global_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 573 | continue; |
| 574 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 575 | switch (ctx->field_num) { |
William Dauchy | 5a982a7 | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 576 | case INF_BUILD_INFO: |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 577 | labels[0].name = ist("version"); |
| 578 | labels[0].value = ist(HAPROXY_VERSION); |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 579 | val = mkf_u32(FN_GAUGE, 1); |
William Dauchy | 5a982a7 | 2021-01-08 13:18:06 +0100 | [diff] [blame] | 580 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 581 | |
| 582 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 583 | val = info[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 584 | } |
| 585 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 586 | 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] | 587 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 588 | goto full; |
| 589 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 590 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 594 | if (out.len) { |
| 595 | if (!htx_add_data_atonce(htx, out)) |
| 596 | return -1; /* Unexpected and unrecoverable error */ |
| 597 | channel_add_input(chn, out.len); |
| 598 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 599 | return ret; |
| 600 | full: |
| 601 | ret = 0; |
| 602 | goto end; |
| 603 | } |
| 604 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 605 | /* Dump frontends metrics (prefixed by "haproxy_frontend_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 606 | * 0 if <htx> is full and -1 in case of any error. */ |
| 607 | static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx) |
| 608 | { |
| 609 | static struct ist prefix = IST("haproxy_frontend_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 610 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 611 | struct proxy *px; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 612 | struct field val; |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 613 | struct channel *chn = sc_ic(appctx_cs(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 614 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 615 | 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] | 616 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 617 | int ret = 1; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 618 | enum promex_front_state state; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 619 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 620 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 621 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 622 | continue; |
| 623 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 624 | while (ctx->px) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 625 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 626 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 627 | px = ctx->px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 628 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 629 | labels[0].name = ist("proxy"); |
| 630 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 631 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 632 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 633 | 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] | 634 | goto next_px; |
| 635 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 636 | 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] | 637 | return -1; |
| 638 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 639 | switch (ctx->field_num) { |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 640 | case ST_F_STATUS: |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 641 | state = !(px->flags & PR_FL_STOPPED); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 642 | for (; ctx->obj_state < PROMEX_FRONT_STATE_COUNT; ctx->obj_state++) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 643 | labels[1].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 644 | labels[1].value = promex_front_st[ctx->obj_state]; |
| 645 | val = mkf_u32(FO_STATUS, state == ctx->obj_state); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 646 | 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] | 647 | &val, labels, &out, max)) |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 648 | goto full; |
| 649 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 650 | ctx->obj_state = 0; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 651 | goto next_px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 652 | case ST_F_REQ_RATE_MAX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 653 | case ST_F_REQ_TOT: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 654 | case ST_F_INTERCEPTED: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 655 | case ST_F_CACHE_LOOKUPS: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 656 | case ST_F_CACHE_HITS: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 657 | case ST_F_COMP_IN: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 658 | case ST_F_COMP_OUT: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 659 | case ST_F_COMP_BYP: |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 660 | case ST_F_COMP_RSP: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 661 | if (px->mode != PR_MODE_HTTP) |
| 662 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 663 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 664 | break; |
Christopher Faulet | 32ef48e | 2021-02-01 14:55:37 +0100 | [diff] [blame] | 665 | case ST_F_HRSP_1XX: |
William Dauchy | b957745 | 2021-01-17 18:27:46 +0100 | [diff] [blame] | 666 | case ST_F_HRSP_2XX: |
| 667 | case ST_F_HRSP_3XX: |
| 668 | case ST_F_HRSP_4XX: |
| 669 | case ST_F_HRSP_5XX: |
| 670 | case ST_F_HRSP_OTHER: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 671 | if (px->mode != PR_MODE_HTTP) |
| 672 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 673 | if (ctx->field_num != ST_F_HRSP_1XX) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 674 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 675 | labels[1].name = ist("code"); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 676 | labels[1].value = promex_hrsp_code[ctx->field_num - ST_F_HRSP_1XX]; |
| 677 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 681 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 684 | 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] | 685 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 686 | goto full; |
| 687 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 688 | ctx->px = px->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 689 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 690 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 691 | ctx->px = proxies_list; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 695 | if (out.len) { |
| 696 | if (!htx_add_data_atonce(htx, out)) |
| 697 | return -1; /* Unexpected and unrecoverable error */ |
| 698 | channel_add_input(chn, out.len); |
| 699 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 700 | return ret; |
| 701 | full: |
| 702 | ret = 0; |
| 703 | goto end; |
| 704 | } |
| 705 | |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 706 | /* Dump listener metrics (prefixed by "haproxy_listen_"). It returns 1 on |
| 707 | * success, 0 if <htx> is full and -1 in case of any error. */ |
| 708 | static int promex_dump_listener_metrics(struct appctx *appctx, struct htx *htx) |
| 709 | { |
| 710 | static struct ist prefix = IST("haproxy_listener_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 711 | struct promex_ctx *ctx = appctx->svcctx; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 712 | struct proxy *px; |
| 713 | struct field val; |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 714 | struct channel *chn = sc_ic(appctx_cs(appctx)); |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 715 | struct ist out = ist2(trash.area, 0); |
| 716 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
| 717 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
| 718 | struct listener *li; |
| 719 | int ret = 1; |
| 720 | enum li_status status; |
| 721 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 722 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 723 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 724 | continue; |
| 725 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 726 | while (ctx->px) { |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 727 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 728 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 729 | px = ctx->px; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 730 | |
| 731 | labels[0].name = ist("proxy"); |
| 732 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 733 | |
| 734 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 735 | 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] | 736 | goto next_px; |
| 737 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 738 | li = ctx->li; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 739 | list_for_each_entry_from(li, &px->conf.listeners, by_fe) { |
| 740 | |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 741 | if (!li->counters) |
| 742 | continue; |
| 743 | |
William Dauchy | baf2273 | 2021-02-25 00:53:13 +0100 | [diff] [blame] | 744 | labels[1].name = ist("listener"); |
| 745 | labels[1].value = ist2(li->name, strlen(li->name)); |
| 746 | |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 747 | if (!stats_fill_li_stats(px, li, 0, stats, |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 748 | ST_F_TOTAL_FIELDS, &(ctx->field_num))) |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 749 | return -1; |
| 750 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 751 | switch (ctx->field_num) { |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 752 | case ST_F_STATUS: |
| 753 | status = get_li_status(li); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 754 | for (; ctx->obj_state < LI_STATE_COUNT; ctx->obj_state++) { |
| 755 | val = mkf_u32(FO_STATUS, status == ctx->obj_state); |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 756 | labels[2].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 757 | labels[2].value = ist(li_status_st[ctx->obj_state]); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 758 | 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] | 759 | &val, labels, &out, max)) |
| 760 | goto full; |
| 761 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 762 | ctx->obj_state = 0; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 763 | continue; |
| 764 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 765 | val = stats[ctx->field_num]; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | if (!promex_dump_metric(appctx, htx, prefix, |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 769 | &promex_st_metrics[ctx->field_num], |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 770 | &val, labels, &out, max)) |
| 771 | goto full; |
| 772 | } |
| 773 | |
| 774 | next_px: |
| 775 | px = px->next; |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 776 | ctx->px = px; |
| 777 | 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] | 778 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 779 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 780 | ctx->px = proxies_list; |
| 781 | ctx->li = LIST_NEXT(&proxies_list->conf.listeners, struct listener *, by_fe); |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | end: |
| 785 | if (out.len) { |
| 786 | if (!htx_add_data_atonce(htx, out)) |
| 787 | return -1; /* Unexpected and unrecoverable error */ |
| 788 | channel_add_input(chn, out.len); |
| 789 | } |
| 790 | return ret; |
| 791 | full: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 792 | ctx->li = li; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 793 | ret = 0; |
| 794 | goto end; |
| 795 | } |
| 796 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 797 | /* Dump backends metrics (prefixed by "haproxy_backend_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 798 | * 0 if <htx> is full and -1 in case of any error. */ |
| 799 | static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx) |
| 800 | { |
| 801 | static struct ist prefix = IST("haproxy_backend_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 802 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 803 | struct proxy *px; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 804 | struct server *sv; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 805 | struct field val; |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 806 | struct channel *chn = sc_ic(appctx_cs(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 807 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 808 | 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] | 809 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 810 | int ret = 1; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 811 | double secs; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 812 | enum promex_back_state bkd_state; |
| 813 | enum promex_srv_state srv_state; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 814 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 815 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 816 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 817 | continue; |
| 818 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 819 | while (ctx->px) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 820 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 821 | unsigned int srv_state_count[PROMEX_SRV_STATE_COUNT] = { 0 }; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 822 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 823 | px = ctx->px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 824 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 825 | labels[0].name = ist("proxy"); |
| 826 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 827 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 828 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 829 | 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] | 830 | goto next_px; |
| 831 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 832 | 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] | 833 | return -1; |
| 834 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 835 | switch (ctx->field_num) { |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 836 | case ST_F_AGG_SRV_CHECK_STATUS: |
| 837 | if (!px->srv) |
| 838 | goto next_px; |
| 839 | sv = px->srv; |
| 840 | while (sv) { |
| 841 | srv_state = promex_srv_status(sv); |
| 842 | srv_state_count[srv_state] += 1; |
| 843 | sv = sv->next; |
| 844 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 845 | for (; ctx->obj_state < PROMEX_SRV_STATE_COUNT; ctx->obj_state++) { |
| 846 | val = mkf_u32(FN_GAUGE, srv_state_count[ctx->obj_state]); |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 847 | labels[1].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 848 | labels[1].value = promex_srv_st[ctx->obj_state]; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 849 | 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] | 850 | &val, labels, &out, max)) |
| 851 | goto full; |
| 852 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 853 | ctx->obj_state = 0; |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 854 | goto next_px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 855 | case ST_F_STATUS: |
William Dauchy | 42d7c40 | 2021-11-07 10:18:47 +0100 | [diff] [blame] | 856 | bkd_state = ((px->lbprm.tot_weight > 0 || !px->srv) ? 1 : 0); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 857 | for (; ctx->obj_state < PROMEX_BACK_STATE_COUNT; ctx->obj_state++) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 858 | labels[1].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 859 | labels[1].value = promex_back_st[ctx->obj_state]; |
| 860 | val = mkf_u32(FO_STATUS, bkd_state == ctx->obj_state); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 861 | 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] | 862 | &val, labels, &out, max)) |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 863 | goto full; |
| 864 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 865 | ctx->obj_state = 0; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 866 | goto next_px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 867 | case ST_F_QTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 868 | 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] | 869 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 870 | break; |
| 871 | case ST_F_CTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 872 | 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] | 873 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 874 | break; |
| 875 | case ST_F_RTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 876 | 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] | 877 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 878 | break; |
| 879 | case ST_F_TTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 880 | 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] | 881 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 882 | break; |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 883 | case ST_F_QT_MAX: |
| 884 | secs = (double)px->be_counters.qtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 885 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 886 | break; |
| 887 | case ST_F_CT_MAX: |
| 888 | secs = (double)px->be_counters.ctime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 889 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 890 | break; |
| 891 | case ST_F_RT_MAX: |
| 892 | secs = (double)px->be_counters.dtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 893 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 894 | break; |
| 895 | case ST_F_TT_MAX: |
| 896 | secs = (double)px->be_counters.ttime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 897 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 898 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 899 | case ST_F_REQ_TOT: |
William Dauchy | 3c6f006 | 2021-01-25 17:29:02 +0100 | [diff] [blame] | 900 | case ST_F_CACHE_LOOKUPS: |
| 901 | case ST_F_CACHE_HITS: |
| 902 | case ST_F_COMP_IN: |
| 903 | case ST_F_COMP_OUT: |
| 904 | case ST_F_COMP_BYP: |
| 905 | case ST_F_COMP_RSP: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 906 | if (px->mode != PR_MODE_HTTP) |
| 907 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 908 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 909 | break; |
Christopher Faulet | 32ef48e | 2021-02-01 14:55:37 +0100 | [diff] [blame] | 910 | case ST_F_HRSP_1XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 911 | case ST_F_HRSP_2XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 912 | case ST_F_HRSP_3XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 913 | case ST_F_HRSP_4XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 914 | case ST_F_HRSP_5XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 915 | case ST_F_HRSP_OTHER: |
| 916 | if (px->mode != PR_MODE_HTTP) |
| 917 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 918 | if (ctx->field_num != ST_F_HRSP_1XX) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 919 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 920 | labels[1].name = ist("code"); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 921 | labels[1].value = promex_hrsp_code[ctx->field_num - ST_F_HRSP_1XX]; |
| 922 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 923 | break; |
| 924 | |
| 925 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 926 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 927 | } |
| 928 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 929 | 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] | 930 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 931 | goto full; |
| 932 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 933 | ctx->px = px->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 934 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 935 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 936 | ctx->px = proxies_list; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 940 | if (out.len) { |
| 941 | if (!htx_add_data_atonce(htx, out)) |
| 942 | return -1; /* Unexpected and unrecoverable error */ |
| 943 | channel_add_input(chn, out.len); |
| 944 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 945 | return ret; |
| 946 | full: |
| 947 | ret = 0; |
| 948 | goto end; |
| 949 | } |
| 950 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 951 | /* Dump servers metrics (prefixed by "haproxy_server_"). It returns 1 on success, |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 952 | * 0 if <htx> is full and -1 in case of any error. */ |
| 953 | static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx) |
| 954 | { |
| 955 | static struct ist prefix = IST("haproxy_server_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 956 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 957 | struct proxy *px; |
| 958 | struct server *sv; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 959 | struct field val; |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 960 | struct channel *chn = sc_ic(appctx_cs(appctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 961 | struct ist out = ist2(trash.area, 0); |
Christopher Faulet | 11921e6 | 2019-07-03 11:43:17 +0200 | [diff] [blame] | 962 | 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] | 963 | struct field *stats = stat_l[STATS_DOMAIN_PROXY]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 964 | int ret = 1; |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 965 | double secs; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 966 | enum promex_srv_state state; |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 967 | const char *check_state; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 968 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 969 | for (;ctx->field_num < ST_F_TOTAL_FIELDS; ctx->field_num++) { |
| 970 | if (!(promex_st_metrics[ctx->field_num].flags & ctx->flags)) |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 971 | continue; |
| 972 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 973 | while (ctx->px) { |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 974 | struct promex_label labels[PROMEX_MAX_LABELS-1] = {}; |
| 975 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 976 | px = ctx->px; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 977 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 978 | labels[0].name = ist("proxy"); |
| 979 | labels[0].value = ist2(px->id, strlen(px->id)); |
| 980 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 981 | /* skip the disabled proxies, global frontend and non-networked ones */ |
Christopher Faulet | dfd10ab | 2021-10-06 14:24:19 +0200 | [diff] [blame] | 982 | 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] | 983 | goto next_px; |
| 984 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 985 | while (ctx->sv) { |
| 986 | sv = ctx->sv; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 987 | |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 988 | labels[1].name = ist("server"); |
| 989 | labels[1].value = ist2(sv->id, strlen(sv->id)); |
| 990 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 991 | 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] | 992 | return -1; |
| 993 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 994 | 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] | 995 | goto next_sv; |
| 996 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 997 | switch (ctx->field_num) { |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 998 | case ST_F_STATUS: |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 999 | state = promex_srv_status(sv); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1000 | for (; ctx->obj_state < PROMEX_SRV_STATE_COUNT; ctx->obj_state++) { |
| 1001 | val = mkf_u32(FO_STATUS, state == ctx->obj_state); |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1002 | labels[2].name = ist("state"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1003 | labels[2].value = promex_srv_st[ctx->obj_state]; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1004 | 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] | 1005 | &val, labels, &out, max)) |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 1006 | goto full; |
| 1007 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1008 | ctx->obj_state = 0; |
William Dauchy | c646459 | 2021-01-27 22:40:17 +0100 | [diff] [blame] | 1009 | goto next_sv; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1010 | case ST_F_QTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1011 | 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] | 1012 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1013 | break; |
| 1014 | case ST_F_CTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1015 | 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] | 1016 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1017 | break; |
| 1018 | case ST_F_RTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1019 | 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] | 1020 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1021 | break; |
| 1022 | case ST_F_TTIME: |
Christopher Faulet | af4bf14 | 2019-09-24 16:35:19 +0200 | [diff] [blame] | 1023 | 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] | 1024 | val = mkf_flt(FN_AVG, secs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1025 | break; |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1026 | case ST_F_QT_MAX: |
| 1027 | secs = (double)sv->counters.qtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1028 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1029 | break; |
| 1030 | case ST_F_CT_MAX: |
| 1031 | secs = (double)sv->counters.ctime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1032 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1033 | break; |
| 1034 | case ST_F_RT_MAX: |
| 1035 | secs = (double)sv->counters.dtime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1036 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1037 | break; |
| 1038 | case ST_F_TT_MAX: |
| 1039 | secs = (double)sv->counters.ttime_max / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1040 | val = mkf_flt(FN_MAX, secs); |
Christopher Faulet | 8fc027d | 2019-11-08 15:05:31 +0100 | [diff] [blame] | 1041 | break; |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 1042 | case ST_F_CHECK_STATUS: |
| 1043 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED) |
| 1044 | goto next_sv; |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1045 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1046 | for (; ctx->obj_state < HCHK_STATUS_SIZE; ctx->obj_state++) { |
| 1047 | if (get_check_status_result(ctx->obj_state) < CHK_RES_FAILED) |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1048 | continue; |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1049 | val = mkf_u32(FO_STATUS, sv->check.status == ctx->obj_state); |
| 1050 | check_state = get_check_status_info(ctx->obj_state); |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1051 | labels[2].name = ist("state"); |
Tim Duesterhus | b113b5c | 2021-09-15 13:58:44 +0200 | [diff] [blame] | 1052 | labels[2].value = ist(check_state); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1053 | 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] | 1054 | &val, labels, &out, max)) |
| 1055 | goto full; |
| 1056 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1057 | ctx->obj_state = 0; |
William Dauchy | de3c326 | 2021-02-01 13:11:51 +0100 | [diff] [blame] | 1058 | goto next_sv; |
Christopher Faulet | cf403f3 | 2019-11-21 14:35:46 +0100 | [diff] [blame] | 1059 | case ST_F_CHECK_CODE: |
| 1060 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED) |
| 1061 | goto next_sv; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1062 | 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] | 1063 | break; |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 1064 | case ST_F_CHECK_DURATION: |
| 1065 | if (sv->check.status < HCHK_STATUS_CHECKED) |
| 1066 | goto next_sv; |
| 1067 | secs = (double)sv->check.duration / 1000.0; |
Christopher Faulet | 37286a5 | 2021-01-20 15:20:53 +0100 | [diff] [blame] | 1068 | val = mkf_flt(FN_DURATION, secs); |
Christopher Faulet | 2711e51 | 2020-02-27 16:12:07 +0100 | [diff] [blame] | 1069 | break; |
Marcin Deranek | 3c27dda | 2020-05-15 18:32:51 +0200 | [diff] [blame] | 1070 | case ST_F_REQ_TOT: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1071 | if (px->mode != PR_MODE_HTTP) |
| 1072 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1073 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1074 | break; |
Christopher Faulet | 32ef48e | 2021-02-01 14:55:37 +0100 | [diff] [blame] | 1075 | case ST_F_HRSP_1XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1076 | case ST_F_HRSP_2XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1077 | case ST_F_HRSP_3XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1078 | case ST_F_HRSP_4XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1079 | case ST_F_HRSP_5XX: |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1080 | case ST_F_HRSP_OTHER: |
| 1081 | if (px->mode != PR_MODE_HTTP) |
| 1082 | goto next_px; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1083 | if (ctx->field_num != ST_F_HRSP_1XX) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1084 | ctx->flags &= ~PROMEX_FL_METRIC_HDR; |
Christopher Faulet | 5a2f938 | 2021-01-28 11:24:17 +0100 | [diff] [blame] | 1085 | labels[2].name = ist("code"); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1086 | labels[2].value = promex_hrsp_code[ctx->field_num - ST_F_HRSP_1XX]; |
| 1087 | val = stats[ctx->field_num]; |
Christopher Faulet | c55a626 | 2020-07-10 15:39:39 +0200 | [diff] [blame] | 1088 | break; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1089 | |
| 1090 | default: |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1091 | val = stats[ctx->field_num]; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1094 | 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] | 1095 | &val, labels, &out, max)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1096 | goto full; |
Christopher Faulet | eba2294 | 2019-11-19 14:18:24 +0100 | [diff] [blame] | 1097 | next_sv: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1098 | ctx->sv = sv->next; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1102 | ctx->px = px->next; |
| 1103 | ctx->sv = (ctx->px ? ctx->px->srv : NULL); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1104 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1105 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 1106 | ctx->px = proxies_list; |
| 1107 | ctx->sv = (ctx->px ? ctx->px->srv : NULL); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | |
| 1111 | end: |
Christopher Faulet | 0c55a15 | 2019-07-04 10:03:28 +0200 | [diff] [blame] | 1112 | if (out.len) { |
| 1113 | if (!htx_add_data_atonce(htx, out)) |
| 1114 | return -1; /* Unexpected and unrecoverable error */ |
| 1115 | channel_add_input(chn, out.len); |
| 1116 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1117 | return ret; |
| 1118 | full: |
| 1119 | ret = 0; |
| 1120 | goto end; |
| 1121 | } |
| 1122 | |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1123 | /* Dump stick table metrics (prefixed by "haproxy_sticktable_"). It returns 1 on success, |
| 1124 | * 0 if <htx> is full and -1 in case of any error. */ |
| 1125 | static int promex_dump_sticktable_metrics(struct appctx *appctx, struct htx *htx) |
| 1126 | { |
| 1127 | static struct ist prefix = IST("haproxy_sticktable_"); |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1128 | struct promex_ctx *ctx = appctx->svcctx; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1129 | struct field val; |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 1130 | struct channel *chn = sc_ic(appctx_cs(appctx)); |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1131 | struct ist out = ist2(trash.area, 0); |
| 1132 | size_t max = htx_get_max_blksz(htx, channel_htx_recv_max(chn, htx)); |
| 1133 | int ret = 1; |
| 1134 | struct stktable *t; |
| 1135 | |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1136 | for (; ctx->field_num < STICKTABLE_TOTAL_FIELDS; ctx->field_num++) { |
| 1137 | if (!(promex_sticktable_metrics[ctx->field_num].flags & ctx->flags)) |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1138 | continue; |
| 1139 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1140 | while (ctx->st) { |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1141 | struct promex_label labels[PROMEX_MAX_LABELS - 1] = {}; |
| 1142 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1143 | t = ctx->st; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1144 | if (!t->size) |
| 1145 | goto next_px; |
| 1146 | |
| 1147 | labels[0].name = ist("name"); |
| 1148 | labels[0].value = ist2(t->id, strlen(t->id)); |
| 1149 | labels[1].name = ist("type"); |
| 1150 | 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] | 1151 | switch (ctx->field_num) { |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1152 | case STICKTABLE_SIZE: |
| 1153 | val = mkf_u32(FN_GAUGE, t->size); |
| 1154 | break; |
| 1155 | case STICKTABLE_USED: |
| 1156 | val = mkf_u32(FN_GAUGE, t->current); |
| 1157 | break; |
| 1158 | default: |
| 1159 | goto next_px; |
| 1160 | } |
| 1161 | |
| 1162 | if (!promex_dump_metric(appctx, htx, prefix, |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1163 | &promex_sticktable_metrics[ctx->field_num], |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1164 | &val, labels, &out, max)) |
| 1165 | goto full; |
| 1166 | |
| 1167 | next_px: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1168 | ctx->st = t->next; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1169 | } |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1170 | ctx->flags |= PROMEX_FL_METRIC_HDR; |
| 1171 | ctx->st = stktables_list; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | end: |
| 1175 | if (out.len) { |
| 1176 | if (!htx_add_data_atonce(htx, out)) |
| 1177 | return -1; /* Unexpected and unrecoverable error */ |
| 1178 | channel_add_input(chn, out.len); |
| 1179 | } |
| 1180 | return ret; |
| 1181 | full: |
| 1182 | ret = 0; |
| 1183 | goto end; |
| 1184 | } |
| 1185 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1186 | /* Dump all metrics (global, frontends, backends and servers) depending on the |
| 1187 | * 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] | 1188 | * -1 in case of any error. |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1189 | * Uses <appctx.ctx.stats.px> as a pointer to the current proxy and <sv>/<li> |
| 1190 | * as pointers to the current server/listener respectively. |
| 1191 | */ |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 1192 | static int promex_dump_metrics(struct appctx *appctx, struct stconn *cs, struct htx *htx) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1193 | { |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1194 | struct promex_ctx *ctx = appctx->svcctx; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1195 | int ret; |
| 1196 | |
| 1197 | switch (appctx->st1) { |
| 1198 | case PROMEX_DUMPER_INIT: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1199 | ctx->px = NULL; |
| 1200 | ctx->st = NULL; |
| 1201 | ctx->li = NULL; |
| 1202 | ctx->sv = NULL; |
| 1203 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_INFO_METRIC); |
| 1204 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1205 | ctx->field_num = INF_NAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1206 | appctx->st1 = PROMEX_DUMPER_GLOBAL; |
| 1207 | /* fall through */ |
| 1208 | |
| 1209 | case PROMEX_DUMPER_GLOBAL: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1210 | if (ctx->flags & PROMEX_FL_SCOPE_GLOBAL) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1211 | ret = promex_dump_global_metrics(appctx, htx); |
| 1212 | if (ret <= 0) { |
| 1213 | if (ret == -1) |
| 1214 | goto error; |
| 1215 | goto full; |
| 1216 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1217 | } |
| 1218 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1219 | ctx->px = proxies_list; |
| 1220 | ctx->st = NULL; |
| 1221 | ctx->li = NULL; |
| 1222 | ctx->sv = NULL; |
| 1223 | ctx->flags &= ~PROMEX_FL_INFO_METRIC; |
| 1224 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_FRONT_METRIC); |
| 1225 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1226 | ctx->field_num = ST_F_PXNAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1227 | appctx->st1 = PROMEX_DUMPER_FRONT; |
| 1228 | /* fall through */ |
| 1229 | |
| 1230 | case PROMEX_DUMPER_FRONT: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1231 | if (ctx->flags & PROMEX_FL_SCOPE_FRONT) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1232 | ret = promex_dump_front_metrics(appctx, htx); |
| 1233 | if (ret <= 0) { |
| 1234 | if (ret == -1) |
| 1235 | goto error; |
| 1236 | goto full; |
| 1237 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1238 | } |
| 1239 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1240 | ctx->px = proxies_list; |
| 1241 | ctx->st = NULL; |
| 1242 | ctx->li = LIST_NEXT(&proxies_list->conf.listeners, struct listener *, by_fe); |
| 1243 | ctx->sv = NULL; |
| 1244 | ctx->flags &= ~PROMEX_FL_FRONT_METRIC; |
| 1245 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_LI_METRIC); |
| 1246 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1247 | ctx->field_num = ST_F_PXNAME; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 1248 | appctx->st1 = PROMEX_DUMPER_LI; |
| 1249 | /* fall through */ |
| 1250 | |
| 1251 | case PROMEX_DUMPER_LI: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1252 | if (ctx->flags & PROMEX_FL_SCOPE_LI) { |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 1253 | ret = promex_dump_listener_metrics(appctx, htx); |
| 1254 | if (ret <= 0) { |
| 1255 | if (ret == -1) |
| 1256 | goto error; |
| 1257 | goto full; |
| 1258 | } |
| 1259 | } |
| 1260 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1261 | ctx->px = proxies_list; |
| 1262 | ctx->st = NULL; |
| 1263 | ctx->li = NULL; |
| 1264 | ctx->sv = NULL; |
| 1265 | ctx->flags &= ~PROMEX_FL_LI_METRIC; |
| 1266 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_BACK_METRIC); |
| 1267 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1268 | ctx->field_num = ST_F_PXNAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1269 | appctx->st1 = PROMEX_DUMPER_BACK; |
| 1270 | /* fall through */ |
| 1271 | |
| 1272 | case PROMEX_DUMPER_BACK: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1273 | if (ctx->flags & PROMEX_FL_SCOPE_BACK) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1274 | ret = promex_dump_back_metrics(appctx, htx); |
| 1275 | if (ret <= 0) { |
| 1276 | if (ret == -1) |
| 1277 | goto error; |
| 1278 | goto full; |
| 1279 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1280 | } |
| 1281 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1282 | ctx->px = proxies_list; |
| 1283 | ctx->st = NULL; |
| 1284 | ctx->li = NULL; |
| 1285 | ctx->sv = ctx->px ? ctx->px->srv : NULL; |
| 1286 | ctx->flags &= ~PROMEX_FL_BACK_METRIC; |
| 1287 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_SRV_METRIC); |
| 1288 | ctx->obj_state = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1289 | ctx->field_num = ST_F_PXNAME; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1290 | appctx->st1 = PROMEX_DUMPER_SRV; |
| 1291 | /* fall through */ |
| 1292 | |
| 1293 | case PROMEX_DUMPER_SRV: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1294 | if (ctx->flags & PROMEX_FL_SCOPE_SERVER) { |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1295 | ret = promex_dump_srv_metrics(appctx, htx); |
| 1296 | if (ret <= 0) { |
| 1297 | if (ret == -1) |
| 1298 | goto error; |
| 1299 | goto full; |
| 1300 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1303 | ctx->px = NULL; |
| 1304 | ctx->st = stktables_list; |
| 1305 | ctx->li = NULL; |
| 1306 | ctx->sv = NULL; |
| 1307 | ctx->flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_SRV_METRIC); |
| 1308 | ctx->flags |= (PROMEX_FL_METRIC_HDR|PROMEX_FL_STICKTABLE_METRIC); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1309 | ctx->field_num = STICKTABLE_SIZE; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1310 | appctx->st1 = PROMEX_DUMPER_STICKTABLE; |
| 1311 | /* fall through */ |
| 1312 | |
| 1313 | case PROMEX_DUMPER_STICKTABLE: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1314 | if (ctx->flags & PROMEX_FL_SCOPE_STICKTABLE) { |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1315 | ret = promex_dump_sticktable_metrics(appctx, htx); |
| 1316 | if (ret <= 0) { |
| 1317 | if (ret == -1) |
| 1318 | goto error; |
| 1319 | goto full; |
| 1320 | } |
| 1321 | } |
| 1322 | |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1323 | ctx->px = NULL; |
| 1324 | ctx->st = NULL; |
| 1325 | ctx->li = NULL; |
| 1326 | ctx->sv = NULL; |
| 1327 | ctx->flags &= ~(PROMEX_FL_METRIC_HDR|PROMEX_FL_STICKTABLE_METRIC); |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1328 | ctx->field_num = 0; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1329 | appctx->st1 = PROMEX_DUMPER_DONE; |
| 1330 | /* fall through */ |
| 1331 | |
| 1332 | case PROMEX_DUMPER_DONE: |
| 1333 | default: |
| 1334 | break; |
| 1335 | } |
| 1336 | |
| 1337 | return 1; |
| 1338 | |
| 1339 | full: |
Willy Tarreau | 99615ed | 2022-05-25 07:29:36 +0200 | [diff] [blame^] | 1340 | sc_need_room(cs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1341 | return 0; |
| 1342 | error: |
| 1343 | /* unrecoverable error */ |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1344 | ctx->px = NULL; |
| 1345 | ctx->st = NULL; |
| 1346 | ctx->li = NULL; |
| 1347 | ctx->sv = NULL; |
| 1348 | ctx->flags = 0; |
Willy Tarreau | de58d24 | 2022-05-03 18:05:23 +0200 | [diff] [blame] | 1349 | ctx->field_num = 0; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1350 | appctx->st1 = PROMEX_DUMPER_DONE; |
| 1351 | return -1; |
| 1352 | } |
| 1353 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1354 | /* 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] | 1355 | * success and -1 on error. */ |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 1356 | static int promex_parse_uri(struct appctx *appctx, struct stconn *cs) |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1357 | { |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1358 | struct promex_ctx *ctx = appctx->svcctx; |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 1359 | struct channel *req = sc_oc(cs); |
| 1360 | struct channel *res = sc_ic(cs); |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1361 | struct htx *req_htx, *res_htx; |
| 1362 | struct htx_sl *sl; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1363 | char *p, *key, *value; |
| 1364 | const char *end; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1365 | struct buffer *err; |
| 1366 | int default_scopes = PROMEX_FL_SCOPE_ALL; |
| 1367 | int len; |
| 1368 | |
| 1369 | /* Get the query-string */ |
| 1370 | req_htx = htxbuf(&req->buf); |
| 1371 | sl = http_get_stline(req_htx); |
| 1372 | if (!sl) |
| 1373 | goto error; |
| 1374 | p = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), '?'); |
| 1375 | if (!p) |
| 1376 | goto end; |
| 1377 | end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl); |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1378 | |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1379 | /* copy the query-string */ |
| 1380 | len = end - p; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1381 | chunk_reset(&trash); |
| 1382 | memcpy(trash.area, p, len); |
| 1383 | trash.area[len] = 0; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1384 | p = trash.area; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1385 | end = trash.area + len; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1386 | |
| 1387 | /* Parse the query-string */ |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1388 | while (p < end && *p && *p != '#') { |
| 1389 | value = NULL; |
| 1390 | |
| 1391 | /* decode parameter name */ |
| 1392 | key = p; |
| 1393 | while (p < end && *p != '=' && *p != '&' && *p != '#') |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1394 | ++p; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1395 | /* found a value */ |
| 1396 | if (*p == '=') { |
| 1397 | *(p++) = 0; |
| 1398 | value = p; |
| 1399 | } |
| 1400 | else if (*p == '&') |
| 1401 | *(p++) = 0; |
| 1402 | else if (*p == '#') |
| 1403 | *p = 0; |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 1404 | len = url_decode(key, 1); |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1405 | if (len == -1) |
| 1406 | goto error; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1407 | |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1408 | /* decode value */ |
| 1409 | if (value) { |
| 1410 | while (p < end && *p != '=' && *p != '&' && *p != '#') |
| 1411 | ++p; |
| 1412 | if (*p == '=') |
| 1413 | goto error; |
| 1414 | if (*p == '&') |
| 1415 | *(p++) = 0; |
| 1416 | else if (*p == '#') |
| 1417 | *p = 0; |
Willy Tarreau | 62ba9ba | 2020-04-23 17:54:47 +0200 | [diff] [blame] | 1418 | len = url_decode(value, 1); |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1419 | if (len == -1) |
| 1420 | goto error; |
| 1421 | } |
| 1422 | |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1423 | if (strcmp(key, "scope") == 0) { |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1424 | default_scopes = 0; /* at least a scope defined, unset default scopes */ |
| 1425 | if (!value) |
| 1426 | goto error; |
| 1427 | else if (*value == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1428 | ctx->flags &= ~PROMEX_FL_SCOPE_ALL; |
William Dauchy | c65f656 | 2019-11-26 12:56:26 +0100 | [diff] [blame] | 1429 | else if (*value == '*') |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1430 | ctx->flags |= PROMEX_FL_SCOPE_ALL; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1431 | else if (strcmp(value, "global") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1432 | ctx->flags |= PROMEX_FL_SCOPE_GLOBAL; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1433 | else if (strcmp(value, "server") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1434 | ctx->flags |= PROMEX_FL_SCOPE_SERVER; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1435 | else if (strcmp(value, "backend") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1436 | ctx->flags |= PROMEX_FL_SCOPE_BACK; |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1437 | else if (strcmp(value, "frontend") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1438 | ctx->flags |= PROMEX_FL_SCOPE_FRONT; |
William Dauchy | e3f7bd5 | 2021-02-14 23:22:56 +0100 | [diff] [blame] | 1439 | else if (strcmp(value, "listener") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1440 | ctx->flags |= PROMEX_FL_SCOPE_LI; |
William Dauchy | 6916422 | 2021-02-07 20:42:38 +0100 | [diff] [blame] | 1441 | else if (strcmp(value, "sticktable") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1442 | ctx->flags |= PROMEX_FL_SCOPE_STICKTABLE; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1443 | else |
| 1444 | goto error; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1445 | } |
Tim Duesterhus | 8cb12a8 | 2021-01-02 22:31:55 +0100 | [diff] [blame] | 1446 | else if (strcmp(key, "no-maint") == 0) |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1447 | ctx->flags |= PROMEX_FL_NO_MAINT_SRV; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | end: |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1451 | ctx->flags |= default_scopes; |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1452 | return 1; |
| 1453 | |
| 1454 | error: |
| 1455 | err = &http_err_chunks[HTTP_ERR_400]; |
| 1456 | channel_erase(res); |
| 1457 | res->buf.data = b_data(err); |
| 1458 | memcpy(res->buf.area, b_head(err), b_data(err)); |
| 1459 | res_htx = htx_from_buf(&res->buf); |
| 1460 | channel_add_input(res, res_htx->data); |
| 1461 | appctx->st0 = PROMEX_ST_END; |
| 1462 | return -1; |
| 1463 | } |
| 1464 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1465 | /* Send HTTP headers of the response. It returns 1 on success and 0 if <htx> is |
| 1466 | * full. */ |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 1467 | static int promex_send_headers(struct appctx *appctx, struct stconn *cs, struct htx *htx) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1468 | { |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 1469 | struct channel *chn = sc_ic(cs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1470 | struct htx_sl *sl; |
| 1471 | unsigned int flags; |
| 1472 | |
| 1473 | 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); |
| 1474 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 1475 | if (!sl) |
| 1476 | goto full; |
| 1477 | sl->info.res.status = 200; |
| 1478 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1479 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain; version=0.0.4")) || |
| 1480 | !htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked")) || |
| 1481 | !htx_add_endof(htx, HTX_BLK_EOH)) |
| 1482 | goto full; |
| 1483 | |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1484 | channel_add_input(chn, htx->data); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1485 | return 1; |
| 1486 | full: |
| 1487 | htx_reset(htx); |
Willy Tarreau | 99615ed | 2022-05-25 07:29:36 +0200 | [diff] [blame^] | 1488 | sc_need_room(cs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | /* The function returns 1 if the initialisation is complete, 0 if |
| 1493 | * an errors occurs and -1 if more data are required for initializing |
| 1494 | * the applet. |
| 1495 | */ |
Christopher Faulet | 4aa1d28 | 2022-01-13 16:01:35 +0100 | [diff] [blame] | 1496 | static int promex_appctx_init(struct appctx *appctx) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1497 | { |
Willy Tarreau | ae1747d | 2022-05-03 17:33:00 +0200 | [diff] [blame] | 1498 | applet_reserve_svcctx(appctx, sizeof(struct promex_ctx)); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1499 | appctx->st0 = PROMEX_ST_INIT; |
Christopher Faulet | c992938 | 2022-05-12 11:52:27 +0200 | [diff] [blame] | 1500 | return 0; |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | /* The main I/O handler for the promex applet. */ |
| 1504 | static void promex_appctx_handle_io(struct appctx *appctx) |
| 1505 | { |
Willy Tarreau | 4596fe2 | 2022-05-17 19:07:51 +0200 | [diff] [blame] | 1506 | struct stconn *cs = appctx_cs(appctx); |
Willy Tarreau | ea27f48 | 2022-05-18 16:10:52 +0200 | [diff] [blame] | 1507 | struct stream *s = __sc_strm(cs); |
Willy Tarreau | 40a9c32 | 2022-05-18 15:55:18 +0200 | [diff] [blame] | 1508 | struct channel *req = sc_oc(cs); |
| 1509 | struct channel *res = sc_ic(cs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1510 | struct htx *req_htx, *res_htx; |
| 1511 | int ret; |
| 1512 | |
| 1513 | res_htx = htx_from_buf(&res->buf); |
Willy Tarreau | 026e8fb | 2022-05-17 19:47:17 +0200 | [diff] [blame] | 1514 | if (unlikely(cs->state == SC_ST_DIS || cs->state == SC_ST_CLO)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1515 | goto out; |
| 1516 | |
Ilya Shipitsin | ce7b00f | 2020-03-23 22:28:40 +0500 | [diff] [blame] | 1517 | /* Check if the input buffer is available. */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1518 | if (!b_size(&res->buf)) { |
Willy Tarreau | 99615ed | 2022-05-25 07:29:36 +0200 | [diff] [blame^] | 1519 | sc_need_room(cs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1520 | goto out; |
| 1521 | } |
| 1522 | |
| 1523 | switch (appctx->st0) { |
| 1524 | case PROMEX_ST_INIT: |
Christopher Faulet | 908628c | 2022-03-25 16:43:49 +0100 | [diff] [blame] | 1525 | ret = promex_parse_uri(appctx, cs); |
Christopher Faulet | 78407ce | 2019-11-18 14:47:08 +0100 | [diff] [blame] | 1526 | if (ret <= 0) { |
| 1527 | if (ret == -1) |
| 1528 | goto error; |
| 1529 | goto out; |
| 1530 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1531 | appctx->st0 = PROMEX_ST_HEAD; |
| 1532 | appctx->st1 = PROMEX_DUMPER_INIT; |
| 1533 | /* fall through */ |
| 1534 | |
| 1535 | case PROMEX_ST_HEAD: |
Christopher Faulet | 908628c | 2022-03-25 16:43:49 +0100 | [diff] [blame] | 1536 | if (!promex_send_headers(appctx, cs, res_htx)) |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1537 | goto out; |
| 1538 | appctx->st0 = ((s->txn->meth == HTTP_METH_HEAD) ? PROMEX_ST_DONE : PROMEX_ST_DUMP); |
| 1539 | /* fall through */ |
| 1540 | |
| 1541 | case PROMEX_ST_DUMP: |
Christopher Faulet | 908628c | 2022-03-25 16:43:49 +0100 | [diff] [blame] | 1542 | ret = promex_dump_metrics(appctx, cs, res_htx); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1543 | if (ret <= 0) { |
| 1544 | if (ret == -1) |
| 1545 | goto error; |
| 1546 | goto out; |
| 1547 | } |
| 1548 | appctx->st0 = PROMEX_ST_DONE; |
| 1549 | /* fall through */ |
| 1550 | |
| 1551 | case PROMEX_ST_DONE: |
Christopher Faulet | be69cbd | 2022-04-07 10:19:46 +0200 | [diff] [blame] | 1552 | /* no more data are expected. If the response buffer is |
| 1553 | * empty, be sure to add something (EOT block in this |
| 1554 | * case) to have something to send. It is important to |
| 1555 | * be sure the EOM flags will be handled by the |
| 1556 | * endpoint. |
| 1557 | */ |
| 1558 | if (htx_is_empty(res_htx)) { |
| 1559 | if (!htx_add_endof(res_htx, HTX_BLK_EOT)) { |
Willy Tarreau | 99615ed | 2022-05-25 07:29:36 +0200 | [diff] [blame^] | 1560 | sc_need_room(cs); |
Christopher Faulet | be69cbd | 2022-04-07 10:19:46 +0200 | [diff] [blame] | 1561 | goto out; |
| 1562 | } |
| 1563 | channel_add_input(res, 1); |
| 1564 | } |
| 1565 | res_htx->flags |= HTX_FL_EOM; |
Christopher Faulet | bef64b2 | 2022-03-07 15:56:20 +0100 | [diff] [blame] | 1566 | res->flags |= CF_EOI; |
Willy Tarreau | d869e13 | 2022-05-17 18:05:31 +0200 | [diff] [blame] | 1567 | se_fl_set(appctx->sedesc, SE_FL_EOI); |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1568 | appctx->st0 = PROMEX_ST_END; |
| 1569 | /* fall through */ |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1570 | |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1571 | case PROMEX_ST_END: |
| 1572 | if (!(res->flags & CF_SHUTR)) { |
| 1573 | res->flags |= CF_READ_NULL; |
Christopher Faulet | da098e6 | 2022-03-31 17:44:45 +0200 | [diff] [blame] | 1574 | cs_shutr(cs); |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1575 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1578 | out: |
| 1579 | htx_to_buf(res_htx, &res->buf); |
Christopher Faulet | 9744f7c | 2019-03-27 15:48:53 +0100 | [diff] [blame] | 1580 | |
| 1581 | /* eat the whole request */ |
| 1582 | if (co_data(req)) { |
| 1583 | req_htx = htx_from_buf(&req->buf); |
| 1584 | co_htx_skip(req, req_htx, co_data(req)); |
| 1585 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1586 | return; |
| 1587 | |
| 1588 | error: |
| 1589 | res->flags |= CF_READ_NULL; |
Christopher Faulet | da098e6 | 2022-03-31 17:44:45 +0200 | [diff] [blame] | 1590 | cs_shutr(cs); |
| 1591 | cs_shutw(cs); |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | struct applet promex_applet = { |
| 1595 | .obj_type = OBJ_TYPE_APPLET, |
| 1596 | .name = "<PROMEX>", /* used for logging */ |
| 1597 | .init = promex_appctx_init, |
| 1598 | .fct = promex_appctx_handle_io, |
| 1599 | }; |
| 1600 | |
| 1601 | static enum act_parse_ret service_parse_prometheus_exporter(const char **args, int *cur_arg, struct proxy *px, |
| 1602 | struct act_rule *rule, char **err) |
| 1603 | { |
| 1604 | /* Prometheus exporter service is only available on "http-request" rulesets */ |
| 1605 | if (rule->from != ACT_F_HTTP_REQ) { |
| 1606 | memprintf(err, "Prometheus exporter service only available on 'http-request' rulesets"); |
| 1607 | return ACT_RET_PRS_ERR; |
| 1608 | } |
Christopher Faulet | f959d08 | 2019-02-07 15:38:42 +0100 | [diff] [blame] | 1609 | |
| 1610 | /* Add applet pointer in the rule. */ |
| 1611 | rule->applet = promex_applet; |
| 1612 | |
| 1613 | return ACT_RET_PRS_OK; |
| 1614 | } |
| 1615 | static void promex_register_build_options(void) |
| 1616 | { |
| 1617 | char *ptr = NULL; |
| 1618 | |
| 1619 | memprintf(&ptr, "Built with the Prometheus exporter as a service"); |
| 1620 | hap_register_build_opts(ptr, 1); |
| 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | static struct action_kw_list service_actions = { ILH, { |
| 1625 | { "prometheus-exporter", service_parse_prometheus_exporter }, |
| 1626 | { /* END */ } |
| 1627 | }}; |
| 1628 | |
| 1629 | INITCALL1(STG_REGISTER, service_keywords_register, &service_actions); |
| 1630 | INITCALL0(STG_REGISTER, promex_register_build_options); |