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