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