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