Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 2 | * include/haproxy/stats-t.h |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 3 | * This file provides structures and types for stats. |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 4 | * |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 5 | * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu |
| 6 | * |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 21 | |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 22 | #ifndef _HAPROXY_STATS_T_H |
| 23 | #define _HAPROXY_STATS_T_H |
| 24 | |
| 25 | #include <haproxy/api-t.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 26 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 27 | /* Flags for applet.ctx.stats.flags */ |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 28 | #define STAT_FMT_HTML 0x00000001 /* dump the stats in HTML format */ |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 29 | #define STAT_FMT_TYPED 0x00000002 /* use the typed output format */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 30 | #define STAT_FMT_JSON 0x00000004 /* dump the stats in JSON format */ |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 31 | #define STAT_HIDE_DOWN 0x00000008 /* hide 'down' servers in the stats page */ |
| 32 | #define STAT_NO_REFRESH 0x00000010 /* do not automatically refresh the stats page */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 33 | #define STAT_ADMIN 0x00000020 /* indicate a stats admin level */ |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 34 | #define STAT_CHUNKED 0x00000040 /* use chunked encoding (HTTP/1.1) */ |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 35 | #define STAT_JSON_SCHM 0x00000080 /* dump the json schema */ |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 36 | |
| 37 | #define STAT_HIDEVER 0x00000100 /* conf: do not report the version and reldate */ |
| 38 | #define STAT_SHNODE 0x00000200 /* conf: show node name */ |
| 39 | #define STAT_SHDESC 0x00000400 /* conf: show description */ |
| 40 | #define STAT_SHLGNDS 0x00000800 /* conf: show legends */ |
Willy Tarreau | 2f39738 | 2019-10-09 11:43:59 +0200 | [diff] [blame] | 41 | #define STAT_SHOW_FDESC 0x00001000 /* show the field descriptions when possible */ |
Amaury Denoyelle | 0b70a8a | 2020-10-05 11:49:45 +0200 | [diff] [blame] | 42 | #define STAT_SHMODULES 0x00002000 /* conf: show modules */ |
Willy Tarreau | 708c416 | 2019-10-09 10:19:16 +0200 | [diff] [blame] | 43 | |
Willy Tarreau | 39f7e6d | 2008-03-17 21:38:24 +0100 | [diff] [blame] | 44 | #define STAT_BOUND 0x00800000 /* bound statistics to selected proxies/types/services */ |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 45 | #define STAT_STARTED 0x01000000 /* some output has occurred */ |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 46 | |
Christopher Faulet | 6338a08 | 2019-09-09 15:50:54 +0200 | [diff] [blame] | 47 | #define STAT_FMT_MASK 0x00000007 |
| 48 | |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 49 | #define STATS_TYPE_FE 0 |
| 50 | #define STATS_TYPE_BE 1 |
| 51 | #define STATS_TYPE_SV 2 |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 52 | #define STATS_TYPE_SO 3 |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 53 | |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame^] | 54 | #define STATS_DOMAIN (0) /* used for bitshifting, type of statistics: proxy or dns */ |
Amaury Denoyelle | 72b16e5 | 2020-10-05 11:49:38 +0200 | [diff] [blame] | 55 | #define STATS_PX_CAP (8) /* used for bitshifting, differentiate obj1 type for proxy statistics */ |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 56 | |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 57 | /* HTTP stats : applet.st0 */ |
| 58 | enum { |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 59 | STAT_HTTP_INIT = 0, /* Initial state */ |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 60 | STAT_HTTP_HEAD, /* send headers before dump */ |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 61 | STAT_HTTP_DUMP, /* dumping stats */ |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 62 | STAT_HTTP_POST, /* waiting post data */ |
| 63 | STAT_HTTP_LAST, /* sending last chunk of response */ |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 64 | STAT_HTTP_DONE, /* dump is finished */ |
| 65 | STAT_HTTP_END, /* finished */ |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 66 | }; |
| 67 | |
Christopher Faulet | 2b9b678 | 2019-02-27 16:42:58 +0100 | [diff] [blame] | 68 | /* status codes available for the stats admin page */ |
| 69 | enum { |
| 70 | STAT_STATUS_INIT = 0, |
| 71 | STAT_STATUS_DENY, /* action denied */ |
| 72 | STAT_STATUS_DONE, /* the action is successful */ |
| 73 | STAT_STATUS_ERRP, /* an error occurred due to invalid values in parameters */ |
| 74 | STAT_STATUS_EXCD, /* an error occurred because the buffer couldn't store all data */ |
| 75 | STAT_STATUS_NONE, /* nothing happened (no action chosen or servers state didn't change) */ |
| 76 | STAT_STATUS_PART, /* the action is partially successful */ |
| 77 | STAT_STATUS_UNKN, /* an unknown error occurred, shouldn't happen */ |
| 78 | STAT_STATUS_IVAL, /* invalid requests (chunked or invalid post) */ |
| 79 | STAT_STATUS_SIZE |
| 80 | }; |
| 81 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 82 | /* HTML form to limit output scope */ |
| 83 | #define STAT_SCOPE_TXT_MAXLEN 20 /* max len for scope substring */ |
| 84 | #define STAT_SCOPE_INPUT_NAME "scope" /* pattern form scope name <input> in html form */ |
| 85 | #define STAT_SCOPE_PATTERN "?" STAT_SCOPE_INPUT_NAME "=" |
| 86 | |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 87 | /* Actions available for the stats admin forms */ |
| 88 | enum { |
| 89 | ST_ADM_ACTION_NONE = 0, |
Thierry Fournier | 31e64ca | 2016-03-23 16:25:49 +0100 | [diff] [blame] | 90 | |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 91 | /* enable/disable health checks */ |
| 92 | ST_ADM_ACTION_DHLTH, |
| 93 | ST_ADM_ACTION_EHLTH, |
| 94 | |
| 95 | /* force health check status */ |
| 96 | ST_ADM_ACTION_HRUNN, |
| 97 | ST_ADM_ACTION_HNOLB, |
| 98 | ST_ADM_ACTION_HDOWN, |
| 99 | |
| 100 | /* enable/disable agent checks */ |
| 101 | ST_ADM_ACTION_DAGENT, |
| 102 | ST_ADM_ACTION_EAGENT, |
| 103 | |
| 104 | /* force agent check status */ |
| 105 | ST_ADM_ACTION_ARUNN, |
| 106 | ST_ADM_ACTION_ADOWN, |
| 107 | |
| 108 | /* set admin state */ |
| 109 | ST_ADM_ACTION_READY, |
| 110 | ST_ADM_ACTION_DRAIN, |
| 111 | ST_ADM_ACTION_MAINT, |
| 112 | ST_ADM_ACTION_SHUTDOWN, |
| 113 | /* these are the ancient actions, still available for compatibility */ |
| 114 | ST_ADM_ACTION_DISABLE, |
| 115 | ST_ADM_ACTION_ENABLE, |
| 116 | ST_ADM_ACTION_STOP, |
| 117 | ST_ADM_ACTION_START, |
Thierry Fournier | 31e64ca | 2016-03-23 16:25:49 +0100 | [diff] [blame] | 118 | }; |
| 119 | |
Thierry Fournier | 31e64ca | 2016-03-23 16:25:49 +0100 | [diff] [blame] | 120 | |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 121 | /* data transmission states for the stats responses */ |
| 122 | enum { |
| 123 | STAT_ST_INIT = 0, |
| 124 | STAT_ST_HEAD, |
| 125 | STAT_ST_INFO, |
| 126 | STAT_ST_LIST, |
| 127 | STAT_ST_END, |
| 128 | STAT_ST_FIN, |
Thierry Fournier | 31e64ca | 2016-03-23 16:25:49 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 131 | /* data transmission states for the stats responses inside a proxy */ |
| 132 | enum { |
| 133 | STAT_PX_ST_INIT = 0, |
| 134 | STAT_PX_ST_TH, |
| 135 | STAT_PX_ST_FE, |
| 136 | STAT_PX_ST_LI, |
| 137 | STAT_PX_ST_SV, |
| 138 | STAT_PX_ST_BE, |
| 139 | STAT_PX_ST_END, |
| 140 | STAT_PX_ST_FIN, |
| 141 | }; |
| 142 | |
Willy Tarreau | 8e62c05 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 143 | /* This level of detail is needed to let the stats consumer know how to |
| 144 | * aggregate them (eg: between processes or cluster nodes). Only a few |
| 145 | * combinations are actually in use, though the mechanism tends to make |
| 146 | * this easy to extend to future uses. |
| 147 | * |
| 148 | * Each reported stats element is typed based on 4 dimensions : |
| 149 | * - the field format : it indicates the validity range of the reported value, |
| 150 | * its limits and how to parse it. 6 types are currently supported : |
| 151 | * empty, signed 32-bit integer, unsigned 32-bit integer, signed 64-bit |
| 152 | * integer, unsigned 64-bit integer, string |
| 153 | * |
| 154 | * - the field origin : how was the value retrieved and what it depends on. |
| 155 | * 5 origins are currently defined : product (eg: haproxy version or |
| 156 | * release date), configuration (eg: a configured limit), key (identifier |
| 157 | * used to group values at a certain level), metric (a measure of something), |
| 158 | * status (something discrete which by definition cannot be averaged nor |
| 159 | * aggregated, such as "listening" versus "full"). |
| 160 | * |
| 161 | * - the field nature : what does the data represent, implying how to aggregate |
| 162 | * it. At least 9 different natures are expected : counter (an increasing |
| 163 | * positive counter that may wrap when its type is overflown such as a byte |
| 164 | * counter), gauge (a measure at any instant that may vary, such as a |
| 165 | * concurrent connection count), a limit (eg: maximum acceptable concurrent |
| 166 | * connections), a minimum (eg: minimum free memory over a period), a |
| 167 | * maximum (eg: highest queue length over a period), an event rate (eg: |
| 168 | * incoming connections per second), a duration that is often aggregated by |
| 169 | * taking the max (eg: service uptime), an age that generally reports the |
| 170 | * last time an event appeared and which generally is aggregated by taking |
| 171 | * the most recent event hence the smallest one, the time which reports a |
| 172 | * discrete instant and cannot obviously be averaged either, a name which |
| 173 | * will generally be the name of an entity (such as a server name or cookie |
| 174 | * name), an output which is mostly used for various unsafe strings that are |
| 175 | * retrieved (eg: last check output, product name, description, etc), and an |
| 176 | * average which indicates that the value is relative and meant to be averaged |
| 177 | * between all nodes (eg: response time, throttling, etc). |
| 178 | * |
| 179 | * - the field scope : if the value is shared with other elements, which ones |
| 180 | * are expected to report the same value. The first scope with the least |
| 181 | * share is the process (most common one) where all data are only relevant |
| 182 | * to the process being consulted. The next one is the service, which is |
| 183 | * valid for all processes launched together (eg: shared SSL cache usage |
| 184 | * among processes). The next one is the system (such as the OS version) |
| 185 | * and which will report the same information for all instances running on |
| 186 | * the same node. The next one is the cluster, which indicates that the |
| 187 | * information are shared with other nodes being part of a same cluster. |
| 188 | * Stick-tables may carry such cluster-wide information. Larger scopes may |
| 189 | * be added in the future such as datacenter, country, continent, planet, |
| 190 | * galaxy, universe, etc. |
| 191 | * |
| 192 | * All these information will be encoded in the field as a bit field so that |
| 193 | * it is easy to pass composite values by simply ORing elements above, and |
| 194 | * to ease the definition of a few field types for the most common field |
| 195 | * combinations. |
| 196 | * |
| 197 | * The enums try to be arranged so that most likely characteristics are |
| 198 | * assigned the value zero, making it easier to add new fields. |
| 199 | * |
| 200 | * Field format has precedence over the other parts of the type. Please avoid |
| 201 | * declaring extra formats unless absolutely needed. The first one, FF_EMPTY, |
| 202 | * must absolutely have value zero so that it is what is returned after a |
| 203 | * memset(0). Furthermore, the producer is responsible for ensuring that when |
| 204 | * this format is set, all other bits of the type as well as the values in the |
| 205 | * union only contain zeroes. This makes it easier for the consumer to use the |
| 206 | * values as the expected type. |
| 207 | */ |
| 208 | |
| 209 | enum field_format { |
| 210 | FF_EMPTY = 0x00000000, |
| 211 | FF_S32 = 0x00000001, |
| 212 | FF_U32 = 0x00000002, |
| 213 | FF_S64 = 0x00000003, |
| 214 | FF_U64 = 0x00000004, |
| 215 | FF_STR = 0x00000005, |
Christopher Faulet | 88a0db2 | 2019-09-24 16:35:10 +0200 | [diff] [blame] | 216 | FF_FLT = 0x00000006, |
Willy Tarreau | 8e62c05 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 217 | FF_MASK = 0x000000FF, |
| 218 | }; |
| 219 | |
| 220 | enum field_origin { |
| 221 | FO_METRIC = 0x00000000, |
| 222 | FO_STATUS = 0x00000100, |
| 223 | FO_KEY = 0x00000200, |
| 224 | FO_CONFIG = 0x00000300, |
| 225 | FO_PRODUCT = 0x00000400, |
| 226 | FO_MASK = 0x0000FF00, |
| 227 | }; |
| 228 | |
| 229 | enum field_nature { |
| 230 | FN_GAUGE = 0x00000000, |
| 231 | FN_LIMIT = 0x00010000, |
| 232 | FN_MIN = 0x00020000, |
| 233 | FN_MAX = 0x00030000, |
| 234 | FN_RATE = 0x00040000, |
| 235 | FN_COUNTER = 0x00050000, |
| 236 | FN_DURATION = 0x00060000, |
| 237 | FN_AGE = 0x00070000, |
| 238 | FN_TIME = 0x00080000, |
| 239 | FN_NAME = 0x00090000, |
| 240 | FN_OUTPUT = 0x000A0000, |
| 241 | FN_AVG = 0x000B0000, |
| 242 | FN_MASK = 0x00FF0000, |
| 243 | }; |
| 244 | |
| 245 | enum field_scope { |
| 246 | FS_PROCESS = 0x00000000, |
| 247 | FS_SERVICE = 0x01000000, |
| 248 | FS_SYSTEM = 0x02000000, |
| 249 | FS_CLUSTER = 0x03000000, |
| 250 | FS_MASK = 0xFF000000, |
| 251 | }; |
| 252 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 253 | /* Show Info fields for CLI output. For any field added here, please add the text |
| 254 | * representation in the info_field_names array below. Please only append at the end, |
| 255 | * before the INF_TOTAL_FIELDS entry, and never insert anything in the middle |
| 256 | * nor at the beginning. |
| 257 | */ |
| 258 | enum info_field { |
| 259 | INF_NAME, |
| 260 | INF_VERSION, |
| 261 | INF_RELEASE_DATE, |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 262 | INF_NBTHREAD, |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 263 | INF_NBPROC, |
| 264 | INF_PROCESS_NUM, |
| 265 | INF_PID, |
| 266 | INF_UPTIME, |
| 267 | INF_UPTIME_SEC, |
| 268 | INF_MEMMAX_MB, |
| 269 | INF_POOL_ALLOC_MB, |
| 270 | INF_POOL_USED_MB, |
| 271 | INF_POOL_FAILED, |
| 272 | INF_ULIMIT_N, |
| 273 | INF_MAXSOCK, |
| 274 | INF_MAXCONN, |
| 275 | INF_HARD_MAXCONN, |
| 276 | INF_CURR_CONN, |
| 277 | INF_CUM_CONN, |
| 278 | INF_CUM_REQ, |
| 279 | INF_MAX_SSL_CONNS, |
| 280 | INF_CURR_SSL_CONNS, |
| 281 | INF_CUM_SSL_CONNS, |
| 282 | INF_MAXPIPES, |
| 283 | INF_PIPES_USED, |
| 284 | INF_PIPES_FREE, |
| 285 | INF_CONN_RATE, |
| 286 | INF_CONN_RATE_LIMIT, |
| 287 | INF_MAX_CONN_RATE, |
| 288 | INF_SESS_RATE, |
| 289 | INF_SESS_RATE_LIMIT, |
| 290 | INF_MAX_SESS_RATE, |
| 291 | INF_SSL_RATE, |
| 292 | INF_SSL_RATE_LIMIT, |
| 293 | INF_MAX_SSL_RATE, |
| 294 | INF_SSL_FRONTEND_KEY_RATE, |
| 295 | INF_SSL_FRONTEND_MAX_KEY_RATE, |
| 296 | INF_SSL_FRONTEND_SESSION_REUSE_PCT, |
| 297 | INF_SSL_BACKEND_KEY_RATE, |
| 298 | INF_SSL_BACKEND_MAX_KEY_RATE, |
| 299 | INF_SSL_CACHE_LOOKUPS, |
| 300 | INF_SSL_CACHE_MISSES, |
| 301 | INF_COMPRESS_BPS_IN, |
| 302 | INF_COMPRESS_BPS_OUT, |
| 303 | INF_COMPRESS_BPS_RATE_LIM, |
| 304 | INF_ZLIB_MEM_USAGE, |
| 305 | INF_MAX_ZLIB_MEM_USAGE, |
| 306 | INF_TASKS, |
| 307 | INF_RUN_QUEUE, |
| 308 | INF_IDLE_PCT, |
| 309 | INF_NODE, |
| 310 | INF_DESCRIPTION, |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 311 | INF_STOPPING, |
| 312 | INF_JOBS, |
William Lallemand | a719926 | 2018-11-16 16:57:20 +0100 | [diff] [blame] | 313 | INF_UNSTOPPABLE_JOBS, |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 314 | INF_LISTENERS, |
Willy Tarreau | 199ad24 | 2018-11-05 16:31:22 +0100 | [diff] [blame] | 315 | INF_ACTIVE_PEERS, |
Willy Tarreau | 2d372c2 | 2018-11-05 17:12:27 +0100 | [diff] [blame] | 316 | INF_CONNECTED_PEERS, |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 317 | INF_DROPPED_LOGS, |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 318 | INF_BUSY_POLLING, |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 319 | INF_FAILED_RESOLUTIONS, |
Willy Tarreau | 7cf0e45 | 2019-05-23 11:39:14 +0200 | [diff] [blame] | 320 | INF_TOTAL_BYTES_OUT, |
Christopher Faulet | aaa7085 | 2020-07-10 13:56:30 +0200 | [diff] [blame] | 321 | INF_TOTAL_SPLICED_BYTES_OUT, |
Willy Tarreau | 7cf0e45 | 2019-05-23 11:39:14 +0200 | [diff] [blame] | 322 | INF_BYTES_OUT_RATE, |
Willy Tarreau | 9b01370 | 2019-10-24 18:18:02 +0200 | [diff] [blame] | 323 | INF_DEBUG_COMMANDS_ISSUED, |
Emeric Brun | 45c457a | 2020-07-09 23:23:34 +0200 | [diff] [blame] | 324 | INF_CUM_LOG_MSGS, |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 325 | |
| 326 | /* must always be the last one */ |
| 327 | INF_TOTAL_FIELDS |
| 328 | }; |
| 329 | |
| 330 | |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 331 | /* Stats fields for CSV output. For any field added here, please add the text |
| 332 | * representation in the stat_field_names array below. Please only append at the end, |
| 333 | * before the ST_F_TOTAL_FIELDS entry, and never insert anything in the middle |
| 334 | * nor at the beginning. |
Thierry Fournier | 31e64ca | 2016-03-23 16:25:49 +0100 | [diff] [blame] | 335 | */ |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 336 | enum stat_field { |
| 337 | ST_F_PXNAME, |
| 338 | ST_F_SVNAME, |
| 339 | ST_F_QCUR, |
| 340 | ST_F_QMAX, |
| 341 | ST_F_SCUR, |
| 342 | ST_F_SMAX, |
| 343 | ST_F_SLIM, |
| 344 | ST_F_STOT, |
| 345 | ST_F_BIN , |
| 346 | ST_F_BOUT, |
| 347 | ST_F_DREQ, |
| 348 | ST_F_DRESP, |
| 349 | ST_F_EREQ, |
| 350 | ST_F_ECON, |
| 351 | ST_F_ERESP, |
| 352 | ST_F_WRETR, |
| 353 | ST_F_WREDIS, |
| 354 | ST_F_STATUS, |
| 355 | ST_F_WEIGHT, |
| 356 | ST_F_ACT, |
| 357 | ST_F_BCK, |
| 358 | ST_F_CHKFAIL, |
| 359 | ST_F_CHKDOWN, |
| 360 | ST_F_LASTCHG, |
| 361 | ST_F_DOWNTIME, |
| 362 | ST_F_QLIMIT, |
| 363 | ST_F_PID, |
| 364 | ST_F_IID, |
| 365 | ST_F_SID, |
| 366 | ST_F_THROTTLE, |
| 367 | ST_F_LBTOT, |
| 368 | ST_F_TRACKED, |
| 369 | ST_F_TYPE, |
| 370 | ST_F_RATE, |
| 371 | ST_F_RATE_LIM, |
| 372 | ST_F_RATE_MAX, |
| 373 | ST_F_CHECK_STATUS, |
| 374 | ST_F_CHECK_CODE, |
| 375 | ST_F_CHECK_DURATION, |
| 376 | ST_F_HRSP_1XX, |
| 377 | ST_F_HRSP_2XX, |
| 378 | ST_F_HRSP_3XX, |
| 379 | ST_F_HRSP_4XX, |
| 380 | ST_F_HRSP_5XX, |
| 381 | ST_F_HRSP_OTHER, |
| 382 | ST_F_HANAFAIL, |
| 383 | ST_F_REQ_RATE, |
| 384 | ST_F_REQ_RATE_MAX, |
| 385 | ST_F_REQ_TOT, |
| 386 | ST_F_CLI_ABRT, |
| 387 | ST_F_SRV_ABRT, |
| 388 | ST_F_COMP_IN, |
| 389 | ST_F_COMP_OUT, |
| 390 | ST_F_COMP_BYP, |
| 391 | ST_F_COMP_RSP, |
| 392 | ST_F_LASTSESS, |
| 393 | ST_F_LAST_CHK, |
| 394 | ST_F_LAST_AGT, |
| 395 | ST_F_QTIME, |
| 396 | ST_F_CTIME, |
| 397 | ST_F_RTIME, |
| 398 | ST_F_TTIME, |
| 399 | ST_F_AGENT_STATUS, |
| 400 | ST_F_AGENT_CODE, |
| 401 | ST_F_AGENT_DURATION, |
| 402 | ST_F_CHECK_DESC, |
| 403 | ST_F_AGENT_DESC, |
| 404 | ST_F_CHECK_RISE, |
| 405 | ST_F_CHECK_FALL, |
| 406 | ST_F_CHECK_HEALTH, |
| 407 | ST_F_AGENT_RISE, |
| 408 | ST_F_AGENT_FALL, |
| 409 | ST_F_AGENT_HEALTH, |
| 410 | ST_F_ADDR, |
| 411 | ST_F_COOKIE, |
| 412 | ST_F_MODE, |
| 413 | ST_F_ALGO, |
| 414 | ST_F_CONN_RATE, |
| 415 | ST_F_CONN_RATE_MAX, |
| 416 | ST_F_CONN_TOT, |
| 417 | ST_F_INTERCEPTED, |
| 418 | ST_F_DCON, |
| 419 | ST_F_DSES, |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 420 | ST_F_WREW, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 421 | ST_F_CONNECT, |
| 422 | ST_F_REUSE, |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 423 | ST_F_CACHE_LOOKUPS, |
| 424 | ST_F_CACHE_HITS, |
Willy Tarreau | f21d17b | 2019-09-08 09:24:56 +0200 | [diff] [blame] | 425 | ST_F_SRV_ICUR, |
| 426 | ST_F_SRV_ILIM, |
Christopher Faulet | 0d1c2a6 | 2019-11-08 14:59:51 +0100 | [diff] [blame] | 427 | ST_F_QT_MAX, |
| 428 | ST_F_CT_MAX, |
| 429 | ST_F_RT_MAX, |
| 430 | ST_F_TT_MAX, |
Christopher Faulet | 0159ee4 | 2019-12-16 14:40:39 +0100 | [diff] [blame] | 431 | ST_F_EINT, |
Willy Tarreau | 3bb617c | 2020-06-29 13:51:05 +0200 | [diff] [blame] | 432 | ST_F_IDLE_CONN_CUR, |
| 433 | ST_F_SAFE_CONN_CUR, |
| 434 | ST_F_USED_CONN_CUR, |
Willy Tarreau | a9fcecb | 2020-06-29 15:38:53 +0200 | [diff] [blame] | 435 | ST_F_NEED_CONN_EST, |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 436 | |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 437 | /* must always be the last one */ |
| 438 | ST_F_TOTAL_FIELDS |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 439 | }; |
| 440 | |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 441 | /* Please consider updating stats_dump_fields_*(), |
| 442 | * stats_dump_.*_info_fields() and stats_*_schema() |
| 443 | * when modifying struct field or related enums. |
| 444 | */ |
| 445 | struct field { |
| 446 | uint32_t type; |
| 447 | union { |
| 448 | int32_t s32; /* FF_S32 */ |
| 449 | uint32_t u32; /* FF_U32 */ |
| 450 | int64_t s64; /* FF_S64 */ |
| 451 | uint64_t u64; /* FF_U64 */ |
| 452 | double flt; /* FF_FLT */ |
| 453 | const char *str; /* FF_STR */ |
| 454 | } u; |
| 455 | }; |
| 456 | |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 457 | enum counters_type { |
| 458 | COUNTERS_FE = 0, |
| 459 | COUNTERS_BE, |
| 460 | COUNTERS_SV, |
| 461 | COUNTERS_LI, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame^] | 462 | COUNTERS_DNS, |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 463 | |
| 464 | COUNTERS_OFF_END |
| 465 | }; |
| 466 | |
| 467 | /* Entity used to generate statistics on an HAProxy component */ |
| 468 | struct stats_module { |
| 469 | struct list list; |
| 470 | const char *name; |
| 471 | |
| 472 | /* functor used to generate the stats module using counters provided through data parameter */ |
| 473 | void (*fill_stats)(void *data, struct field *); |
| 474 | |
| 475 | struct name_desc *stats; /* name/description of stats provided by the module */ |
| 476 | void *counters; /* initial values of allocated counters */ |
| 477 | size_t counters_off[COUNTERS_OFF_END]; /* list of offsets of allocated counters in various objects */ |
| 478 | size_t stats_count; /* count of stats provided */ |
| 479 | size_t counters_size; /* sizeof counters */ |
| 480 | |
| 481 | uint32_t domain_flags; /* stats application domain for this module */ |
Amaury Denoyelle | d3700a7 | 2020-10-05 11:49:43 +0200 | [diff] [blame] | 482 | char clearable; /* reset on a clear counters */ |
Amaury Denoyelle | 58d395e | 2020-10-05 11:49:40 +0200 | [diff] [blame] | 483 | }; |
| 484 | |
Amaury Denoyelle | 730c727 | 2020-10-05 11:49:41 +0200 | [diff] [blame] | 485 | struct extra_counters { |
| 486 | char *data; /* heap containing counters allocated in a linear fashion */ |
| 487 | size_t size; /* size of allocated data */ |
| 488 | enum counters_type type; /* type of object containing the counters */ |
| 489 | }; |
| 490 | |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 491 | /* stats_domain is used in a flag as a 1 byte field */ |
| 492 | enum stats_domain { |
| 493 | STATS_DOMAIN_PROXY = 0, |
Amaury Denoyelle | fbd0bc9 | 2020-10-05 11:49:46 +0200 | [diff] [blame^] | 494 | STATS_DOMAIN_DNS, |
Amaury Denoyelle | 072f97e | 2020-10-05 11:49:37 +0200 | [diff] [blame] | 495 | STATS_DOMAIN_COUNT, |
| 496 | |
| 497 | STATS_DOMAIN_MASK = 0xff |
| 498 | }; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 499 | |
Amaury Denoyelle | 72b16e5 | 2020-10-05 11:49:38 +0200 | [diff] [blame] | 500 | /* used in a flag as a 1 byte field */ |
| 501 | enum stats_domain_px_cap { |
| 502 | STATS_PX_CAP_FE = 0x01, |
| 503 | STATS_PX_CAP_BE = 0x02, |
| 504 | STATS_PX_CAP_SRV = 0x04, |
| 505 | STATS_PX_CAP_LI = 0x08, |
| 506 | |
| 507 | STATS_PX_CAP_MASK = 0xff |
| 508 | }; |
| 509 | |
Amaury Denoyelle | 730c727 | 2020-10-05 11:49:41 +0200 | [diff] [blame] | 510 | #define EXTRA_COUNTERS(name) \ |
| 511 | struct extra_counters *name |
| 512 | |
| 513 | #define EXTRA_COUNTERS_GET(counters, mod) \ |
| 514 | (void *)((counters)->data + (mod)->counters_off[(counters)->type]) |
| 515 | |
| 516 | #define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label) \ |
| 517 | do { \ |
| 518 | typeof(*counters) _ctr; \ |
| 519 | _ctr = calloc(1, sizeof(*_ctr)); \ |
| 520 | if (!_ctr) \ |
| 521 | goto alloc_failed_label; \ |
| 522 | _ctr->type = (ctype); \ |
| 523 | *(counters) = _ctr; \ |
| 524 | } while (0) |
| 525 | |
| 526 | #define EXTRA_COUNTERS_ADD(mod, counters, new_counters, csize) \ |
| 527 | do { \ |
| 528 | typeof(counters) _ctr = (counters); \ |
| 529 | (mod)->counters_off[_ctr->type] = _ctr->size; \ |
| 530 | _ctr->size += (csize); \ |
| 531 | } while (0) |
| 532 | |
| 533 | #define EXTRA_COUNTERS_ALLOC(counters, alloc_failed_label) \ |
| 534 | do { \ |
| 535 | typeof(counters) _ctr = (counters); \ |
| 536 | _ctr->data = malloc((_ctr)->size); \ |
| 537 | if (!_ctr->data) \ |
| 538 | goto alloc_failed_label; \ |
| 539 | } while (0) |
| 540 | |
| 541 | #define EXTRA_COUNTERS_INIT(counters, mod, init_counters, init_counters_size) \ |
| 542 | do { \ |
| 543 | typeof(counters) _ctr = (counters); \ |
| 544 | memcpy(_ctr->data + mod->counters_off[_ctr->type], \ |
| 545 | (init_counters), (init_counters_size)); \ |
| 546 | } while (0) |
| 547 | |
| 548 | #define EXTRA_COUNTERS_FREE(counters) \ |
| 549 | do { \ |
| 550 | if (counters) { \ |
| 551 | free((counters)->data); \ |
| 552 | free(counters); \ |
| 553 | } \ |
| 554 | } while (0) |
| 555 | |
Willy Tarreau | 2eec9b5 | 2020-06-04 19:58:55 +0200 | [diff] [blame] | 556 | #endif /* _HAPROXY_STATS_T_H */ |