William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Functions dedicated to statistics output and the stats socket |
| 3 | * |
| 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
| 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <ctype.h> |
| 15 | #include <errno.h> |
| 16 | #include <fcntl.h> |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
| 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
| 27 | #include <common/cfgparse.h> |
| 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
Willy Tarreau | 35b51c6 | 2018-09-10 15:38:55 +0200 | [diff] [blame] | 31 | #include <common/http.h> |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 32 | #include <common/htx.h> |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 33 | #include <common/initcall.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 34 | #include <common/memory.h> |
| 35 | #include <common/mini-clist.h> |
| 36 | #include <common/standard.h> |
| 37 | #include <common/ticks.h> |
| 38 | #include <common/time.h> |
| 39 | #include <common/uri_auth.h> |
| 40 | #include <common/version.h> |
| 41 | #include <common/base64.h> |
| 42 | |
| 43 | #include <types/applet.h> |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 44 | #include <types/cli.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 45 | #include <types/global.h> |
| 46 | #include <types/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 47 | #include <types/stats.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 48 | |
| 49 | #include <proto/backend.h> |
| 50 | #include <proto/channel.h> |
| 51 | #include <proto/checks.h> |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 52 | #include <proto/cli.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 53 | #include <proto/compression.h> |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 54 | #include <proto/dns.h> |
William Lallemand | 9ed6203 | 2016-11-21 17:49:11 +0100 | [diff] [blame] | 55 | #include <proto/stats.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 56 | #include <proto/fd.h> |
| 57 | #include <proto/freq_ctr.h> |
| 58 | #include <proto/frontend.h> |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 59 | #include <proto/http_htx.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 60 | #include <proto/log.h> |
| 61 | #include <proto/pattern.h> |
| 62 | #include <proto/pipe.h> |
| 63 | #include <proto/listener.h> |
| 64 | #include <proto/map.h> |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 65 | #include <proto/proto_http.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 66 | #include <proto/proxy.h> |
| 67 | #include <proto/sample.h> |
| 68 | #include <proto/session.h> |
Willy Tarreau | c125cef | 2019-05-10 09:58:43 +0200 | [diff] [blame] | 69 | #include <proto/ssl_sock.h> |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 70 | #include <proto/stream.h> |
| 71 | #include <proto/server.h> |
| 72 | #include <proto/raw_sock.h> |
| 73 | #include <proto/stream_interface.h> |
| 74 | #include <proto/task.h> |
| 75 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 76 | |
Christopher Faulet | 2b9b678 | 2019-02-27 16:42:58 +0100 | [diff] [blame] | 77 | /* status codes available for the stats admin page (strictly 4 chars length) */ |
| 78 | const char *stat_status_codes[STAT_STATUS_SIZE] = { |
| 79 | [STAT_STATUS_DENY] = "DENY", |
| 80 | [STAT_STATUS_DONE] = "DONE", |
| 81 | [STAT_STATUS_ERRP] = "ERRP", |
| 82 | [STAT_STATUS_EXCD] = "EXCD", |
| 83 | [STAT_STATUS_NONE] = "NONE", |
| 84 | [STAT_STATUS_PART] = "PART", |
| 85 | [STAT_STATUS_UNKN] = "UNKN", |
| 86 | [STAT_STATUS_IVAL] = "IVAL", |
| 87 | }; |
| 88 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 89 | /* These are the field names for each INF_* field position. Please pay attention |
| 90 | * to always use the exact same name except that the strings for new names must |
| 91 | * be lower case or CamelCase while the enum entries must be upper case. |
| 92 | */ |
| 93 | const char *info_field_names[INF_TOTAL_FIELDS] = { |
| 94 | [INF_NAME] = "Name", |
| 95 | [INF_VERSION] = "Version", |
| 96 | [INF_RELEASE_DATE] = "Release_date", |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 97 | [INF_NBTHREAD] = "Nbthread", |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 98 | [INF_NBPROC] = "Nbproc", |
| 99 | [INF_PROCESS_NUM] = "Process_num", |
| 100 | [INF_PID] = "Pid", |
| 101 | [INF_UPTIME] = "Uptime", |
| 102 | [INF_UPTIME_SEC] = "Uptime_sec", |
| 103 | [INF_MEMMAX_MB] = "Memmax_MB", |
| 104 | [INF_POOL_ALLOC_MB] = "PoolAlloc_MB", |
| 105 | [INF_POOL_USED_MB] = "PoolUsed_MB", |
| 106 | [INF_POOL_FAILED] = "PoolFailed", |
| 107 | [INF_ULIMIT_N] = "Ulimit-n", |
| 108 | [INF_MAXSOCK] = "Maxsock", |
| 109 | [INF_MAXCONN] = "Maxconn", |
| 110 | [INF_HARD_MAXCONN] = "Hard_maxconn", |
| 111 | [INF_CURR_CONN] = "CurrConns", |
| 112 | [INF_CUM_CONN] = "CumConns", |
| 113 | [INF_CUM_REQ] = "CumReq", |
| 114 | [INF_MAX_SSL_CONNS] = "MaxSslConns", |
| 115 | [INF_CURR_SSL_CONNS] = "CurrSslConns", |
| 116 | [INF_CUM_SSL_CONNS] = "CumSslConns", |
| 117 | [INF_MAXPIPES] = "Maxpipes", |
| 118 | [INF_PIPES_USED] = "PipesUsed", |
| 119 | [INF_PIPES_FREE] = "PipesFree", |
| 120 | [INF_CONN_RATE] = "ConnRate", |
| 121 | [INF_CONN_RATE_LIMIT] = "ConnRateLimit", |
| 122 | [INF_MAX_CONN_RATE] = "MaxConnRate", |
| 123 | [INF_SESS_RATE] = "SessRate", |
| 124 | [INF_SESS_RATE_LIMIT] = "SessRateLimit", |
| 125 | [INF_MAX_SESS_RATE] = "MaxSessRate", |
| 126 | [INF_SSL_RATE] = "SslRate", |
| 127 | [INF_SSL_RATE_LIMIT] = "SslRateLimit", |
| 128 | [INF_MAX_SSL_RATE] = "MaxSslRate", |
| 129 | [INF_SSL_FRONTEND_KEY_RATE] = "SslFrontendKeyRate", |
| 130 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = "SslFrontendMaxKeyRate", |
| 131 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = "SslFrontendSessionReuse_pct", |
| 132 | [INF_SSL_BACKEND_KEY_RATE] = "SslBackendKeyRate", |
| 133 | [INF_SSL_BACKEND_MAX_KEY_RATE] = "SslBackendMaxKeyRate", |
| 134 | [INF_SSL_CACHE_LOOKUPS] = "SslCacheLookups", |
| 135 | [INF_SSL_CACHE_MISSES] = "SslCacheMisses", |
| 136 | [INF_COMPRESS_BPS_IN] = "CompressBpsIn", |
| 137 | [INF_COMPRESS_BPS_OUT] = "CompressBpsOut", |
| 138 | [INF_COMPRESS_BPS_RATE_LIM] = "CompressBpsRateLim", |
| 139 | [INF_ZLIB_MEM_USAGE] = "ZlibMemUsage", |
| 140 | [INF_MAX_ZLIB_MEM_USAGE] = "MaxZlibMemUsage", |
| 141 | [INF_TASKS] = "Tasks", |
| 142 | [INF_RUN_QUEUE] = "Run_queue", |
| 143 | [INF_IDLE_PCT] = "Idle_pct", |
| 144 | [INF_NODE] = "node", |
| 145 | [INF_DESCRIPTION] = "description", |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 146 | [INF_STOPPING] = "Stopping", |
| 147 | [INF_JOBS] = "Jobs", |
William Lallemand | a719926 | 2018-11-16 16:57:20 +0100 | [diff] [blame] | 148 | [INF_UNSTOPPABLE_JOBS] = "Unstoppable Jobs", |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 149 | [INF_LISTENERS] = "Listeners", |
Willy Tarreau | 199ad24 | 2018-11-05 16:31:22 +0100 | [diff] [blame] | 150 | [INF_ACTIVE_PEERS] = "ActivePeers", |
Willy Tarreau | 2d372c2 | 2018-11-05 17:12:27 +0100 | [diff] [blame] | 151 | [INF_CONNECTED_PEERS] = "ConnectedPeers", |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 152 | [INF_DROPPED_LOGS] = "DroppedLogs", |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 153 | [INF_BUSY_POLLING] = "BusyPolling", |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 154 | [INF_FAILED_RESOLUTIONS] = "FailedResolutions", |
Willy Tarreau | 7cf0e45 | 2019-05-23 11:39:14 +0200 | [diff] [blame] | 155 | [INF_TOTAL_BYTES_OUT] = "TotalBytesOut", |
| 156 | [INF_BYTES_OUT_RATE] = "BytesOutRate", |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 157 | }; |
| 158 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 159 | const char *stat_field_names[ST_F_TOTAL_FIELDS] = { |
| 160 | [ST_F_PXNAME] = "pxname", |
| 161 | [ST_F_SVNAME] = "svname", |
| 162 | [ST_F_QCUR] = "qcur", |
| 163 | [ST_F_QMAX] = "qmax", |
| 164 | [ST_F_SCUR] = "scur", |
| 165 | [ST_F_SMAX] = "smax", |
| 166 | [ST_F_SLIM] = "slim", |
| 167 | [ST_F_STOT] = "stot", |
| 168 | [ST_F_BIN] = "bin", |
| 169 | [ST_F_BOUT] = "bout", |
| 170 | [ST_F_DREQ] = "dreq", |
| 171 | [ST_F_DRESP] = "dresp", |
| 172 | [ST_F_EREQ] = "ereq", |
| 173 | [ST_F_ECON] = "econ", |
| 174 | [ST_F_ERESP] = "eresp", |
| 175 | [ST_F_WRETR] = "wretr", |
| 176 | [ST_F_WREDIS] = "wredis", |
| 177 | [ST_F_STATUS] = "status", |
| 178 | [ST_F_WEIGHT] = "weight", |
| 179 | [ST_F_ACT] = "act", |
| 180 | [ST_F_BCK] = "bck", |
| 181 | [ST_F_CHKFAIL] = "chkfail", |
| 182 | [ST_F_CHKDOWN] = "chkdown", |
| 183 | [ST_F_LASTCHG] = "lastchg", |
| 184 | [ST_F_DOWNTIME] = "downtime", |
| 185 | [ST_F_QLIMIT] = "qlimit", |
| 186 | [ST_F_PID] = "pid", |
| 187 | [ST_F_IID] = "iid", |
| 188 | [ST_F_SID] = "sid", |
| 189 | [ST_F_THROTTLE] = "throttle", |
| 190 | [ST_F_LBTOT] = "lbtot", |
| 191 | [ST_F_TRACKED] = "tracked", |
| 192 | [ST_F_TYPE] = "type", |
| 193 | [ST_F_RATE] = "rate", |
| 194 | [ST_F_RATE_LIM] = "rate_lim", |
| 195 | [ST_F_RATE_MAX] = "rate_max", |
| 196 | [ST_F_CHECK_STATUS] = "check_status", |
| 197 | [ST_F_CHECK_CODE] = "check_code", |
| 198 | [ST_F_CHECK_DURATION] = "check_duration", |
| 199 | [ST_F_HRSP_1XX] = "hrsp_1xx", |
| 200 | [ST_F_HRSP_2XX] = "hrsp_2xx", |
| 201 | [ST_F_HRSP_3XX] = "hrsp_3xx", |
| 202 | [ST_F_HRSP_4XX] = "hrsp_4xx", |
| 203 | [ST_F_HRSP_5XX] = "hrsp_5xx", |
| 204 | [ST_F_HRSP_OTHER] = "hrsp_other", |
| 205 | [ST_F_HANAFAIL] = "hanafail", |
| 206 | [ST_F_REQ_RATE] = "req_rate", |
| 207 | [ST_F_REQ_RATE_MAX] = "req_rate_max", |
| 208 | [ST_F_REQ_TOT] = "req_tot", |
| 209 | [ST_F_CLI_ABRT] = "cli_abrt", |
| 210 | [ST_F_SRV_ABRT] = "srv_abrt", |
| 211 | [ST_F_COMP_IN] = "comp_in", |
| 212 | [ST_F_COMP_OUT] = "comp_out", |
| 213 | [ST_F_COMP_BYP] = "comp_byp", |
| 214 | [ST_F_COMP_RSP] = "comp_rsp", |
| 215 | [ST_F_LASTSESS] = "lastsess", |
| 216 | [ST_F_LAST_CHK] = "last_chk", |
| 217 | [ST_F_LAST_AGT] = "last_agt", |
| 218 | [ST_F_QTIME] = "qtime", |
| 219 | [ST_F_CTIME] = "ctime", |
| 220 | [ST_F_RTIME] = "rtime", |
| 221 | [ST_F_TTIME] = "ttime", |
| 222 | [ST_F_AGENT_STATUS] = "agent_status", |
| 223 | [ST_F_AGENT_CODE] = "agent_code", |
| 224 | [ST_F_AGENT_DURATION] = "agent_duration", |
| 225 | [ST_F_CHECK_DESC] = "check_desc", |
| 226 | [ST_F_AGENT_DESC] = "agent_desc", |
| 227 | [ST_F_CHECK_RISE] = "check_rise", |
| 228 | [ST_F_CHECK_FALL] = "check_fall", |
| 229 | [ST_F_CHECK_HEALTH] = "check_health", |
| 230 | [ST_F_AGENT_RISE] = "agent_rise", |
| 231 | [ST_F_AGENT_FALL] = "agent_fall", |
| 232 | [ST_F_AGENT_HEALTH] = "agent_health", |
| 233 | [ST_F_ADDR] = "addr", |
| 234 | [ST_F_COOKIE] = "cookie", |
| 235 | [ST_F_MODE] = "mode", |
| 236 | [ST_F_ALGO] = "algo", |
| 237 | [ST_F_CONN_RATE] = "conn_rate", |
| 238 | [ST_F_CONN_RATE_MAX] = "conn_rate_max", |
| 239 | [ST_F_CONN_TOT] = "conn_tot", |
| 240 | [ST_F_INTERCEPTED] = "intercepted", |
| 241 | [ST_F_DCON] = "dcon", |
| 242 | [ST_F_DSES] = "dses", |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 243 | [ST_F_WREW] = "wrew", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 244 | [ST_F_CONNECT] = "connect", |
| 245 | [ST_F_REUSE] = "reuse", |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 246 | [ST_F_CACHE_LOOKUPS] = "cache_lookups", |
| 247 | [ST_F_CACHE_HITS] = "cache_hits", |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 248 | }; |
| 249 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 250 | /* one line of info */ |
Christopher Faulet | 1bc04c7 | 2017-10-29 20:14:08 +0100 | [diff] [blame] | 251 | static THREAD_LOCAL struct field info[INF_TOTAL_FIELDS]; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 252 | /* one line of stats */ |
Christopher Faulet | 1bc04c7 | 2017-10-29 20:14:08 +0100 | [diff] [blame] | 253 | static THREAD_LOCAL struct field stats[ST_F_TOTAL_FIELDS]; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 254 | |
| 255 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 256 | static int stats_putchk(struct channel *chn, struct htx *htx, struct buffer *chk) |
| 257 | { |
| 258 | if (htx) { |
Christopher Faulet | 69fc88c | 2019-01-07 14:27:53 +0100 | [diff] [blame] | 259 | if (chk->data >= channel_htx_recv_max(chn, htx)) |
| 260 | return 0; |
Willy Tarreau | 0a7ef02 | 2019-05-28 10:30:11 +0200 | [diff] [blame] | 261 | if (!htx_add_data_atonce(htx, ist2(chk->area, chk->data))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 262 | return 0; |
Christopher Faulet | 5adbeeb | 2019-01-02 14:34:39 +0100 | [diff] [blame] | 263 | channel_add_input(chn, chk->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 264 | chk->data = 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 265 | } |
| 266 | else { |
| 267 | if (ci_putchk(chn, chk) == -1) |
| 268 | return 0; |
| 269 | } |
| 270 | return 1; |
| 271 | } |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 272 | |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 273 | static const char *stats_scope_ptr(struct appctx *appctx, struct stream_interface *si) |
| 274 | { |
| 275 | const char *p; |
| 276 | |
| 277 | if (IS_HTX_STRM(si_strm(si))) { |
| 278 | struct channel *req = si_oc(si); |
| 279 | struct htx *htx = htxbuf(&req->buf); |
Christopher Faulet | 8fa60e4 | 2019-05-23 11:04:05 +0200 | [diff] [blame] | 280 | struct htx_blk *blk; |
| 281 | struct ist uri; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 282 | |
Christopher Faulet | 8fa60e4 | 2019-05-23 11:04:05 +0200 | [diff] [blame] | 283 | blk = htx_get_head_blk(htx); |
| 284 | BUG_ON(htx_get_blk_type(blk) != HTX_BLK_REQ_SL); |
| 285 | ALREADY_CHECKED(blk); |
| 286 | uri = htx_sl_req_uri(htx_get_blk_ptr(htx, blk)); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 287 | p = uri.ptr; |
| 288 | } |
| 289 | else |
| 290 | p = co_head(si_oc(si)); |
| 291 | |
| 292 | return p + appctx->ctx.stats.scope_str; |
| 293 | } |
| 294 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 295 | /* |
| 296 | * http_stats_io_handler() |
| 297 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 298 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 299 | * -> stats_dump_json_header() // emits the JSON headers (same as above) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 300 | * -> stats_dump_html_head() // emits the HTML headers |
| 301 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 302 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 303 | * -> stats_dump_html_px_hdr() |
| 304 | * -> stats_dump_fe_stats() |
| 305 | * -> stats_dump_li_stats() |
| 306 | * -> stats_dump_sv_stats() |
| 307 | * -> stats_dump_be_stats() |
| 308 | * -> stats_dump_html_px_end() |
| 309 | * -> stats_dump_html_end() // emits HTML trailer |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 310 | * -> stats_dump_json_end() // emits JSON trailer |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 311 | */ |
| 312 | |
| 313 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 314 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 315 | * for clearing it if needed. |
| 316 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 317 | * so please only append new fields at the end, never in the middle. |
| 318 | */ |
| 319 | static void stats_dump_csv_header() |
| 320 | { |
| 321 | int field; |
| 322 | |
| 323 | chunk_appendf(&trash, "# "); |
| 324 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) |
| 325 | chunk_appendf(&trash, "%s,", stat_field_names[field]); |
| 326 | |
| 327 | chunk_appendf(&trash, "\n"); |
| 328 | } |
| 329 | |
| 330 | |
| 331 | /* Emits a stats field without any surrounding element and properly encoded to |
| 332 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 333 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 334 | int stats_emit_raw_data_field(struct buffer *out, const struct field *f) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 335 | { |
| 336 | switch (field_format(f, 0)) { |
| 337 | case FF_EMPTY: return 1; |
| 338 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 339 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 340 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 341 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 342 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 343 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 348 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 349 | * if the buffer is full. |
| 350 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 351 | int stats_emit_typed_data_field(struct buffer *out, const struct field *f) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 352 | { |
| 353 | switch (field_format(f, 0)) { |
| 354 | case FF_EMPTY: return 1; |
| 355 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 356 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 357 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 358 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
| 359 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 360 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 361 | } |
| 362 | } |
| 363 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 364 | /* Limit JSON integer values to the range [-(2**53)+1, (2**53)-1] as per |
| 365 | * the recommendation for interoperable integers in section 6 of RFC 7159. |
| 366 | */ |
| 367 | #define JSON_INT_MAX ((1ULL << 53) - 1) |
| 368 | #define JSON_INT_MIN (0 - JSON_INT_MAX) |
| 369 | |
| 370 | /* Emits a stats field value and its type in JSON. |
| 371 | * Returns non-zero on success, 0 on error. |
| 372 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 373 | int stats_emit_json_data_field(struct buffer *out, const struct field *f) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 374 | { |
| 375 | int old_len; |
| 376 | char buf[20]; |
| 377 | const char *type, *value = buf, *quote = ""; |
| 378 | |
| 379 | switch (field_format(f, 0)) { |
| 380 | case FF_EMPTY: return 1; |
| 381 | case FF_S32: type = "\"s32\""; |
| 382 | snprintf(buf, sizeof(buf), "%d", f->u.s32); |
| 383 | break; |
| 384 | case FF_U32: type = "\"u32\""; |
| 385 | snprintf(buf, sizeof(buf), "%u", f->u.u32); |
| 386 | break; |
| 387 | case FF_S64: type = "\"s64\""; |
| 388 | if (f->u.s64 < JSON_INT_MIN || f->u.s64 > JSON_INT_MAX) |
| 389 | return 0; |
| 390 | type = "\"s64\""; |
| 391 | snprintf(buf, sizeof(buf), "%lld", (long long)f->u.s64); |
| 392 | break; |
| 393 | case FF_U64: if (f->u.u64 > JSON_INT_MAX) |
| 394 | return 0; |
| 395 | type = "\"u64\""; |
| 396 | snprintf(buf, sizeof(buf), "%llu", |
| 397 | (unsigned long long) f->u.u64); |
| 398 | break; |
| 399 | case FF_STR: type = "\"str\""; |
| 400 | value = field_str(f, 0); |
| 401 | quote = "\""; |
| 402 | break; |
| 403 | default: snprintf(buf, sizeof(buf), "%u", f->type); |
| 404 | type = buf; |
| 405 | value = "unknown"; |
| 406 | quote = "\""; |
| 407 | break; |
| 408 | } |
| 409 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 410 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 411 | chunk_appendf(out, ",\"value\":{\"type\":%s,\"value\":%s%s%s}", |
| 412 | type, quote, value, quote); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 413 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 414 | } |
| 415 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 416 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 417 | * Returns non-zero on success, 0 if the buffer is full. |
| 418 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 419 | int stats_emit_field_tags(struct buffer *out, const struct field *f, |
| 420 | char delim) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 421 | { |
| 422 | char origin, nature, scope; |
| 423 | |
| 424 | switch (field_origin(f, 0)) { |
| 425 | case FO_METRIC: origin = 'M'; break; |
| 426 | case FO_STATUS: origin = 'S'; break; |
| 427 | case FO_KEY: origin = 'K'; break; |
| 428 | case FO_CONFIG: origin = 'C'; break; |
| 429 | case FO_PRODUCT: origin = 'P'; break; |
| 430 | default: origin = '?'; break; |
| 431 | } |
| 432 | |
| 433 | switch (field_nature(f, 0)) { |
| 434 | case FN_GAUGE: nature = 'G'; break; |
| 435 | case FN_LIMIT: nature = 'L'; break; |
| 436 | case FN_MIN: nature = 'm'; break; |
| 437 | case FN_MAX: nature = 'M'; break; |
| 438 | case FN_RATE: nature = 'R'; break; |
| 439 | case FN_COUNTER: nature = 'C'; break; |
| 440 | case FN_DURATION: nature = 'D'; break; |
| 441 | case FN_AGE: nature = 'A'; break; |
| 442 | case FN_TIME: nature = 'T'; break; |
| 443 | case FN_NAME: nature = 'N'; break; |
| 444 | case FN_OUTPUT: nature = 'O'; break; |
| 445 | case FN_AVG: nature = 'a'; break; |
| 446 | default: nature = '?'; break; |
| 447 | } |
| 448 | |
| 449 | switch (field_scope(f, 0)) { |
| 450 | case FS_PROCESS: scope = 'P'; break; |
| 451 | case FS_SERVICE: scope = 'S'; break; |
| 452 | case FS_SYSTEM: scope = 's'; break; |
| 453 | case FS_CLUSTER: scope = 'C'; break; |
| 454 | default: scope = '?'; break; |
| 455 | } |
| 456 | |
| 457 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 458 | } |
| 459 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 460 | /* Emits an encoding of the field type as JSON. |
| 461 | * Returns non-zero on success, 0 if the buffer is full. |
| 462 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 463 | int stats_emit_json_field_tags(struct buffer *out, const struct field *f) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 464 | { |
| 465 | const char *origin, *nature, *scope; |
| 466 | int old_len; |
| 467 | |
| 468 | switch (field_origin(f, 0)) { |
| 469 | case FO_METRIC: origin = "Metric"; break; |
| 470 | case FO_STATUS: origin = "Status"; break; |
| 471 | case FO_KEY: origin = "Key"; break; |
| 472 | case FO_CONFIG: origin = "Config"; break; |
| 473 | case FO_PRODUCT: origin = "Product"; break; |
| 474 | default: origin = "Unknown"; break; |
| 475 | } |
| 476 | |
| 477 | switch (field_nature(f, 0)) { |
| 478 | case FN_GAUGE: nature = "Gauge"; break; |
| 479 | case FN_LIMIT: nature = "Limit"; break; |
| 480 | case FN_MIN: nature = "Min"; break; |
| 481 | case FN_MAX: nature = "Max"; break; |
| 482 | case FN_RATE: nature = "Rate"; break; |
| 483 | case FN_COUNTER: nature = "Counter"; break; |
| 484 | case FN_DURATION: nature = "Duration"; break; |
| 485 | case FN_AGE: nature = "Age"; break; |
| 486 | case FN_TIME: nature = "Time"; break; |
| 487 | case FN_NAME: nature = "Name"; break; |
| 488 | case FN_OUTPUT: nature = "Output"; break; |
| 489 | case FN_AVG: nature = "Avg"; break; |
| 490 | default: nature = "Unknown"; break; |
| 491 | } |
| 492 | |
| 493 | switch (field_scope(f, 0)) { |
| 494 | case FS_PROCESS: scope = "Process"; break; |
| 495 | case FS_SERVICE: scope = "Service"; break; |
| 496 | case FS_SYSTEM: scope = "System"; break; |
| 497 | case FS_CLUSTER: scope = "Cluster"; break; |
| 498 | default: scope = "Unknown"; break; |
| 499 | } |
| 500 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 501 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 502 | chunk_appendf(out, "\"tags\":{" |
| 503 | "\"origin\":\"%s\"," |
| 504 | "\"nature\":\"%s\"," |
| 505 | "\"scope\":\"%s\"" |
| 506 | "}", origin, nature, scope); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 507 | return !(old_len == out->data); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 508 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 509 | |
| 510 | /* Dump all fields from <stats> into <out> using CSV format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 511 | static int stats_dump_fields_csv(struct buffer *out, |
| 512 | const struct field *stats) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 513 | { |
| 514 | int field; |
| 515 | |
| 516 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 517 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 518 | return 0; |
| 519 | if (!chunk_strcat(out, ",")) |
| 520 | return 0; |
| 521 | } |
| 522 | chunk_strcat(out, "\n"); |
| 523 | return 1; |
| 524 | } |
| 525 | |
| 526 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 527 | static int stats_dump_fields_typed(struct buffer *out, |
| 528 | const struct field *stats) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 529 | { |
| 530 | int field; |
| 531 | |
| 532 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 533 | if (!stats[field].type) |
| 534 | continue; |
| 535 | |
| 536 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 537 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 538 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 539 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 540 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 541 | '?', |
| 542 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 543 | field, stat_field_names[field], stats[ST_F_PID].u.u32); |
| 544 | |
| 545 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 546 | return 0; |
| 547 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 548 | return 0; |
| 549 | if (!chunk_strcat(out, "\n")) |
| 550 | return 0; |
| 551 | } |
| 552 | return 1; |
| 553 | } |
| 554 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 555 | /* Dump all fields from <stats> into <out> using the "show info json" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 556 | static int stats_dump_json_info_fields(struct buffer *out, |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 557 | const struct field *info) |
| 558 | { |
| 559 | int field; |
| 560 | int started = 0; |
| 561 | |
| 562 | if (!chunk_strcat(out, "[")) |
| 563 | return 0; |
| 564 | |
| 565 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 566 | int old_len; |
| 567 | |
| 568 | if (!field_format(info, field)) |
| 569 | continue; |
| 570 | |
| 571 | if (started && !chunk_strcat(out, ",")) |
| 572 | goto err; |
| 573 | started = 1; |
| 574 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 575 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 576 | chunk_appendf(out, |
| 577 | "{\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 578 | "\"processNum\":%u,", |
| 579 | field, info_field_names[field], |
| 580 | info[INF_PROCESS_NUM].u.u32); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 581 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 582 | goto err; |
| 583 | |
| 584 | if (!stats_emit_json_field_tags(out, &info[field])) |
| 585 | goto err; |
| 586 | |
| 587 | if (!stats_emit_json_data_field(out, &info[field])) |
| 588 | goto err; |
| 589 | |
| 590 | if (!chunk_strcat(out, "}")) |
| 591 | goto err; |
| 592 | } |
| 593 | |
| 594 | if (!chunk_strcat(out, "]")) |
| 595 | goto err; |
| 596 | return 1; |
| 597 | |
| 598 | err: |
| 599 | chunk_reset(out); |
| 600 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}"); |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 605 | static int stats_dump_fields_json(struct buffer *out, |
| 606 | const struct field *stats, |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 607 | int first_stat) |
| 608 | { |
| 609 | int field; |
| 610 | int started = 0; |
| 611 | |
| 612 | if (!first_stat && !chunk_strcat(out, ",")) |
| 613 | return 0; |
| 614 | if (!chunk_strcat(out, "[")) |
| 615 | return 0; |
| 616 | |
| 617 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 618 | const char *obj_type; |
| 619 | int old_len; |
| 620 | |
| 621 | if (!stats[field].type) |
| 622 | continue; |
| 623 | |
| 624 | if (started && !chunk_strcat(out, ",")) |
| 625 | goto err; |
| 626 | started = 1; |
| 627 | |
| 628 | switch (stats[ST_F_TYPE].u.u32) { |
| 629 | case STATS_TYPE_FE: obj_type = "Frontend"; break; |
| 630 | case STATS_TYPE_BE: obj_type = "Backend"; break; |
| 631 | case STATS_TYPE_SO: obj_type = "Listener"; break; |
| 632 | case STATS_TYPE_SV: obj_type = "Server"; break; |
| 633 | default: obj_type = "Unknown"; break; |
| 634 | } |
| 635 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 636 | old_len = out->data; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 637 | chunk_appendf(out, |
| 638 | "{" |
| 639 | "\"objType\":\"%s\"," |
| 640 | "\"proxyId\":%d," |
| 641 | "\"id\":%d," |
| 642 | "\"field\":{\"pos\":%d,\"name\":\"%s\"}," |
| 643 | "\"processNum\":%u,", |
| 644 | obj_type, stats[ST_F_IID].u.u32, |
| 645 | stats[ST_F_SID].u.u32, field, |
| 646 | stat_field_names[field], stats[ST_F_PID].u.u32); |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 647 | if (old_len == out->data) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 648 | goto err; |
| 649 | |
| 650 | if (!stats_emit_json_field_tags(out, &stats[field])) |
| 651 | goto err; |
| 652 | |
| 653 | if (!stats_emit_json_data_field(out, &stats[field])) |
| 654 | goto err; |
| 655 | |
| 656 | if (!chunk_strcat(out, "}")) |
| 657 | goto err; |
| 658 | } |
| 659 | |
| 660 | if (!chunk_strcat(out, "]")) |
| 661 | goto err; |
| 662 | |
| 663 | return 1; |
| 664 | |
| 665 | err: |
| 666 | chunk_reset(out); |
| 667 | if (!first_stat) |
| 668 | chunk_strcat(out, ","); |
| 669 | chunk_appendf(out, "{\"errorStr\":\"output buffer too short\"}"); |
| 670 | return 0; |
| 671 | } |
| 672 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 673 | /* Dump all fields from <stats> into <out> using the HTML format. A column is |
| 674 | * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info |
| 675 | * are provided if ST_SHLGNDS is present in <flags>. |
| 676 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 677 | static int stats_dump_fields_html(struct buffer *out, |
| 678 | const struct field *stats, |
| 679 | unsigned int flags) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 680 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 681 | struct buffer src; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 682 | |
| 683 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
| 684 | chunk_appendf(out, |
| 685 | /* name, queue */ |
| 686 | "<tr class=\"frontend\">"); |
| 687 | |
| 688 | if (flags & ST_SHOWADMIN) { |
| 689 | /* Column sub-heading for Enable or Disable server */ |
| 690 | chunk_appendf(out, "<td></td>"); |
| 691 | } |
| 692 | |
| 693 | chunk_appendf(out, |
| 694 | "<td class=ac>" |
| 695 | "<a name=\"%s/Frontend\"></a>" |
| 696 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 697 | "<td colspan=3></td>" |
| 698 | "", |
| 699 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 700 | |
| 701 | chunk_appendf(out, |
| 702 | /* sessions rate : current */ |
| 703 | "<td><u>%s<div class=tips><table class=det>" |
| 704 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 705 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 706 | "", |
| 707 | U2H(stats[ST_F_RATE].u.u32), |
| 708 | U2H(stats[ST_F_CONN_RATE].u.u32), |
| 709 | U2H(stats[ST_F_RATE].u.u32)); |
| 710 | |
| 711 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 712 | chunk_appendf(out, |
| 713 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
| 714 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
| 715 | |
| 716 | chunk_appendf(out, |
| 717 | "</table></div></u></td>" |
| 718 | /* sessions rate : max */ |
| 719 | "<td><u>%s<div class=tips><table class=det>" |
| 720 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 721 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 722 | "", |
| 723 | U2H(stats[ST_F_RATE_MAX].u.u32), |
| 724 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
| 725 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 726 | |
| 727 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 728 | chunk_appendf(out, |
| 729 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
| 730 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
| 731 | |
| 732 | chunk_appendf(out, |
| 733 | "</table></div></u></td>" |
| 734 | /* sessions rate : limit */ |
| 735 | "<td>%s</td>", |
| 736 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
| 737 | |
| 738 | chunk_appendf(out, |
| 739 | /* sessions: current, max, limit, total */ |
| 740 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 741 | "<td><u>%s<div class=tips><table class=det>" |
| 742 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 743 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 744 | "", |
| 745 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 746 | U2H(stats[ST_F_STOT].u.u64), |
| 747 | U2H(stats[ST_F_CONN_TOT].u.u64), |
| 748 | U2H(stats[ST_F_STOT].u.u64)); |
| 749 | |
| 750 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 751 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 752 | chunk_appendf(out, |
| 753 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 754 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 755 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 756 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 757 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 758 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 759 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 760 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 761 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 762 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 763 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 764 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 765 | "", |
| 766 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 767 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 768 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 769 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 770 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 771 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 772 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 773 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 774 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 775 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 776 | U2H(stats[ST_F_INTERCEPTED].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 777 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 778 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 779 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 780 | (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0, |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 781 | U2H(stats[ST_F_WREW].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | chunk_appendf(out, |
| 785 | "</table></div></u></td>" |
| 786 | /* sessions: lbtot, lastsess */ |
| 787 | "<td></td><td></td>" |
| 788 | /* bytes : in */ |
| 789 | "<td>%s</td>" |
| 790 | "", |
| 791 | U2H(stats[ST_F_BIN].u.u64)); |
| 792 | |
| 793 | chunk_appendf(out, |
| 794 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 795 | "<td>%s%s<div class=tips><table class=det>" |
| 796 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 797 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 798 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 799 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 800 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 801 | "</table></div>%s</td>", |
| 802 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 803 | U2H(stats[ST_F_BOUT].u.u64), |
| 804 | U2H(stats[ST_F_BOUT].u.u64), |
| 805 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 806 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 807 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 808 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 809 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 810 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 811 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 812 | |
| 813 | chunk_appendf(out, |
| 814 | /* denied: req, resp */ |
| 815 | "<td>%s</td><td>%s</td>" |
| 816 | /* errors : request, connect, response */ |
| 817 | "<td>%s</td><td></td><td></td>" |
| 818 | /* warnings: retries, redispatches */ |
| 819 | "<td></td><td></td>" |
| 820 | /* server status : reflect frontend status */ |
| 821 | "<td class=ac>%s</td>" |
| 822 | /* rest of server: nothing */ |
| 823 | "<td class=ac colspan=8></td></tr>" |
| 824 | "", |
| 825 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 826 | U2H(stats[ST_F_EREQ].u.u64), |
| 827 | field_str(stats, ST_F_STATUS)); |
| 828 | } |
| 829 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
| 830 | chunk_appendf(out, "<tr class=socket>"); |
| 831 | if (flags & ST_SHOWADMIN) { |
| 832 | /* Column sub-heading for Enable or Disable server */ |
| 833 | chunk_appendf(out, "<td></td>"); |
| 834 | } |
| 835 | |
| 836 | chunk_appendf(out, |
| 837 | /* frontend name, listener name */ |
| 838 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 839 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 840 | "", |
| 841 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 842 | (flags & ST_SHLGNDS)?"<u>":"", |
| 843 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 844 | |
| 845 | if (flags & ST_SHLGNDS) { |
| 846 | chunk_appendf(out, "<div class=tips>"); |
| 847 | |
| 848 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
| 849 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 850 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 851 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 852 | else if (*field_str(stats, ST_F_ADDR)) |
| 853 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 854 | |
| 855 | /* id */ |
| 856 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
| 857 | } |
| 858 | |
| 859 | chunk_appendf(out, |
| 860 | /* queue */ |
| 861 | "%s</td><td colspan=3></td>" |
| 862 | /* sessions rate: current, max, limit */ |
| 863 | "<td colspan=3> </td>" |
| 864 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 865 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 866 | "<td>%s</td><td> </td><td> </td>" |
| 867 | /* bytes: in, out */ |
| 868 | "<td>%s</td><td>%s</td>" |
| 869 | "", |
| 870 | (flags & ST_SHLGNDS)?"</u>":"", |
| 871 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 872 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 873 | |
| 874 | chunk_appendf(out, |
| 875 | /* denied: req, resp */ |
| 876 | "<td>%s</td><td>%s</td>" |
| 877 | /* errors: request, connect, response */ |
| 878 | "<td>%s</td><td></td><td></td>" |
| 879 | /* warnings: retries, redispatches */ |
| 880 | "<td></td><td></td>" |
| 881 | /* server status: reflect listener status */ |
| 882 | "<td class=ac>%s</td>" |
| 883 | /* rest of server: nothing */ |
| 884 | "<td class=ac colspan=8></td></tr>" |
| 885 | "", |
| 886 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 887 | U2H(stats[ST_F_EREQ].u.u64), |
| 888 | field_str(stats, ST_F_STATUS)); |
| 889 | } |
| 890 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 891 | const char *style; |
| 892 | |
| 893 | /* determine the style to use depending on the server's state, |
| 894 | * its health and weight. There isn't a 1-to-1 mapping between |
| 895 | * state and styles for the cases where the server is (still) |
| 896 | * up. The reason is that we don't want to report nolb and |
| 897 | * drain with the same color. |
| 898 | */ |
| 899 | |
| 900 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 901 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 902 | style = "down"; |
| 903 | } |
| 904 | else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) { |
| 905 | style = "going_up"; |
| 906 | } |
| 907 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) { |
| 908 | style = "going_down"; |
| 909 | } |
| 910 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 911 | style = "nolb"; |
| 912 | } |
| 913 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 914 | style = "no_check"; |
| 915 | } |
| 916 | else if (!stats[ST_F_CHKFAIL].type || |
| 917 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 918 | /* no check or max health = UP */ |
| 919 | if (stats[ST_F_WEIGHT].u.u32) |
| 920 | style = "up"; |
| 921 | else |
| 922 | style = "draining"; |
| 923 | } |
| 924 | else { |
| 925 | style = "going_down"; |
| 926 | } |
| 927 | |
| 928 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
| 929 | chunk_appendf(out, "<tr class=\"maintain\">"); |
| 930 | else |
| 931 | chunk_appendf(out, |
| 932 | "<tr class=\"%s_%s\">", |
| 933 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
| 934 | |
| 935 | |
| 936 | if (flags & ST_SHOWADMIN) |
| 937 | chunk_appendf(out, |
David Harrigan | d3db35a | 2016-12-30 12:12:49 +0000 | [diff] [blame] | 938 | "<td><input class='%s-checkbox' type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 939 | field_str(stats, ST_F_PXNAME), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 940 | field_str(stats, ST_F_SVNAME)); |
| 941 | |
| 942 | chunk_appendf(out, |
| 943 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 944 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 945 | "", |
| 946 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 947 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 948 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 949 | |
| 950 | if (flags & ST_SHLGNDS) { |
| 951 | chunk_appendf(out, "<div class=tips>"); |
| 952 | |
| 953 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
| 954 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
| 955 | else if (*field_str(stats, ST_F_ADDR) == '[') |
| 956 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
| 957 | else if (*field_str(stats, ST_F_ADDR)) |
| 958 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
| 959 | |
| 960 | /* id */ |
| 961 | chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); |
| 962 | |
| 963 | /* cookie */ |
| 964 | if (stats[ST_F_COOKIE].type) { |
| 965 | chunk_appendf(out, ", cookie: '"); |
| 966 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 967 | chunk_htmlencode(out, &src); |
| 968 | chunk_appendf(out, "'"); |
| 969 | } |
| 970 | |
| 971 | chunk_appendf(out, "</div>"); |
| 972 | } |
| 973 | |
| 974 | chunk_appendf(out, |
| 975 | /* queue : current, max, limit */ |
| 976 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 977 | /* sessions rate : current, max, limit */ |
| 978 | "<td>%s</td><td>%s</td><td></td>" |
| 979 | "", |
| 980 | (flags & ST_SHLGNDS) ? "</u>" : "", |
| 981 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 982 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 983 | |
| 984 | chunk_appendf(out, |
| 985 | /* sessions: current, max, limit, total */ |
| 986 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 987 | "<td><u>%s<div class=tips><table class=det>" |
| 988 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 989 | "", |
| 990 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 991 | U2H(stats[ST_F_STOT].u.u64), |
| 992 | U2H(stats[ST_F_STOT].u.u64)); |
| 993 | |
| 994 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 995 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 996 | unsigned long long tot; |
| 997 | |
| 998 | tot = stats[ST_F_HRSP_OTHER].u.u64; |
| 999 | tot += stats[ST_F_HRSP_1XX].u.u64; |
| 1000 | tot += stats[ST_F_HRSP_2XX].u.u64; |
| 1001 | tot += stats[ST_F_HRSP_3XX].u.u64; |
| 1002 | tot += stats[ST_F_HRSP_4XX].u.u64; |
| 1003 | tot += stats[ST_F_HRSP_5XX].u.u64; |
| 1004 | |
| 1005 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1006 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1007 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1008 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 1009 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1010 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1011 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1012 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1013 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1014 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1015 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1016 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1017 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1018 | U2H(stats[ST_F_REUSE].u.u64), |
| 1019 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1020 | (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1021 | U2H(tot), |
| 1022 | U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0, |
| 1023 | U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0, |
| 1024 | U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0, |
| 1025 | U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0, |
| 1026 | U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0, |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1027 | U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0, |
| 1028 | U2H(stats[ST_F_WREW].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 1032 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 1033 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32)); |
| 1034 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 1035 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 1036 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32)); |
| 1037 | |
| 1038 | chunk_appendf(out, |
| 1039 | "</table></div></u></td>" |
| 1040 | /* sessions: lbtot, last */ |
| 1041 | "<td>%s</td><td>%s</td>", |
| 1042 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1043 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
| 1044 | |
| 1045 | chunk_appendf(out, |
| 1046 | /* bytes : in, out */ |
| 1047 | "<td>%s</td><td>%s</td>" |
| 1048 | /* denied: req, resp */ |
| 1049 | "<td></td><td>%s</td>" |
| 1050 | /* errors : request, connect */ |
| 1051 | "<td></td><td>%s</td>" |
| 1052 | /* errors : response */ |
| 1053 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1054 | /* warnings: retries, redispatches */ |
| 1055 | "<td>%lld</td><td>%lld</td>" |
| 1056 | "", |
| 1057 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 1058 | U2H(stats[ST_F_DRESP].u.u64), |
| 1059 | U2H(stats[ST_F_ECON].u.u64), |
| 1060 | U2H(stats[ST_F_ERESP].u.u64), |
| 1061 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1062 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1063 | (long long)stats[ST_F_WRETR].u.u64, |
| 1064 | (long long)stats[ST_F_WREDIS].u.u64); |
| 1065 | |
| 1066 | /* status, last change */ |
| 1067 | chunk_appendf(out, "<td class=ac>"); |
| 1068 | |
| 1069 | /* FIXME!!!! |
| 1070 | * LASTCHG should contain the last change for *this* server and must be computed |
| 1071 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 1072 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 1073 | */ |
| 1074 | |
| 1075 | |
| 1076 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
| 1077 | chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); |
| 1078 | } |
| 1079 | else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) { |
| 1080 | chunk_strcat(out, "<i>no check</i>"); |
| 1081 | } |
| 1082 | else { |
| 1083 | chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); |
| 1084 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
| 1085 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
| 1086 | chunk_strcat(out, " ↑"); |
| 1087 | } |
| 1088 | else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) |
| 1089 | chunk_strcat(out, " ↓"); |
| 1090 | } |
| 1091 | |
| 1092 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
| 1093 | stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { |
| 1094 | chunk_appendf(out, |
| 1095 | "</td><td class=ac><u> %s", |
| 1096 | field_str(stats, ST_F_AGENT_STATUS)); |
| 1097 | |
| 1098 | if (stats[ST_F_AGENT_CODE].type) |
| 1099 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
| 1100 | |
| 1101 | if (stats[ST_F_AGENT_DURATION].type) |
| 1102 | chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); |
| 1103 | |
| 1104 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC)); |
| 1105 | |
| 1106 | if (*field_str(stats, ST_F_LAST_AGT)) { |
| 1107 | chunk_appendf(out, ": "); |
| 1108 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
| 1109 | chunk_htmlencode(out, &src); |
| 1110 | } |
| 1111 | chunk_appendf(out, "</div></u>"); |
| 1112 | } |
| 1113 | else if (stats[ST_F_CHECK_STATUS].type) { |
| 1114 | chunk_appendf(out, |
| 1115 | "</td><td class=ac><u> %s", |
| 1116 | field_str(stats, ST_F_CHECK_STATUS)); |
| 1117 | |
| 1118 | if (stats[ST_F_CHECK_CODE].type) |
| 1119 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
| 1120 | |
| 1121 | if (stats[ST_F_CHECK_DURATION].type) |
| 1122 | chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); |
| 1123 | |
| 1124 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC)); |
| 1125 | |
| 1126 | if (*field_str(stats, ST_F_LAST_CHK)) { |
| 1127 | chunk_appendf(out, ": "); |
| 1128 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
| 1129 | chunk_htmlencode(out, &src); |
| 1130 | } |
| 1131 | chunk_appendf(out, "</div></u>"); |
| 1132 | } |
| 1133 | else |
| 1134 | chunk_appendf(out, "</td><td>"); |
| 1135 | |
| 1136 | chunk_appendf(out, |
| 1137 | /* weight */ |
| 1138 | "</td><td class=ac>%d</td>" |
| 1139 | /* act, bck */ |
| 1140 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 1141 | "", |
| 1142 | stats[ST_F_WEIGHT].u.u32, |
| 1143 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 1144 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 1145 | |
| 1146 | /* check failures: unique, fatal, down time */ |
| 1147 | if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) { |
| 1148 | chunk_appendf(out, "<td class=ac colspan=3>resolution</td>"); |
| 1149 | } |
| 1150 | else if (stats[ST_F_CHKFAIL].type) { |
| 1151 | chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64); |
| 1152 | |
| 1153 | if (stats[ST_F_HANAFAIL].type) |
| 1154 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
| 1155 | |
| 1156 | chunk_appendf(out, |
| 1157 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 1158 | "<td>%lld</td><td>%s</td>" |
| 1159 | "", |
| 1160 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 1161 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 1162 | } |
| 1163 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 1164 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
| 1165 | chunk_appendf(out, |
| 1166 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 1167 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 1168 | } |
| 1169 | else |
| 1170 | chunk_appendf(out, "<td colspan=3></td>"); |
| 1171 | |
| 1172 | /* throttle */ |
| 1173 | if (stats[ST_F_THROTTLE].type) |
| 1174 | chunk_appendf(out, "<td class=ac>%d %%</td></tr>\n", stats[ST_F_THROTTLE].u.u32); |
| 1175 | else |
| 1176 | chunk_appendf(out, "<td class=ac>-</td></tr>\n"); |
| 1177 | } |
| 1178 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
| 1179 | chunk_appendf(out, "<tr class=\"backend\">"); |
| 1180 | if (flags & ST_SHOWADMIN) { |
| 1181 | /* Column sub-heading for Enable or Disable server */ |
| 1182 | chunk_appendf(out, "<td></td>"); |
| 1183 | } |
| 1184 | chunk_appendf(out, |
| 1185 | "<td class=ac>" |
| 1186 | /* name */ |
| 1187 | "%s<a name=\"%s/Backend\"></a>" |
| 1188 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 1189 | "", |
| 1190 | (flags & ST_SHLGNDS)?"<u>":"", |
| 1191 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 1192 | |
| 1193 | if (flags & ST_SHLGNDS) { |
| 1194 | /* balancing */ |
| 1195 | chunk_appendf(out, "<div class=tips>balancing: %s", |
| 1196 | field_str(stats, ST_F_ALGO)); |
| 1197 | |
| 1198 | /* cookie */ |
| 1199 | if (stats[ST_F_COOKIE].type) { |
| 1200 | chunk_appendf(out, ", cookie: '"); |
| 1201 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
| 1202 | chunk_htmlencode(out, &src); |
| 1203 | chunk_appendf(out, "'"); |
| 1204 | } |
| 1205 | chunk_appendf(out, "</div>"); |
| 1206 | } |
| 1207 | |
| 1208 | chunk_appendf(out, |
| 1209 | "%s</td>" |
| 1210 | /* queue : current, max */ |
| 1211 | "<td>%s</td><td>%s</td><td></td>" |
| 1212 | /* sessions rate : current, max, limit */ |
| 1213 | "<td>%s</td><td>%s</td><td></td>" |
| 1214 | "", |
| 1215 | (flags & ST_SHLGNDS)?"</u>":"", |
| 1216 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 1217 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 1218 | |
| 1219 | chunk_appendf(out, |
| 1220 | /* sessions: current, max, limit, total */ |
| 1221 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 1222 | "<td><u>%s<div class=tips><table class=det>" |
| 1223 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 1224 | "", |
Willy Tarreau | 8e0f175 | 2016-12-12 15:07:29 +0100 | [diff] [blame] | 1225 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1226 | U2H(stats[ST_F_STOT].u.u64), |
| 1227 | U2H(stats[ST_F_STOT].u.u64)); |
| 1228 | |
| 1229 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1230 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
| 1231 | chunk_appendf(out, |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1232 | "<tr><th>New connections:</th><td>%s</td></tr>" |
| 1233 | "<tr><th>Reused connections:</th><td>%s</td><td>(%d%%)</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1234 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 1235 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 1236 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 1237 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1238 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 1239 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 1240 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 1241 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1242 | "<tr><th>Cache lookups:</th><td>%s</td></tr>" |
| 1243 | "<tr><th>Cache hits:</th><td>%s</td><td>(%d%%)</td></tr>" |
Willy Tarreau | 1b0f85e | 2018-05-28 15:12:40 +0200 | [diff] [blame] | 1244 | "<tr><th>Failed hdr rewrites:</th><td>%s</td></tr>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1245 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
| 1246 | "", |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1247 | U2H(stats[ST_F_CONNECT].u.u64), |
| 1248 | U2H(stats[ST_F_REUSE].u.u64), |
| 1249 | (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64) ? |
| 1250 | (int)(100 * stats[ST_F_REUSE].u.u64 / (stats[ST_F_CONNECT].u.u64 + stats[ST_F_REUSE].u.u64)) : 0, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1251 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 1252 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 1253 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 1254 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 1255 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 1256 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 1257 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 1258 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 1259 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
Willy Tarreau | feead3a | 2018-12-14 13:48:44 +0100 | [diff] [blame] | 1260 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1261 | U2H(stats[ST_F_CACHE_LOOKUPS].u.u64), |
| 1262 | U2H(stats[ST_F_CACHE_HITS].u.u64), |
| 1263 | stats[ST_F_CACHE_LOOKUPS].u.u64 ? |
| 1264 | (int)(100 * stats[ST_F_CACHE_HITS].u.u64 / stats[ST_F_CACHE_LOOKUPS].u.u64) : 0, |
Willy Tarreau | feead3a | 2018-12-14 13:48:44 +0100 | [diff] [blame] | 1265 | U2H(stats[ST_F_WREW].u.u64)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 1269 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32)); |
| 1270 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
| 1271 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 1272 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32)); |
| 1273 | |
| 1274 | chunk_appendf(out, |
| 1275 | "</table></div></u></td>" |
| 1276 | /* sessions: lbtot, last */ |
| 1277 | "<td>%s</td><td>%s</td>" |
| 1278 | /* bytes: in */ |
| 1279 | "<td>%s</td>" |
| 1280 | "", |
| 1281 | U2H(stats[ST_F_LBTOT].u.u64), |
| 1282 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 1283 | U2H(stats[ST_F_BIN].u.u64)); |
| 1284 | |
| 1285 | chunk_appendf(out, |
| 1286 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 1287 | "<td>%s%s<div class=tips><table class=det>" |
| 1288 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 1289 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 1290 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1291 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 1292 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 1293 | "</table></div>%s</td>", |
| 1294 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 1295 | U2H(stats[ST_F_BOUT].u.u64), |
| 1296 | U2H(stats[ST_F_BOUT].u.u64), |
| 1297 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 1298 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 1299 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 1300 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 1301 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 1302 | stats[ST_F_BOUT].u.u64 ? (int)((stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64) * 100 / stats[ST_F_BOUT].u.u64) : 0, |
| 1303 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 1304 | |
| 1305 | chunk_appendf(out, |
| 1306 | /* denied: req, resp */ |
| 1307 | "<td>%s</td><td>%s</td>" |
| 1308 | /* errors : request, connect */ |
| 1309 | "<td></td><td>%s</td>" |
| 1310 | /* errors : response */ |
| 1311 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 1312 | /* warnings: retries, redispatches */ |
| 1313 | "<td>%lld</td><td>%lld</td>" |
| 1314 | /* backend status: reflect backend status (up/down): we display UP |
| 1315 | * if the backend has known working servers or if it has no server at |
| 1316 | * all (eg: for stats). Then we display the total weight, number of |
| 1317 | * active and backups. */ |
| 1318 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 1319 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 1320 | "", |
| 1321 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 1322 | U2H(stats[ST_F_ECON].u.u64), |
| 1323 | U2H(stats[ST_F_ERESP].u.u64), |
| 1324 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 1325 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 1326 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 1327 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 1328 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
| 1329 | stats[ST_F_WEIGHT].u.u32, |
| 1330 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 1331 | |
| 1332 | chunk_appendf(out, |
| 1333 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 1334 | "<td class=ac> </td><td>%d</td>" |
| 1335 | "<td>%s</td>" |
| 1336 | "<td></td>" |
| 1337 | "</tr>", |
| 1338 | stats[ST_F_CHKDOWN].u.u32, |
| 1339 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
| 1340 | } |
| 1341 | return 1; |
| 1342 | } |
| 1343 | |
| 1344 | int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx) |
| 1345 | { |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1346 | int ret; |
| 1347 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1348 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
| 1349 | flags |= ST_SHOWADMIN; |
| 1350 | |
| 1351 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1352 | ret = stats_dump_fields_html(&trash, stats, flags); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1353 | else if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1354 | ret = stats_dump_fields_typed(&trash, stats); |
| 1355 | else if (appctx->ctx.stats.flags & STAT_FMT_JSON) |
| 1356 | ret = stats_dump_fields_json(&trash, stats, |
| 1357 | !(appctx->ctx.stats.flags & |
| 1358 | STAT_STARTED)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1359 | else |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 1360 | ret = stats_dump_fields_csv(&trash, stats); |
| 1361 | |
| 1362 | if (ret) |
| 1363 | appctx->ctx.stats.flags |= STAT_STARTED; |
| 1364 | |
| 1365 | return ret; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | /* Fill <stats> with the frontend statistics. <stats> is |
| 1369 | * preallocated array of length <len>. The length of the array |
| 1370 | * must be at least ST_F_TOTAL_FIELDS. If this length is less then |
| 1371 | * this value, the function returns 0, otherwise, it returns 1. |
| 1372 | */ |
| 1373 | int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len) |
| 1374 | { |
| 1375 | if (len < ST_F_TOTAL_FIELDS) |
| 1376 | return 0; |
| 1377 | |
| 1378 | memset(stats, 0, sizeof(*stats) * len); |
| 1379 | |
| 1380 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1381 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
| 1382 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1383 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 1384 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 1385 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 1386 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 1387 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 1388 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 1389 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 1390 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 1391 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 1392 | stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); |
| 1393 | stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); |
| 1394 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); |
| 1395 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 1396 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1397 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 1398 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 1399 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 1400 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 1401 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 1402 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->fe_counters.failed_rewrites); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1403 | |
| 1404 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1405 | if (px->mode == PR_MODE_HTTP) { |
| 1406 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 1407 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 1408 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 1409 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 1410 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 1411 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
| 1412 | stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1413 | stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_lookups); |
| 1414 | stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cache_hits); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 1418 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 1419 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 1420 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 1421 | |
| 1422 | /* compression: in, out, bypassed, responses */ |
| 1423 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 1424 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 1425 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 1426 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 1427 | |
| 1428 | /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */ |
| 1429 | stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 1430 | stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 1431 | stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 1432 | |
| 1433 | return 1; |
| 1434 | } |
| 1435 | |
| 1436 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 1437 | * the state from stream interface <si>. The caller is responsible for clearing |
| 1438 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 1439 | */ |
| 1440 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
| 1441 | { |
| 1442 | struct appctx *appctx = __objt_appctx(si->end); |
| 1443 | |
| 1444 | if (!(px->cap & PR_CAP_FE)) |
| 1445 | return 0; |
| 1446 | |
| 1447 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 1448 | return 0; |
| 1449 | |
| 1450 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS)) |
| 1451 | return 0; |
| 1452 | |
| 1453 | return stats_dump_one_line(stats, 0, px, appctx); |
| 1454 | } |
| 1455 | |
| 1456 | /* Fill <stats> with the listener statistics. <stats> is |
| 1457 | * preallocated array of length <len>. The length of the array |
| 1458 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 1459 | * then this value, the function returns 0, otherwise, it |
| 1460 | * returns 1. <flags> can take the value ST_SHLGNDS. |
| 1461 | */ |
| 1462 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
| 1463 | struct field *stats, int len) |
| 1464 | { |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 1465 | struct buffer *out = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1466 | |
| 1467 | if (len < ST_F_TOTAL_FIELDS) |
| 1468 | return 0; |
| 1469 | |
| 1470 | if (!l->counters) |
| 1471 | return 0; |
| 1472 | |
| 1473 | chunk_reset(out); |
| 1474 | memset(stats, 0, sizeof(*stats) * len); |
| 1475 | |
| 1476 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1477 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name); |
| 1478 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1479 | stats[ST_F_SCUR] = mkf_u32(0, l->nbconn); |
| 1480 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max); |
| 1481 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn); |
| 1482 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 1483 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 1484 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 1485 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 1486 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 1487 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 1488 | stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn); |
| 1489 | stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess); |
Willy Tarreau | a8cf66b | 2019-02-27 16:49:00 +0100 | [diff] [blame] | 1490 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (!l->maxconn || l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1491 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 1492 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1493 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 1494 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 1495 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, l->counters->failed_rewrites); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1496 | |
| 1497 | if (flags & ST_SHLGNDS) { |
| 1498 | char str[INET6_ADDRSTRLEN]; |
| 1499 | int port; |
| 1500 | |
| 1501 | port = get_host_port(&l->addr); |
| 1502 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 1503 | case AF_INET: |
| 1504 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 1505 | chunk_appendf(out, "%s:%d", str, port); |
| 1506 | break; |
| 1507 | case AF_INET6: |
| 1508 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 1509 | chunk_appendf(out, "[%s]:%d", str, port); |
| 1510 | break; |
| 1511 | case AF_UNIX: |
| 1512 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 1513 | break; |
| 1514 | case -1: |
| 1515 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 1516 | chunk_strcat(out, strerror(errno)); |
| 1517 | break; |
| 1518 | default: /* address family not supported */ |
| 1519 | break; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | return 1; |
| 1524 | } |
| 1525 | |
| 1526 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 1527 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 1528 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 1529 | * otherwise. |
| 1530 | */ |
| 1531 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
| 1532 | { |
| 1533 | struct appctx *appctx = __objt_appctx(si->end); |
| 1534 | |
| 1535 | if (!stats_fill_li_stats(px, l, flags, stats, ST_F_TOTAL_FIELDS)) |
| 1536 | return 0; |
| 1537 | |
| 1538 | return stats_dump_one_line(stats, flags, px, appctx); |
| 1539 | } |
| 1540 | |
| 1541 | enum srv_stats_state { |
| 1542 | SRV_STATS_STATE_DOWN = 0, |
| 1543 | SRV_STATS_STATE_DOWN_AGENT, |
| 1544 | SRV_STATS_STATE_GOING_UP, |
| 1545 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 1546 | SRV_STATS_STATE_UP, |
| 1547 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 1548 | SRV_STATS_STATE_NOLB, |
| 1549 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 1550 | SRV_STATS_STATE_DRAIN, |
| 1551 | SRV_STATS_STATE_DRAIN_AGENT, |
| 1552 | SRV_STATS_STATE_NO_CHECK, |
| 1553 | |
| 1554 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 1555 | }; |
| 1556 | |
| 1557 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 1558 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 1559 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 1560 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 1561 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 1562 | [SRV_STATS_STATE_UP] = "UP", |
| 1563 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 1564 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 1565 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 1566 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 1567 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 1568 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 1569 | }; |
| 1570 | |
| 1571 | /* Fill <stats> with the server statistics. <stats> is |
| 1572 | * preallocated array of length <len>. The length of the array |
| 1573 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 1574 | * then this value, the function returns 0, otherwise, it |
| 1575 | * returns 1. <flags> can take the value ST_SHLGNDS. |
| 1576 | */ |
| 1577 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 1578 | struct field *stats, int len) |
| 1579 | { |
| 1580 | struct server *via, *ref; |
| 1581 | char str[INET6_ADDRSTRLEN]; |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 1582 | struct buffer *out = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1583 | enum srv_stats_state state; |
| 1584 | char *fld_status; |
| 1585 | |
| 1586 | if (len < ST_F_TOTAL_FIELDS) |
| 1587 | return 0; |
| 1588 | |
| 1589 | memset(stats, 0, sizeof(*stats) * len); |
| 1590 | |
| 1591 | /* we have "via" which is the tracked server as described in the configuration, |
| 1592 | * and "ref" which is the checked server and the end of the chain. |
| 1593 | */ |
| 1594 | via = sv->track ? sv->track : sv; |
| 1595 | ref = via; |
| 1596 | while (ref->track) |
| 1597 | ref = ref->track; |
| 1598 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1599 | if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1600 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 1601 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
| 1602 | state = SRV_STATS_STATE_UP_GOING_DOWN; |
| 1603 | } else { |
| 1604 | state = SRV_STATS_STATE_UP; |
| 1605 | } |
| 1606 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1607 | if (sv->cur_admin & SRV_ADMF_DRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1608 | if (ref->agent.state & CHK_ST_ENABLED) |
| 1609 | state = SRV_STATS_STATE_DRAIN_AGENT; |
| 1610 | else if (state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 1611 | state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
| 1612 | else |
| 1613 | state = SRV_STATS_STATE_DRAIN; |
| 1614 | } |
| 1615 | |
| 1616 | if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 1617 | state = SRV_STATS_STATE_NO_CHECK; |
| 1618 | } |
| 1619 | } |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1620 | else if (sv->cur_state == SRV_ST_STOPPING) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1621 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 1622 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
| 1623 | state = SRV_STATS_STATE_NOLB; |
| 1624 | } else { |
| 1625 | state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
| 1626 | } |
| 1627 | } |
| 1628 | else { /* stopped */ |
| 1629 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
| 1630 | state = SRV_STATS_STATE_DOWN_AGENT; |
| 1631 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
| 1632 | state = SRV_STATS_STATE_DOWN; /* DOWN */ |
| 1633 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
| 1634 | state = SRV_STATS_STATE_GOING_UP; |
| 1635 | } else { |
| 1636 | state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | chunk_reset(out); |
| 1641 | |
| 1642 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1643 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id); |
| 1644 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1645 | stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend); |
| 1646 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 1647 | stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess); |
| 1648 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 1649 | |
| 1650 | if (sv->maxconn) |
| 1651 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 1652 | |
| 1653 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 1654 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 1655 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 1656 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu); |
| 1657 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 1658 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 1659 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 1660 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 1661 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, sv->counters.failed_rewrites); |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1662 | stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, sv->counters.connect); |
| 1663 | stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, sv->counters.reuse); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1664 | |
| 1665 | /* status */ |
| 1666 | fld_status = chunk_newstr(out); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1667 | if (sv->cur_admin & SRV_ADMF_RMAINT) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1668 | chunk_appendf(out, "MAINT (resolution)"); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1669 | else if (sv->cur_admin & SRV_ADMF_IMAINT) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1670 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1671 | else if (sv->cur_admin & SRV_ADMF_MAINT) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1672 | chunk_appendf(out, "MAINT"); |
| 1673 | else |
| 1674 | chunk_appendf(out, |
| 1675 | srv_hlt_st[state], |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1676 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 1677 | (ref->cur_state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1678 | |
| 1679 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status); |
| 1680 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1681 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1682 | stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 1683 | stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
| 1684 | |
| 1685 | /* check failures: unique, fatal; last change, total downtime */ |
| 1686 | if (sv->check.state & CHK_ST_ENABLED) { |
| 1687 | stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 1688 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 1689 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 1690 | } |
| 1691 | |
| 1692 | if (sv->maxqueue) |
| 1693 | stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
| 1694 | |
| 1695 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 1696 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1697 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
| 1698 | |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 1699 | if (sv->cur_state == SRV_ST_STARTING && !server_is_draining(sv)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1700 | stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
| 1701 | |
| 1702 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
| 1703 | |
| 1704 | if (sv->track) { |
| 1705 | char *fld_track = chunk_newstr(out); |
| 1706 | |
| 1707 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 1708 | stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 1709 | } |
| 1710 | |
| 1711 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 1712 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 1713 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max); |
| 1714 | |
| 1715 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 1716 | const char *fld_chksts; |
| 1717 | |
| 1718 | fld_chksts = chunk_newstr(out); |
| 1719 | chunk_strcat(out, "* "); // for check in progress |
| 1720 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 1721 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 1722 | fld_chksts += 2; // skip "* " |
| 1723 | stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
| 1724 | |
| 1725 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 1726 | stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code); |
| 1727 | |
| 1728 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 1729 | stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); |
| 1730 | |
| 1731 | stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 1732 | stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc); |
| 1733 | stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 1734 | stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 1735 | stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 1736 | } |
| 1737 | |
| 1738 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 1739 | const char *fld_chksts; |
| 1740 | |
| 1741 | fld_chksts = chunk_newstr(out); |
| 1742 | chunk_strcat(out, "* "); // for check in progress |
| 1743 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 1744 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 1745 | fld_chksts += 2; // skip "* " |
| 1746 | stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
| 1747 | |
| 1748 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 1749 | stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); |
| 1750 | |
| 1751 | if (sv->agent.status >= HCHK_STATUS_CHECKED) |
| 1752 | stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); |
| 1753 | |
| 1754 | stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 1755 | stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 1756 | stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 1757 | stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 1758 | stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 1759 | } |
| 1760 | |
| 1761 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1762 | if (px->mode == PR_MODE_HTTP) { |
| 1763 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 1764 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 1765 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 1766 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 1767 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 1768 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 1769 | } |
| 1770 | |
| 1771 | if (ref->observe) |
| 1772 | stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
| 1773 | |
| 1774 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 1775 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 1776 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv)); |
| 1777 | |
| 1778 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES)); |
| 1779 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES)); |
| 1780 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES)); |
| 1781 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 1782 | |
| 1783 | if (flags & ST_SHLGNDS) { |
| 1784 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 1785 | case AF_INET: |
| 1786 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
Willy Tarreau | 04276f3 | 2017-01-06 17:41:29 +0100 | [diff] [blame] | 1787 | chunk_appendf(out, "%s:%d", str, sv->svc_port); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1788 | break; |
| 1789 | case AF_INET6: |
| 1790 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
Willy Tarreau | 04276f3 | 2017-01-06 17:41:29 +0100 | [diff] [blame] | 1791 | chunk_appendf(out, "[%s]:%d", str, sv->svc_port); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1792 | break; |
| 1793 | case AF_UNIX: |
| 1794 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 1795 | break; |
| 1796 | case -1: |
| 1797 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 1798 | chunk_strcat(out, strerror(errno)); |
| 1799 | break; |
| 1800 | default: /* address family not supported */ |
| 1801 | break; |
| 1802 | } |
| 1803 | |
| 1804 | if (sv->cookie) |
| 1805 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 1806 | } |
| 1807 | |
| 1808 | return 1; |
| 1809 | } |
| 1810 | |
| 1811 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 1812 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 1813 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 1814 | * if it emits anything, zero otherwise. |
| 1815 | */ |
| 1816 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv) |
| 1817 | { |
| 1818 | struct appctx *appctx = __objt_appctx(si->end); |
| 1819 | |
| 1820 | if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS)) |
| 1821 | return 0; |
| 1822 | |
| 1823 | return stats_dump_one_line(stats, flags, px, appctx); |
| 1824 | } |
| 1825 | |
| 1826 | /* Fill <stats> with the backend statistics. <stats> is |
| 1827 | * preallocated array of length <len>. The length of the array |
| 1828 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 1829 | * then this value, the function returns 0, otherwise, it |
| 1830 | * returns 1. <flags> can take the value ST_SHLGNDS. |
| 1831 | */ |
| 1832 | int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len) |
| 1833 | { |
| 1834 | if (len < ST_F_TOTAL_FIELDS) |
| 1835 | return 0; |
| 1836 | |
| 1837 | memset(stats, 0, sizeof(*stats) * len); |
| 1838 | |
| 1839 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 1840 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND"); |
| 1841 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
| 1842 | stats[ST_F_QCUR] = mkf_u32(0, px->nbpend); |
| 1843 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
Thierry FOURNIER | 0ff98a4 | 2016-12-19 16:50:42 +0100 | [diff] [blame] | 1844 | stats[ST_F_SCUR] = mkf_u32(0, px->beconn); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1845 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 1846 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 1847 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 1848 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 1849 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 1850 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 1851 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 1852 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 1853 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 1854 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 1855 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
Tim Duesterhus | 3fd1973 | 2018-05-27 20:35:08 +0200 | [diff] [blame] | 1856 | stats[ST_F_WREW] = mkf_u64(FN_COUNTER, px->be_counters.failed_rewrites); |
Willy Tarreau | f157384 | 2018-12-14 11:35:36 +0100 | [diff] [blame] | 1857 | stats[ST_F_CONNECT] = mkf_u64(FN_COUNTER, px->be_counters.connect); |
| 1858 | stats[ST_F_REUSE] = mkf_u64(FN_COUNTER, px->be_counters.reuse); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1859 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 1860 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 1861 | stats[ST_F_ACT] = mkf_u32(0, px->srv_act); |
| 1862 | stats[ST_F_BCK] = mkf_u32(0, px->srv_bck); |
| 1863 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans); |
| 1864 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change); |
| 1865 | if (px->srv) |
| 1866 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 1867 | |
| 1868 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 1869 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 1870 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 1871 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 1872 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 1873 | stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 1874 | stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max); |
| 1875 | |
| 1876 | if (flags & ST_SHLGNDS) { |
| 1877 | if (px->cookie_name) |
| 1878 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name); |
| 1879 | stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 1880 | } |
| 1881 | |
| 1882 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 1883 | if (px->mode == PR_MODE_HTTP) { |
| 1884 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 1885 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 1886 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 1887 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 1888 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 1889 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 1890 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
Willy Tarreau | a1214a5 | 2018-12-14 14:00:25 +0100 | [diff] [blame] | 1891 | stats[ST_F_CACHE_LOOKUPS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_lookups); |
| 1892 | stats[ST_F_CACHE_HITS] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cache_hits); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 1896 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 1897 | |
| 1898 | /* compression: in, out, bypassed, responses */ |
| 1899 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 1900 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 1901 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 1902 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 1903 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px)); |
| 1904 | |
| 1905 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES)); |
| 1906 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES)); |
| 1907 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); |
| 1908 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 1909 | |
| 1910 | return 1; |
| 1911 | } |
| 1912 | |
| 1913 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 1914 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 1915 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 1916 | */ |
| 1917 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 1918 | { |
| 1919 | struct appctx *appctx = __objt_appctx(si->end); |
| 1920 | |
| 1921 | if (!(px->cap & PR_CAP_BE)) |
| 1922 | return 0; |
| 1923 | |
| 1924 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 1925 | return 0; |
| 1926 | |
| 1927 | if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS)) |
| 1928 | return 0; |
| 1929 | |
| 1930 | return stats_dump_one_line(stats, flags, px, appctx); |
| 1931 | } |
| 1932 | |
| 1933 | /* Dumps the HTML table header for proxy <px> to the trash for and uses the state from |
| 1934 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
| 1935 | * for clearing the trash if needed. |
| 1936 | */ |
| 1937 | static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri) |
| 1938 | { |
| 1939 | struct appctx *appctx = __objt_appctx(si->end); |
| 1940 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 1941 | |
| 1942 | if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
| 1943 | /* A form to enable/disable this proxy servers */ |
| 1944 | |
| 1945 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 1946 | scope_txt[0] = 0; |
| 1947 | if (appctx->ctx.stats.scope_len) { |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 1948 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
| 1949 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1950 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 1951 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1952 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
| 1953 | } |
| 1954 | |
| 1955 | chunk_appendf(&trash, |
| 1956 | "<form method=\"post\">"); |
| 1957 | } |
| 1958 | |
| 1959 | /* print a new table */ |
| 1960 | chunk_appendf(&trash, |
| 1961 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 1962 | "<tr class=\"titre\">" |
| 1963 | "<th class=\"pxname\" width=\"10%%\">"); |
| 1964 | |
| 1965 | chunk_appendf(&trash, |
| 1966 | "<a name=\"%s\"></a>%s" |
| 1967 | "<a class=px href=\"#%s\">%s</a>", |
| 1968 | px->id, |
| 1969 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 1970 | px->id, px->id); |
| 1971 | |
| 1972 | if (uri->flags & ST_SHLGNDS) { |
| 1973 | /* cap, mode, id */ |
| 1974 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
| 1975 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 1976 | px->uuid); |
| 1977 | chunk_appendf(&trash, "</div>"); |
| 1978 | } |
| 1979 | |
| 1980 | chunk_appendf(&trash, |
| 1981 | "%s</th>" |
| 1982 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 1983 | "</tr>\n" |
| 1984 | "</table>\n" |
| 1985 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 1986 | "<tr class=\"titre\">", |
| 1987 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 1988 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 1989 | |
| 1990 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
| 1991 | /* Column heading for Enable or Disable server */ |
David Harrigan | d3db35a | 2016-12-30 12:12:49 +0000 | [diff] [blame] | 1992 | chunk_appendf(&trash, |
| 1993 | "<th rowspan=2 width=1><input type=\"checkbox\" \ |
| 1994 | onclick=\"for(c in document.getElementsByClassName('%s-checkbox')) \ |
| 1995 | document.getElementsByClassName('%s-checkbox').item(c).checked = this.checked\"></th>", |
| 1996 | px->id, |
| 1997 | px->id); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | chunk_appendf(&trash, |
| 2001 | "<th rowspan=2></th>" |
| 2002 | "<th colspan=3>Queue</th>" |
| 2003 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
| 2004 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 2005 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 2006 | "<th colspan=9>Server</th>" |
| 2007 | "</tr>\n" |
| 2008 | "<tr class=\"titre\">" |
| 2009 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 2010 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
| 2011 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>" |
| 2012 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 2013 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 2014 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 2015 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 2016 | "<th>Thrtle</th>\n" |
| 2017 | "</tr>"); |
| 2018 | } |
| 2019 | |
| 2020 | /* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from |
| 2021 | * stream interface <si>. The caller is responsible for clearing the trash if needed. |
| 2022 | */ |
| 2023 | static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px) |
| 2024 | { |
| 2025 | struct appctx *appctx = __objt_appctx(si->end); |
| 2026 | chunk_appendf(&trash, "</table>"); |
| 2027 | |
| 2028 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
| 2029 | /* close the form used to enable/disable this proxy servers */ |
| 2030 | chunk_appendf(&trash, |
| 2031 | "Choose the action to perform on the checked servers : " |
| 2032 | "<select name=action>" |
| 2033 | "<option value=\"\"></option>" |
| 2034 | "<option value=\"ready\">Set state to READY</option>" |
| 2035 | "<option value=\"drain\">Set state to DRAIN</option>" |
| 2036 | "<option value=\"maint\">Set state to MAINT</option>" |
| 2037 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 2038 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 2039 | "<option value=\"hrunn\">Health: force UP</option>" |
| 2040 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 2041 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 2042 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 2043 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 2044 | "<option value=\"arunn\">Agent: force UP</option>" |
| 2045 | "<option value=\"adown\">Agent: force DOWN</option>" |
| 2046 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 2047 | "</select>" |
| 2048 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 2049 | " <input type=\"submit\" value=\"Apply\">" |
| 2050 | "</form>", |
| 2051 | px->uuid); |
| 2052 | } |
| 2053 | |
| 2054 | chunk_appendf(&trash, "<p>\n"); |
| 2055 | } |
| 2056 | |
| 2057 | /* |
| 2058 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 2059 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 2060 | * buffer space, or non-zero if everything completed. This function is used |
| 2061 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 2062 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
| 2063 | */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2064 | int stats_dump_proxy_to_buffer(struct stream_interface *si, struct htx *htx, |
| 2065 | struct proxy *px, struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2066 | { |
| 2067 | struct appctx *appctx = __objt_appctx(si->end); |
| 2068 | struct stream *s = si_strm(si); |
| 2069 | struct channel *rep = si_ic(si); |
| 2070 | struct server *sv, *svs; /* server and server-state, server-state=server or server->track */ |
| 2071 | struct listener *l; |
| 2072 | unsigned int flags; |
| 2073 | |
| 2074 | if (uri) |
| 2075 | flags = uri->flags; |
William Lallemand | 07a62f7 | 2017-05-24 00:57:40 +0200 | [diff] [blame] | 2076 | else if ((strm_li(s)->bind_conf->level & ACCESS_LVL_MASK) >= ACCESS_LVL_OPER) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2077 | flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC; |
| 2078 | else |
| 2079 | flags = ST_SHNODE | ST_SHDESC; |
| 2080 | |
| 2081 | chunk_reset(&trash); |
| 2082 | |
| 2083 | switch (appctx->ctx.stats.px_st) { |
| 2084 | case STAT_PX_ST_INIT: |
| 2085 | /* we are on a new proxy */ |
| 2086 | if (uri && uri->scope) { |
| 2087 | /* we have a limited scope, we have to check the proxy name */ |
| 2088 | struct stat_scope *scope; |
| 2089 | int len; |
| 2090 | |
| 2091 | len = strlen(px->id); |
| 2092 | scope = uri->scope; |
| 2093 | |
| 2094 | while (scope) { |
| 2095 | /* match exact proxy name */ |
| 2096 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 2097 | break; |
| 2098 | |
| 2099 | /* match '.' which means 'self' proxy */ |
| 2100 | if (!strcmp(scope->px_id, ".") && px == s->be) |
| 2101 | break; |
| 2102 | scope = scope->next; |
| 2103 | } |
| 2104 | |
| 2105 | /* proxy name not found : don't dump anything */ |
| 2106 | if (scope == NULL) |
| 2107 | return 1; |
| 2108 | } |
| 2109 | |
| 2110 | /* if the user has requested a limited output and the proxy |
| 2111 | * name does not match, skip it. |
| 2112 | */ |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2113 | if (appctx->ctx.stats.scope_len) { |
| 2114 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
| 2115 | |
| 2116 | if (strnistr(px->id, strlen(px->id), scope_ptr, appctx->ctx.stats.scope_len) == NULL) |
| 2117 | return 1; |
| 2118 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2119 | |
| 2120 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 2121 | (appctx->ctx.stats.iid != -1) && |
| 2122 | (px->uuid != appctx->ctx.stats.iid)) |
| 2123 | return 1; |
| 2124 | |
| 2125 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
| 2126 | /* fall through */ |
| 2127 | |
| 2128 | case STAT_PX_ST_TH: |
| 2129 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
| 2130 | stats_dump_html_px_hdr(si, px, uri); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2131 | if (!stats_putchk(rep, htx, &trash)) |
| 2132 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
| 2135 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
| 2136 | /* fall through */ |
| 2137 | |
| 2138 | case STAT_PX_ST_FE: |
| 2139 | /* print the frontend */ |
| 2140 | if (stats_dump_fe_stats(si, px)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2141 | if (!stats_putchk(rep, htx, &trash)) |
| 2142 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 2146 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
| 2147 | /* fall through */ |
| 2148 | |
| 2149 | case STAT_PX_ST_LI: |
| 2150 | /* stats.l has been initialized above */ |
| 2151 | for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2152 | if (htx) { |
| 2153 | if (htx_almost_full(htx)) |
| 2154 | goto full; |
| 2155 | } |
| 2156 | else { |
| 2157 | if (buffer_almost_full(&rep->buf)) |
| 2158 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
| 2162 | if (!l->counters) |
| 2163 | continue; |
| 2164 | |
| 2165 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 2166 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
| 2167 | break; |
| 2168 | |
| 2169 | if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid) |
| 2170 | continue; |
| 2171 | } |
| 2172 | |
| 2173 | /* print the frontend */ |
| 2174 | if (stats_dump_li_stats(si, px, l, flags)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2175 | if (!stats_putchk(rep, htx, &trash)) |
| 2176 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2177 | } |
| 2178 | } |
| 2179 | |
| 2180 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 2181 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
| 2182 | /* fall through */ |
| 2183 | |
| 2184 | case STAT_PX_ST_SV: |
| 2185 | /* stats.sv has been initialized above */ |
| 2186 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2187 | if (htx) { |
| 2188 | if (htx_almost_full(htx)) |
| 2189 | goto full; |
| 2190 | } |
| 2191 | else { |
| 2192 | if (buffer_almost_full(&rep->buf)) |
| 2193 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | sv = appctx->ctx.stats.sv; |
| 2197 | |
| 2198 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 2199 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
| 2200 | break; |
| 2201 | |
| 2202 | if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid) |
| 2203 | continue; |
| 2204 | } |
| 2205 | |
| 2206 | svs = sv; |
| 2207 | while (svs->track) |
| 2208 | svs = svs->track; |
| 2209 | |
| 2210 | /* do not report servers which are DOWN and not changing state */ |
| 2211 | if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) && |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2212 | ((sv->cur_admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 2213 | (sv->cur_state == SRV_ST_STOPPED && /* server is down */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2214 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 2215 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 2216 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
| 2217 | continue; |
| 2218 | } |
| 2219 | |
| 2220 | if (stats_dump_sv_stats(si, px, flags, sv)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2221 | if (!stats_putchk(rep, htx, &trash)) |
| 2222 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2223 | } |
| 2224 | } /* for sv */ |
| 2225 | |
| 2226 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
| 2227 | /* fall through */ |
| 2228 | |
| 2229 | case STAT_PX_ST_BE: |
| 2230 | /* print the backend */ |
| 2231 | if (stats_dump_be_stats(si, px, flags)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2232 | if (!stats_putchk(rep, htx, &trash)) |
| 2233 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
| 2237 | /* fall through */ |
| 2238 | |
| 2239 | case STAT_PX_ST_END: |
| 2240 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
| 2241 | stats_dump_html_px_end(si, px); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2242 | if (!stats_putchk(rep, htx, &trash)) |
| 2243 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
| 2247 | /* fall through */ |
| 2248 | |
| 2249 | case STAT_PX_ST_FIN: |
| 2250 | return 1; |
| 2251 | |
| 2252 | default: |
| 2253 | /* unknown state, we should put an abort() here ! */ |
| 2254 | return 1; |
| 2255 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2256 | |
| 2257 | full: |
| 2258 | si_rx_room_blk(si); |
| 2259 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 2263 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
| 2264 | */ |
| 2265 | static void stats_dump_html_head(struct uri_auth *uri) |
| 2266 | { |
| 2267 | /* WARNING! This must fit in the first buffer !!! */ |
| 2268 | chunk_appendf(&trash, |
| 2269 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 2270 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 2271 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 2272 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 2273 | "<style type=\"text/css\"><!--\n" |
| 2274 | "body {" |
| 2275 | " font-family: arial, helvetica, sans-serif;" |
| 2276 | " font-size: 12px;" |
| 2277 | " font-weight: normal;" |
| 2278 | " color: black;" |
| 2279 | " background: white;" |
| 2280 | "}\n" |
| 2281 | "th,td {" |
| 2282 | " font-size: 10px;" |
| 2283 | "}\n" |
| 2284 | "h1 {" |
| 2285 | " font-size: x-large;" |
| 2286 | " margin-bottom: 0.5em;" |
| 2287 | "}\n" |
| 2288 | "h2 {" |
| 2289 | " font-family: helvetica, arial;" |
| 2290 | " font-size: x-large;" |
| 2291 | " font-weight: bold;" |
| 2292 | " font-style: italic;" |
| 2293 | " color: #6020a0;" |
| 2294 | " margin-top: 0em;" |
| 2295 | " margin-bottom: 0em;" |
| 2296 | "}\n" |
| 2297 | "h3 {" |
| 2298 | " font-family: helvetica, arial;" |
| 2299 | " font-size: 16px;" |
| 2300 | " font-weight: bold;" |
| 2301 | " color: #b00040;" |
| 2302 | " background: #e8e8d0;" |
| 2303 | " margin-top: 0em;" |
| 2304 | " margin-bottom: 0em;" |
| 2305 | "}\n" |
| 2306 | "li {" |
| 2307 | " margin-top: 0.25em;" |
| 2308 | " margin-right: 2em;" |
| 2309 | "}\n" |
| 2310 | ".hr {margin-top: 0.25em;" |
| 2311 | " border-color: black;" |
| 2312 | " border-bottom-style: solid;" |
| 2313 | "}\n" |
| 2314 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 2315 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 2316 | ".frontend {background: #e8e8d0;}\n" |
| 2317 | ".socket {background: #d0d0d0;}\n" |
| 2318 | ".backend {background: #e8e8d0;}\n" |
| 2319 | ".active_down {background: #ff9090;}\n" |
| 2320 | ".active_going_up {background: #ffd020;}\n" |
| 2321 | ".active_going_down {background: #ffffa0;}\n" |
| 2322 | ".active_up {background: #c0ffc0;}\n" |
| 2323 | ".active_nolb {background: #20a0ff;}\n" |
| 2324 | ".active_draining {background: #20a0FF;}\n" |
| 2325 | ".active_no_check {background: #e0e0e0;}\n" |
| 2326 | ".backup_down {background: #ff9090;}\n" |
| 2327 | ".backup_going_up {background: #ff80ff;}\n" |
| 2328 | ".backup_going_down {background: #c060ff;}\n" |
| 2329 | ".backup_up {background: #b0d0ff;}\n" |
| 2330 | ".backup_nolb {background: #90b0e0;}\n" |
| 2331 | ".backup_draining {background: #cc9900;}\n" |
| 2332 | ".backup_no_check {background: #e0e0e0;}\n" |
| 2333 | ".maintain {background: #c07820;}\n" |
| 2334 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 2335 | "\n" |
| 2336 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 2337 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 2338 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 2339 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 2340 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 2341 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 2342 | "\n" |
| 2343 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 2344 | "table.tbl td { text-align: right; border-width: 1px 1px 1px 1px; border-style: solid solid solid solid; padding: 2px 3px; border-color: gray; white-space: nowrap;}\n" |
| 2345 | "table.tbl td.ac { text-align: center;}\n" |
| 2346 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 2347 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 2348 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 2349 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 2350 | "\n" |
| 2351 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 2352 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 2353 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
| 2354 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 2355 | "table.det th { text-align: left; border-width: 0px; padding: 0px 1px 0px 0px; font-style:normal;font-size:11px;font-weight:bold;font-family: sans-serif;}\n" |
| 2356 | "table.det td { text-align: right; border-width: 0px; padding: 0px 0px 0px 4px; white-space: nowrap; font-style:normal;font-size:11px;font-weight:normal;}\n" |
| 2357 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
| 2358 | "div.tips {\n" |
| 2359 | " display:block;\n" |
| 2360 | " visibility:hidden;\n" |
| 2361 | " z-index:2147483647;\n" |
| 2362 | " position:absolute;\n" |
| 2363 | " padding:2px 4px 3px;\n" |
| 2364 | " background:#f0f060; color:#000000;\n" |
| 2365 | " border:1px solid #7040c0;\n" |
| 2366 | " white-space:nowrap;\n" |
| 2367 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 2368 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 2369 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 2370 | "}\n" |
| 2371 | "u:hover div.tips {visibility:visible;}\n" |
| 2372 | "-->\n" |
| 2373 | "</style></head>\n", |
| 2374 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 2375 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 2376 | ); |
| 2377 | } |
| 2378 | |
| 2379 | /* Dumps the HTML stats information block to the trash for and uses the state from |
| 2380 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
| 2381 | * for clearing the trash if needed. |
| 2382 | */ |
| 2383 | static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri) |
| 2384 | { |
| 2385 | struct appctx *appctx = __objt_appctx(si->end); |
| 2386 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
| 2387 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2388 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 2389 | unsigned long long bps = (unsigned long long)read_freq_ctr(&global.out_32bps) * 32; |
| 2390 | |
| 2391 | /* Turn the bytes per second to bits per second and take care of the |
| 2392 | * usual ethernet overhead in order to help figure how far we are from |
| 2393 | * interface saturation since it's the only case which usually matters. |
| 2394 | * For this we count the total size of an Ethernet frame on the wire |
| 2395 | * including preamble and IFG (1538) for the largest TCP segment it |
| 2396 | * transports (1448 with TCP timestamps). This is not valid for smaller |
| 2397 | * packets (under-estimated), but it gives a reasonably accurate |
| 2398 | * estimation of how far we are from uplink saturation. |
| 2399 | */ |
| 2400 | bps = bps * 8 * 1538 / 1448; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2401 | |
| 2402 | /* WARNING! this has to fit the first packet too. |
| 2403 | * We are around 3.5 kB, add adding entries will |
| 2404 | * become tricky if we want to support 4kB buffers ! |
| 2405 | */ |
| 2406 | chunk_appendf(&trash, |
| 2407 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 2408 | PRODUCT_NAME "%s</a></h1>\n" |
| 2409 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 2410 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 2411 | "<h3>> General process information</h3>\n" |
| 2412 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 2413 | "<p><b>pid = </b> %d (process #%d, nbproc = %d, nbthread = %d)<br>\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2414 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 2415 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 2416 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 2417 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec; bit rate = %.3f %cbps<br>\n" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2418 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 2419 | "</td><td align=\"center\" nowrap>\n" |
| 2420 | "<table class=\"lgd\"><tr>\n" |
| 2421 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 2422 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
| 2423 | "</tr><tr>\n" |
| 2424 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 2425 | "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>" |
| 2426 | "</tr><tr>\n" |
| 2427 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 2428 | "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
| 2429 | "</tr><tr>\n" |
| 2430 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 2431 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
| 2432 | "</tr><tr>\n" |
| 2433 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
| 2434 | "</tr><tr>\n" |
| 2435 | "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance </td>" |
| 2436 | "</tr></table>\n" |
| 2437 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
| 2438 | "</td>" |
| 2439 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 2440 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 2441 | "", |
Willy Tarreau | 909b9d8 | 2019-01-04 18:20:32 +0100 | [diff] [blame] | 2442 | (uri->flags & ST_HIDEVER) ? "" : (stats_version_string), |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2443 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 2444 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 2445 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 2446 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 2447 | pid, relative_pid, global.nbproc, global.nbthread, |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2448 | up / 86400, (up % 86400) / 3600, |
| 2449 | (up % 3600) / 60, (up % 60), |
| 2450 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 2451 | global.rlimit_memmax ? " MB" : "", |
| 2452 | global.rlimit_nofile, |
| 2453 | global.maxsock, global.maxconn, global.maxpipes, |
| 2454 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
Willy Tarreau | 1713c03 | 2019-05-23 12:23:55 +0200 | [diff] [blame] | 2455 | bps >= 1000000000UL ? (bps / 1000000000.0) : bps >= 1000000UL ? (bps / 1000000.0) : (bps / 1000.0), |
| 2456 | bps >= 1000000000UL ? 'G' : bps >= 1000000UL ? 'M' : 'k', |
Willy Tarreau | 81036f2 | 2019-05-20 19:24:50 +0200 | [diff] [blame] | 2457 | tasks_run_queue_cur, nb_tasks_cur, ti->idle_pct |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2458 | ); |
| 2459 | |
| 2460 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2461 | memcpy(scope_txt, scope_ptr, appctx->ctx.stats.scope_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2462 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
| 2463 | |
| 2464 | chunk_appendf(&trash, |
| 2465 | "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
| 2466 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
| 2467 | STAT_SCOPE_TXT_MAXLEN); |
| 2468 | |
| 2469 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 2470 | scope_txt[0] = 0; |
| 2471 | if (appctx->ctx.stats.scope_len) { |
| 2472 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2473 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2474 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
| 2475 | } |
| 2476 | |
| 2477 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
| 2478 | chunk_appendf(&trash, |
| 2479 | "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n", |
| 2480 | uri->uri_prefix, |
| 2481 | "", |
| 2482 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2483 | scope_txt); |
| 2484 | else |
| 2485 | chunk_appendf(&trash, |
| 2486 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
| 2487 | uri->uri_prefix, |
| 2488 | ";up", |
| 2489 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2490 | scope_txt); |
| 2491 | |
| 2492 | if (uri->refresh > 0) { |
| 2493 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
| 2494 | chunk_appendf(&trash, |
| 2495 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
| 2496 | uri->uri_prefix, |
| 2497 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2498 | "", |
| 2499 | scope_txt); |
| 2500 | else |
| 2501 | chunk_appendf(&trash, |
| 2502 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
| 2503 | uri->uri_prefix, |
| 2504 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2505 | ";norefresh", |
| 2506 | scope_txt); |
| 2507 | } |
| 2508 | |
| 2509 | chunk_appendf(&trash, |
| 2510 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
| 2511 | uri->uri_prefix, |
| 2512 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2513 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2514 | scope_txt); |
| 2515 | |
| 2516 | chunk_appendf(&trash, |
| 2517 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
| 2518 | uri->uri_prefix, |
| 2519 | (uri->refresh > 0) ? ";norefresh" : "", |
| 2520 | scope_txt); |
| 2521 | |
| 2522 | chunk_appendf(&trash, |
| 2523 | "</ul></td>" |
| 2524 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 2525 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 2526 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 2527 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 2528 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 2529 | "</ul>" |
| 2530 | "</td>" |
| 2531 | "</tr></table>\n" |
| 2532 | "" |
| 2533 | ); |
| 2534 | |
| 2535 | if (appctx->ctx.stats.st_code) { |
| 2536 | switch (appctx->ctx.stats.st_code) { |
| 2537 | case STAT_STATUS_DONE: |
| 2538 | chunk_appendf(&trash, |
| 2539 | "<p><div class=active_up>" |
| 2540 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2541 | "Action processed successfully." |
| 2542 | "</div>\n", uri->uri_prefix, |
| 2543 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2544 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2545 | scope_txt); |
| 2546 | break; |
| 2547 | case STAT_STATUS_NONE: |
| 2548 | chunk_appendf(&trash, |
| 2549 | "<p><div class=active_going_down>" |
| 2550 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2551 | "Nothing has changed." |
| 2552 | "</div>\n", uri->uri_prefix, |
| 2553 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2554 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2555 | scope_txt); |
| 2556 | break; |
| 2557 | case STAT_STATUS_PART: |
| 2558 | chunk_appendf(&trash, |
| 2559 | "<p><div class=active_going_down>" |
| 2560 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2561 | "Action partially processed.<br>" |
| 2562 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
| 2563 | "</div>\n", uri->uri_prefix, |
| 2564 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2565 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2566 | scope_txt); |
| 2567 | break; |
| 2568 | case STAT_STATUS_ERRP: |
| 2569 | chunk_appendf(&trash, |
| 2570 | "<p><div class=active_down>" |
| 2571 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2572 | "Action not processed because of invalid parameters." |
| 2573 | "<ul>" |
| 2574 | "<li>The action is maybe unknown.</li>" |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2575 | "<li>Invalid key parameter (empty or too long).</li>" |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2576 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 2577 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 2578 | "</ul>" |
| 2579 | "</div>\n", uri->uri_prefix, |
| 2580 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2581 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2582 | scope_txt); |
| 2583 | break; |
| 2584 | case STAT_STATUS_EXCD: |
| 2585 | chunk_appendf(&trash, |
| 2586 | "<p><div class=active_down>" |
| 2587 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2588 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 2589 | "You should retry with less servers at a time.</b>" |
| 2590 | "</div>\n", uri->uri_prefix, |
| 2591 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2592 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2593 | scope_txt); |
| 2594 | break; |
| 2595 | case STAT_STATUS_DENY: |
| 2596 | chunk_appendf(&trash, |
| 2597 | "<p><div class=active_down>" |
| 2598 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2599 | "<b>Action denied.</b>" |
| 2600 | "</div>\n", uri->uri_prefix, |
| 2601 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2602 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2603 | scope_txt); |
| 2604 | break; |
Christopher Faulet | 3c2ecf7 | 2019-02-27 16:41:27 +0100 | [diff] [blame] | 2605 | case STAT_STATUS_IVAL: |
| 2606 | chunk_appendf(&trash, |
| 2607 | "<p><div class=active_down>" |
| 2608 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2609 | "<b>Invalid requests (unsupported method or chunked encoded request).</b>" |
| 2610 | "</div>\n", uri->uri_prefix, |
| 2611 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2612 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2613 | scope_txt); |
| 2614 | break; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2615 | default: |
| 2616 | chunk_appendf(&trash, |
| 2617 | "<p><div class=active_no_check>" |
| 2618 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
| 2619 | "Unexpected result." |
| 2620 | "</div>\n", uri->uri_prefix, |
| 2621 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 2622 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 2623 | scope_txt); |
| 2624 | } |
| 2625 | chunk_appendf(&trash, "<p>\n"); |
| 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 2630 | * for clearing the trash if needed. |
| 2631 | */ |
| 2632 | static void stats_dump_html_end() |
| 2633 | { |
| 2634 | chunk_appendf(&trash, "</body></html>\n"); |
| 2635 | } |
| 2636 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 2637 | /* Dumps the stats JSON header to the trash buffer which. The caller is responsible |
| 2638 | * for clearing it if needed. |
| 2639 | */ |
| 2640 | static void stats_dump_json_header() |
| 2641 | { |
| 2642 | chunk_strcat(&trash, "["); |
| 2643 | } |
| 2644 | |
| 2645 | |
| 2646 | /* Dumps the JSON stats trailer block to the trash. The caller is responsible |
| 2647 | * for clearing the trash if needed. |
| 2648 | */ |
| 2649 | static void stats_dump_json_end() |
| 2650 | { |
| 2651 | chunk_strcat(&trash, "]"); |
| 2652 | } |
| 2653 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2654 | /* This function dumps statistics onto the stream interface's read buffer in |
| 2655 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
| 2656 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 2657 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
| 2658 | * and the stream must be closed, or -1 in case of any error. This function is |
| 2659 | * used by both the CLI and the HTTP handlers. |
| 2660 | */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2661 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct htx *htx, |
| 2662 | struct uri_auth *uri) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2663 | { |
| 2664 | struct appctx *appctx = __objt_appctx(si->end); |
| 2665 | struct channel *rep = si_ic(si); |
| 2666 | struct proxy *px; |
| 2667 | |
| 2668 | chunk_reset(&trash); |
| 2669 | |
| 2670 | switch (appctx->st2) { |
| 2671 | case STAT_ST_INIT: |
| 2672 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
| 2673 | /* fall through */ |
| 2674 | |
| 2675 | case STAT_ST_HEAD: |
| 2676 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
| 2677 | stats_dump_html_head(uri); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 2678 | else if (appctx->ctx.stats.flags & STAT_FMT_JSON) |
Willy Tarreau | 9d7fb63 | 2017-04-11 07:53:04 +0200 | [diff] [blame] | 2679 | stats_dump_json_header(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2680 | else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED)) |
| 2681 | stats_dump_csv_header(); |
| 2682 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2683 | if (!stats_putchk(rep, htx, &trash)) |
| 2684 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2685 | |
| 2686 | appctx->st2 = STAT_ST_INFO; |
| 2687 | /* fall through */ |
| 2688 | |
| 2689 | case STAT_ST_INFO: |
| 2690 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
| 2691 | stats_dump_html_info(si, uri); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2692 | if (!stats_putchk(rep, htx, &trash)) |
| 2693 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2694 | } |
| 2695 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 2696 | appctx->ctx.stats.px = proxies_list; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2697 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 2698 | appctx->st2 = STAT_ST_LIST; |
| 2699 | /* fall through */ |
| 2700 | |
| 2701 | case STAT_ST_LIST: |
| 2702 | /* dump proxies */ |
| 2703 | while (appctx->ctx.stats.px) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2704 | if (htx) { |
| 2705 | if (htx_almost_full(htx)) |
| 2706 | goto full; |
| 2707 | } |
| 2708 | else { |
| 2709 | if (buffer_almost_full(&rep->buf)) |
| 2710 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | px = appctx->ctx.stats.px; |
| 2714 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 2715 | if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2716 | if (stats_dump_proxy_to_buffer(si, htx, px, uri) == 0) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2717 | return 0; |
| 2718 | |
| 2719 | appctx->ctx.stats.px = px->next; |
| 2720 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 2721 | } |
| 2722 | /* here, we just have reached the last proxy */ |
| 2723 | |
| 2724 | appctx->st2 = STAT_ST_END; |
| 2725 | /* fall through */ |
| 2726 | |
| 2727 | case STAT_ST_END: |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 2728 | if (appctx->ctx.stats.flags & (STAT_FMT_HTML|STAT_FMT_JSON)) { |
| 2729 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
| 2730 | stats_dump_html_end(); |
| 2731 | else |
| 2732 | stats_dump_json_end(); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2733 | if (!stats_putchk(rep, htx, &trash)) |
| 2734 | goto full; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | appctx->st2 = STAT_ST_FIN; |
| 2738 | /* fall through */ |
| 2739 | |
| 2740 | case STAT_ST_FIN: |
| 2741 | return 1; |
| 2742 | |
| 2743 | default: |
| 2744 | /* unknown state ! */ |
| 2745 | appctx->st2 = STAT_ST_FIN; |
| 2746 | return -1; |
| 2747 | } |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 2748 | |
| 2749 | full: |
| 2750 | si_rx_room_blk(si); |
| 2751 | return 0; |
| 2752 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | /* We reached the stats page through a POST request. The appctx is |
| 2756 | * expected to have already been allocated by the caller. |
| 2757 | * Parse the posted data and enable/disable servers if necessary. |
| 2758 | * Returns 1 if request was parsed or zero if it needs more data. |
| 2759 | */ |
| 2760 | static int stats_process_http_post(struct stream_interface *si) |
| 2761 | { |
| 2762 | struct stream *s = si_strm(si); |
| 2763 | struct appctx *appctx = objt_appctx(si->end); |
| 2764 | |
| 2765 | struct proxy *px = NULL; |
| 2766 | struct server *sv = NULL; |
| 2767 | |
| 2768 | char key[LINESIZE]; |
| 2769 | int action = ST_ADM_ACTION_NONE; |
| 2770 | int reprocess = 0; |
| 2771 | |
| 2772 | int total_servers = 0; |
| 2773 | int altered_servers = 0; |
| 2774 | |
| 2775 | char *first_param, *cur_param, *next_param, *end_params; |
| 2776 | char *st_cur_param = NULL; |
| 2777 | char *st_next_param = NULL; |
| 2778 | |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2779 | struct buffer *temp = get_trash_chunk(); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2780 | |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2781 | if (IS_HTX_STRM(s)) { |
| 2782 | struct htx *htx = htxbuf(&s->req.buf); |
| 2783 | struct htx_blk *blk; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2784 | |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2785 | /* we need more data */ |
| 2786 | if (s->txn->req.msg_state < HTTP_MSG_DONE) { |
| 2787 | /* check if we can receive more */ |
| 2788 | if (htx_free_data_space(htx) <= global.tune.maxrewrite) { |
| 2789 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
| 2790 | goto out; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2791 | } |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2792 | goto wait; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2793 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2794 | |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2795 | /* The request was fully received. Copy data */ |
Christopher Faulet | 8fa60e4 | 2019-05-23 11:04:05 +0200 | [diff] [blame] | 2796 | blk = htx_get_head_blk(htx); |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2797 | while (blk) { |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2798 | enum htx_blk_type type = htx_get_blk_type(blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2799 | |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 2800 | if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT) |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2801 | break; |
| 2802 | if (type == HTX_BLK_DATA) { |
| 2803 | struct ist v = htx_get_blk_value(htx, blk); |
| 2804 | |
| 2805 | if (!chunk_memcat(temp, v.ptr, v.len)) { |
| 2806 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
| 2807 | goto out; |
| 2808 | } |
| 2809 | } |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 2810 | blk = htx_get_next_blk(htx, blk); |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2811 | } |
| 2812 | } |
| 2813 | else { |
| 2814 | int reql; |
| 2815 | |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2816 | /* we need more data */ |
| 2817 | if (s->txn->req.msg_state < HTTP_MSG_DONE) { |
| 2818 | /* check if we can receive more */ |
| 2819 | if (c_room(&s->req) <= global.tune.maxrewrite) { |
| 2820 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
| 2821 | goto out; |
| 2822 | } |
| 2823 | goto wait; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2824 | } |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2825 | reql = co_getblk(si_oc(si), temp->area, s->txn->req.body_len, |
| 2826 | s->txn->req.eoh + 2); |
| 2827 | if (reql <= 0) { |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2828 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
| 2829 | goto out; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2830 | } |
| 2831 | temp->data = reql; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2832 | } |
| 2833 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 2834 | first_param = temp->area; |
Christopher Faulet | a361837 | 2018-12-13 21:59:56 +0100 | [diff] [blame] | 2835 | end_params = temp->area + temp->data; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2836 | cur_param = next_param = end_params; |
| 2837 | *end_params = '\0'; |
| 2838 | |
| 2839 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
| 2840 | |
| 2841 | /* |
| 2842 | * Parse the parameters in reverse order to only store the last value. |
| 2843 | * From the html form, the backend and the action are at the end. |
| 2844 | */ |
| 2845 | while (cur_param > first_param) { |
| 2846 | char *value; |
| 2847 | int poffset, plen; |
| 2848 | |
| 2849 | cur_param--; |
| 2850 | |
| 2851 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 2852 | reprocess_servers: |
| 2853 | /* Parse the key */ |
| 2854 | poffset = (cur_param != first_param ? 1 : 0); |
| 2855 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 2856 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 2857 | strncpy(key, cur_param + poffset, plen); |
| 2858 | key[plen - 1] = '\0'; |
| 2859 | } else { |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 2860 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2861 | goto out; |
| 2862 | } |
| 2863 | |
| 2864 | /* Parse the value */ |
| 2865 | value = key; |
| 2866 | while (*value != '\0' && *value != '=') { |
| 2867 | value++; |
| 2868 | } |
| 2869 | if (*value == '=') { |
| 2870 | /* Ok, a value is found, we can mark the end of the key */ |
| 2871 | *value++ = '\0'; |
| 2872 | } |
| 2873 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 2874 | break; |
| 2875 | |
| 2876 | /* Now we can check the key to see what to do */ |
| 2877 | if (!px && (strcmp(key, "b") == 0)) { |
| 2878 | if ((px = proxy_be_by_name(value)) == NULL) { |
| 2879 | /* the backend name is unknown or ambiguous (duplicate names) */ |
| 2880 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
| 2881 | goto out; |
| 2882 | } |
| 2883 | } |
| 2884 | else if (!action && (strcmp(key, "action") == 0)) { |
| 2885 | if (strcmp(value, "ready") == 0) { |
| 2886 | action = ST_ADM_ACTION_READY; |
| 2887 | } |
| 2888 | else if (strcmp(value, "drain") == 0) { |
| 2889 | action = ST_ADM_ACTION_DRAIN; |
| 2890 | } |
| 2891 | else if (strcmp(value, "maint") == 0) { |
| 2892 | action = ST_ADM_ACTION_MAINT; |
| 2893 | } |
| 2894 | else if (strcmp(value, "shutdown") == 0) { |
| 2895 | action = ST_ADM_ACTION_SHUTDOWN; |
| 2896 | } |
| 2897 | else if (strcmp(value, "dhlth") == 0) { |
| 2898 | action = ST_ADM_ACTION_DHLTH; |
| 2899 | } |
| 2900 | else if (strcmp(value, "ehlth") == 0) { |
| 2901 | action = ST_ADM_ACTION_EHLTH; |
| 2902 | } |
| 2903 | else if (strcmp(value, "hrunn") == 0) { |
| 2904 | action = ST_ADM_ACTION_HRUNN; |
| 2905 | } |
| 2906 | else if (strcmp(value, "hnolb") == 0) { |
| 2907 | action = ST_ADM_ACTION_HNOLB; |
| 2908 | } |
| 2909 | else if (strcmp(value, "hdown") == 0) { |
| 2910 | action = ST_ADM_ACTION_HDOWN; |
| 2911 | } |
| 2912 | else if (strcmp(value, "dagent") == 0) { |
| 2913 | action = ST_ADM_ACTION_DAGENT; |
| 2914 | } |
| 2915 | else if (strcmp(value, "eagent") == 0) { |
| 2916 | action = ST_ADM_ACTION_EAGENT; |
| 2917 | } |
| 2918 | else if (strcmp(value, "arunn") == 0) { |
| 2919 | action = ST_ADM_ACTION_ARUNN; |
| 2920 | } |
| 2921 | else if (strcmp(value, "adown") == 0) { |
| 2922 | action = ST_ADM_ACTION_ADOWN; |
| 2923 | } |
| 2924 | /* else these are the old supported methods */ |
| 2925 | else if (strcmp(value, "disable") == 0) { |
| 2926 | action = ST_ADM_ACTION_DISABLE; |
| 2927 | } |
| 2928 | else if (strcmp(value, "enable") == 0) { |
| 2929 | action = ST_ADM_ACTION_ENABLE; |
| 2930 | } |
| 2931 | else if (strcmp(value, "stop") == 0) { |
| 2932 | action = ST_ADM_ACTION_STOP; |
| 2933 | } |
| 2934 | else if (strcmp(value, "start") == 0) { |
| 2935 | action = ST_ADM_ACTION_START; |
| 2936 | } |
| 2937 | else { |
| 2938 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
| 2939 | goto out; |
| 2940 | } |
| 2941 | } |
| 2942 | else if (strcmp(key, "s") == 0) { |
| 2943 | if (!(px && action)) { |
| 2944 | /* |
| 2945 | * Indicates that we'll need to reprocess the parameters |
| 2946 | * as soon as backend and action are known |
| 2947 | */ |
| 2948 | if (!reprocess) { |
| 2949 | st_cur_param = cur_param; |
| 2950 | st_next_param = next_param; |
| 2951 | } |
| 2952 | reprocess = 1; |
| 2953 | } |
| 2954 | else if ((sv = findserver(px, value)) != NULL) { |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 2955 | HA_SPIN_LOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2956 | switch (action) { |
| 2957 | case ST_ADM_ACTION_DISABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2958 | if (!(sv->cur_admin & SRV_ADMF_FMAINT)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2959 | altered_servers++; |
| 2960 | total_servers++; |
| 2961 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page"); |
| 2962 | } |
| 2963 | break; |
| 2964 | case ST_ADM_ACTION_ENABLE: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2965 | if (sv->cur_admin & SRV_ADMF_FMAINT) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2966 | altered_servers++; |
| 2967 | total_servers++; |
| 2968 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
| 2969 | } |
| 2970 | break; |
| 2971 | case ST_ADM_ACTION_STOP: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2972 | if (!(sv->cur_admin & SRV_ADMF_FDRAIN)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2973 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page"); |
| 2974 | altered_servers++; |
| 2975 | total_servers++; |
| 2976 | } |
| 2977 | break; |
| 2978 | case ST_ADM_ACTION_START: |
Emeric Brun | 52a91d3 | 2017-08-31 14:41:55 +0200 | [diff] [blame] | 2979 | if (sv->cur_admin & SRV_ADMF_FDRAIN) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 2980 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 2981 | altered_servers++; |
| 2982 | total_servers++; |
| 2983 | } |
| 2984 | break; |
| 2985 | case ST_ADM_ACTION_DHLTH: |
| 2986 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 2987 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2988 | altered_servers++; |
| 2989 | total_servers++; |
| 2990 | } |
| 2991 | break; |
| 2992 | case ST_ADM_ACTION_EHLTH: |
| 2993 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 2994 | sv->check.state |= CHK_ST_ENABLED; |
| 2995 | altered_servers++; |
| 2996 | total_servers++; |
| 2997 | } |
| 2998 | break; |
| 2999 | case ST_ADM_ACTION_HRUNN: |
| 3000 | if (!(sv->track)) { |
| 3001 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3002 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3003 | altered_servers++; |
| 3004 | total_servers++; |
| 3005 | } |
| 3006 | break; |
| 3007 | case ST_ADM_ACTION_HNOLB: |
| 3008 | if (!(sv->track)) { |
| 3009 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3010 | srv_set_stopping(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3011 | altered_servers++; |
| 3012 | total_servers++; |
| 3013 | } |
| 3014 | break; |
| 3015 | case ST_ADM_ACTION_HDOWN: |
| 3016 | if (!(sv->track)) { |
| 3017 | sv->check.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3018 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3019 | altered_servers++; |
| 3020 | total_servers++; |
| 3021 | } |
| 3022 | break; |
| 3023 | case ST_ADM_ACTION_DAGENT: |
| 3024 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 3025 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 3026 | altered_servers++; |
| 3027 | total_servers++; |
| 3028 | } |
| 3029 | break; |
| 3030 | case ST_ADM_ACTION_EAGENT: |
| 3031 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 3032 | sv->agent.state |= CHK_ST_ENABLED; |
| 3033 | altered_servers++; |
| 3034 | total_servers++; |
| 3035 | } |
| 3036 | break; |
| 3037 | case ST_ADM_ACTION_ARUNN: |
| 3038 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 3039 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3040 | srv_set_running(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3041 | altered_servers++; |
| 3042 | total_servers++; |
| 3043 | } |
| 3044 | break; |
| 3045 | case ST_ADM_ACTION_ADOWN: |
| 3046 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 3047 | sv->agent.health = 0; |
Emeric Brun | 5a13351 | 2017-10-19 14:42:30 +0200 | [diff] [blame] | 3048 | srv_set_stopped(sv, "changed from Web interface", NULL); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3049 | altered_servers++; |
| 3050 | total_servers++; |
| 3051 | } |
| 3052 | break; |
| 3053 | case ST_ADM_ACTION_READY: |
| 3054 | srv_adm_set_ready(sv); |
| 3055 | altered_servers++; |
| 3056 | total_servers++; |
| 3057 | break; |
| 3058 | case ST_ADM_ACTION_DRAIN: |
| 3059 | srv_adm_set_drain(sv); |
| 3060 | altered_servers++; |
| 3061 | total_servers++; |
| 3062 | break; |
| 3063 | case ST_ADM_ACTION_MAINT: |
| 3064 | srv_adm_set_maint(sv); |
| 3065 | altered_servers++; |
| 3066 | total_servers++; |
| 3067 | break; |
| 3068 | case ST_ADM_ACTION_SHUTDOWN: |
| 3069 | if (px->state != PR_STSTOPPED) { |
| 3070 | struct stream *sess, *sess_bck; |
| 3071 | |
| 3072 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 3073 | if (sess->srv_conn == sv) |
| 3074 | stream_shutdown(sess, SF_ERR_KILLED); |
| 3075 | |
| 3076 | altered_servers++; |
| 3077 | total_servers++; |
| 3078 | } |
| 3079 | break; |
| 3080 | } |
Christopher Faulet | 2a944ee | 2017-11-07 10:42:54 +0100 | [diff] [blame] | 3081 | HA_SPIN_UNLOCK(SERVER_LOCK, &sv->lock); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3082 | } else { |
| 3083 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 3084 | total_servers++; |
| 3085 | } |
| 3086 | } |
| 3087 | if (reprocess && px && action) { |
| 3088 | /* Now, we know the backend and the action chosen by the user. |
| 3089 | * We can safely restart from the first server parameter |
| 3090 | * to reprocess them |
| 3091 | */ |
| 3092 | cur_param = st_cur_param; |
| 3093 | next_param = st_next_param; |
| 3094 | reprocess = 0; |
| 3095 | goto reprocess_servers; |
| 3096 | } |
| 3097 | |
| 3098 | next_param = cur_param; |
| 3099 | } |
| 3100 | } |
| 3101 | |
| 3102 | if (total_servers == 0) { |
| 3103 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
| 3104 | } |
| 3105 | else if (altered_servers == 0) { |
| 3106 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
| 3107 | } |
| 3108 | else if (altered_servers == total_servers) { |
| 3109 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
| 3110 | } |
| 3111 | else { |
| 3112 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
| 3113 | } |
| 3114 | out: |
| 3115 | return 1; |
Christopher Faulet | 2f9a41d | 2019-02-27 15:30:57 +0100 | [diff] [blame] | 3116 | wait: |
| 3117 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
| 3118 | return 0; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | |
| 3122 | static int stats_send_htx_headers(struct stream_interface *si, struct htx *htx) |
| 3123 | { |
| 3124 | struct stream *s = si_strm(si); |
| 3125 | struct uri_auth *uri = s->be->uri_auth; |
| 3126 | struct appctx *appctx = __objt_appctx(si->end); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3127 | struct htx_sl *sl; |
| 3128 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3129 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3130 | 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); |
| 3131 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("200"), ist("OK")); |
| 3132 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3133 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3134 | sl->info.res.status = 200; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3135 | |
Christopher Faulet | b829f4c | 2019-03-29 16:13:55 +0100 | [diff] [blame] | 3136 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache"))) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3137 | goto full; |
| 3138 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
| 3139 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/html"))) |
| 3140 | goto full; |
| 3141 | } |
| 3142 | else { |
| 3143 | if (!htx_add_header(htx, ist("Content-Type"), ist("text/plain"))) |
| 3144 | goto full; |
| 3145 | } |
| 3146 | |
| 3147 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) { |
| 3148 | const char *refresh = U2A(uri->refresh); |
| 3149 | if (!htx_add_header(htx, ist("Refresh"), ist2(refresh, strlen(refresh)))) |
| 3150 | goto full; |
| 3151 | } |
| 3152 | |
| 3153 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 3154 | if (!htx_add_header(htx, ist("Transfer-Encoding"), ist("chunked"))) |
| 3155 | goto full; |
| 3156 | } |
| 3157 | |
| 3158 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 3159 | goto full; |
| 3160 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 3161 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3162 | return 1; |
| 3163 | |
| 3164 | full: |
| 3165 | htx_reset(htx); |
| 3166 | si_rx_room_blk(si); |
| 3167 | return 0; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3168 | } |
| 3169 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3170 | |
| 3171 | static int stats_send_htx_redirect(struct stream_interface *si, struct htx *htx) |
| 3172 | { |
| 3173 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3174 | struct stream *s = si_strm(si); |
| 3175 | struct uri_auth *uri = s->be->uri_auth; |
| 3176 | struct appctx *appctx = __objt_appctx(si->end); |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3177 | struct htx_sl *sl; |
| 3178 | unsigned int flags; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3179 | |
| 3180 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3181 | scope_txt[0] = 0; |
| 3182 | if (appctx->ctx.stats.scope_len) { |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3183 | const char *scope_ptr = stats_scope_ptr(appctx, si); |
| 3184 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3185 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Christopher Faulet | ed7a066 | 2019-01-14 11:07:34 +0100 | [diff] [blame] | 3186 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, appctx->ctx.stats.scope_len); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3187 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
| 3188 | } |
| 3189 | |
| 3190 | /* We don't want to land on the posted stats page because a refresh will |
| 3191 | * repost the data. We don't want this to happen on accident so we redirect |
| 3192 | * the browse to the stats page with a GET. |
| 3193 | */ |
| 3194 | chunk_printf(&trash, "%s;st=%s%s%s%s", |
| 3195 | uri->uri_prefix, |
| 3196 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 3197 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 3198 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 3199 | stat_status_codes[appctx->ctx.stats.st_code] : |
| 3200 | stat_status_codes[STAT_STATUS_UNKN], |
| 3201 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3202 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3203 | scope_txt); |
| 3204 | |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3205 | flags = (HTX_SL_F_IS_RESP|HTX_SL_F_VER_11|HTX_SL_F_XFER_LEN|HTX_SL_F_CHNK); |
| 3206 | sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/1.1"), ist("303"), ist("See Other")); |
| 3207 | if (!sl) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3208 | goto full; |
Christopher Faulet | f1ba18d | 2018-11-26 21:37:08 +0100 | [diff] [blame] | 3209 | sl->info.res.status = 303; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3210 | |
| 3211 | if (!htx_add_header(htx, ist("Cache-Control"), ist("no-cache")) || |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3212 | !htx_add_header(htx, ist("Content-Type"), ist("text/plain")) || |
| 3213 | !htx_add_header(htx, ist("Content-Length"), ist("0")) || |
| 3214 | !htx_add_header(htx, ist("Location"), ist2(trash.area, trash.data))) |
| 3215 | goto full; |
| 3216 | |
| 3217 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 3218 | goto full; |
| 3219 | |
Christopher Faulet | 1e2d636 | 2019-02-27 16:28:48 +0100 | [diff] [blame] | 3220 | channel_add_input(&s->res, htx->data); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3221 | return 1; |
| 3222 | |
| 3223 | full: |
| 3224 | htx_reset(htx); |
| 3225 | si_rx_room_blk(si); |
| 3226 | return 0; |
| 3227 | } |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3228 | |
| 3229 | static int stats_send_http_headers(struct stream_interface *si) |
| 3230 | { |
| 3231 | struct stream *s = si_strm(si); |
| 3232 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 21ff2c4 | 2018-09-20 11:01:01 +0200 | [diff] [blame] | 3233 | struct appctx *appctx = __objt_appctx(si->end); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3234 | |
| 3235 | chunk_printf(&trash, |
| 3236 | "HTTP/1.1 200 OK\r\n" |
| 3237 | "Cache-Control: no-cache\r\n" |
| 3238 | "Connection: close\r\n" |
| 3239 | "Content-Type: %s\r\n", |
| 3240 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
| 3241 | |
| 3242 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
| 3243 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 3244 | uri->refresh); |
| 3245 | |
| 3246 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 3247 | |
| 3248 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 3249 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 3250 | else |
| 3251 | chunk_appendf(&trash, "\r\n"); |
| 3252 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3253 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3254 | si_rx_room_blk(si); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3255 | return 0; |
| 3256 | } |
| 3257 | |
| 3258 | return 1; |
| 3259 | } |
| 3260 | |
| 3261 | static int stats_send_http_redirect(struct stream_interface *si) |
| 3262 | { |
| 3263 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 3264 | struct stream *s = si_strm(si); |
| 3265 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 21ff2c4 | 2018-09-20 11:01:01 +0200 | [diff] [blame] | 3266 | struct appctx *appctx = __objt_appctx(si->end); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3267 | |
| 3268 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
| 3269 | scope_txt[0] = 0; |
| 3270 | if (appctx->ctx.stats.scope_len) { |
| 3271 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 89faf5d | 2018-06-07 18:16:48 +0200 | [diff] [blame] | 3272 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), co_head(si_oc(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3273 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
| 3274 | } |
| 3275 | |
| 3276 | /* We don't want to land on the posted stats page because a refresh will |
| 3277 | * repost the data. We don't want this to happen on accident so we redirect |
| 3278 | * the browse to the stats page with a GET. |
| 3279 | */ |
| 3280 | chunk_printf(&trash, |
| 3281 | "HTTP/1.1 303 See Other\r\n" |
| 3282 | "Cache-Control: no-cache\r\n" |
| 3283 | "Content-Type: text/plain\r\n" |
| 3284 | "Connection: close\r\n" |
| 3285 | "Location: %s;st=%s%s%s%s\r\n" |
| 3286 | "Content-length: 0\r\n" |
| 3287 | "\r\n", |
| 3288 | uri->uri_prefix, |
| 3289 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 3290 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 3291 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 3292 | stat_status_codes[appctx->ctx.stats.st_code] : |
| 3293 | stat_status_codes[STAT_STATUS_UNKN], |
| 3294 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 3295 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
| 3296 | scope_txt); |
| 3297 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3298 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3299 | si_rx_room_blk(si); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3300 | return 0; |
| 3301 | } |
| 3302 | |
| 3303 | return 1; |
| 3304 | } |
| 3305 | |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3306 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3307 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3308 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 3309 | * appctx->st0 contains the operation in progress (dump, done). The handler |
| 3310 | * automatically unregisters itself once transfer is complete. |
| 3311 | */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3312 | static void htx_stats_io_handler(struct appctx *appctx) |
| 3313 | { |
| 3314 | struct stream_interface *si = appctx->owner; |
| 3315 | struct stream *s = si_strm(si); |
| 3316 | struct channel *req = si_oc(si); |
| 3317 | struct channel *res = si_ic(si); |
| 3318 | struct htx *req_htx, *res_htx; |
| 3319 | |
| 3320 | res_htx = htx_from_buf(&res->buf); |
| 3321 | |
| 3322 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3323 | goto out; |
| 3324 | |
| 3325 | /* Check if the input buffer is avalaible. */ |
| 3326 | if (!b_size(&res->buf)) { |
| 3327 | si_rx_room_blk(si); |
| 3328 | goto out; |
| 3329 | } |
| 3330 | |
| 3331 | /* check that the output is not closed */ |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3332 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_SHUTR)) |
| 3333 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3334 | |
| 3335 | /* all states are processed in sequence */ |
| 3336 | if (appctx->st0 == STAT_HTTP_HEAD) { |
| 3337 | if (stats_send_htx_headers(si, res_htx)) { |
| 3338 | if (s->txn->meth == HTTP_METH_HEAD) |
| 3339 | appctx->st0 = STAT_HTTP_DONE; |
| 3340 | else |
| 3341 | appctx->st0 = STAT_HTTP_DUMP; |
| 3342 | } |
| 3343 | } |
| 3344 | |
| 3345 | if (appctx->st0 == STAT_HTTP_DUMP) { |
| 3346 | if (stats_dump_stat_to_buffer(si, res_htx, s->be->uri_auth)) |
| 3347 | appctx->st0 = STAT_HTTP_DONE; |
| 3348 | } |
| 3349 | |
| 3350 | if (appctx->st0 == STAT_HTTP_POST) { |
| 3351 | if (stats_process_http_post(si)) |
| 3352 | appctx->st0 = STAT_HTTP_LAST; |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3353 | else if (req->flags & CF_SHUTR) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3354 | appctx->st0 = STAT_HTTP_DONE; |
| 3355 | } |
| 3356 | |
| 3357 | if (appctx->st0 == STAT_HTTP_LAST) { |
| 3358 | if (stats_send_htx_redirect(si, res_htx)) |
| 3359 | appctx->st0 = STAT_HTTP_DONE; |
| 3360 | } |
| 3361 | |
| 3362 | if (appctx->st0 == STAT_HTTP_DONE) { |
Christopher Faulet | 54b5e21 | 2019-06-04 10:08:28 +0200 | [diff] [blame] | 3363 | /* Don't add TLR because mux-h1 will take care of it */ |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3364 | if (!htx_add_endof(res_htx, HTX_BLK_EOM)) { |
| 3365 | si_rx_room_blk(si); |
| 3366 | goto out; |
| 3367 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3368 | channel_add_input(&s->res, 1); |
| 3369 | appctx->st0 = STAT_HTTP_END; |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3370 | } |
| 3371 | |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3372 | if (appctx->st0 == STAT_HTTP_END) { |
| 3373 | if (!(res->flags & CF_SHUTR)) { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3374 | res->flags |= CF_READ_NULL; |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3375 | si_shutr(si); |
| 3376 | } |
| 3377 | |
| 3378 | /* eat the whole request */ |
| 3379 | if (co_data(req)) { |
| 3380 | req_htx = htx_from_buf(&req->buf); |
| 3381 | co_htx_skip(req, req_htx, co_data(req)); |
| 3382 | htx_to_buf(req_htx, &req->buf); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3383 | } |
| 3384 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3385 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3386 | out: |
| 3387 | /* we have left the request in the buffer for the case where we |
| 3388 | * process a POST, and this automatically re-enables activity on |
| 3389 | * read. It's better to indicate that we want to stop reading when |
| 3390 | * we're sending, so that we know there's at most one direction |
| 3391 | * deciding to wake the applet up. It saves it from looping when |
| 3392 | * emitting large blocks into small TCP windows. |
| 3393 | */ |
Christopher Faulet | 27ba2dc | 2018-12-05 11:53:24 +0100 | [diff] [blame] | 3394 | htx_to_buf(res_htx, &res->buf); |
| 3395 | if (!channel_is_empty(res)) |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3396 | si_stop_get(si); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | |
| 3400 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 3401 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
| 3402 | * appctx->st0 contains the operation in progress (dump, done). The handler |
| 3403 | * automatically unregisters itself once transfer is complete. |
| 3404 | */ |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3405 | static void http_stats_io_handler(struct appctx *appctx) |
| 3406 | { |
| 3407 | struct stream_interface *si = appctx->owner; |
| 3408 | struct stream *s = si_strm(si); |
| 3409 | struct channel *req = si_oc(si); |
| 3410 | struct channel *res = si_ic(si); |
| 3411 | |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3412 | if (IS_HTX_STRM(s)) |
| 3413 | return htx_stats_io_handler(appctx); |
| 3414 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3415 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 3416 | goto out; |
| 3417 | |
Joseph Herlant | 29023ec | 2018-11-15 13:39:46 -0800 | [diff] [blame] | 3418 | /* Check if the input buffer is available. */ |
Willy Tarreau | c9fa048 | 2018-07-10 17:43:27 +0200 | [diff] [blame] | 3419 | if (res->buf.size == 0) { |
Willy Tarreau | 4b962a4 | 2018-11-15 11:03:21 +0100 | [diff] [blame] | 3420 | /* already subscribed, we'll be called later once the buffer is |
| 3421 | * available. |
| 3422 | */ |
Christopher Faulet | a73e59b | 2016-12-09 17:30:18 +0100 | [diff] [blame] | 3423 | goto out; |
| 3424 | } |
| 3425 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3426 | /* check that the output is not closed */ |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3427 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW|CF_SHUTR)) |
| 3428 | appctx->st0 = STAT_HTTP_END; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3429 | |
| 3430 | /* all states are processed in sequence */ |
| 3431 | if (appctx->st0 == STAT_HTTP_HEAD) { |
| 3432 | if (stats_send_http_headers(si)) { |
| 3433 | if (s->txn->meth == HTTP_METH_HEAD) |
| 3434 | appctx->st0 = STAT_HTTP_DONE; |
| 3435 | else |
| 3436 | appctx->st0 = STAT_HTTP_DUMP; |
| 3437 | } |
| 3438 | } |
| 3439 | |
| 3440 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 97f538b | 2018-06-15 19:41:31 +0200 | [diff] [blame] | 3441 | unsigned int prev_len = ci_data(si_ic(si)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3442 | unsigned int data_len; |
| 3443 | unsigned int last_len; |
| 3444 | unsigned int last_fwd = 0; |
| 3445 | |
| 3446 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 3447 | /* One difficulty we're facing is that we must prevent |
| 3448 | * the input data from being automatically forwarded to |
| 3449 | * the output area. For this, we temporarily disable |
| 3450 | * forwarding on the channel. |
| 3451 | */ |
| 3452 | last_fwd = si_ic(si)->to_forward; |
| 3453 | si_ic(si)->to_forward = 0; |
| 3454 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3455 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3456 | si_rx_room_blk(si); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3457 | si_ic(si)->to_forward = last_fwd; |
| 3458 | goto out; |
| 3459 | } |
| 3460 | } |
| 3461 | |
Willy Tarreau | 97f538b | 2018-06-15 19:41:31 +0200 | [diff] [blame] | 3462 | data_len = ci_data(si_ic(si)); |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 3463 | if (stats_dump_stat_to_buffer(si, NULL, s->be->uri_auth)) |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3464 | appctx->st0 = STAT_HTTP_DONE; |
| 3465 | |
Willy Tarreau | 97f538b | 2018-06-15 19:41:31 +0200 | [diff] [blame] | 3466 | last_len = ci_data(si_ic(si)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3467 | |
| 3468 | /* Now we must either adjust or remove the chunk size. This is |
| 3469 | * not easy because the chunk size might wrap at the end of the |
| 3470 | * buffer, so we pretend we have nothing in the buffer, we write |
| 3471 | * the size, then restore the buffer's contents. Note that we can |
| 3472 | * only do that because no forwarding is scheduled on the stats |
| 3473 | * applet. |
| 3474 | */ |
| 3475 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 3476 | si_ic(si)->total -= (last_len - prev_len); |
Willy Tarreau | 97f538b | 2018-06-15 19:41:31 +0200 | [diff] [blame] | 3477 | b_sub(si_ib(si), (last_len - prev_len)); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3478 | |
| 3479 | if (last_len != data_len) { |
| 3480 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3481 | if (ci_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3482 | si_rx_room_blk(si); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3483 | |
| 3484 | si_ic(si)->total += (last_len - data_len); |
Willy Tarreau | 97f538b | 2018-06-15 19:41:31 +0200 | [diff] [blame] | 3485 | b_add(si_ib(si), last_len - data_len); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3486 | } |
| 3487 | /* now re-enable forwarding */ |
| 3488 | channel_forward(si_ic(si), last_fwd); |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | if (appctx->st0 == STAT_HTTP_POST) { |
| 3493 | if (stats_process_http_post(si)) |
| 3494 | appctx->st0 = STAT_HTTP_LAST; |
| 3495 | else if (si_oc(si)->flags & CF_SHUTR) |
| 3496 | appctx->st0 = STAT_HTTP_DONE; |
| 3497 | } |
| 3498 | |
| 3499 | if (appctx->st0 == STAT_HTTP_LAST) { |
| 3500 | if (stats_send_http_redirect(si)) |
| 3501 | appctx->st0 = STAT_HTTP_DONE; |
| 3502 | } |
| 3503 | |
| 3504 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 3505 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 3506 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3507 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3508 | si_rx_room_blk(si); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3509 | goto out; |
| 3510 | } |
| 3511 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3512 | appctx->st0 = STAT_HTTP_END; |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3513 | } |
| 3514 | |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3515 | if (appctx->st0 == STAT_HTTP_END) { |
| 3516 | if (!(res->flags & CF_SHUTR)) { |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3517 | res->flags |= CF_READ_NULL; |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3518 | si_shutr(si); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3519 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3520 | |
| 3521 | /* eat the whole request */ |
| 3522 | if (co_data(req)) |
| 3523 | co_skip(si_oc(si), co_data(si_oc(si))); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3524 | } |
Christopher Faulet | 3a78aa6 | 2019-02-27 16:19:48 +0100 | [diff] [blame] | 3525 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3526 | out: |
Willy Tarreau | 055ba4f | 2018-07-24 17:05:54 +0200 | [diff] [blame] | 3527 | /* we have left the request in the buffer for the case where we |
| 3528 | * process a POST, and this automatically re-enables activity on |
| 3529 | * read. It's better to indicate that we want to stop reading when |
| 3530 | * we're sending, so that we know there's at most one direction |
| 3531 | * deciding to wake the applet up. It saves it from looping when |
| 3532 | * emitting large blocks into small TCP windows. |
| 3533 | */ |
| 3534 | if (!channel_is_empty(res)) |
Willy Tarreau | 0cd3bd6 | 2018-11-06 18:46:37 +0100 | [diff] [blame] | 3535 | si_stop_get(si); |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 3536 | } |
| 3537 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3538 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3539 | static int stats_dump_info_fields(struct buffer *out, |
| 3540 | const struct field *info) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3541 | { |
| 3542 | int field; |
| 3543 | |
| 3544 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 3545 | if (!field_format(info, field)) |
| 3546 | continue; |
| 3547 | |
| 3548 | if (!chunk_appendf(out, "%s: ", info_field_names[field])) |
| 3549 | return 0; |
| 3550 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 3551 | return 0; |
| 3552 | if (!chunk_strcat(out, "\n")) |
| 3553 | return 0; |
| 3554 | } |
| 3555 | return 1; |
| 3556 | } |
| 3557 | |
| 3558 | /* Dump all fields from <info> into <out> using the "show info typed" format */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3559 | static int stats_dump_typed_info_fields(struct buffer *out, |
| 3560 | const struct field *info) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3561 | { |
| 3562 | int field; |
| 3563 | |
| 3564 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 3565 | if (!field_format(info, field)) |
| 3566 | continue; |
| 3567 | |
| 3568 | if (!chunk_appendf(out, "%d.%s.%u:", field, info_field_names[field], info[INF_PROCESS_NUM].u.u32)) |
| 3569 | return 0; |
| 3570 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 3571 | return 0; |
| 3572 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 3573 | return 0; |
| 3574 | if (!chunk_strcat(out, "\n")) |
| 3575 | return 0; |
| 3576 | } |
| 3577 | return 1; |
| 3578 | } |
| 3579 | |
| 3580 | /* Fill <info> with HAProxy global info. <info> is preallocated |
| 3581 | * array of length <len>. The length of the aray must be |
| 3582 | * INF_TOTAL_FIELDS. If this length is less then this value, the |
| 3583 | * function returns 0, otherwise, it returns 1. |
| 3584 | */ |
| 3585 | int stats_fill_info(struct field *info, int len) |
| 3586 | { |
| 3587 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3588 | struct buffer *out = get_trash_chunk(); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3589 | |
| 3590 | #ifdef USE_OPENSSL |
| 3591 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 3592 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 3593 | int ssl_reuse = 0; |
| 3594 | |
| 3595 | if (ssl_key_rate < ssl_sess_rate) { |
| 3596 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 3597 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 3598 | } |
| 3599 | #endif |
| 3600 | |
| 3601 | if (len < INF_TOTAL_FIELDS) |
| 3602 | return 0; |
| 3603 | |
| 3604 | chunk_reset(out); |
| 3605 | memset(info, 0, sizeof(*info) * len); |
| 3606 | |
| 3607 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
Willy Tarreau | 909b9d8 | 2019-01-04 18:20:32 +0100 | [diff] [blame] | 3608 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_version); |
| 3609 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, haproxy_date); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3610 | |
Yves Lafon | 9531728 | 2018-02-26 11:10:37 +0100 | [diff] [blame] | 3611 | info[INF_NBTHREAD] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbthread); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3612 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 3613 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 3614 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 3615 | |
| 3616 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 3617 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 3618 | |
| 3619 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 3620 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 3621 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 3622 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 3623 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 3624 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 3625 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 3626 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 3627 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 3628 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 3629 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 3630 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 3631 | #ifdef USE_OPENSSL |
| 3632 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 3633 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 3634 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 3635 | #endif |
| 3636 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 3637 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 3638 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 3639 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 3640 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 3641 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 3642 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 3643 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 3644 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 3645 | |
| 3646 | #ifdef USE_OPENSSL |
| 3647 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3648 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3649 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3650 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3651 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3652 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3653 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3654 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3655 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3656 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3657 | #endif |
| 3658 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3659 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3660 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3661 | #ifdef USE_ZLIB |
| 3662 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3663 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3664 | #endif |
| 3665 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
Christopher Faulet | 34c5cc9 | 2016-12-06 09:15:30 +0100 | [diff] [blame] | 3666 | info[INF_RUN_QUEUE] = mkf_u32(0, tasks_run_queue_cur); |
Willy Tarreau | 81036f2 | 2019-05-20 19:24:50 +0200 | [diff] [blame] | 3667 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, ti->idle_pct); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3668 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3669 | if (global.desc) |
| 3670 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 3671 | info[INF_STOPPING] = mkf_u32(0, stopping); |
| 3672 | info[INF_JOBS] = mkf_u32(0, jobs); |
William Lallemand | a719926 | 2018-11-16 16:57:20 +0100 | [diff] [blame] | 3673 | info[INF_UNSTOPPABLE_JOBS] = mkf_u32(0, unstoppable_jobs); |
Willy Tarreau | 00098ea | 2018-11-05 14:38:13 +0100 | [diff] [blame] | 3674 | info[INF_LISTENERS] = mkf_u32(0, listeners); |
Willy Tarreau | 199ad24 | 2018-11-05 16:31:22 +0100 | [diff] [blame] | 3675 | info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers); |
Willy Tarreau | 2d372c2 | 2018-11-05 17:12:27 +0100 | [diff] [blame] | 3676 | info[INF_CONNECTED_PEERS] = mkf_u32(0, connected_peers); |
Willy Tarreau | 13ef773 | 2018-11-12 07:25:28 +0100 | [diff] [blame] | 3677 | info[INF_DROPPED_LOGS] = mkf_u32(0, dropped_logs); |
Willy Tarreau | beb859a | 2018-11-22 18:07:59 +0100 | [diff] [blame] | 3678 | info[INF_BUSY_POLLING] = mkf_u32(0, !!(global.tune.options & GTUNE_BUSY_POLLING)); |
Baptiste Assmann | 333939c | 2019-01-21 08:34:50 +0100 | [diff] [blame] | 3679 | info[INF_FAILED_RESOLUTIONS] = mkf_u32(0, dns_failed_resolutions); |
Willy Tarreau | 7cf0e45 | 2019-05-23 11:39:14 +0200 | [diff] [blame] | 3680 | info[INF_TOTAL_BYTES_OUT] = mkf_u64(0, global.out_bytes); |
| 3681 | info[INF_BYTES_OUT_RATE] = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3682 | |
| 3683 | return 1; |
| 3684 | } |
| 3685 | |
| 3686 | /* This function dumps information onto the stream interface's read buffer. |
| 3687 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3688 | * No state is used. |
| 3689 | */ |
| 3690 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
| 3691 | { |
| 3692 | struct appctx *appctx = __objt_appctx(si->end); |
| 3693 | |
| 3694 | if (!stats_fill_info(info, INF_TOTAL_FIELDS)) |
| 3695 | return 0; |
| 3696 | |
| 3697 | chunk_reset(&trash); |
| 3698 | |
| 3699 | if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3700 | stats_dump_typed_info_fields(&trash, info); |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 3701 | else if (appctx->ctx.stats.flags & STAT_FMT_JSON) |
| 3702 | stats_dump_json_info_fields(&trash, info); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3703 | else |
| 3704 | stats_dump_info_fields(&trash, info); |
| 3705 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3706 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3707 | si_rx_room_blk(si); |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 3708 | return 0; |
| 3709 | } |
| 3710 | |
| 3711 | return 1; |
| 3712 | } |
| 3713 | |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3714 | /* This function dumps the schema onto the stream interface's read buffer. |
| 3715 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3716 | * No state is used. |
| 3717 | * |
| 3718 | * Integer values bouned to the range [-(2**53)+1, (2**53)-1] as |
| 3719 | * per the recommendation for interoperable integers in section 6 of RFC 7159. |
| 3720 | */ |
Willy Tarreau | 83061a8 | 2018-07-13 11:56:34 +0200 | [diff] [blame] | 3721 | static void stats_dump_json_schema(struct buffer *out) |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3722 | { |
| 3723 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 3724 | int old_len = out->data; |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3725 | |
| 3726 | chunk_strcat(out, |
| 3727 | "{" |
| 3728 | "\"$schema\":\"http://json-schema.org/draft-04/schema#\"," |
| 3729 | "\"oneOf\":[" |
| 3730 | "{" |
| 3731 | "\"title\":\"Info\"," |
| 3732 | "\"type\":\"array\"," |
| 3733 | "\"items\":{" |
| 3734 | "\"properties\":{" |
| 3735 | "\"title\":\"InfoItem\"," |
| 3736 | "\"type\":\"object\"," |
| 3737 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 3738 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 3739 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 3740 | "\"value\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 3741 | "}," |
| 3742 | "\"required\":[\"field\",\"processNum\",\"tags\"," |
| 3743 | "\"value\"]" |
| 3744 | "}" |
| 3745 | "}," |
| 3746 | "{" |
| 3747 | "\"title\":\"Stat\"," |
| 3748 | "\"type\":\"array\"," |
| 3749 | "\"items\":{" |
| 3750 | "\"title\":\"InfoItem\"," |
| 3751 | "\"type\":\"object\"," |
| 3752 | "\"properties\":{" |
| 3753 | "\"objType\":{" |
| 3754 | "\"enum\":[\"Frontend\",\"Backend\",\"Listener\"," |
| 3755 | "\"Server\",\"Unknown\"]" |
| 3756 | "}," |
| 3757 | "\"proxyId\":{" |
| 3758 | "\"type\":\"integer\"," |
| 3759 | "\"minimum\":0" |
| 3760 | "}," |
| 3761 | "\"id\":{" |
| 3762 | "\"type\":\"integer\"," |
| 3763 | "\"minimum\":0" |
| 3764 | "}," |
| 3765 | "\"field\":{\"$ref\":\"#/definitions/field\"}," |
| 3766 | "\"processNum\":{\"$ref\":\"#/definitions/processNum\"}," |
| 3767 | "\"tags\":{\"$ref\":\"#/definitions/tags\"}," |
| 3768 | "\"typedValue\":{\"$ref\":\"#/definitions/typedValue\"}" |
| 3769 | "}," |
| 3770 | "\"required\":[\"objType\",\"proxyId\",\"id\"," |
| 3771 | "\"field\",\"processNum\",\"tags\"," |
| 3772 | "\"value\"]" |
| 3773 | "}" |
| 3774 | "}," |
| 3775 | "{" |
| 3776 | "\"title\":\"Error\"," |
| 3777 | "\"type\":\"object\"," |
| 3778 | "\"properties\":{" |
| 3779 | "\"errorStr\":{" |
| 3780 | "\"type\":\"string\"" |
| 3781 | "}," |
| 3782 | "\"required\":[\"errorStr\"]" |
| 3783 | "}" |
| 3784 | "}" |
| 3785 | "]," |
| 3786 | "\"definitions\":{" |
| 3787 | "\"field\":{" |
| 3788 | "\"type\":\"object\"," |
| 3789 | "\"pos\":{" |
| 3790 | "\"type\":\"integer\"," |
| 3791 | "\"minimum\":0" |
| 3792 | "}," |
| 3793 | "\"name\":{" |
| 3794 | "\"type\":\"string\"" |
| 3795 | "}," |
| 3796 | "\"required\":[\"pos\",\"name\"]" |
| 3797 | "}," |
| 3798 | "\"processNum\":{" |
| 3799 | "\"type\":\"integer\"," |
| 3800 | "\"minimum\":1" |
| 3801 | "}," |
| 3802 | "\"tags\":{" |
| 3803 | "\"type\":\"object\"," |
| 3804 | "\"origin\":{" |
| 3805 | "\"type\":\"string\"," |
| 3806 | "\"enum\":[\"Metric\",\"Status\",\"Key\"," |
| 3807 | "\"Config\",\"Product\",\"Unknown\"]" |
| 3808 | "}," |
| 3809 | "\"nature\":{" |
| 3810 | "\"type\":\"string\"," |
| 3811 | "\"enum\":[\"Gauge\",\"Limit\",\"Min\",\"Max\"," |
| 3812 | "\"Rate\",\"Counter\",\"Duration\"," |
| 3813 | "\"Age\",\"Time\",\"Name\",\"Output\"," |
| 3814 | "\"Avg\", \"Unknown\"]" |
| 3815 | "}," |
| 3816 | "\"scope\":{" |
| 3817 | "\"type\":\"string\"," |
| 3818 | "\"enum\":[\"Cluster\",\"Process\",\"Service\"," |
| 3819 | "\"System\",\"Unknown\"]" |
| 3820 | "}," |
| 3821 | "\"required\":[\"origin\",\"nature\",\"scope\"]" |
| 3822 | "}," |
| 3823 | "\"typedValue\":{" |
| 3824 | "\"type\":\"object\"," |
| 3825 | "\"oneOf\":[" |
| 3826 | "{\"$ref\":\"#/definitions/typedValue/definitions/s32Value\"}," |
| 3827 | "{\"$ref\":\"#/definitions/typedValue/definitions/s64Value\"}," |
| 3828 | "{\"$ref\":\"#/definitions/typedValue/definitions/u32Value\"}," |
| 3829 | "{\"$ref\":\"#/definitions/typedValue/definitions/u64Value\"}," |
| 3830 | "{\"$ref\":\"#/definitions/typedValue/definitions/strValue\"}" |
| 3831 | "]," |
| 3832 | "\"definitions\":{" |
| 3833 | "\"s32Value\":{" |
| 3834 | "\"properties\":{" |
| 3835 | "\"type\":{" |
| 3836 | "\"type\":\"string\"," |
| 3837 | "\"enum\":[\"s32\"]" |
| 3838 | "}," |
| 3839 | "\"value\":{" |
| 3840 | "\"type\":\"integer\"," |
| 3841 | "\"minimum\":-2147483648," |
| 3842 | "\"maximum\":2147483647" |
| 3843 | "}" |
| 3844 | "}," |
| 3845 | "\"required\":[\"type\",\"value\"]" |
| 3846 | "}," |
| 3847 | "\"s64Value\":{" |
| 3848 | "\"properties\":{" |
| 3849 | "\"type\":{" |
| 3850 | "\"type\":\"string\"," |
| 3851 | "\"enum\":[\"s64\"]" |
| 3852 | "}," |
| 3853 | "\"value\":{" |
| 3854 | "\"type\":\"integer\"," |
| 3855 | "\"minimum\":-9007199254740991," |
| 3856 | "\"maximum\":9007199254740991" |
| 3857 | "}" |
| 3858 | "}," |
| 3859 | "\"required\":[\"type\",\"value\"]" |
| 3860 | "}," |
| 3861 | "\"u32Value\":{" |
| 3862 | "\"properties\":{" |
| 3863 | "\"type\":{" |
| 3864 | "\"type\":\"string\"," |
| 3865 | "\"enum\":[\"u32\"]" |
| 3866 | "}," |
| 3867 | "\"value\":{" |
| 3868 | "\"type\":\"integer\"," |
| 3869 | "\"minimum\":0," |
| 3870 | "\"maximum\":4294967295" |
| 3871 | "}" |
| 3872 | "}," |
| 3873 | "\"required\":[\"type\",\"value\"]" |
| 3874 | "}," |
| 3875 | "\"u64Value\":{" |
| 3876 | "\"properties\":{" |
| 3877 | "\"type\":{" |
| 3878 | "\"type\":\"string\"," |
| 3879 | "\"enum\":[\"u64\"]" |
| 3880 | "}," |
| 3881 | "\"value\":{" |
| 3882 | "\"type\":\"integer\"," |
| 3883 | "\"minimum\":0," |
| 3884 | "\"maximum\":9007199254740991" |
| 3885 | "}" |
| 3886 | "}," |
| 3887 | "\"required\":[\"type\",\"value\"]" |
| 3888 | "}," |
| 3889 | "\"strValue\":{" |
| 3890 | "\"properties\":{" |
| 3891 | "\"type\":{" |
| 3892 | "\"type\":\"string\"," |
| 3893 | "\"enum\":[\"str\"]" |
| 3894 | "}," |
| 3895 | "\"value\":{\"type\":\"string\"}" |
| 3896 | "}," |
| 3897 | "\"required\":[\"type\",\"value\"]" |
| 3898 | "}," |
| 3899 | "\"unknownValue\":{" |
| 3900 | "\"properties\":{" |
| 3901 | "\"type\":{" |
| 3902 | "\"type\":\"integer\"," |
| 3903 | "\"minimum\":0" |
| 3904 | "}," |
| 3905 | "\"value\":{" |
| 3906 | "\"type\":\"string\"," |
| 3907 | "\"enum\":[\"unknown\"]" |
| 3908 | "}" |
| 3909 | "}," |
| 3910 | "\"required\":[\"type\",\"value\"]" |
| 3911 | "}" |
| 3912 | "}" |
| 3913 | "}" |
| 3914 | "}" |
| 3915 | "}"); |
| 3916 | |
Willy Tarreau | 843b7cb | 2018-07-13 10:54:26 +0200 | [diff] [blame] | 3917 | if (old_len == out->data) { |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3918 | chunk_reset(out); |
| 3919 | chunk_appendf(out, |
| 3920 | "{\"errorStr\":\"output buffer too short\"}"); |
| 3921 | } |
| 3922 | } |
| 3923 | |
| 3924 | /* This function dumps the schema onto the stream interface's read buffer. |
| 3925 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3926 | * No state is used. |
| 3927 | */ |
| 3928 | static int stats_dump_json_schema_to_buffer(struct stream_interface *si) |
| 3929 | { |
| 3930 | chunk_reset(&trash); |
| 3931 | |
| 3932 | stats_dump_json_schema(&trash); |
| 3933 | |
Willy Tarreau | 06d80a9 | 2017-10-19 14:32:15 +0200 | [diff] [blame] | 3934 | if (ci_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | db39843 | 2018-11-15 11:08:52 +0100 | [diff] [blame] | 3935 | si_rx_room_blk(si); |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 3936 | return 0; |
| 3937 | } |
| 3938 | |
| 3939 | return 1; |
| 3940 | } |
| 3941 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 3942 | static int cli_parse_clear_counters(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 3943 | { |
| 3944 | struct proxy *px; |
| 3945 | struct server *sv; |
| 3946 | struct listener *li; |
| 3947 | int clrall = 0; |
| 3948 | |
| 3949 | if (strcmp(args[2], "all") == 0) |
| 3950 | clrall = 1; |
| 3951 | |
| 3952 | /* check permissions */ |
| 3953 | if (!cli_has_level(appctx, ACCESS_LVL_OPER) || |
| 3954 | (clrall && !cli_has_level(appctx, ACCESS_LVL_ADMIN))) |
| 3955 | return 1; |
| 3956 | |
Olivier Houchard | fbc74e8 | 2017-11-24 16:54:05 +0100 | [diff] [blame] | 3957 | for (px = proxies_list; px; px = px->next) { |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 3958 | if (clrall) { |
| 3959 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 3960 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 3961 | } |
| 3962 | else { |
| 3963 | px->be_counters.conn_max = 0; |
| 3964 | px->be_counters.p.http.rps_max = 0; |
| 3965 | px->be_counters.sps_max = 0; |
| 3966 | px->be_counters.cps_max = 0; |
| 3967 | px->be_counters.nbpend_max = 0; |
| 3968 | |
| 3969 | px->fe_counters.conn_max = 0; |
| 3970 | px->fe_counters.p.http.rps_max = 0; |
| 3971 | px->fe_counters.sps_max = 0; |
| 3972 | px->fe_counters.cps_max = 0; |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | for (sv = px->srv; sv; sv = sv->next) |
| 3976 | if (clrall) |
| 3977 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 3978 | else { |
| 3979 | sv->counters.cur_sess_max = 0; |
| 3980 | sv->counters.nbpend_max = 0; |
| 3981 | sv->counters.sps_max = 0; |
| 3982 | } |
| 3983 | |
| 3984 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
| 3985 | if (li->counters) { |
| 3986 | if (clrall) |
| 3987 | memset(li->counters, 0, sizeof(*li->counters)); |
| 3988 | else |
| 3989 | li->counters->conn_max = 0; |
| 3990 | } |
| 3991 | } |
| 3992 | |
| 3993 | global.cps_max = 0; |
| 3994 | global.sps_max = 0; |
Olivier Houchard | 00bc3cb | 2017-10-17 19:23:25 +0200 | [diff] [blame] | 3995 | global.ssl_max = 0; |
| 3996 | global.ssl_fe_keys_max = 0; |
| 3997 | global.ssl_be_keys_max = 0; |
Willy Tarreau | d80cb4e | 2018-01-20 19:30:13 +0100 | [diff] [blame] | 3998 | |
| 3999 | memset(activity, 0, sizeof(activity)); |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4000 | return 1; |
| 4001 | } |
| 4002 | |
| 4003 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 4004 | static int cli_parse_show_info(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4005 | { |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 4006 | appctx->ctx.stats.scope_str = 0; |
| 4007 | appctx->ctx.stats.scope_len = 0; |
| 4008 | appctx->ctx.stats.flags = 0; |
| 4009 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4010 | if (strcmp(args[2], "typed") == 0) |
| 4011 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 4012 | else if (strcmp(args[2], "json") == 0) |
| 4013 | appctx->ctx.stats.flags |= STAT_FMT_JSON; |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4014 | return 0; |
| 4015 | } |
| 4016 | |
| 4017 | |
Aurélien Nephtali | abbf607 | 2018-04-18 13:26:46 +0200 | [diff] [blame] | 4018 | static int cli_parse_show_stat(char **args, char *payload, struct appctx *appctx, void *private) |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4019 | { |
Willy Tarreau | d25fc79 | 2016-12-16 12:33:47 +0100 | [diff] [blame] | 4020 | appctx->ctx.stats.scope_str = 0; |
| 4021 | appctx->ctx.stats.scope_len = 0; |
| 4022 | appctx->ctx.stats.flags = 0; |
| 4023 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4024 | if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 4025 | struct proxy *px; |
| 4026 | |
| 4027 | px = proxy_find_by_name(args[2], 0, 0); |
| 4028 | if (px) |
| 4029 | appctx->ctx.stats.iid = px->uuid; |
| 4030 | else |
| 4031 | appctx->ctx.stats.iid = atoi(args[2]); |
| 4032 | |
| 4033 | if (!appctx->ctx.stats.iid) { |
Andjelko Iharos | c3680ec | 2017-07-20 16:49:14 +0200 | [diff] [blame] | 4034 | appctx->ctx.cli.severity = LOG_ERR; |
Willy Tarreau | a1b1ed5 | 2016-11-25 08:50:58 +0100 | [diff] [blame] | 4035 | appctx->ctx.cli.msg = "No such proxy.\n"; |
| 4036 | appctx->st0 = CLI_ST_PRINT; |
| 4037 | return 1; |
| 4038 | } |
| 4039 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4040 | appctx->ctx.stats.flags |= STAT_BOUND; |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4041 | appctx->ctx.stats.type = atoi(args[3]); |
| 4042 | appctx->ctx.stats.sid = atoi(args[4]); |
| 4043 | if (strcmp(args[5], "typed") == 0) |
| 4044 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 4045 | else if (strcmp(args[5], "json") == 0) |
| 4046 | appctx->ctx.stats.flags |= STAT_FMT_JSON; |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4047 | } |
| 4048 | else if (strcmp(args[2], "typed") == 0) |
| 4049 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Simon Horman | 05ee213 | 2017-01-04 09:37:25 +0100 | [diff] [blame] | 4050 | else if (strcmp(args[2], "json") == 0) |
| 4051 | appctx->ctx.stats.flags |= STAT_FMT_JSON; |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4052 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4053 | return 0; |
| 4054 | } |
| 4055 | |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4056 | static int cli_io_handler_dump_info(struct appctx *appctx) |
| 4057 | { |
| 4058 | return stats_dump_info_to_buffer(appctx->owner); |
| 4059 | } |
| 4060 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4061 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 4062 | * used to send raw stats over a socket. |
| 4063 | */ |
| 4064 | static int cli_io_handler_dump_stat(struct appctx *appctx) |
| 4065 | { |
Christopher Faulet | ef77922 | 2018-10-31 08:47:01 +0100 | [diff] [blame] | 4066 | return stats_dump_stat_to_buffer(appctx->owner, NULL, NULL); |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4067 | } |
| 4068 | |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4069 | static int cli_io_handler_dump_json_schema(struct appctx *appctx) |
| 4070 | { |
| 4071 | return stats_dump_json_schema_to_buffer(appctx->owner); |
| 4072 | } |
| 4073 | |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4074 | /* register cli keywords */ |
| 4075 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | 89d467c | 2016-11-23 11:02:40 +0100 | [diff] [blame] | 4076 | { { "clear", "counters", NULL }, "clear counters : clear max statistics counters (add 'all' for all counters)", cli_parse_clear_counters, NULL, NULL }, |
Willy Tarreau | 0baac8c | 2016-11-22 16:36:53 +0100 | [diff] [blame] | 4077 | { { "show", "info", NULL }, "show info : report information about the running process", cli_parse_show_info, cli_io_handler_dump_info, NULL }, |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4078 | { { "show", "stat", NULL }, "show stat : report counters for each proxy and server", cli_parse_show_stat, cli_io_handler_dump_stat, NULL }, |
Simon Horman | 6f6bb38 | 2017-01-04 09:37:26 +0100 | [diff] [blame] | 4079 | { { "show", "schema", "json", NULL }, "show schema json : report schema used for stats", NULL, cli_io_handler_dump_json_schema, NULL }, |
Willy Tarreau | 2b812e2 | 2016-11-22 16:18:05 +0100 | [diff] [blame] | 4080 | {{},} |
| 4081 | }}; |
| 4082 | |
Willy Tarreau | 0108d90 | 2018-11-25 19:14:37 +0100 | [diff] [blame] | 4083 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 4084 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4085 | struct applet http_stats_applet = { |
| 4086 | .obj_type = OBJ_TYPE_APPLET, |
| 4087 | .name = "<STATS>", /* used for logging */ |
| 4088 | .fct = http_stats_io_handler, |
| 4089 | .release = NULL, |
| 4090 | }; |
| 4091 | |
William Lallemand | 74c24fb | 2016-11-21 17:18:36 +0100 | [diff] [blame] | 4092 | /* |
| 4093 | * Local variables: |
| 4094 | * c-indent-level: 8 |
| 4095 | * c-basic-offset: 8 |
| 4096 | * End: |
| 4097 | */ |