Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 1 | /* |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 2 | * Functions dedicated to statistics output and the stats socket |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3 | * |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4 | * Copyright 2000-2012 Willy Tarreau <w@1wt.eu> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5 | * Copyright 2007-2009 Krzysztof Piotr Oledzki <ole@ans.pl> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 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> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 20 | #include <pwd.h> |
| 21 | #include <grp.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 22 | |
| 23 | #include <sys/socket.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/types.h> |
| 26 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 27 | #include <common/cfgparse.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 28 | #include <common/compat.h> |
| 29 | #include <common/config.h> |
| 30 | #include <common/debug.h> |
| 31 | #include <common/memory.h> |
| 32 | #include <common/mini-clist.h> |
| 33 | #include <common/standard.h> |
Willy Tarreau | 0c303ee | 2008-07-07 00:09:58 +0200 | [diff] [blame] | 34 | #include <common/ticks.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 35 | #include <common/time.h> |
| 36 | #include <common/uri_auth.h> |
| 37 | #include <common/version.h> |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 38 | #include <common/base64.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 39 | |
Willy Tarreau | 8a8d83b | 2015-04-13 13:24:54 +0200 | [diff] [blame] | 40 | #include <types/applet.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 41 | #include <types/global.h> |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 42 | #include <types/dns.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 43 | |
| 44 | #include <proto/backend.h> |
Willy Tarreau | c7e4238 | 2012-08-24 19:22:53 +0200 | [diff] [blame] | 45 | #include <proto/channel.h> |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 46 | #include <proto/checks.h> |
William Lallemand | e3a7d99 | 2012-11-20 11:25:20 +0100 | [diff] [blame] | 47 | #include <proto/compression.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 48 | #include <proto/dumpstats.h> |
| 49 | #include <proto/fd.h> |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 50 | #include <proto/freq_ctr.h> |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 51 | #include <proto/frontend.h> |
Willy Tarreau | eb47268 | 2010-05-28 18:46:57 +0200 | [diff] [blame] | 52 | #include <proto/log.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 53 | #include <proto/pattern.h> |
Willy Tarreau | a206fa9 | 2009-01-25 14:02:00 +0100 | [diff] [blame] | 54 | #include <proto/pipe.h> |
Willy Tarreau | d1d5454 | 2012-09-12 22:58:11 +0200 | [diff] [blame] | 55 | #include <proto/listener.h> |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 56 | #include <proto/map.h> |
Willy Tarreau | e6d9702 | 2012-11-23 11:19:33 +0100 | [diff] [blame] | 57 | #include <proto/proto_http.h> |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 58 | #include <proto/proto_uxst.h> |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 59 | #include <proto/proxy.h> |
Willy Tarreau | 1cf8f08 | 2014-02-07 12:14:54 +0100 | [diff] [blame] | 60 | #include <proto/sample.h> |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 61 | #include <proto/session.h> |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 62 | #include <proto/stream.h> |
Krzysztof Oledzki | 8513094 | 2007-10-22 16:21:10 +0200 | [diff] [blame] | 63 | #include <proto/server.h> |
Willy Tarreau | 75bf2c9 | 2012-08-20 17:01:35 +0200 | [diff] [blame] | 64 | #include <proto/raw_sock.h> |
Willy Tarreau | dded32d | 2008-11-30 19:48:07 +0100 | [diff] [blame] | 65 | #include <proto/stream_interface.h> |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 66 | #include <proto/task.h> |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 67 | |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 68 | #ifdef USE_OPENSSL |
| 69 | #include <proto/ssl_sock.h> |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 70 | #include <types/ssl_sock.h> |
Willy Tarreau | 7a0169a | 2012-11-19 17:13:16 +0100 | [diff] [blame] | 71 | #endif |
| 72 | |
Willy Tarreau | c4832de | 2016-01-11 18:12:26 +0100 | [diff] [blame] | 73 | /* These are the field names for each INF_* field position. Please pay attention |
| 74 | * to always use the exact same name except that the strings for new names must |
| 75 | * be lower case or CamelCase while the enum entries must be upper case. |
| 76 | */ |
| 77 | const char *info_field_names[INF_TOTAL_FIELDS] = { |
| 78 | [INF_NAME] = "Name", |
| 79 | [INF_VERSION] = "Version", |
| 80 | [INF_RELEASE_DATE] = "Release_date", |
| 81 | [INF_NBPROC] = "Nbproc", |
| 82 | [INF_PROCESS_NUM] = "Process_num", |
| 83 | [INF_PID] = "Pid", |
| 84 | [INF_UPTIME] = "Uptime", |
| 85 | [INF_UPTIME_SEC] = "Uptime_sec", |
| 86 | [INF_MEMMAX_MB] = "Memmax_MB", |
| 87 | [INF_POOL_ALLOC_MB] = "PoolAlloc_MB", |
| 88 | [INF_POOL_USED_MB] = "PoolUsed_MB", |
| 89 | [INF_POOL_FAILED] = "PoolFailed", |
| 90 | [INF_ULIMIT_N] = "Ulimit-n", |
| 91 | [INF_MAXSOCK] = "Maxsock", |
| 92 | [INF_MAXCONN] = "Maxconn", |
| 93 | [INF_HARD_MAXCONN] = "Hard_maxconn", |
| 94 | [INF_CURR_CONN] = "CurrConns", |
| 95 | [INF_CUM_CONN] = "CumConns", |
| 96 | [INF_CUM_REQ] = "CumReq", |
| 97 | [INF_MAX_SSL_CONNS] = "MaxSslConns", |
| 98 | [INF_CURR_SSL_CONNS] = "CurrSslConns", |
| 99 | [INF_CUM_SSL_CONNS] = "CumSslConns", |
| 100 | [INF_MAXPIPES] = "Maxpipes", |
| 101 | [INF_PIPES_USED] = "PipesUsed", |
| 102 | [INF_PIPES_FREE] = "PipesFree", |
| 103 | [INF_CONN_RATE] = "ConnRate", |
| 104 | [INF_CONN_RATE_LIMIT] = "ConnRateLimit", |
| 105 | [INF_MAX_CONN_RATE] = "MaxConnRate", |
| 106 | [INF_SESS_RATE] = "SessRate", |
| 107 | [INF_SESS_RATE_LIMIT] = "SessRateLimit", |
| 108 | [INF_MAX_SESS_RATE] = "MaxSessRate", |
| 109 | [INF_SSL_RATE] = "SslRate", |
| 110 | [INF_SSL_RATE_LIMIT] = "SslRateLimit", |
| 111 | [INF_MAX_SSL_RATE] = "MaxSslRate", |
| 112 | [INF_SSL_FRONTEND_KEY_RATE] = "SslFrontendKeyRate", |
| 113 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = "SslFrontendMaxKeyRate", |
| 114 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = "SslFrontendSessionReuse_pct", |
| 115 | [INF_SSL_BACKEND_KEY_RATE] = "SslBackendKeyRate", |
| 116 | [INF_SSL_BACKEND_MAX_KEY_RATE] = "SslBackendMaxKeyRate", |
| 117 | [INF_SSL_CACHE_LOOKUPS] = "SslCacheLookups", |
| 118 | [INF_SSL_CACHE_MISSES] = "SslCacheMisses", |
| 119 | [INF_COMPRESS_BPS_IN] = "CompressBpsIn", |
| 120 | [INF_COMPRESS_BPS_OUT] = "CompressBpsOut", |
| 121 | [INF_COMPRESS_BPS_RATE_LIM] = "CompressBpsRateLim", |
| 122 | [INF_ZLIB_MEM_USAGE] = "ZlibMemUsage", |
| 123 | [INF_MAX_ZLIB_MEM_USAGE] = "MaxZlibMemUsage", |
| 124 | [INF_TASKS] = "Tasks", |
| 125 | [INF_RUN_QUEUE] = "Run_queue", |
| 126 | [INF_IDLE_PCT] = "Idle_pct", |
| 127 | [INF_NODE] = "node", |
| 128 | [INF_DESCRIPTION] = "description", |
| 129 | }; |
| 130 | |
| 131 | /* one line of stats */ |
| 132 | static struct field info[INF_TOTAL_FIELDS]; |
| 133 | |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 134 | /* These are the field names for each ST_F_* field position. Please pay attention |
| 135 | * to always use the exact same name except that the strings must be lower case |
| 136 | * while the enum entries must be upper case. |
| 137 | */ |
| 138 | const char *stat_field_names[ST_F_TOTAL_FIELDS] = { |
| 139 | [ST_F_PXNAME] = "pxname", |
| 140 | [ST_F_SVNAME] = "svname", |
| 141 | [ST_F_QCUR] = "qcur", |
| 142 | [ST_F_QMAX] = "qmax", |
| 143 | [ST_F_SCUR] = "scur", |
| 144 | [ST_F_SMAX] = "smax", |
| 145 | [ST_F_SLIM] = "slim", |
| 146 | [ST_F_STOT] = "stot", |
| 147 | [ST_F_BIN] = "bin", |
| 148 | [ST_F_BOUT] = "bout", |
| 149 | [ST_F_DREQ] = "dreq", |
| 150 | [ST_F_DRESP] = "dresp", |
| 151 | [ST_F_EREQ] = "ereq", |
| 152 | [ST_F_ECON] = "econ", |
| 153 | [ST_F_ERESP] = "eresp", |
| 154 | [ST_F_WRETR] = "wretr", |
| 155 | [ST_F_WREDIS] = "wredis", |
| 156 | [ST_F_STATUS] = "status", |
| 157 | [ST_F_WEIGHT] = "weight", |
| 158 | [ST_F_ACT] = "act", |
| 159 | [ST_F_BCK] = "bck", |
| 160 | [ST_F_CHKFAIL] = "chkfail", |
| 161 | [ST_F_CHKDOWN] = "chkdown", |
| 162 | [ST_F_LASTCHG] = "lastchg", |
| 163 | [ST_F_DOWNTIME] = "downtime", |
| 164 | [ST_F_QLIMIT] = "qlimit", |
| 165 | [ST_F_PID] = "pid", |
| 166 | [ST_F_IID] = "iid", |
| 167 | [ST_F_SID] = "sid", |
| 168 | [ST_F_THROTTLE] = "throttle", |
| 169 | [ST_F_LBTOT] = "lbtot", |
| 170 | [ST_F_TRACKED] = "tracked", |
| 171 | [ST_F_TYPE] = "type", |
| 172 | [ST_F_RATE] = "rate", |
| 173 | [ST_F_RATE_LIM] = "rate_lim", |
| 174 | [ST_F_RATE_MAX] = "rate_max", |
| 175 | [ST_F_CHECK_STATUS] = "check_status", |
| 176 | [ST_F_CHECK_CODE] = "check_code", |
| 177 | [ST_F_CHECK_DURATION] = "check_duration", |
| 178 | [ST_F_HRSP_1XX] = "hrsp_1xx", |
| 179 | [ST_F_HRSP_2XX] = "hrsp_2xx", |
| 180 | [ST_F_HRSP_3XX] = "hrsp_3xx", |
| 181 | [ST_F_HRSP_4XX] = "hrsp_4xx", |
| 182 | [ST_F_HRSP_5XX] = "hrsp_5xx", |
| 183 | [ST_F_HRSP_OTHER] = "hrsp_other", |
| 184 | [ST_F_HANAFAIL] = "hanafail", |
| 185 | [ST_F_REQ_RATE] = "req_rate", |
| 186 | [ST_F_REQ_RATE_MAX] = "req_rate_max", |
| 187 | [ST_F_REQ_TOT] = "req_tot", |
| 188 | [ST_F_CLI_ABRT] = "cli_abrt", |
| 189 | [ST_F_SRV_ABRT] = "srv_abrt", |
| 190 | [ST_F_COMP_IN] = "comp_in", |
| 191 | [ST_F_COMP_OUT] = "comp_out", |
| 192 | [ST_F_COMP_BYP] = "comp_byp", |
| 193 | [ST_F_COMP_RSP] = "comp_rsp", |
| 194 | [ST_F_LASTSESS] = "lastsess", |
| 195 | [ST_F_LAST_CHK] = "last_chk", |
| 196 | [ST_F_LAST_AGT] = "last_agt", |
| 197 | [ST_F_QTIME] = "qtime", |
| 198 | [ST_F_CTIME] = "ctime", |
| 199 | [ST_F_RTIME] = "rtime", |
| 200 | [ST_F_TTIME] = "ttime", |
Willy Tarreau | 7f61884 | 2016-01-08 11:40:03 +0100 | [diff] [blame] | 201 | [ST_F_AGENT_STATUS] = "agent_status", |
| 202 | [ST_F_AGENT_CODE] = "agent_code", |
| 203 | [ST_F_AGENT_DURATION] = "agent_duration", |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 204 | [ST_F_CHECK_DESC] = "check_desc", |
| 205 | [ST_F_AGENT_DESC] = "agent_desc", |
Willy Tarreau | 3141f59 | 2016-01-08 14:25:28 +0100 | [diff] [blame] | 206 | [ST_F_CHECK_RISE] = "check_rise", |
| 207 | [ST_F_CHECK_FALL] = "check_fall", |
| 208 | [ST_F_CHECK_HEALTH] = "check_health", |
| 209 | [ST_F_AGENT_RISE] = "agent_rise", |
| 210 | [ST_F_AGENT_FALL] = "agent_fall", |
| 211 | [ST_F_AGENT_HEALTH] = "agent_health", |
Willy Tarreau | 3a4ec3a | 2016-01-08 15:35:43 +0100 | [diff] [blame] | 212 | [ST_F_ADDR] = "addr", |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 213 | [ST_F_COOKIE] = "cookie", |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 214 | [ST_F_MODE] = "mode", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 215 | [ST_F_ALGO] = "algo", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 216 | [ST_F_CONN_RATE] = "conn_rate", |
| 217 | [ST_F_CONN_RATE_MAX] = "conn_rate_max", |
| 218 | [ST_F_CONN_TOT] = "conn_tot", |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 219 | [ST_F_INTERCEPTED] = "intercepted", |
Willy Tarreau | 8a90b8e | 2016-10-21 18:15:32 +0200 | [diff] [blame] | 220 | [ST_F_DCON] = "dcon", |
Willy Tarreau | a5bc36b | 2016-10-21 18:16:27 +0200 | [diff] [blame] | 221 | [ST_F_DSES] = "dses", |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 222 | }; |
| 223 | |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 224 | /* one line of stats */ |
| 225 | static struct field stats[ST_F_TOTAL_FIELDS]; |
| 226 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 227 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 228 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 229 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 230 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 231 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 232 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 233 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 234 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 235 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 236 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 237 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri); |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 238 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 239 | static int stats_pats_list(struct stream_interface *si); |
| 240 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 241 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 242 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 243 | static int stats_tlskeys_list(struct stream_interface *si); |
| 244 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 245 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 246 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 247 | static int dump_servers_state(struct stream_interface *si, struct chunk *buf); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 248 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 249 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 250 | * cli_io_handler() |
| 251 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 252 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 253 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 254 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 255 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 256 | * -> stats_dump_stat_to_buffer() // "show stat" |
Cyril Bonté | a8322f9 | 2016-05-06 12:18:51 +0200 | [diff] [blame] | 257 | * -> stats_dump_resolvers_to_buffer() // "show stat resolvers <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 258 | * -> stats_dump_csv_header() |
| 259 | * -> stats_dump_proxy_to_buffer() |
| 260 | * -> stats_dump_fe_stats() |
| 261 | * -> stats_dump_li_stats() |
| 262 | * -> stats_dump_sv_stats() |
| 263 | * -> stats_dump_be_stats() |
| 264 | * |
| 265 | * http_stats_io_handler() |
| 266 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 267 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 268 | * -> stats_dump_html_head() // emits the HTML headers |
| 269 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 270 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 271 | * -> stats_dump_html_px_hdr() |
| 272 | * -> stats_dump_fe_stats() |
| 273 | * -> stats_dump_li_stats() |
| 274 | * -> stats_dump_sv_stats() |
| 275 | * -> stats_dump_be_stats() |
| 276 | * -> stats_dump_html_px_end() |
| 277 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 278 | */ |
| 279 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 280 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 281 | |
| 282 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 283 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 284 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 285 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 286 | " help : this message\n" |
| 287 | " prompt : toggle interactive mode with prompt\n" |
| 288 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 289 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 290 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 291 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 292 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 293 | " show stat : report counters for each proxy and server\n" |
Cyril Bonté | a8322f9 | 2016-05-06 12:18:51 +0200 | [diff] [blame] | 294 | " show stat resolvers [id]: dumps counters from all resolvers section and\n" |
| 295 | " associated name servers\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 296 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 297 | " show sess [id] : report the list of current sessions or dump this session\n" |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 298 | " show table [id]: report table usage stats or dump this table's contents\n" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 299 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 300 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 301 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 302 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 303 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 304 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 305 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 306 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 307 | " disable : put a server or frontend in maintenance mode\n" |
| 308 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 309 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 310 | " show acl [id] : report available acls or dump an acl's contents\n" |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 311 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 312 | " add acl : add acl entry\n" |
| 313 | " del acl : delete acl entry\n" |
| 314 | " clear acl <id> : clear the content of this acl\n" |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 315 | " show map [id] : report available maps or dump a map's contents\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 316 | " get map : reports the keys and values matching a sample for a map\n" |
| 317 | " set map : modify map entry\n" |
| 318 | " add map : add map entry\n" |
| 319 | " del map : delete map entry\n" |
| 320 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 321 | " set ssl <stmt> : set statement for ssl\n" |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 322 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 323 | " show tls-keys [id|*]: show tls keys references or dump tls ticket keys when id specified\n" |
| 324 | #endif |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 325 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 326 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 327 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 328 | "Permission denied\n" |
| 329 | ""; |
| 330 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 331 | |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 332 | static char *dynamic_usage_msg = NULL; |
| 333 | |
| 334 | /* List head of cli keywords */ |
| 335 | struct cli_kw_list cli_keywords = { |
| 336 | .list = LIST_HEAD_INIT(cli_keywords.list) |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 337 | }; |
| 338 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 339 | extern const char *stat_status_codes[]; |
| 340 | |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 341 | char *cli_gen_usage_msg() |
| 342 | { |
| 343 | struct cli_kw_list *kw_list; |
| 344 | struct cli_kw *kw; |
| 345 | struct chunk *tmp = get_trash_chunk(); |
| 346 | struct chunk out; |
| 347 | |
| 348 | free(dynamic_usage_msg); |
| 349 | dynamic_usage_msg = NULL; |
| 350 | |
| 351 | if (LIST_ISEMPTY(&cli_keywords.list)) |
| 352 | return NULL; |
| 353 | |
| 354 | chunk_reset(tmp); |
| 355 | chunk_strcat(tmp, stats_sock_usage_msg); |
| 356 | list_for_each_entry(kw_list, &cli_keywords.list, list) { |
| 357 | kw = &kw_list->kw[0]; |
| 358 | while (kw->usage) { |
| 359 | chunk_appendf(tmp, " %s\n", kw->usage); |
| 360 | kw++; |
| 361 | } |
| 362 | } |
| 363 | chunk_init(&out, NULL, 0); |
| 364 | chunk_dup(&out, tmp); |
| 365 | dynamic_usage_msg = out.str; |
| 366 | return dynamic_usage_msg; |
| 367 | } |
| 368 | |
| 369 | struct cli_kw* cli_find_kw(char **args) |
| 370 | { |
| 371 | struct cli_kw_list *kw_list; |
| 372 | struct cli_kw *kw;/* current cli_kw */ |
| 373 | char **tmp_args; |
| 374 | const char **tmp_str_kw; |
| 375 | int found = 0; |
| 376 | |
| 377 | if (LIST_ISEMPTY(&cli_keywords.list)) |
| 378 | return NULL; |
| 379 | |
| 380 | list_for_each_entry(kw_list, &cli_keywords.list, list) { |
| 381 | kw = &kw_list->kw[0]; |
| 382 | while (*kw->str_kw) { |
| 383 | tmp_args = args; |
| 384 | tmp_str_kw = kw->str_kw; |
| 385 | while (*tmp_str_kw) { |
| 386 | if (strcmp(*tmp_str_kw, *tmp_args) == 0) { |
| 387 | found = 1; |
| 388 | } else { |
| 389 | found = 0; |
| 390 | break; |
| 391 | } |
| 392 | tmp_args++; |
| 393 | tmp_str_kw++; |
| 394 | } |
| 395 | if (found) |
| 396 | return (kw); |
| 397 | kw++; |
| 398 | } |
| 399 | } |
| 400 | return NULL; |
| 401 | } |
| 402 | |
| 403 | void cli_register_kw(struct cli_kw_list *kw_list) |
| 404 | { |
| 405 | LIST_ADDQ(&cli_keywords.list, &kw_list->list); |
| 406 | } |
| 407 | |
| 408 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 409 | /* allocate a new stats frontend named <name>, and return it |
| 410 | * (or NULL in case of lack of memory). |
| 411 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 412 | static struct proxy *alloc_stats_fe(const char *name, const char *file, int line) |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 413 | { |
| 414 | struct proxy *fe; |
| 415 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 416 | fe = calloc(1, sizeof(*fe)); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 417 | if (!fe) |
| 418 | return NULL; |
| 419 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 420 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 421 | fe->next = proxy; |
| 422 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 423 | fe->last_change = now.tv_sec; |
| 424 | fe->id = strdup("GLOBAL"); |
| 425 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 426 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 427 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 428 | fe->conf.file = strdup(file); |
| 429 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 430 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 431 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 432 | |
| 433 | /* the stats frontend is the only one able to assign ID #0 */ |
| 434 | fe->conf.id.key = fe->uuid = 0; |
| 435 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 436 | return fe; |
| 437 | } |
| 438 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 439 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 440 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 441 | * error message into the <err> buffer which will be preallocated. The trailing |
| 442 | * '\n' must not be written. The function must be called with <args> pointing to |
| 443 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 444 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 445 | static int stats_parse_global(char **args, int section_type, struct proxy *curpx, |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 446 | struct proxy *defpx, const char *file, int line, |
| 447 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 448 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 449 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 450 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 451 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 452 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 453 | int cur_arg; |
| 454 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 455 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 456 | memprintf(err, "'%s %s' in global section expects an address or a path to a UNIX socket", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 457 | return -1; |
| 458 | } |
| 459 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 460 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 461 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 462 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 463 | return -1; |
| 464 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 467 | bind_conf = bind_conf_alloc(&global.stats_fe->conf.bind, file, line, args[2]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 468 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 469 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 470 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 471 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 472 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 473 | return -1; |
| 474 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 475 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 476 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 477 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 478 | static int bind_dumped; |
| 479 | struct bind_kw *kw; |
| 480 | |
| 481 | kw = bind_find_kw(args[cur_arg]); |
| 482 | if (kw) { |
| 483 | if (!kw->parse) { |
| 484 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 485 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 486 | return -1; |
| 487 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 488 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 489 | if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, err) != 0) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 490 | if (err && *err) |
| 491 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 492 | else |
| 493 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 494 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 495 | return -1; |
| 496 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 497 | |
| 498 | cur_arg += 1 + kw->skip; |
| 499 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 500 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 501 | |
| 502 | if (!bind_dumped) { |
| 503 | bind_dump_kws(err); |
| 504 | indent_msg(err, 4); |
| 505 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 506 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 507 | |
| 508 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 509 | args[0], args[1], args[cur_arg], |
| 510 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 511 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 512 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 513 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 514 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 515 | l->maxconn = global.stats_fe->maxconn; |
| 516 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 517 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 518 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 519 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 520 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 521 | l->nice = -64; /* we want to boost priority for local stats */ |
| 522 | global.maxsock += l->maxconn; |
| 523 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 524 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 525 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 526 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 527 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 528 | |
| 529 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 530 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 531 | return -1; |
| 532 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 533 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 534 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 535 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 536 | return -1; |
| 537 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 538 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 539 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 540 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 541 | return -1; |
| 542 | } |
| 543 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 544 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 545 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 546 | else if (!strcmp(args[1], "maxconn")) { |
| 547 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 548 | |
| 549 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 550 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 551 | return -1; |
| 552 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 553 | |
| 554 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 555 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 556 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 557 | return -1; |
| 558 | } |
| 559 | } |
| 560 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 561 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 562 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 563 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 564 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 565 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 566 | if (!global.stats_fe) { |
| 567 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 568 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 569 | return -1; |
| 570 | } |
| 571 | } |
| 572 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 573 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 574 | unsigned int low, high; |
| 575 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 576 | if (strcmp(args[cur_arg], "all") == 0) { |
| 577 | set = 0; |
| 578 | break; |
| 579 | } |
| 580 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 581 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 582 | } |
| 583 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 584 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 585 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 586 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 587 | char *dash = strchr(args[cur_arg], '-'); |
| 588 | |
| 589 | low = high = str2uic(args[cur_arg]); |
| 590 | if (dash) |
| 591 | high = str2uic(dash + 1); |
| 592 | |
| 593 | if (high < low) { |
| 594 | unsigned int swap = low; |
| 595 | low = high; |
| 596 | high = swap; |
| 597 | } |
| 598 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 599 | if (low < 1 || high > LONGBITS) { |
| 600 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 601 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 602 | return -1; |
| 603 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 604 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 605 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 606 | } |
| 607 | else { |
| 608 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 609 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 610 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 611 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 612 | } |
| 613 | cur_arg++; |
| 614 | } |
| 615 | global.stats_fe->bind_proc = set; |
| 616 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 617 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 618 | memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 619 | return -1; |
| 620 | } |
| 621 | return 0; |
| 622 | } |
| 623 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 624 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 625 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 626 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 627 | * so please only append new fields at the end, never in the middle. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 628 | */ |
| 629 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 630 | { |
Willy Tarreau | f614229 | 2016-01-04 17:24:29 +0100 | [diff] [blame] | 631 | int field; |
| 632 | |
| 633 | chunk_appendf(&trash, "# "); |
| 634 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) |
| 635 | chunk_appendf(&trash, "%s,", stat_field_names[field]); |
| 636 | |
| 637 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 638 | } |
| 639 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 640 | /* print a string of text buffer to <out>. The format is : |
| 641 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
Chad Lavoie | 1666930 | 2016-10-04 16:10:40 -0400 | [diff] [blame] | 642 | * Other non-printable chars are encoded "\xHH". Space, '\', and '=' are also escaped. |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 643 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 644 | */ |
| 645 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 646 | { |
| 647 | unsigned char c; |
| 648 | int ptr = 0; |
| 649 | |
| 650 | while (buf[ptr] && ptr < bsize) { |
| 651 | c = buf[ptr]; |
Chad Lavoie | 1666930 | 2016-10-04 16:10:40 -0400 | [diff] [blame] | 652 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ' && c != '=') { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 653 | if (out->len > out->size - 1) |
| 654 | break; |
| 655 | out->str[out->len++] = c; |
| 656 | } |
Chad Lavoie | 1666930 | 2016-10-04 16:10:40 -0400 | [diff] [blame] | 657 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ' || c == '=') { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 658 | if (out->len > out->size - 2) |
| 659 | break; |
| 660 | out->str[out->len++] = '\\'; |
| 661 | switch (c) { |
| 662 | case ' ': c = ' '; break; |
| 663 | case '\t': c = 't'; break; |
| 664 | case '\n': c = 'n'; break; |
| 665 | case '\r': c = 'r'; break; |
| 666 | case '\e': c = 'e'; break; |
| 667 | case '\\': c = '\\'; break; |
Chad Lavoie | 1666930 | 2016-10-04 16:10:40 -0400 | [diff] [blame] | 668 | case '=': c = '='; break; |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 669 | } |
| 670 | out->str[out->len++] = c; |
| 671 | } |
| 672 | else { |
| 673 | if (out->len > out->size - 4) |
| 674 | break; |
| 675 | out->str[out->len++] = '\\'; |
| 676 | out->str[out->len++] = 'x'; |
| 677 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 678 | out->str[out->len++] = hextab[c & 0xF]; |
| 679 | } |
| 680 | ptr++; |
| 681 | } |
| 682 | |
| 683 | return ptr; |
| 684 | } |
| 685 | |
| 686 | /* print a buffer in hexa. |
| 687 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 688 | */ |
| 689 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 690 | { |
| 691 | unsigned char c; |
| 692 | int ptr = 0; |
| 693 | |
| 694 | while (ptr < bsize) { |
| 695 | c = buf[ptr]; |
| 696 | |
| 697 | if (out->len > out->size - 2) |
| 698 | break; |
| 699 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 700 | out->str[out->len++] = hextab[c & 0xF]; |
| 701 | |
| 702 | ptr++; |
| 703 | } |
| 704 | return ptr; |
| 705 | } |
| 706 | |
| 707 | /* Dump the status of a table to a stream interface's |
| 708 | * read buffer. It returns 0 if the output buffer is full |
| 709 | * and needs to be called again, otherwise non-zero. |
| 710 | */ |
| 711 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 712 | struct proxy *proxy, struct proxy *target) |
| 713 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 714 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 715 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 716 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 717 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 718 | |
| 719 | /* any other information should be dumped here */ |
| 720 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 721 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 722 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 723 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 724 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 725 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 726 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 727 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 728 | |
| 729 | return 1; |
| 730 | } |
| 731 | |
| 732 | /* Dump the a table entry to a stream interface's |
| 733 | * read buffer. It returns 0 if the output buffer is full |
| 734 | * and needs to be called again, otherwise non-zero. |
| 735 | */ |
| 736 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 737 | struct proxy *proxy, struct stksess *entry) |
| 738 | { |
| 739 | int dt; |
| 740 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 741 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 742 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 743 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 744 | char addr[INET_ADDRSTRLEN]; |
| 745 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 746 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 747 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 748 | else if (proxy->table.type == SMP_T_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 749 | char addr[INET6_ADDRSTRLEN]; |
| 750 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 751 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 752 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 753 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 754 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 755 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 756 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 757 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 758 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 759 | } |
| 760 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 761 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 762 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 763 | } |
| 764 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 765 | chunk_appendf(msg, " use=%d exp=%d", entry->ref_cnt - 1, tick_remain(now_ms, entry->expire)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 766 | |
| 767 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 768 | void *ptr; |
| 769 | |
| 770 | if (proxy->table.data_ofs[dt] == 0) |
| 771 | continue; |
| 772 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 773 | chunk_appendf(msg, " %s(%d)=", stktable_data_types[dt].name, proxy->table.data_arg[dt].u); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 774 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 775 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 776 | |
| 777 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 778 | switch (stktable_data_types[dt].std_type) { |
| 779 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 780 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 781 | break; |
| 782 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 783 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 784 | break; |
| 785 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 786 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 787 | break; |
| 788 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 789 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 790 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 791 | proxy->table.data_arg[dt].u)); |
| 792 | break; |
| 793 | } |
| 794 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 795 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 796 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 797 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 798 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 799 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 800 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 801 | |
| 802 | return 1; |
| 803 | } |
| 804 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 805 | static void stats_sock_table_key_request(struct stream_interface *si, char **args, int action) |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 806 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 807 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 808 | struct appctx *appctx = __objt_appctx(si->end); |
| 809 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 810 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 811 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 812 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 813 | long long value; |
| 814 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 815 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 816 | void *ptr; |
| 817 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 818 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 819 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 820 | |
| 821 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 822 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 823 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 824 | return; |
| 825 | } |
| 826 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 827 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 828 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 829 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 830 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 831 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 832 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 833 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 834 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 835 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 836 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 837 | { |
| 838 | char *endptr; |
| 839 | unsigned long val; |
| 840 | errno = 0; |
| 841 | val = strtoul(args[4], &endptr, 10); |
| 842 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 843 | (errno != 0 && val == 0) || endptr == args[4] || |
| 844 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 845 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 846 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 847 | return; |
| 848 | } |
| 849 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 850 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 851 | break; |
| 852 | } |
| 853 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 854 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 855 | static_table_key->key = args[4]; |
| 856 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 857 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 858 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 859 | switch (action) { |
| 860 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 861 | appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 862 | break; |
| 863 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 864 | appctx->ctx.cli.msg = "Removing keys from ip tables of type other than ip, ipv6, string and integer is not supported\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 865 | break; |
| 866 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 867 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 868 | break; |
| 869 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 870 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 871 | return; |
| 872 | } |
| 873 | |
| 874 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 875 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 876 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 877 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 878 | return; |
| 879 | } |
| 880 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 881 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 882 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 883 | switch (action) { |
| 884 | case STAT_CLI_O_TAB: |
| 885 | if (!ts) |
| 886 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 887 | chunk_reset(&trash); |
| 888 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 889 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 890 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 891 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 892 | |
| 893 | case STAT_CLI_O_CLR: |
| 894 | if (!ts) |
| 895 | return; |
| 896 | if (ts->ref_cnt) { |
| 897 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 898 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 899 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 900 | return; |
| 901 | } |
| 902 | stksess_kill(&px->table, ts); |
| 903 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 904 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 905 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 906 | if (ts) |
| 907 | stktable_touch(&px->table, ts, 1); |
| 908 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 909 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 910 | if (!ts) { |
| 911 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 912 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 913 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 914 | return; |
| 915 | } |
| 916 | stktable_store(&px->table, ts, 1); |
| 917 | } |
| 918 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 919 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 920 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 921 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 922 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 923 | return; |
| 924 | } |
| 925 | |
| 926 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 927 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 928 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 929 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 930 | return; |
| 931 | } |
| 932 | |
| 933 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 934 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 935 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 936 | return; |
| 937 | } |
| 938 | |
| 939 | if (!*args[cur_arg+1] || strl2llrc(args[cur_arg+1], strlen(args[cur_arg+1]), &value) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 940 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 941 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 942 | return; |
| 943 | } |
| 944 | |
| 945 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 946 | |
| 947 | switch (stktable_data_types[data_type].std_type) { |
| 948 | case STD_T_SINT: |
| 949 | stktable_data_cast(ptr, std_t_sint) = value; |
| 950 | break; |
| 951 | case STD_T_UINT: |
| 952 | stktable_data_cast(ptr, std_t_uint) = value; |
| 953 | break; |
| 954 | case STD_T_ULL: |
| 955 | stktable_data_cast(ptr, std_t_ull) = value; |
| 956 | break; |
| 957 | case STD_T_FRQP: |
| 958 | /* We set both the current and previous values. That way |
| 959 | * the reported frequency is stable during all the period |
| 960 | * then slowly fades out. This allows external tools to |
| 961 | * push measures without having to update them too often. |
| 962 | */ |
| 963 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 964 | frqp->curr_tick = now_ms; |
| 965 | frqp->prev_ctr = 0; |
| 966 | frqp->curr_ctr = value; |
| 967 | break; |
| 968 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 969 | } |
| 970 | break; |
| 971 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 972 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 973 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 974 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 975 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 976 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 977 | } |
| 978 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 979 | static void stats_sock_table_data_request(struct stream_interface *si, char **args, int action) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 980 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 981 | struct appctx *appctx = __objt_appctx(si->end); |
| 982 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 983 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 984 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 985 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 986 | return; |
| 987 | } |
| 988 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 989 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 990 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 991 | if (appctx->ctx.table.data_type < 0) { |
| 992 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 993 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 997 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 998 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 999 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1000 | return; |
| 1001 | } |
| 1002 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1003 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 1004 | if (appctx->ctx.table.data_op < 0) { |
| 1005 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 1006 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1007 | return; |
| 1008 | } |
| 1009 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1010 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 1011 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 1012 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1013 | return; |
| 1014 | } |
| 1015 | } |
| 1016 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1017 | static void stats_sock_table_request(struct stream_interface *si, char **args, int action) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1018 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1019 | struct appctx *appctx = __objt_appctx(si->end); |
| 1020 | |
| 1021 | appctx->ctx.table.data_type = -1; |
| 1022 | appctx->st2 = STAT_ST_INIT; |
| 1023 | appctx->ctx.table.target = NULL; |
| 1024 | appctx->ctx.table.proxy = NULL; |
| 1025 | appctx->ctx.table.entry = NULL; |
| 1026 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1027 | |
| 1028 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 1029 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1030 | if (!appctx->ctx.table.target) { |
| 1031 | appctx->ctx.cli.msg = "No such table\n"; |
| 1032 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1033 | return; |
| 1034 | } |
| 1035 | } |
| 1036 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1037 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1038 | goto err_args; |
| 1039 | return; |
| 1040 | } |
| 1041 | |
| 1042 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1043 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1044 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1045 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1046 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1047 | goto err_args; |
| 1048 | |
| 1049 | return; |
| 1050 | |
| 1051 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1052 | switch (action) { |
| 1053 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1054 | appctx->ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1055 | break; |
| 1056 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1057 | appctx->ctx.cli.msg = "Required arguments: <table> \"data.<store_data_type>\" <operator> <value> or <table> key <key>\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1058 | break; |
| 1059 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1060 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1061 | break; |
| 1062 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1063 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1064 | } |
| 1065 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1066 | /* Expects to find a frontend named <arg> and returns it, otherwise displays various |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1067 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1068 | * level to be admin. |
| 1069 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1070 | static struct proxy *expect_frontend_admin(struct stream *s, struct stream_interface *si, const char *arg) |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1071 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1072 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1073 | struct proxy *px; |
| 1074 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1075 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1076 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1077 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1078 | return NULL; |
| 1079 | } |
| 1080 | |
| 1081 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1082 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 1083 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1084 | return NULL; |
| 1085 | } |
| 1086 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 1087 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1088 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1089 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 1090 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1091 | return NULL; |
| 1092 | } |
| 1093 | return px; |
| 1094 | } |
| 1095 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1096 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 1097 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1098 | * and returns NULL. This function also expects the stream level to be admin. Note: |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1099 | * the <arg> is modified to remove the '/'. |
| 1100 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1101 | static struct server *expect_server_admin(struct stream *s, struct stream_interface *si, char *arg) |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1102 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1103 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1104 | struct proxy *px; |
| 1105 | struct server *sv; |
| 1106 | char *line; |
| 1107 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1108 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1109 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1110 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1111 | return NULL; |
| 1112 | } |
| 1113 | |
| 1114 | /* split "backend/server" and make <line> point to server */ |
| 1115 | for (line = arg; *line; line++) |
| 1116 | if (*line == '/') { |
| 1117 | *line++ = '\0'; |
| 1118 | break; |
| 1119 | } |
| 1120 | |
| 1121 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1122 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1123 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1124 | return NULL; |
| 1125 | } |
| 1126 | |
| 1127 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1128 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1129 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1130 | return NULL; |
| 1131 | } |
| 1132 | |
| 1133 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1134 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 1135 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1136 | return NULL; |
| 1137 | } |
| 1138 | |
| 1139 | return sv; |
| 1140 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1141 | |
| 1142 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1143 | * each reference. The variable <getnext> must contain the current node, |
| 1144 | * <end> point to the root node. |
| 1145 | */ |
| 1146 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1147 | static inline |
| 1148 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1149 | { |
| 1150 | struct tls_keys_ref *ref = getnext; |
| 1151 | |
| 1152 | while (1) { |
| 1153 | |
| 1154 | /* Get next list entry. */ |
| 1155 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1156 | |
| 1157 | /* If the entry is the last of the list, return NULL. */ |
| 1158 | if (&ref->list == end) |
| 1159 | return NULL; |
| 1160 | |
| 1161 | return ref; |
| 1162 | } |
| 1163 | } |
| 1164 | |
| 1165 | static inline |
| 1166 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1167 | { |
| 1168 | int id; |
| 1169 | char *error; |
| 1170 | |
| 1171 | /* If the reference starts by a '#', this is numeric id. */ |
| 1172 | if (reference[0] == '#') { |
| 1173 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1174 | id = strtol(reference + 1, &error, 10); |
| 1175 | if (*error != '\0') |
| 1176 | return NULL; |
| 1177 | |
| 1178 | /* Perform the unique id lookup. */ |
| 1179 | return tlskeys_ref_lookupid(id); |
| 1180 | } |
| 1181 | |
| 1182 | /* Perform the string lookup. */ |
| 1183 | return tlskeys_ref_lookup(reference); |
| 1184 | } |
| 1185 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1186 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1187 | /* This function is used with map and acl management. It permits to browse |
| 1188 | * each reference. The variable <getnext> must contain the current node, |
| 1189 | * <end> point to the root node and the <flags> permit to filter required |
| 1190 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1191 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1192 | static inline |
| 1193 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1194 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1195 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1196 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1197 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1198 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1199 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1200 | /* Get next list entry. */ |
| 1201 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1202 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1203 | /* If the entry is the last of the list, return NULL. */ |
| 1204 | if (&ref->list == end) |
| 1205 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1206 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1207 | /* If the entry match the flag, return it. */ |
| 1208 | if (ref->flags & flags) |
| 1209 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1213 | static inline |
| 1214 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1215 | { |
| 1216 | int id; |
| 1217 | char *error; |
| 1218 | |
| 1219 | /* If the reference starts by a '#', this is numeric id. */ |
| 1220 | if (reference[0] == '#') { |
| 1221 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1222 | id = strtol(reference + 1, &error, 10); |
| 1223 | if (*error != '\0') |
| 1224 | return NULL; |
| 1225 | |
| 1226 | /* Perform the unique id lookup. */ |
| 1227 | return pat_ref_lookupid(id); |
| 1228 | } |
| 1229 | |
| 1230 | /* Perform the string lookup. */ |
| 1231 | return pat_ref_lookup(reference); |
| 1232 | } |
| 1233 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1234 | /* This function is used with map and acl management. It permits to browse |
| 1235 | * each reference. |
| 1236 | */ |
| 1237 | static inline |
| 1238 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1239 | { |
| 1240 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1241 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1242 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1243 | return NULL; |
| 1244 | return expr; |
| 1245 | } |
| 1246 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1247 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1248 | * called from an applet running in a stream interface. The function returns 1 |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1249 | * if the request was understood, otherwise zero. It sets appctx->st0 to a value |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 1250 | * designating the function which will have to process the request, which can |
| 1251 | * also be the print function to display the return message set into cli.msg. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1252 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1253 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1254 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1255 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1256 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1257 | char *args[MAX_STATS_ARGS + 1]; |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 1258 | struct cli_kw *kw; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1259 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1260 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1261 | |
| 1262 | while (isspace((unsigned char)*line)) |
| 1263 | line++; |
| 1264 | |
| 1265 | arg = 0; |
| 1266 | args[arg] = line; |
| 1267 | |
| 1268 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1269 | if (*line == '\\') { |
| 1270 | line++; |
| 1271 | if (*line == '\0') |
| 1272 | break; |
| 1273 | } |
| 1274 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1275 | *line++ = '\0'; |
| 1276 | |
| 1277 | while (isspace((unsigned char)*line)) |
| 1278 | line++; |
| 1279 | |
| 1280 | args[++arg] = line; |
| 1281 | continue; |
| 1282 | } |
| 1283 | |
| 1284 | line++; |
| 1285 | } |
| 1286 | |
| 1287 | while (++arg <= MAX_STATS_ARGS) |
| 1288 | args[arg] = line; |
| 1289 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1290 | /* remove \ */ |
| 1291 | arg = 0; |
| 1292 | while (*args[arg] != '\0') { |
| 1293 | j = 0; |
| 1294 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1295 | if (args[arg][i] == '\\') |
| 1296 | continue; |
| 1297 | args[arg][j] = args[arg][i]; |
| 1298 | j++; |
| 1299 | } |
| 1300 | args[arg][j] = '\0'; |
| 1301 | arg++; |
| 1302 | } |
| 1303 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1304 | appctx->ctx.stats.scope_str = 0; |
| 1305 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1306 | appctx->ctx.stats.flags = 0; |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 1307 | if ((kw = cli_find_kw(args))) { |
| 1308 | if (kw->parse) { |
Thierry FOURNIER / OZON.IO | 6a22dcb | 2016-11-12 10:51:33 +0100 | [diff] [blame] | 1309 | if (kw->parse(args, appctx, kw->private) == 0 && kw->io_handler) { |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 1310 | appctx->st0 = STAT_CLI_O_CUSTOM; |
| 1311 | appctx->io_handler = kw->io_handler; |
Thierry FOURNIER / OZON.IO | 6a22dcb | 2016-11-12 10:51:33 +0100 | [diff] [blame] | 1312 | appctx->io_release = kw->io_release; |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | } else if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1316 | if (strcmp(args[1], "backend") == 0) { |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 1317 | appctx->ctx.be.px = NULL; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1318 | appctx->st2 = STAT_ST_INIT; |
| 1319 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1320 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1321 | else if (strcmp(args[1], "env") == 0) { |
| 1322 | extern char **environ; |
| 1323 | |
| 1324 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1325 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1326 | appctx->st0 = STAT_CLI_PRINT; |
| 1327 | return 1; |
| 1328 | } |
| 1329 | appctx->ctx.env.var = environ; |
| 1330 | appctx->st2 = STAT_ST_INIT; |
| 1331 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1332 | |
| 1333 | if (*args[2]) { |
| 1334 | int len = strlen(args[2]); |
| 1335 | |
| 1336 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1337 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1338 | (*appctx->ctx.env.var)[len] == '=') |
| 1339 | break; |
| 1340 | } |
| 1341 | if (!*appctx->ctx.env.var) { |
| 1342 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1343 | appctx->st0 = STAT_CLI_PRINT; |
| 1344 | return 1; |
| 1345 | } |
| 1346 | appctx->st2 = STAT_ST_END; |
| 1347 | } |
| 1348 | } |
| 1349 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1350 | if (strcmp(args[2], "resolvers") == 0) { |
| 1351 | struct dns_resolvers *presolvers; |
| 1352 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1353 | if (*args[3]) { |
| 1354 | appctx->ctx.resolvers.ptr = NULL; |
| 1355 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1356 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1357 | appctx->ctx.resolvers.ptr = presolvers; |
| 1358 | break; |
| 1359 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1360 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1361 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1362 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1363 | appctx->st0 = STAT_CLI_PRINT; |
| 1364 | return 1; |
| 1365 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | appctx->st2 = STAT_ST_INIT; |
| 1369 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1370 | return 1; |
| 1371 | } |
| 1372 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1373 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1374 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1375 | appctx->ctx.stats.type = atoi(args[3]); |
| 1376 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1377 | if (strcmp(args[5], "typed") == 0) |
| 1378 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1379 | } |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1380 | else if (strcmp(args[2], "typed") == 0) |
| 1381 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1382 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1383 | appctx->st2 = STAT_ST_INIT; |
| 1384 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1385 | } |
| 1386 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 1387 | if (strcmp(args[2], "typed") == 0) |
| 1388 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1389 | appctx->st2 = STAT_ST_INIT; |
| 1390 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1391 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1392 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1393 | appctx->ctx.server_state.iid = 0; |
| 1394 | appctx->ctx.server_state.px = NULL; |
| 1395 | appctx->ctx.server_state.sv = NULL; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1396 | |
| 1397 | /* check if a backend name has been provided */ |
| 1398 | if (*args[3]) { |
| 1399 | /* read server state from local file */ |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1400 | appctx->ctx.server_state.px = proxy_be_by_name(args[3]); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1401 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1402 | if (!appctx->ctx.server_state.px) { |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1403 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1404 | appctx->st0 = STAT_CLI_PRINT; |
| 1405 | return 1; |
| 1406 | } |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1407 | appctx->ctx.server_state.iid = appctx->ctx.server_state.px->uuid; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1408 | } |
| 1409 | appctx->st2 = STAT_ST_INIT; |
| 1410 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1411 | return 1; |
| 1412 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1413 | else if (strcmp(args[1], "pools") == 0) { |
| 1414 | appctx->st2 = STAT_ST_INIT; |
| 1415 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1416 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1417 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1418 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1419 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1420 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1421 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1422 | return 1; |
| 1423 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1424 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1425 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1426 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1427 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1428 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1429 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1430 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1431 | appctx->ctx.sess.pos = 0; |
| 1432 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1433 | } |
| 1434 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1435 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1436 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1437 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1438 | return 1; |
| 1439 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1440 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1441 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1442 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1443 | appctx->ctx.errors.iid = -1; |
| 1444 | appctx->ctx.errors.px = NULL; |
| 1445 | appctx->st2 = STAT_ST_INIT; |
| 1446 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1447 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1448 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1449 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1450 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1451 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1452 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 1453 | appctx->ctx.tlskeys.dump_all = 0; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1454 | /* no parameter, shows only file list */ |
| 1455 | if (!*args[2]) { |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 1456 | appctx->ctx.tlskeys.dump_all = 1; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1457 | appctx->st2 = STAT_ST_INIT; |
| 1458 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1459 | return 1; |
| 1460 | } |
| 1461 | |
| 1462 | if (args[2][0] == '*') { |
| 1463 | /* list every TLS ticket keys */ |
| 1464 | appctx->ctx.tlskeys.ref = NULL; |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 1465 | appctx->ctx.tlskeys.dump_all = 1; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1466 | } else { |
| 1467 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[2]); |
| 1468 | if(!appctx->ctx.tlskeys.ref) { |
| 1469 | appctx->ctx.cli.msg = "'show tls-keys' unable to locate referenced filename\n"; |
| 1470 | appctx->st0 = STAT_CLI_PRINT; |
| 1471 | return 1; |
| 1472 | } |
| 1473 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1474 | appctx->st2 = STAT_ST_INIT; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1475 | appctx->st0 = STAT_CLI_O_TLSK_ENT; |
| 1476 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1477 | #else |
| 1478 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1479 | "that doesn't support specifying TLS ticket keys\n"; |
| 1480 | appctx->st0 = STAT_CLI_PRINT; |
| 1481 | #endif |
| 1482 | return 1; |
| 1483 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1484 | else if (strcmp(args[1], "map") == 0 || |
| 1485 | strcmp(args[1], "acl") == 0) { |
| 1486 | |
| 1487 | /* Set ACL or MAP flags. */ |
| 1488 | if (args[1][0] == 'm') |
| 1489 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1490 | else |
| 1491 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1492 | |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 1493 | /* no parameter: display all map available */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1494 | if (!*args[2]) { |
| 1495 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1496 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1497 | return 1; |
| 1498 | } |
| 1499 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1500 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1501 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1502 | if (!appctx->ctx.map.ref || |
| 1503 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1504 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1505 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1506 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1507 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1508 | appctx->st0 = STAT_CLI_PRINT; |
| 1509 | return 1; |
| 1510 | } |
| 1511 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1512 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1513 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1514 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1515 | return 0; |
| 1516 | } |
| 1517 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1518 | else if (strcmp(args[0], "clear") == 0) { |
| 1519 | if (strcmp(args[1], "counters") == 0) { |
| 1520 | struct proxy *px; |
| 1521 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1522 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1523 | int clrall = 0; |
| 1524 | |
| 1525 | if (strcmp(args[2], "all") == 0) |
| 1526 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1527 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1528 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1529 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1530 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1531 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1532 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1533 | return 1; |
| 1534 | } |
| 1535 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1536 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1537 | if (clrall) { |
| 1538 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1539 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1540 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1541 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1542 | px->be_counters.conn_max = 0; |
| 1543 | px->be_counters.p.http.rps_max = 0; |
| 1544 | px->be_counters.sps_max = 0; |
| 1545 | px->be_counters.cps_max = 0; |
| 1546 | px->be_counters.nbpend_max = 0; |
| 1547 | |
| 1548 | px->fe_counters.conn_max = 0; |
| 1549 | px->fe_counters.p.http.rps_max = 0; |
| 1550 | px->fe_counters.sps_max = 0; |
| 1551 | px->fe_counters.cps_max = 0; |
| 1552 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1553 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1554 | |
| 1555 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1556 | if (clrall) |
| 1557 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1558 | else { |
| 1559 | sv->counters.cur_sess_max = 0; |
| 1560 | sv->counters.nbpend_max = 0; |
| 1561 | sv->counters.sps_max = 0; |
| 1562 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1563 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1564 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1565 | if (li->counters) { |
| 1566 | if (clrall) |
| 1567 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1568 | else |
| 1569 | li->counters->conn_max = 0; |
| 1570 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1571 | } |
| 1572 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1573 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1574 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1575 | return 1; |
| 1576 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1577 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1578 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1579 | /* end of processing */ |
| 1580 | return 1; |
| 1581 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1582 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1583 | /* Set ACL or MAP flags. */ |
| 1584 | if (args[1][0] == 'm') |
| 1585 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1586 | else |
| 1587 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1588 | |
| 1589 | /* no parameter */ |
| 1590 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1591 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1592 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1593 | else |
| 1594 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1595 | appctx->st0 = STAT_CLI_PRINT; |
| 1596 | return 1; |
| 1597 | } |
| 1598 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1599 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1600 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1601 | if (!appctx->ctx.map.ref || |
| 1602 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1603 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1604 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1605 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1606 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1607 | appctx->st0 = STAT_CLI_PRINT; |
| 1608 | return 1; |
| 1609 | } |
| 1610 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1611 | /* Clear all. */ |
| 1612 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1613 | |
| 1614 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1615 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1616 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1617 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1618 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1619 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1620 | return 0; |
| 1621 | } |
| 1622 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1623 | else if (strcmp(args[0], "get") == 0) { |
| 1624 | if (strcmp(args[1], "weight") == 0) { |
| 1625 | struct proxy *px; |
| 1626 | struct server *sv; |
| 1627 | |
| 1628 | /* split "backend/server" and make <line> point to server */ |
| 1629 | for (line = args[2]; *line; line++) |
| 1630 | if (*line == '/') { |
| 1631 | *line++ = '\0'; |
| 1632 | break; |
| 1633 | } |
| 1634 | |
| 1635 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1636 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1637 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1638 | return 1; |
| 1639 | } |
| 1640 | |
| 1641 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1642 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1643 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1644 | return 1; |
| 1645 | } |
| 1646 | |
| 1647 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1648 | snprintf(trash.str, trash.size, "%d (initial %d)\n", sv->uweight, sv->iweight); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1649 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1650 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1651 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1652 | return 1; |
| 1653 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1654 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1655 | /* Set flags. */ |
| 1656 | if (args[1][0] == 'm') |
| 1657 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1658 | else |
| 1659 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1660 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1661 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1662 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1663 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1664 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1665 | else |
| 1666 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1667 | appctx->st0 = STAT_CLI_PRINT; |
| 1668 | return 1; |
| 1669 | } |
| 1670 | |
| 1671 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1672 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1673 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1674 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1675 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1676 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1677 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1678 | appctx->st0 = STAT_CLI_PRINT; |
| 1679 | return 1; |
| 1680 | } |
| 1681 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1682 | /* copy input string. The string must be allocated because |
| 1683 | * it may be used over multiple iterations. It's released |
| 1684 | * at the end and upon abort anyway. |
| 1685 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1686 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1687 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1688 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1689 | if (!appctx->ctx.map.chunk.str) { |
| 1690 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1691 | appctx->st0 = STAT_CLI_PRINT; |
| 1692 | return 1; |
| 1693 | } |
| 1694 | |
| 1695 | /* prepare response */ |
| 1696 | appctx->st2 = STAT_ST_INIT; |
| 1697 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1698 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1699 | else { /* not "get weight" */ |
| 1700 | return 0; |
| 1701 | } |
| 1702 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1703 | else if (strcmp(args[0], "set") == 0) { |
| 1704 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1705 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1706 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1707 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1708 | sv = expect_server_admin(s, si, args[2]); |
| 1709 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1710 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1711 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1712 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1713 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1714 | appctx->ctx.cli.msg = warning; |
| 1715 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1716 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1717 | return 1; |
| 1718 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1719 | else if (strcmp(args[1], "server") == 0) { |
| 1720 | struct server *sv; |
| 1721 | const char *warning; |
| 1722 | |
| 1723 | sv = expect_server_admin(s, si, args[2]); |
| 1724 | if (!sv) |
| 1725 | return 1; |
| 1726 | |
| 1727 | if (strcmp(args[3], "weight") == 0) { |
| 1728 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1729 | if (warning) { |
| 1730 | appctx->ctx.cli.msg = warning; |
| 1731 | appctx->st0 = STAT_CLI_PRINT; |
| 1732 | } |
| 1733 | } |
| 1734 | else if (strcmp(args[3], "state") == 0) { |
| 1735 | if (strcmp(args[4], "ready") == 0) |
| 1736 | srv_adm_set_ready(sv); |
| 1737 | else if (strcmp(args[4], "drain") == 0) |
| 1738 | srv_adm_set_drain(sv); |
| 1739 | else if (strcmp(args[4], "maint") == 0) |
| 1740 | srv_adm_set_maint(sv); |
| 1741 | else { |
| 1742 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1743 | appctx->st0 = STAT_CLI_PRINT; |
| 1744 | } |
| 1745 | } |
| 1746 | else if (strcmp(args[3], "health") == 0) { |
| 1747 | if (sv->track) { |
| 1748 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1749 | appctx->st0 = STAT_CLI_PRINT; |
| 1750 | } |
| 1751 | else if (strcmp(args[4], "up") == 0) { |
| 1752 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1753 | srv_set_running(sv, "changed from CLI"); |
| 1754 | } |
| 1755 | else if (strcmp(args[4], "stopping") == 0) { |
| 1756 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1757 | srv_set_stopping(sv, "changed from CLI"); |
| 1758 | } |
| 1759 | else if (strcmp(args[4], "down") == 0) { |
| 1760 | sv->check.health = 0; |
| 1761 | srv_set_stopped(sv, "changed from CLI"); |
| 1762 | } |
| 1763 | else { |
| 1764 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1765 | appctx->st0 = STAT_CLI_PRINT; |
| 1766 | } |
| 1767 | } |
| 1768 | else if (strcmp(args[3], "agent") == 0) { |
| 1769 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1770 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1771 | appctx->st0 = STAT_CLI_PRINT; |
| 1772 | } |
| 1773 | else if (strcmp(args[4], "up") == 0) { |
| 1774 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1775 | srv_set_running(sv, "changed from CLI"); |
| 1776 | } |
| 1777 | else if (strcmp(args[4], "down") == 0) { |
| 1778 | sv->agent.health = 0; |
| 1779 | srv_set_stopped(sv, "changed from CLI"); |
| 1780 | } |
| 1781 | else { |
| 1782 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1783 | appctx->st0 = STAT_CLI_PRINT; |
| 1784 | } |
| 1785 | } |
Baptiste Assmann | 5094656 | 2016-08-31 23:26:29 +0200 | [diff] [blame] | 1786 | else if (strcmp(args[3], "check-port") == 0) { |
| 1787 | int i = 0; |
| 1788 | if (strl2irc(args[4], strlen(args[4]), &i) != 0) { |
| 1789 | appctx->ctx.cli.msg = "'set server <srv> check-port' expects an integer as argument.\n"; |
| 1790 | appctx->st0 = STAT_CLI_PRINT; |
| 1791 | } |
| 1792 | if ((i < 0) || (i > 65535)) { |
| 1793 | appctx->ctx.cli.msg = "provided port is not valid.\n"; |
| 1794 | appctx->st0 = STAT_CLI_PRINT; |
| 1795 | } |
| 1796 | /* prevent the update of port to 0 if MAPPORTS are in use */ |
| 1797 | if ((sv->flags & SRV_F_MAPPORTS) && (i == 0)) { |
| 1798 | appctx->ctx.cli.msg = "can't unset 'port' since MAPPORTS is in use.\n"; |
| 1799 | appctx->st0 = STAT_CLI_PRINT; |
| 1800 | return 1; |
| 1801 | } |
| 1802 | sv->check.port = i; |
| 1803 | appctx->ctx.cli.msg = "health check port updated.\n"; |
| 1804 | appctx->st0 = STAT_CLI_PRINT; |
| 1805 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1806 | else if (strcmp(args[3], "addr") == 0) { |
Baptiste Assmann | 3749ebf | 2016-08-03 22:34:12 +0200 | [diff] [blame] | 1807 | char *addr = NULL; |
| 1808 | char *port = NULL; |
| 1809 | if (strlen(args[4]) == 0) { |
Willy Tarreau | a33ec24 | 2016-11-04 18:21:32 +0100 | [diff] [blame] | 1810 | appctx->ctx.cli.msg = "set server <b>/<s> addr requires an address and optionally a port.\n"; |
Baptiste Assmann | 3749ebf | 2016-08-03 22:34:12 +0200 | [diff] [blame] | 1811 | appctx->st0 = STAT_CLI_PRINT; |
| 1812 | return 1; |
| 1813 | } |
| 1814 | else { |
| 1815 | addr = args[4]; |
| 1816 | } |
| 1817 | if (strcmp(args[5], "port") == 0) { |
| 1818 | port = args[6]; |
| 1819 | } |
| 1820 | warning = update_server_addr_port(sv, addr, port, "stats socket command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1821 | if (warning) { |
| 1822 | appctx->ctx.cli.msg = warning; |
| 1823 | appctx->st0 = STAT_CLI_PRINT; |
| 1824 | } |
Willy Tarreau | a33ec24 | 2016-11-04 18:21:32 +0100 | [diff] [blame] | 1825 | srv_clr_admin_flag(sv, SRV_ADMF_RMAINT); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1826 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1827 | else { |
Baptiste Assmann | 5094656 | 2016-08-31 23:26:29 +0200 | [diff] [blame] | 1828 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight', 'addr' and 'check-port'.\n"; |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1829 | appctx->st0 = STAT_CLI_PRINT; |
| 1830 | } |
| 1831 | return 1; |
| 1832 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1833 | else if (strcmp(args[1], "timeout") == 0) { |
| 1834 | if (strcmp(args[2], "cli") == 0) { |
| 1835 | unsigned timeout; |
| 1836 | const char *res; |
| 1837 | |
| 1838 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1839 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1840 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1841 | return 1; |
| 1842 | } |
| 1843 | |
| 1844 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1845 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1846 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1847 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1848 | return 1; |
| 1849 | } |
| 1850 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1851 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1852 | return 1; |
| 1853 | } |
| 1854 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1855 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1856 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1857 | return 1; |
| 1858 | } |
| 1859 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1860 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1861 | if (strcmp(args[2], "frontend") == 0) { |
| 1862 | struct proxy *px; |
| 1863 | struct listener *l; |
| 1864 | int v; |
| 1865 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1866 | px = expect_frontend_admin(s, si, args[3]); |
| 1867 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1868 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1869 | |
| 1870 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1871 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1872 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1873 | return 1; |
| 1874 | } |
| 1875 | |
| 1876 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1877 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1878 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1879 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1880 | return 1; |
| 1881 | } |
| 1882 | |
| 1883 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1884 | * its listeners. The blocked ones will be dequeued. |
| 1885 | */ |
| 1886 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1887 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1888 | l->maxconn = v; |
| 1889 | if (l->state == LI_FULL) |
| 1890 | resume_listener(l); |
| 1891 | } |
| 1892 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1893 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1894 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1895 | |
| 1896 | return 1; |
| 1897 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1898 | else if (strcmp(args[2], "server") == 0) { |
| 1899 | struct server *sv; |
Nenad Merdanovic | 5c3ed34 | 2016-04-24 23:10:07 +0200 | [diff] [blame] | 1900 | const char *warning; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1901 | |
| 1902 | sv = expect_server_admin(s, si, args[3]); |
| 1903 | if (!sv) |
| 1904 | return 1; |
| 1905 | |
Nenad Merdanovic | 5c3ed34 | 2016-04-24 23:10:07 +0200 | [diff] [blame] | 1906 | warning = server_parse_maxconn_change_request(sv, args[4]); |
| 1907 | if (warning) { |
| 1908 | appctx->ctx.cli.msg = warning; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1909 | appctx->st0 = STAT_CLI_PRINT; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1912 | return 1; |
| 1913 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1914 | else if (strcmp(args[2], "global") == 0) { |
| 1915 | int v; |
| 1916 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1917 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1918 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1919 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1920 | return 1; |
| 1921 | } |
| 1922 | |
| 1923 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1924 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1925 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1926 | return 1; |
| 1927 | } |
| 1928 | |
| 1929 | v = atoi(args[3]); |
| 1930 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1931 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1932 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1933 | return 1; |
| 1934 | } |
| 1935 | |
| 1936 | /* check for unlimited values */ |
| 1937 | if (v <= 0) |
| 1938 | v = global.hardmaxconn; |
| 1939 | |
| 1940 | global.maxconn = v; |
| 1941 | |
| 1942 | /* Dequeues all of the listeners waiting for a resource */ |
| 1943 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1944 | dequeue_all_listeners(&global_listener_queue); |
| 1945 | |
| 1946 | return 1; |
| 1947 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1948 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1949 | appctx->ctx.cli.msg = "'set maxconn' only supports 'frontend', 'server', and 'global'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1950 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1951 | return 1; |
| 1952 | } |
| 1953 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1954 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1955 | if (strcmp(args[2], "connections") == 0) { |
| 1956 | if (strcmp(args[3], "global") == 0) { |
| 1957 | int v; |
| 1958 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1959 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1960 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1961 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1962 | return 1; |
| 1963 | } |
| 1964 | |
| 1965 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1966 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1967 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1968 | return 1; |
| 1969 | } |
| 1970 | |
| 1971 | v = atoi(args[4]); |
| 1972 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1973 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1974 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1975 | return 1; |
| 1976 | } |
| 1977 | |
| 1978 | global.cps_lim = v; |
| 1979 | |
| 1980 | /* Dequeues all of the listeners waiting for a resource */ |
| 1981 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1982 | dequeue_all_listeners(&global_listener_queue); |
| 1983 | |
| 1984 | return 1; |
| 1985 | } |
| 1986 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1987 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1988 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1989 | return 1; |
| 1990 | } |
| 1991 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1992 | else if (strcmp(args[2], "sessions") == 0) { |
| 1993 | if (strcmp(args[3], "global") == 0) { |
| 1994 | int v; |
| 1995 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1996 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1997 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1998 | appctx->st0 = STAT_CLI_PRINT; |
| 1999 | return 1; |
| 2000 | } |
| 2001 | |
| 2002 | if (!*args[4]) { |
| 2003 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2004 | appctx->st0 = STAT_CLI_PRINT; |
| 2005 | return 1; |
| 2006 | } |
| 2007 | |
| 2008 | v = atoi(args[4]); |
| 2009 | if (v < 0) { |
| 2010 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2011 | appctx->st0 = STAT_CLI_PRINT; |
| 2012 | return 1; |
| 2013 | } |
| 2014 | |
| 2015 | global.sps_lim = v; |
| 2016 | |
| 2017 | /* Dequeues all of the listeners waiting for a resource */ |
| 2018 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2019 | dequeue_all_listeners(&global_listener_queue); |
| 2020 | |
| 2021 | return 1; |
| 2022 | } |
| 2023 | else { |
| 2024 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 2025 | appctx->st0 = STAT_CLI_PRINT; |
| 2026 | return 1; |
| 2027 | } |
| 2028 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2029 | #ifdef USE_OPENSSL |
| 2030 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 2031 | if (strcmp(args[3], "global") == 0) { |
| 2032 | int v; |
| 2033 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2034 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2035 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2036 | appctx->st0 = STAT_CLI_PRINT; |
| 2037 | return 1; |
| 2038 | } |
| 2039 | |
| 2040 | if (!*args[4]) { |
| 2041 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2042 | appctx->st0 = STAT_CLI_PRINT; |
| 2043 | return 1; |
| 2044 | } |
| 2045 | |
| 2046 | v = atoi(args[4]); |
| 2047 | if (v < 0) { |
| 2048 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2049 | appctx->st0 = STAT_CLI_PRINT; |
| 2050 | return 1; |
| 2051 | } |
| 2052 | |
| 2053 | global.ssl_lim = v; |
| 2054 | |
| 2055 | /* Dequeues all of the listeners waiting for a resource */ |
| 2056 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2057 | dequeue_all_listeners(&global_listener_queue); |
| 2058 | |
| 2059 | return 1; |
| 2060 | } |
| 2061 | else { |
| 2062 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 2063 | appctx->st0 = STAT_CLI_PRINT; |
| 2064 | return 1; |
| 2065 | } |
| 2066 | } |
| 2067 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2068 | else if (strcmp(args[2], "http-compression") == 0) { |
| 2069 | if (strcmp(args[3], "global") == 0) { |
| 2070 | int v; |
| 2071 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 2072 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 2073 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2074 | appctx->st0 = STAT_CLI_PRINT; |
| 2075 | return 1; |
| 2076 | } |
| 2077 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2078 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2079 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 2080 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2081 | return 1; |
| 2082 | } |
| 2083 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2084 | v = atoi(args[4]); |
| 2085 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 2086 | } |
| 2087 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2088 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 2089 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2090 | return 1; |
| 2091 | } |
| 2092 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2093 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2094 | appctx->ctx.cli.msg = "'set rate-limit' supports 'connections', 'sessions', 'ssl-sessions', and 'http-compression'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2095 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2096 | return 1; |
| 2097 | } |
| 2098 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 2099 | else if (strcmp(args[1], "table") == 0) { |
| 2100 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 2101 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2102 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2103 | char *err; |
| 2104 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2105 | /* Set flags. */ |
| 2106 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2107 | |
| 2108 | /* Expect three parameters: map name, key and new value. */ |
| 2109 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 2110 | appctx->ctx.cli.msg = "'set map' expects three parameters: map identifier, key and value.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2111 | appctx->st0 = STAT_CLI_PRINT; |
| 2112 | return 1; |
| 2113 | } |
| 2114 | |
| 2115 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2116 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2117 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2118 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2119 | appctx->st0 = STAT_CLI_PRINT; |
| 2120 | return 1; |
| 2121 | } |
| 2122 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2123 | /* If the entry identifier start with a '#', it is considered as |
| 2124 | * pointer id |
| 2125 | */ |
| 2126 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2127 | struct pat_ref_elt *ref; |
| 2128 | long long int conv; |
| 2129 | char *error; |
| 2130 | |
| 2131 | /* Convert argument to integer value. */ |
| 2132 | conv = strtoll(&args[3][1], &error, 16); |
| 2133 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2134 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2135 | appctx->st0 = STAT_CLI_PRINT; |
| 2136 | return 1; |
| 2137 | } |
| 2138 | |
| 2139 | /* Convert and check integer to pointer. */ |
| 2140 | ref = (struct pat_ref_elt *)(long)conv; |
| 2141 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2142 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2143 | appctx->st0 = STAT_CLI_PRINT; |
| 2144 | return 1; |
| 2145 | } |
| 2146 | |
| 2147 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2148 | err = NULL; |
| 2149 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 2150 | if (err) |
| 2151 | memprintf(&err, "%s.\n", err); |
| 2152 | appctx->ctx.cli.err = err; |
| 2153 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2154 | return 1; |
| 2155 | } |
| 2156 | } |
| 2157 | else { |
| 2158 | /* Else, use the entry identifier as pattern |
| 2159 | * string, and update the value. |
| 2160 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2161 | err = NULL; |
| 2162 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 2163 | if (err) |
| 2164 | memprintf(&err, "%s.\n", err); |
| 2165 | appctx->ctx.cli.err = err; |
| 2166 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2167 | return 1; |
| 2168 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2169 | } |
| 2170 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2171 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2172 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2173 | return 1; |
| 2174 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2175 | #ifdef USE_OPENSSL |
| 2176 | else if (strcmp(args[1], "ssl") == 0) { |
| 2177 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 2178 | #if (defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB && !defined OPENSSL_NO_OCSP) |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2179 | char *err = NULL; |
| 2180 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 2181 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2182 | if (!*args[3]) { |
| 2183 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 2184 | appctx->st0 = STAT_CLI_PRINT; |
| 2185 | return 1; |
| 2186 | } |
| 2187 | |
| 2188 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 2189 | if (trash.len < 0) { |
| 2190 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 2191 | appctx->st0 = STAT_CLI_PRINT; |
| 2192 | return 1; |
| 2193 | } |
| 2194 | |
| 2195 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 2196 | if (err) { |
| 2197 | memprintf(&err, "%s.\n", err); |
| 2198 | appctx->ctx.cli.err = err; |
| 2199 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 2200 | } |
| 2201 | return 1; |
| 2202 | } |
| 2203 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2204 | appctx->st0 = STAT_CLI_PRINT; |
| 2205 | return 1; |
| 2206 | #else |
| 2207 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2208 | appctx->st0 = STAT_CLI_PRINT; |
| 2209 | return 1; |
| 2210 | #endif |
| 2211 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2212 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2213 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2214 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2215 | if (!*args[3] || !*args[4]) { |
| 2216 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2217 | appctx->st0 = STAT_CLI_PRINT; |
| 2218 | return 1; |
| 2219 | } |
| 2220 | |
| 2221 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2222 | if(!appctx->ctx.tlskeys.ref) { |
| 2223 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2224 | appctx->st0 = STAT_CLI_PRINT; |
| 2225 | return 1; |
| 2226 | } |
| 2227 | |
| 2228 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2229 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2230 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2231 | appctx->st0 = STAT_CLI_PRINT; |
| 2232 | return 1; |
| 2233 | } |
| 2234 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2235 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2236 | appctx->ctx.tlskeys.ref->tls_ticket_enc_index = (appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 1) % TLS_TICKETS_NO; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2237 | |
| 2238 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2239 | appctx->st0 = STAT_CLI_PRINT; |
| 2240 | return 1; |
| 2241 | #else |
| 2242 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2243 | "that doesn't support specifying TLS ticket keys\n"; |
| 2244 | appctx->st0 = STAT_CLI_PRINT; |
| 2245 | return 1; |
| 2246 | #endif |
| 2247 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2248 | else { |
| 2249 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2250 | appctx->st0 = STAT_CLI_PRINT; |
| 2251 | return 1; |
| 2252 | } |
| 2253 | } |
| 2254 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2255 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2256 | return 0; |
| 2257 | } |
| 2258 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2259 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2260 | if (strcmp(args[1], "agent") == 0) { |
| 2261 | struct server *sv; |
| 2262 | |
| 2263 | sv = expect_server_admin(s, si, args[2]); |
| 2264 | if (!sv) |
| 2265 | return 1; |
| 2266 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2267 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2268 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2269 | appctx->st0 = STAT_CLI_PRINT; |
| 2270 | return 1; |
| 2271 | } |
| 2272 | |
| 2273 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2274 | return 1; |
| 2275 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2276 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2277 | struct server *sv; |
| 2278 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2279 | sv = expect_server_admin(s, si, args[2]); |
| 2280 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2281 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2282 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2283 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2284 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2285 | appctx->st0 = STAT_CLI_PRINT; |
| 2286 | return 1; |
| 2287 | } |
| 2288 | |
| 2289 | sv->check.state |= CHK_ST_ENABLED; |
| 2290 | return 1; |
| 2291 | } |
| 2292 | else if (strcmp(args[1], "server") == 0) { |
| 2293 | struct server *sv; |
| 2294 | |
| 2295 | sv = expect_server_admin(s, si, args[2]); |
| 2296 | if (!sv) |
| 2297 | return 1; |
| 2298 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2299 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2300 | return 1; |
| 2301 | } |
| 2302 | else if (strcmp(args[1], "frontend") == 0) { |
| 2303 | struct proxy *px; |
| 2304 | |
| 2305 | px = expect_frontend_admin(s, si, args[2]); |
| 2306 | if (!px) |
| 2307 | return 1; |
| 2308 | |
| 2309 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2310 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2311 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2312 | return 1; |
| 2313 | } |
| 2314 | |
| 2315 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2316 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2317 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2318 | return 1; |
| 2319 | } |
| 2320 | |
| 2321 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2322 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2323 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2324 | return 1; |
| 2325 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2326 | return 1; |
| 2327 | } |
| 2328 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2329 | appctx->ctx.cli.msg = "'enable' only supports 'agent', 'frontend', 'health', and 'server'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2330 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2331 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2335 | if (strcmp(args[1], "agent") == 0) { |
| 2336 | struct server *sv; |
| 2337 | |
| 2338 | sv = expect_server_admin(s, si, args[2]); |
| 2339 | if (!sv) |
| 2340 | return 1; |
| 2341 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2342 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2343 | return 1; |
| 2344 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2345 | else if (strcmp(args[1], "health") == 0) { |
| 2346 | struct server *sv; |
| 2347 | |
| 2348 | sv = expect_server_admin(s, si, args[2]); |
| 2349 | if (!sv) |
| 2350 | return 1; |
| 2351 | |
| 2352 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2353 | return 1; |
| 2354 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2355 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2356 | struct server *sv; |
| 2357 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2358 | sv = expect_server_admin(s, si, args[2]); |
| 2359 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2360 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2361 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2362 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2363 | return 1; |
| 2364 | } |
| 2365 | else if (strcmp(args[1], "frontend") == 0) { |
| 2366 | struct proxy *px; |
| 2367 | |
| 2368 | px = expect_frontend_admin(s, si, args[2]); |
| 2369 | if (!px) |
| 2370 | return 1; |
| 2371 | |
| 2372 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2373 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2374 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2375 | return 1; |
| 2376 | } |
| 2377 | |
| 2378 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2379 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2380 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2381 | return 1; |
| 2382 | } |
| 2383 | |
| 2384 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2385 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2386 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2387 | return 1; |
| 2388 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2389 | return 1; |
| 2390 | } |
| 2391 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2392 | appctx->ctx.cli.msg = "'disable' only supports 'agent', 'frontend', 'health', and 'server'.\n"; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2393 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2394 | return 1; |
| 2395 | } |
| 2396 | } |
| 2397 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2398 | if (strcmp(args[1], "frontend") == 0) { |
| 2399 | struct proxy *px; |
| 2400 | |
| 2401 | px = expect_frontend_admin(s, si, args[2]); |
| 2402 | if (!px) |
| 2403 | return 1; |
| 2404 | |
| 2405 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2406 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2407 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2408 | return 1; |
| 2409 | } |
| 2410 | |
| 2411 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2412 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2413 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2414 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2415 | stop_proxy(px); |
| 2416 | return 1; |
| 2417 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2418 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2419 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2420 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2421 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2422 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2423 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2424 | return 1; |
| 2425 | } |
| 2426 | |
| 2427 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2428 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2429 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2430 | return 1; |
| 2431 | } |
| 2432 | |
| 2433 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2434 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2435 | /* first, look for the requested stream in the stream table */ |
| 2436 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2437 | if (sess == ptr) |
| 2438 | break; |
| 2439 | } |
| 2440 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2441 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2442 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2443 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2444 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2445 | return 1; |
| 2446 | } |
| 2447 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2448 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2449 | return 1; |
| 2450 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2451 | else if (strcmp(args[1], "sessions") == 0) { |
| 2452 | if (strcmp(args[2], "server") == 0) { |
| 2453 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2454 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2455 | |
| 2456 | sv = expect_server_admin(s, si, args[3]); |
| 2457 | if (!sv) |
| 2458 | return 1; |
| 2459 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2460 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2461 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2462 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2463 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2464 | |
| 2465 | return 1; |
| 2466 | } |
| 2467 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2468 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2469 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2470 | return 1; |
| 2471 | } |
| 2472 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2473 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2474 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2475 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2476 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2477 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2478 | } |
| 2479 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2480 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2481 | if (args[1][0] == 'm') |
| 2482 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2483 | else |
| 2484 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2485 | |
| 2486 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2487 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2488 | if (!*args[2] || !*args[3]) { |
| 2489 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2490 | appctx->st0 = STAT_CLI_PRINT; |
| 2491 | return 1; |
| 2492 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2493 | } |
| 2494 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2495 | else { |
| 2496 | if (!*args[2] || !*args[3]) { |
| 2497 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2498 | appctx->st0 = STAT_CLI_PRINT; |
| 2499 | return 1; |
| 2500 | } |
| 2501 | } |
| 2502 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2503 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2504 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2505 | if (!appctx->ctx.map.ref || |
| 2506 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2507 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2508 | appctx->st0 = STAT_CLI_PRINT; |
| 2509 | return 1; |
| 2510 | } |
| 2511 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2512 | /* If the entry identifier start with a '#', it is considered as |
| 2513 | * pointer id |
| 2514 | */ |
| 2515 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2516 | struct pat_ref_elt *ref; |
| 2517 | long long int conv; |
| 2518 | char *error; |
| 2519 | |
| 2520 | /* Convert argument to integer value. */ |
| 2521 | conv = strtoll(&args[3][1], &error, 16); |
| 2522 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2523 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2524 | appctx->st0 = STAT_CLI_PRINT; |
| 2525 | return 1; |
| 2526 | } |
| 2527 | |
| 2528 | /* Convert and check integer to pointer. */ |
| 2529 | ref = (struct pat_ref_elt *)(long)conv; |
| 2530 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2531 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2532 | appctx->st0 = STAT_CLI_PRINT; |
| 2533 | return 1; |
| 2534 | } |
| 2535 | |
| 2536 | /* Try to delete the entry. */ |
| 2537 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2538 | /* The entry is not found, send message. */ |
| 2539 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2540 | appctx->st0 = STAT_CLI_PRINT; |
| 2541 | return 1; |
| 2542 | } |
| 2543 | } |
| 2544 | else { |
| 2545 | /* Else, use the entry identifier as pattern |
| 2546 | * string and try to delete the entry. |
| 2547 | */ |
| 2548 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2549 | /* The entry is not found, send message. */ |
| 2550 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2551 | appctx->st0 = STAT_CLI_PRINT; |
| 2552 | return 1; |
| 2553 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2554 | } |
| 2555 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2556 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2557 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2558 | return 1; |
| 2559 | } |
| 2560 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2561 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2562 | appctx->st0 = STAT_CLI_PRINT; |
| 2563 | return 1; |
| 2564 | } |
| 2565 | } |
| 2566 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2567 | if (strcmp(args[1], "map") == 0 || |
| 2568 | strcmp(args[1], "acl") == 0) { |
| 2569 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2570 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2571 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2572 | /* Set flags. */ |
| 2573 | if (args[1][0] == 'm') |
| 2574 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2575 | else |
| 2576 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2577 | |
| 2578 | /* If the keywork is "map", we expect three parameters, if it |
| 2579 | * is "acl", we expect only two parameters |
| 2580 | */ |
| 2581 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2582 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2583 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2584 | appctx->st0 = STAT_CLI_PRINT; |
| 2585 | return 1; |
| 2586 | } |
| 2587 | } |
| 2588 | else { |
| 2589 | if (!*args[2] || !*args[3]) { |
| 2590 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2591 | appctx->st0 = STAT_CLI_PRINT; |
| 2592 | return 1; |
| 2593 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2594 | } |
| 2595 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2596 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2597 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2598 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2599 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2600 | appctx->ctx.cli.msg = "Unknown map identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2601 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2602 | appctx->ctx.cli.msg = "Unknown ACL identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2603 | appctx->st0 = STAT_CLI_PRINT; |
| 2604 | return 1; |
| 2605 | } |
| 2606 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2607 | /* The command "add acl" is prohibited if the reference |
| 2608 | * use samples. |
| 2609 | */ |
| 2610 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2611 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2612 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2613 | "You must use the command 'add map' to add values.\n"; |
| 2614 | appctx->st0 = STAT_CLI_PRINT; |
| 2615 | return 1; |
| 2616 | } |
| 2617 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2618 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2619 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2620 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2621 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], args[4], &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2622 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2623 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2624 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2625 | if (err) |
| 2626 | memprintf(&err, "%s.\n", err); |
| 2627 | appctx->ctx.cli.err = err; |
| 2628 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2629 | return 1; |
| 2630 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2631 | |
| 2632 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2633 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2634 | return 1; |
| 2635 | } |
| 2636 | else { /* unknown "del" parameter */ |
| 2637 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2638 | appctx->st0 = STAT_CLI_PRINT; |
| 2639 | return 1; |
| 2640 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2641 | } |
| 2642 | else { /* not "show" nor "clear" nor "get" nor "set" nor "enable" nor "disable" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2643 | return 0; |
| 2644 | } |
| 2645 | return 1; |
| 2646 | } |
| 2647 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2648 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2649 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2650 | * state machine handling requests and various responses. We read a request, |
| 2651 | * then we process it and send the response, and we possibly display a prompt. |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2652 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2653 | * STAT_CLI_* constants. appctx->st1 is used to indicate whether prompt is enabled |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2654 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2655 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2656 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2657 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2658 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2659 | struct channel *req = si_oc(si); |
| 2660 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2661 | int reql; |
| 2662 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2663 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2664 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2665 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2666 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2667 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2668 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2669 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2670 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2671 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2672 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2673 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2674 | /* Let's close for real now. We just close the request |
| 2675 | * side, the conditions below will complete if needed. |
| 2676 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2677 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2678 | break; |
| 2679 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2680 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2681 | /* ensure we have some output room left in the event we |
| 2682 | * would want to return some info right after parsing. |
| 2683 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2684 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2685 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2686 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2687 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2688 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2689 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2690 | if (reql <= 0) { /* closed or EOL not found */ |
| 2691 | if (reql == 0) |
| 2692 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2693 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2694 | continue; |
| 2695 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2696 | |
Chad Lavoie | e3f5031 | 2016-05-26 16:42:25 -0400 | [diff] [blame] | 2697 | /* seek for a possible unescaped semi-colon. If we find |
| 2698 | * one, we replace it with an LF and skip only this part. |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2699 | */ |
Chad Lavoie | e3f5031 | 2016-05-26 16:42:25 -0400 | [diff] [blame] | 2700 | for (len = 0; len < reql; len++) { |
| 2701 | if (trash.str[len] == '\\') { |
| 2702 | len++; |
| 2703 | continue; |
| 2704 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2705 | if (trash.str[len] == ';') { |
| 2706 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2707 | reql = len + 1; |
| 2708 | break; |
| 2709 | } |
Chad Lavoie | e3f5031 | 2016-05-26 16:42:25 -0400 | [diff] [blame] | 2710 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2711 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2712 | /* now it is time to check that we have a full line, |
| 2713 | * remove the trailing \n and possibly \r, then cut the |
| 2714 | * line. |
| 2715 | */ |
| 2716 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2717 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2718 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2719 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2720 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2721 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2722 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2723 | len--; |
| 2724 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2725 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2726 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2727 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2728 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2729 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2730 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2731 | continue; |
| 2732 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2733 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2734 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2735 | else if (strcmp(trash.str, "help") == 0 || |
| 2736 | !stats_sock_parse_request(si, trash.str)) { |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 2737 | cli_gen_usage_msg(); |
| 2738 | if (dynamic_usage_msg) |
| 2739 | appctx->ctx.cli.msg = dynamic_usage_msg; |
| 2740 | else |
| 2741 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2742 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2743 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2744 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2745 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2746 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2747 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2748 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2749 | /* if prompt is disabled, print help on empty lines, |
| 2750 | * so that the user at least knows how to enable |
| 2751 | * prompt and find help. |
| 2752 | */ |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 2753 | cli_gen_usage_msg(); |
| 2754 | if (dynamic_usage_msg) |
| 2755 | appctx->ctx.cli.msg = dynamic_usage_msg; |
| 2756 | else |
| 2757 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2758 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2762 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2763 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2764 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2765 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2766 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2767 | case STAT_CLI_PROMPT: |
| 2768 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2769 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2770 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2771 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2772 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2773 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2774 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2775 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2776 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2777 | free(appctx->ctx.cli.err); |
| 2778 | appctx->st0 = STAT_CLI_PROMPT; |
| 2779 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2780 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2781 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2782 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2783 | case STAT_CLI_O_BACKEND: |
| 2784 | if (stats_dump_backend_to_buffer(si)) |
| 2785 | appctx->st0 = STAT_CLI_PROMPT; |
| 2786 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2787 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2788 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2789 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2790 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2791 | case STAT_CLI_O_SERVERS_STATE: |
| 2792 | if (stats_dump_servers_state_to_buffer(si)) |
| 2793 | appctx->st0 = STAT_CLI_PROMPT; |
| 2794 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2795 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2796 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2797 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2798 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2799 | case STAT_CLI_O_RESOLVERS: |
| 2800 | if (stats_dump_resolvers_to_buffer(si)) |
| 2801 | appctx->st0 = STAT_CLI_PROMPT; |
| 2802 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2803 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2804 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2805 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2806 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2807 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2808 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2809 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2810 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2811 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2812 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2813 | if (stats_table_request(si, appctx->st0)) |
| 2814 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2815 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2816 | case STAT_CLI_O_PATS: |
| 2817 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2818 | appctx->st0 = STAT_CLI_PROMPT; |
| 2819 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2820 | case STAT_CLI_O_PAT: |
| 2821 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2822 | appctx->st0 = STAT_CLI_PROMPT; |
| 2823 | break; |
| 2824 | case STAT_CLI_O_MLOOK: |
| 2825 | if (stats_map_lookup(si)) |
| 2826 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2827 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2828 | case STAT_CLI_O_POOLS: |
| 2829 | if (stats_dump_pools_to_buffer(si)) |
| 2830 | appctx->st0 = STAT_CLI_PROMPT; |
| 2831 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2832 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2833 | case STAT_CLI_O_TLSK: |
| 2834 | if (stats_tlskeys_list(si)) |
| 2835 | appctx->st0 = STAT_CLI_PROMPT; |
| 2836 | break; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 2837 | case STAT_CLI_O_TLSK_ENT: |
| 2838 | if (stats_tlskeys_list(si)) |
| 2839 | appctx->st0 = STAT_CLI_PROMPT; |
| 2840 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2841 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2842 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2843 | if (stats_dump_env_to_buffer(si)) |
| 2844 | appctx->st0 = STAT_CLI_PROMPT; |
| 2845 | break; |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 2846 | case STAT_CLI_O_CUSTOM: /* use custom pointer */ |
| 2847 | if (appctx->io_handler) |
Thierry FOURNIER / OZON.IO | 6a22dcb | 2016-11-12 10:51:33 +0100 | [diff] [blame] | 2848 | if (appctx->io_handler(appctx)) { |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 2849 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER / OZON.IO | 6a22dcb | 2016-11-12 10:51:33 +0100 | [diff] [blame] | 2850 | if (appctx->io_release) { |
| 2851 | appctx->io_release(appctx); |
| 2852 | appctx->io_release = NULL; |
| 2853 | } |
| 2854 | } |
William Lallemand | 1e08cd8 | 2016-10-13 17:57:55 +0200 | [diff] [blame] | 2855 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2856 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2857 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2858 | break; |
| 2859 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2860 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2861 | /* The post-command prompt is either LF alone or LF + '> ' in interactive mode */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2862 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2863 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2864 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2865 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2866 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2867 | } |
| 2868 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2869 | /* If the output functions are still there, it means they require more room. */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2870 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2871 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2872 | |
| 2873 | /* Now we close the output if one of the writers did so, |
| 2874 | * or if we're not in interactive mode and the request |
| 2875 | * buffer is empty. This still allows pipelined requests |
| 2876 | * to be sent in non-interactive mode. |
| 2877 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2878 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2879 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2880 | continue; |
| 2881 | } |
| 2882 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2883 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2884 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2885 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2886 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2887 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2888 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2889 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2890 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2891 | /* Other side has closed, let's abort if we have no more processing to do |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2892 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2893 | * we forward the close to the request side so that it flows upstream to |
| 2894 | * the client. |
| 2895 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2896 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2897 | } |
| 2898 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2899 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST) && (appctx->st0 < STAT_CLI_OUTPUT)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2900 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2901 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2902 | /* We have no more processing to do, and nothing more to send, and |
| 2903 | * the client side has closed. So we'll forward this state downstream |
| 2904 | * on the response buffer. |
| 2905 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2906 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2907 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2908 | } |
| 2909 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2910 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2911 | DPRINTF(stderr, "%s@%d: st=%d, rqf=%x, rpf=%x, rqh=%d, rqs=%d, rh=%d, rs=%d\n", |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2912 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2913 | si->state, req->flags, res->flags, req->buf->i, req->buf->o, res->buf->i, res->buf->o); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2914 | } |
| 2915 | |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2916 | /* Emits a stats field without any surrounding element and properly encoded to |
| 2917 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 2918 | */ |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 2919 | int stats_emit_raw_data_field(struct chunk *out, const struct field *f) |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2920 | { |
| 2921 | switch (field_format(f, 0)) { |
| 2922 | case FF_EMPTY: return 1; |
| 2923 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 2924 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 2925 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 2926 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 2927 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 2928 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 2929 | } |
| 2930 | } |
| 2931 | |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 2932 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 2933 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 2934 | * if the buffer is full. |
| 2935 | */ |
| 2936 | int stats_emit_typed_data_field(struct chunk *out, const struct field *f) |
| 2937 | { |
| 2938 | switch (field_format(f, 0)) { |
| 2939 | case FF_EMPTY: return 1; |
| 2940 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 2941 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 2942 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 2943 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
| 2944 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 2945 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 2950 | * Returns non-zero on success, 0 if the buffer is full. |
| 2951 | */ |
| 2952 | int stats_emit_field_tags(struct chunk *out, const struct field *f, char delim) |
| 2953 | { |
| 2954 | char origin, nature, scope; |
| 2955 | |
| 2956 | switch (field_origin(f, 0)) { |
| 2957 | case FO_METRIC: origin = 'M'; break; |
| 2958 | case FO_STATUS: origin = 'S'; break; |
| 2959 | case FO_KEY: origin = 'K'; break; |
| 2960 | case FO_CONFIG: origin = 'C'; break; |
| 2961 | case FO_PRODUCT: origin = 'P'; break; |
| 2962 | default: origin = '?'; break; |
| 2963 | } |
| 2964 | |
| 2965 | switch (field_nature(f, 0)) { |
| 2966 | case FN_GAUGE: nature = 'G'; break; |
| 2967 | case FN_LIMIT: nature = 'L'; break; |
| 2968 | case FN_MIN: nature = 'm'; break; |
| 2969 | case FN_MAX: nature = 'M'; break; |
| 2970 | case FN_RATE: nature = 'R'; break; |
| 2971 | case FN_COUNTER: nature = 'C'; break; |
| 2972 | case FN_DURATION: nature = 'D'; break; |
| 2973 | case FN_AGE: nature = 'A'; break; |
| 2974 | case FN_TIME: nature = 'T'; break; |
| 2975 | case FN_NAME: nature = 'N'; break; |
| 2976 | case FN_OUTPUT: nature = 'O'; break; |
| 2977 | case FN_AVG: nature = 'a'; break; |
| 2978 | default: nature = '?'; break; |
| 2979 | } |
| 2980 | |
| 2981 | switch (field_scope(f, 0)) { |
| 2982 | case FS_PROCESS: scope = 'P'; break; |
| 2983 | case FS_SERVICE: scope = 'S'; break; |
| 2984 | case FS_SYSTEM: scope = 's'; break; |
| 2985 | case FS_CLUSTER: scope = 'C'; break; |
| 2986 | default: scope = '?'; break; |
| 2987 | } |
| 2988 | |
| 2989 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 2990 | } |
| 2991 | |
Willy Tarreau | bf95cba | 2016-01-11 18:27:29 +0100 | [diff] [blame] | 2992 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
| 2993 | static int stats_dump_info_fields(struct chunk *out, const struct field *info) |
| 2994 | { |
| 2995 | int field; |
| 2996 | |
| 2997 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 2998 | if (!field_format(info, field)) |
| 2999 | continue; |
| 3000 | |
| 3001 | if (!chunk_appendf(out, "%s: ", info_field_names[field])) |
| 3002 | return 0; |
| 3003 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 3004 | return 0; |
| 3005 | if (!chunk_strcat(out, "\n")) |
| 3006 | return 0; |
| 3007 | } |
| 3008 | return 1; |
| 3009 | } |
| 3010 | |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 3011 | /* Dump all fields from <info> into <out> using the "show info typed" format */ |
| 3012 | static int stats_dump_typed_info_fields(struct chunk *out, const struct field *info) |
| 3013 | { |
| 3014 | int field; |
| 3015 | |
| 3016 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 3017 | if (!field_format(info, field)) |
| 3018 | continue; |
| 3019 | |
| 3020 | if (!chunk_appendf(out, "%d.%s.%u:", field, info_field_names[field], info[INF_PROCESS_NUM].u.u32)) |
| 3021 | return 0; |
| 3022 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 3023 | return 0; |
| 3024 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 3025 | return 0; |
| 3026 | if (!chunk_strcat(out, "\n")) |
| 3027 | return 0; |
| 3028 | } |
| 3029 | return 1; |
| 3030 | } |
| 3031 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 3032 | /* Fill <info> with HAProxy global info. <info> is preallocated |
| 3033 | * array of length <len>. The length of the aray must be |
| 3034 | * INF_TOTAL_FIELDS. If this length is less then this value, the |
| 3035 | * function returns 0, otherwise, it returns 1. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3036 | */ |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 3037 | int stats_fill_info(struct field *info, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3038 | { |
| 3039 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 3040 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3041 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 3042 | #ifdef USE_OPENSSL |
| 3043 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 3044 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 3045 | int ssl_reuse = 0; |
| 3046 | |
| 3047 | if (ssl_key_rate < ssl_sess_rate) { |
| 3048 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 3049 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 3050 | } |
| 3051 | #endif |
| 3052 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 3053 | if (len < INF_TOTAL_FIELDS) |
| 3054 | return 0; |
| 3055 | |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 3056 | chunk_reset(out); |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 3057 | memset(info, 0, sizeof(*info) * len); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 3058 | |
| 3059 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
| 3060 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION); |
| 3061 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE); |
| 3062 | |
| 3063 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 3064 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 3065 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 3066 | |
| 3067 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 3068 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 3069 | |
| 3070 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 3071 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 3072 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 3073 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 3074 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 3075 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 3076 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 3077 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 3078 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 3079 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 3080 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 3081 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 3082 | #ifdef USE_OPENSSL |
| 3083 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 3084 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 3085 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 3086 | #endif |
| 3087 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 3088 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 3089 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 3090 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 3091 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 3092 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 3093 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 3094 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 3095 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 3096 | |
| 3097 | #ifdef USE_OPENSSL |
| 3098 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3099 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3100 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3101 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3102 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3103 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3104 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3105 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3106 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3107 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3108 | #endif |
| 3109 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3110 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3111 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3112 | #ifdef USE_ZLIB |
| 3113 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3114 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3115 | #endif |
| 3116 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
| 3117 | info[INF_RUN_QUEUE] = mkf_u32(0, run_queue_cur); |
| 3118 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct); |
| 3119 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3120 | if (global.desc) |
| 3121 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
| 3122 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 3123 | return 1; |
| 3124 | } |
| 3125 | |
| 3126 | /* This function dumps information onto the stream interface's read buffer. |
| 3127 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3128 | * No state is used. |
| 3129 | */ |
| 3130 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
| 3131 | { |
| 3132 | struct appctx *appctx = __objt_appctx(si->end); |
| 3133 | |
| 3134 | if (!stats_fill_info(info, INF_TOTAL_FIELDS)) |
| 3135 | return 0; |
| 3136 | |
Willy Tarreau | 1b4ba1e | 2016-01-11 18:29:04 +0100 | [diff] [blame] | 3137 | chunk_reset(&trash); |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 3138 | |
| 3139 | if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3140 | stats_dump_typed_info_fields(&trash, info); |
| 3141 | else |
| 3142 | stats_dump_info_fields(&trash, info); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3143 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3144 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3145 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3146 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3147 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3148 | |
| 3149 | return 1; |
| 3150 | } |
| 3151 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3152 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 3153 | * These information are all the parameters which may change during HAProxy runtime. |
| 3154 | * By default, we only export to the last known server state file format. |
| 3155 | * These information can be used at next startup to recover same level of server state. |
| 3156 | */ |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3157 | static int dump_servers_state(struct stream_interface *si, struct chunk *buf) |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3158 | { |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3159 | struct appctx *appctx = __objt_appctx(si->end); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3160 | struct server *srv; |
| 3161 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 3162 | time_t srv_time_since_last_change; |
| 3163 | int bk_f_forced_id, srv_f_forced_id; |
| 3164 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3165 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3166 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 3167 | if (appctx->ctx.server_state.px->bind_proc && !(appctx->ctx.server_state.px->bind_proc & (1UL << (relative_pid - 1)))) |
| 3168 | return 1; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3169 | |
Cyril Bonté | d55bd7a | 2016-05-27 00:06:45 +0200 | [diff] [blame] | 3170 | if (!appctx->ctx.server_state.sv) |
| 3171 | appctx->ctx.server_state.sv = appctx->ctx.server_state.px->srv; |
| 3172 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3173 | for (; appctx->ctx.server_state.sv != NULL; appctx->ctx.server_state.sv = srv->next) { |
| 3174 | srv = appctx->ctx.server_state.sv; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3175 | srv_addr[0] = '\0'; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3176 | |
| 3177 | switch (srv->addr.ss_family) { |
| 3178 | case AF_INET: |
| 3179 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 3180 | srv_addr, INET_ADDRSTRLEN + 1); |
| 3181 | break; |
| 3182 | case AF_INET6: |
| 3183 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 3184 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 3185 | break; |
| 3186 | } |
| 3187 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3188 | bk_f_forced_id = appctx->ctx.server_state.px->options & PR_O_FORCED_ID ? 1 : 0; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3189 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 3190 | |
| 3191 | chunk_appendf(buf, |
| 3192 | "%d %s " |
| 3193 | "%d %s %s " |
| 3194 | "%d %d %d %d %ld " |
| 3195 | "%d %d %d %d %d " |
| 3196 | "%d %d" |
| 3197 | "\n", |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3198 | appctx->ctx.server_state.px->uuid, appctx->ctx.server_state.px->id, |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3199 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 3200 | srv->state, srv->admin, srv->uweight, srv->iweight, (long int)srv_time_since_last_change, |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3201 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 3202 | bk_f_forced_id, srv_f_forced_id); |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3203 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3204 | si_applet_cant_put(si); |
| 3205 | return 0; |
| 3206 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3207 | } |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3208 | return 1; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3209 | } |
| 3210 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3211 | /* Parses backend list and simply report backend names */ |
| 3212 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 3213 | { |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 3214 | struct appctx *appctx = __objt_appctx(si->end); |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3215 | extern struct proxy *proxy; |
| 3216 | struct proxy *curproxy; |
| 3217 | |
| 3218 | chunk_reset(&trash); |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3219 | |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 3220 | if (!appctx->ctx.be.px) { |
| 3221 | chunk_printf(&trash, "# name\n"); |
| 3222 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3223 | si_applet_cant_put(si); |
| 3224 | return 0; |
| 3225 | } |
| 3226 | appctx->ctx.be.px = proxy; |
| 3227 | } |
| 3228 | |
| 3229 | for (; appctx->ctx.be.px != NULL; appctx->ctx.be.px = curproxy->next) { |
| 3230 | curproxy = appctx->ctx.be.px; |
| 3231 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3232 | /* looking for backends only */ |
| 3233 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3234 | continue; |
| 3235 | |
| 3236 | /* we don't want to list a backend which is bound to this process */ |
| 3237 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 3238 | continue; |
| 3239 | |
| 3240 | chunk_appendf(&trash, "%s\n", curproxy->id); |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 3241 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3242 | si_applet_cant_put(si); |
| 3243 | return 0; |
| 3244 | } |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | return 1; |
| 3248 | } |
| 3249 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3250 | /* Parses backend list or simply use backend name provided by the user to return |
| 3251 | * states of servers to stdout. |
| 3252 | */ |
| 3253 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 3254 | { |
| 3255 | struct appctx *appctx = __objt_appctx(si->end); |
| 3256 | extern struct proxy *proxy; |
| 3257 | struct proxy *curproxy; |
| 3258 | |
| 3259 | chunk_reset(&trash); |
| 3260 | |
Willy Tarreau | a58c435 | 2016-06-22 14:51:40 +0200 | [diff] [blame] | 3261 | if (appctx->st2 == STAT_ST_INIT) { |
| 3262 | if (!appctx->ctx.server_state.px) |
| 3263 | appctx->ctx.server_state.px = proxy; |
| 3264 | appctx->st2 = STAT_ST_HEAD; |
| 3265 | } |
| 3266 | |
| 3267 | if (appctx->st2 == STAT_ST_HEAD) { |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3268 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3269 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3270 | si_applet_cant_put(si); |
| 3271 | return 0; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3272 | } |
Willy Tarreau | a58c435 | 2016-06-22 14:51:40 +0200 | [diff] [blame] | 3273 | appctx->st2 = STAT_ST_INFO; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3274 | } |
| 3275 | |
Willy Tarreau | a58c435 | 2016-06-22 14:51:40 +0200 | [diff] [blame] | 3276 | /* STAT_ST_INFO */ |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3277 | for (; appctx->ctx.server_state.px != NULL; appctx->ctx.server_state.px = curproxy->next) { |
| 3278 | curproxy = appctx->ctx.server_state.px; |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3279 | /* servers are only in backends */ |
| 3280 | if (curproxy->cap & PR_CAP_BE) { |
| 3281 | if (!dump_servers_state(si, &trash)) |
| 3282 | return 0; |
| 3283 | |
| 3284 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3285 | si_applet_cant_put(si); |
| 3286 | return 0; |
| 3287 | } |
| 3288 | } |
| 3289 | /* only the selected proxy is dumped */ |
| 3290 | if (appctx->ctx.server_state.iid) |
| 3291 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | return 1; |
| 3295 | } |
| 3296 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3297 | /* This function dumps memory usage information onto the stream interface's |
| 3298 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3299 | * completion. No state is used. |
| 3300 | */ |
| 3301 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3302 | { |
| 3303 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3304 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3305 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3306 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3307 | } |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 3308 | return 1; |
| 3309 | } |
| 3310 | |
| 3311 | /* Dump all fields from <stats> into <out> using CSV format */ |
| 3312 | static int stats_dump_fields_csv(struct chunk *out, const struct field *stats) |
| 3313 | { |
| 3314 | int field; |
| 3315 | |
| 3316 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3317 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 3318 | return 0; |
| 3319 | if (!chunk_strcat(out, ",")) |
| 3320 | return 0; |
| 3321 | } |
Conrad Hoffmann | 692c938 | 2016-04-01 20:40:58 +0200 | [diff] [blame] | 3322 | chunk_strcat(out, "\n"); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3323 | return 1; |
| 3324 | } |
| 3325 | |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3326 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
| 3327 | static int stats_dump_fields_typed(struct chunk *out, const struct field *stats) |
| 3328 | { |
| 3329 | int field; |
| 3330 | |
| 3331 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3332 | if (!stats[field].type) |
| 3333 | continue; |
| 3334 | |
| 3335 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 3336 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 3337 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 3338 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 3339 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 3340 | '?', |
| 3341 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 3342 | field, stat_field_names[field], stats[ST_F_PID].u.u32); |
| 3343 | |
| 3344 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 3345 | return 0; |
| 3346 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 3347 | return 0; |
| 3348 | if (!chunk_strcat(out, "\n")) |
| 3349 | return 0; |
| 3350 | } |
| 3351 | return 1; |
| 3352 | } |
| 3353 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3354 | /* Dump all fields from <stats> into <out> using the HTML format. A column is |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3355 | * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info |
| 3356 | * are provided if ST_SHLGNDS is present in <flags>. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3357 | */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3358 | static int stats_dump_fields_html(struct chunk *out, const struct field *stats, unsigned int flags) |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3359 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3360 | struct chunk src; |
| 3361 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3362 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3363 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3364 | /* name, queue */ |
| 3365 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3366 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3367 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3368 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3369 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3370 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3371 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3372 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | "<td class=ac>" |
| 3374 | "<a name=\"%s/Frontend\"></a>" |
| 3375 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3376 | "<td colspan=3></td>" |
| 3377 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3378 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3379 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3380 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3381 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3382 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3383 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3384 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3385 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3386 | U2H(stats[ST_F_RATE].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3387 | U2H(stats[ST_F_CONN_RATE].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3388 | U2H(stats[ST_F_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3389 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3390 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3391 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3392 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3393 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3394 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3395 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3396 | "</table></div></u></td>" |
| 3397 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3398 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3399 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3400 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3401 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3402 | U2H(stats[ST_F_RATE_MAX].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3403 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3404 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3405 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3406 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3407 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3408 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3409 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3410 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3411 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3412 | "</table></div></u></td>" |
| 3413 | /* sessions rate : limit */ |
| 3414 | "<td>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3415 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3416 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3417 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3418 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3419 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3420 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3421 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3422 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3423 | "", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3424 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3425 | U2H(stats[ST_F_STOT].u.u64), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3426 | U2H(stats[ST_F_CONN_TOT].u.u64), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3427 | U2H(stats[ST_F_STOT].u.u64)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3428 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3429 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3430 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3431 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3432 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3433 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3434 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3435 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3436 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3437 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3438 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3439 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3440 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3441 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3442 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3443 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3444 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3445 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3446 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3447 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3448 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3449 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3450 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3451 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3452 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3453 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3454 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3455 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3456 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3457 | /* sessions: lbtot, lastsess */ |
| 3458 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3459 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3460 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3461 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3462 | U2H(stats[ST_F_BIN].u.u64)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3463 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3464 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3465 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3466 | "<td>%s%s<div class=tips><table class=det>" |
| 3467 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3468 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3469 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3470 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3471 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3472 | "</table></div>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3473 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3474 | U2H(stats[ST_F_BOUT].u.u64), |
| 3475 | U2H(stats[ST_F_BOUT].u.u64), |
| 3476 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3477 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3478 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3479 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 3480 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 3481 | 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, |
| 3482 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3483 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3484 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3485 | /* denied: req, resp */ |
| 3486 | "<td>%s</td><td>%s</td>" |
| 3487 | /* errors : request, connect, response */ |
| 3488 | "<td>%s</td><td></td><td></td>" |
| 3489 | /* warnings: retries, redispatches */ |
| 3490 | "<td></td><td></td>" |
| 3491 | /* server status : reflect frontend status */ |
| 3492 | "<td class=ac>%s</td>" |
| 3493 | /* rest of server: nothing */ |
| 3494 | "<td class=ac colspan=8></td></tr>" |
| 3495 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3496 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3497 | U2H(stats[ST_F_EREQ].u.u64), |
| 3498 | field_str(stats, ST_F_STATUS)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3499 | } |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3500 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3501 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3502 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3503 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3504 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3505 | } |
| 3506 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3507 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3508 | /* frontend name, listener name */ |
| 3509 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3510 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3511 | "", |
| 3512 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3513 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3514 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 3515 | |
| 3516 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3517 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3518 | |
| 3519 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3520 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3521 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3522 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3523 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3524 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3525 | |
| 3526 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3527 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3528 | } |
| 3529 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3530 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3531 | /* queue */ |
| 3532 | "%s</td><td colspan=3></td>" |
| 3533 | /* sessions rate: current, max, limit */ |
| 3534 | "<td colspan=3> </td>" |
| 3535 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 3536 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3537 | "<td>%s</td><td> </td><td> </td>" |
| 3538 | /* bytes: in, out */ |
| 3539 | "<td>%s</td><td>%s</td>" |
| 3540 | "", |
| 3541 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3542 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3543 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 3544 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3545 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3546 | /* denied: req, resp */ |
| 3547 | "<td>%s</td><td>%s</td>" |
| 3548 | /* errors: request, connect, response */ |
| 3549 | "<td>%s</td><td></td><td></td>" |
| 3550 | /* warnings: retries, redispatches */ |
| 3551 | "<td></td><td></td>" |
| 3552 | /* server status: reflect listener status */ |
| 3553 | "<td class=ac>%s</td>" |
| 3554 | /* rest of server: nothing */ |
| 3555 | "<td class=ac colspan=8></td></tr>" |
| 3556 | "", |
| 3557 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3558 | U2H(stats[ST_F_EREQ].u.u64), |
| 3559 | field_str(stats, ST_F_STATUS)); |
| 3560 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3561 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 3562 | const char *style; |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3563 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3564 | /* determine the style to use depending on the server's state, |
| 3565 | * its health and weight. There isn't a 1-to-1 mapping between |
| 3566 | * state and styles for the cases where the server is (still) |
| 3567 | * up. The reason is that we don't want to report nolb and |
| 3568 | * drain with the same color. |
| 3569 | */ |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3570 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3571 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 3572 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 3573 | style = "down"; |
| 3574 | } |
| 3575 | else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) { |
| 3576 | style = "going_up"; |
| 3577 | } |
| 3578 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) { |
| 3579 | style = "going_down"; |
| 3580 | } |
| 3581 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 3582 | style = "nolb"; |
| 3583 | } |
| 3584 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 3585 | style = "no_check"; |
| 3586 | } |
| 3587 | else if (!stats[ST_F_CHKFAIL].type || |
| 3588 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 3589 | /* no check or max health = UP */ |
| 3590 | if (stats[ST_F_WEIGHT].u.u32) |
| 3591 | style = "up"; |
| 3592 | else |
| 3593 | style = "draining"; |
| 3594 | } |
| 3595 | else { |
| 3596 | style = "going_down"; |
| 3597 | } |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3598 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3599 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3600 | chunk_appendf(out, "<tr class=\"maintain\">"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3601 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3602 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3603 | "<tr class=\"%s_%s\">", |
| 3604 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3605 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3606 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3607 | if (flags & ST_SHOWADMIN) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3608 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3609 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3610 | field_str(stats, ST_F_SVNAME)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3611 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3612 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3613 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3614 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3615 | "", |
| 3616 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3617 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3618 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3619 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3620 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3621 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3622 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3623 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3624 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3625 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3626 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3627 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3628 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3629 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3630 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3631 | chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3632 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3633 | /* cookie */ |
| 3634 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3635 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3636 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3637 | chunk_htmlencode(out, &src); |
| 3638 | chunk_appendf(out, "'"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3639 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3640 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3641 | chunk_appendf(out, "</div>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3642 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3643 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3644 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3645 | /* queue : current, max, limit */ |
| 3646 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 3647 | /* sessions rate : current, max, limit */ |
| 3648 | "<td>%s</td><td>%s</td><td></td>" |
| 3649 | "", |
| 3650 | (flags & ST_SHLGNDS) ? "</u>" : "", |
| 3651 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 3652 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
Willy Tarreau | 4607fad | 2016-01-06 15:41:29 +0100 | [diff] [blame] | 3653 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3654 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3655 | /* sessions: current, max, limit, total */ |
| 3656 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3657 | "<td><u>%s<div class=tips><table class=det>" |
| 3658 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3659 | "", |
| 3660 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 3661 | U2H(stats[ST_F_STOT].u.u64), |
| 3662 | U2H(stats[ST_F_STOT].u.u64)); |
Willy Tarreau | 4607fad | 2016-01-06 15:41:29 +0100 | [diff] [blame] | 3663 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3664 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3665 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3666 | unsigned long long tot; |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3667 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3668 | tot = stats[ST_F_HRSP_OTHER].u.u64; |
| 3669 | tot += stats[ST_F_HRSP_1XX].u.u64; |
| 3670 | tot += stats[ST_F_HRSP_2XX].u.u64; |
| 3671 | tot += stats[ST_F_HRSP_3XX].u.u64; |
| 3672 | tot += stats[ST_F_HRSP_4XX].u.u64; |
| 3673 | tot += stats[ST_F_HRSP_5XX].u.u64; |
| 3674 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3675 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3676 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3677 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3678 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3679 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3680 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3681 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3682 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3683 | "", |
| 3684 | U2H(tot), |
| 3685 | U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0, |
| 3686 | U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0, |
| 3687 | U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0, |
| 3688 | U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0, |
| 3689 | U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0, |
| 3690 | U2H(stats[ST_F_HRSP_OTHER].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_OTHER].u.u64 / tot) : 0); |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3691 | } |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3692 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3693 | chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3694 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3695 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32)); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3696 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3697 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3698 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32)); |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 3699 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3700 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3701 | "</table></div></u></td>" |
| 3702 | /* sessions: lbtot, last */ |
| 3703 | "<td>%s</td><td>%s</td>", |
| 3704 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3705 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3706 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3707 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3708 | /* bytes : in, out */ |
| 3709 | "<td>%s</td><td>%s</td>" |
| 3710 | /* denied: req, resp */ |
| 3711 | "<td></td><td>%s</td>" |
| 3712 | /* errors : request, connect */ |
| 3713 | "<td></td><td>%s</td>" |
| 3714 | /* errors : response */ |
| 3715 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3716 | /* warnings: retries, redispatches */ |
| 3717 | "<td>%lld</td><td>%lld</td>" |
| 3718 | "", |
| 3719 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 3720 | U2H(stats[ST_F_DRESP].u.u64), |
| 3721 | U2H(stats[ST_F_ECON].u.u64), |
| 3722 | U2H(stats[ST_F_ERESP].u.u64), |
| 3723 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3724 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3725 | (long long)stats[ST_F_WRETR].u.u64, |
| 3726 | (long long)stats[ST_F_WREDIS].u.u64); |
| 3727 | |
| 3728 | /* status, last change */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3729 | chunk_appendf(out, "<td class=ac>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3730 | |
| 3731 | /* FIXME!!!! |
| 3732 | * LASTCHG should contain the last change for *this* server and must be computed |
| 3733 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 3734 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 3735 | */ |
| 3736 | |
| 3737 | |
| 3738 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3739 | chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3740 | } |
| 3741 | else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3742 | chunk_strcat(out, "<i>no check</i>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3743 | } |
| 3744 | else { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3745 | chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3746 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
| 3747 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3748 | chunk_strcat(out, " ↑"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3749 | } |
| 3750 | else if (stats[ST_F_CHECK_HEALTH].u.u32 < stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3751 | chunk_strcat(out, " ↓"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
| 3755 | stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3756 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3757 | "</td><td class=ac><u> %s", |
| 3758 | field_str(stats, ST_F_AGENT_STATUS)); |
| 3759 | |
| 3760 | if (stats[ST_F_AGENT_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3761 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3762 | |
David Carlier | 08d35de | 2016-06-27 14:12:59 +0100 | [diff] [blame] | 3763 | if (stats[ST_F_AGENT_DURATION].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3764 | chunk_appendf(out, " in %lums", (long)stats[ST_F_AGENT_DURATION].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3765 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3766 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_AGENT_DESC)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3767 | |
| 3768 | if (*field_str(stats, ST_F_LAST_AGT)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3769 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3770 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3771 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3772 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3773 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3774 | } |
| 3775 | else if (stats[ST_F_CHECK_STATUS].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3776 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3777 | "</td><td class=ac><u> %s", |
| 3778 | field_str(stats, ST_F_CHECK_STATUS)); |
| 3779 | |
| 3780 | if (stats[ST_F_CHECK_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3781 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3782 | |
David Carlier | 08d35de | 2016-06-27 14:12:59 +0100 | [diff] [blame] | 3783 | if (stats[ST_F_CHECK_DURATION].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3784 | chunk_appendf(out, " in %lums", (long)stats[ST_F_CHECK_DURATION].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3785 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3786 | chunk_appendf(out, "<div class=tips>%s", field_str(stats, ST_F_CHECK_DESC)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3787 | |
| 3788 | if (*field_str(stats, ST_F_LAST_CHK)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3789 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3790 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3791 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3792 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3793 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3794 | } |
| 3795 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3796 | chunk_appendf(out, "</td><td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3797 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3798 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3799 | /* weight */ |
| 3800 | "</td><td class=ac>%d</td>" |
| 3801 | /* act, bck */ |
| 3802 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3803 | "", |
| 3804 | stats[ST_F_WEIGHT].u.u32, |
| 3805 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 3806 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 3807 | |
| 3808 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | b96dd28 | 2016-11-09 14:45:51 +0100 | [diff] [blame] | 3809 | if (strcmp(field_str(stats, ST_F_STATUS), "MAINT (resolution)") == 0) { |
| 3810 | chunk_appendf(out, "<td class=ac colspan=3>resolution</td>"); |
| 3811 | } |
| 3812 | else if (stats[ST_F_CHKFAIL].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3813 | chunk_appendf(out, "<td><u>%lld", (long long)stats[ST_F_CHKFAIL].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3814 | |
| 3815 | if (stats[ST_F_HANAFAIL].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3816 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3817 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3818 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3819 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 3820 | "<td>%lld</td><td>%s</td>" |
| 3821 | "", |
| 3822 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 3823 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 3824 | } |
| 3825 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 3826 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3827 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3828 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 3829 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 3830 | } |
| 3831 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3832 | chunk_appendf(out, "<td colspan=3></td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3833 | |
| 3834 | /* throttle */ |
| 3835 | if (stats[ST_F_THROTTLE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3836 | chunk_appendf(out, "<td class=ac>%d %%</td></tr>\n", stats[ST_F_THROTTLE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3837 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3838 | chunk_appendf(out, "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3839 | } |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3840 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3841 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3842 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3843 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3844 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3845 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3846 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3847 | "<td class=ac>" |
| 3848 | /* name */ |
| 3849 | "%s<a name=\"%s/Backend\"></a>" |
| 3850 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3851 | "", |
| 3852 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3853 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 3854 | |
| 3855 | if (flags & ST_SHLGNDS) { |
| 3856 | /* balancing */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3857 | chunk_appendf(out, "<div class=tips>balancing: %s", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 3858 | field_str(stats, ST_F_ALGO)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3859 | |
| 3860 | /* cookie */ |
| 3861 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3862 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3863 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3864 | chunk_htmlencode(out, &src); |
| 3865 | chunk_appendf(out, "'"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3866 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3867 | chunk_appendf(out, "</div>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3868 | } |
| 3869 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3870 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3871 | "%s</td>" |
| 3872 | /* queue : current, max */ |
| 3873 | "<td>%s</td><td>%s</td><td></td>" |
| 3874 | /* sessions rate : current, max, limit */ |
| 3875 | "<td>%s</td><td>%s</td><td></td>" |
| 3876 | "", |
| 3877 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3878 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 3879 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 3880 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3881 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3882 | /* sessions: current, max, limit, total */ |
| 3883 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3884 | "<td><u>%s<div class=tips><table class=det>" |
| 3885 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3886 | "", |
| 3887 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3888 | U2H(stats[ST_F_STOT].u.u64), |
| 3889 | U2H(stats[ST_F_STOT].u.u64)); |
| 3890 | |
| 3891 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3892 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3893 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3894 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3895 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3896 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3897 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3898 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3899 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3900 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3901 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3902 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3903 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
| 3904 | "", |
| 3905 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3906 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3907 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3908 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3909 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3910 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3911 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3912 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3913 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3914 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3915 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3916 | } |
| 3917 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3918 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
Willy Tarreau | 1f6367f | 2016-10-01 09:12:08 +0200 | [diff] [blame] | 3919 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_CTIME].u.u32)); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3920 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3921 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3922 | chunk_appendf(out, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_TTIME].u.u32)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3923 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3924 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3925 | "</table></div></u></td>" |
| 3926 | /* sessions: lbtot, last */ |
| 3927 | "<td>%s</td><td>%s</td>" |
| 3928 | /* bytes: in */ |
| 3929 | "<td>%s</td>" |
| 3930 | "", |
| 3931 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3932 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 3933 | U2H(stats[ST_F_BIN].u.u64)); |
| 3934 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3935 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3936 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 3937 | "<td>%s%s<div class=tips><table class=det>" |
| 3938 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3939 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3940 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3941 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3942 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3943 | "</table></div>%s</td>", |
| 3944 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3945 | U2H(stats[ST_F_BOUT].u.u64), |
| 3946 | U2H(stats[ST_F_BOUT].u.u64), |
| 3947 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3948 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3949 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3950 | U2H(stats[ST_F_COMP_BYP].u.u64), |
Christopher Faulet | 0b64f62 | 2016-04-28 15:09:31 +0200 | [diff] [blame] | 3951 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3952 | 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, |
| 3953 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 3954 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3955 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3956 | /* denied: req, resp */ |
| 3957 | "<td>%s</td><td>%s</td>" |
| 3958 | /* errors : request, connect */ |
| 3959 | "<td></td><td>%s</td>" |
| 3960 | /* errors : response */ |
| 3961 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3962 | /* warnings: retries, redispatches */ |
| 3963 | "<td>%lld</td><td>%lld</td>" |
| 3964 | /* backend status: reflect backend status (up/down): we display UP |
| 3965 | * if the backend has known working servers or if it has no server at |
| 3966 | * all (eg: for stats). Then we display the total weight, number of |
| 3967 | * active and backups. */ |
| 3968 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3969 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3970 | "", |
| 3971 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3972 | U2H(stats[ST_F_ECON].u.u64), |
| 3973 | U2H(stats[ST_F_ERESP].u.u64), |
| 3974 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3975 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3976 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 3977 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 3978 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
| 3979 | stats[ST_F_WEIGHT].u.u32, |
| 3980 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 3981 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3982 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3983 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3984 | "<td class=ac> </td><td>%d</td>" |
| 3985 | "<td>%s</td>" |
| 3986 | "<td></td>" |
| 3987 | "</tr>", |
| 3988 | stats[ST_F_CHKDOWN].u.u32, |
| 3989 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
| 3990 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3991 | return 1; |
| 3992 | } |
| 3993 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3994 | static int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx) |
| 3995 | { |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3996 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
| 3997 | flags |= ST_SHOWADMIN; |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3998 | |
| 3999 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 4000 | return stats_dump_fields_html(&trash, stats, flags); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 4001 | else if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 4002 | return stats_dump_fields_typed(&trash, stats); |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4003 | else |
| 4004 | return stats_dump_fields_csv(&trash, stats); |
| 4005 | } |
| 4006 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 4007 | /* Fill <stats> with the frontend statistics. <stats> is |
| 4008 | * preallocated array of length <len>. The length of the array |
| 4009 | * must be at least ST_F_TOTAL_FIELDS. If this length is less then |
| 4010 | * this value, the function returns 0, otherwise, it returns 1. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4011 | */ |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 4012 | int stats_fill_fe_stats(struct proxy *px, struct field *stats, int len) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4013 | { |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 4014 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4015 | return 0; |
| 4016 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 4017 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4018 | |
| 4019 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4020 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4021 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4022 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 4023 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 4024 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 4025 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 4026 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 4027 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 4028 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 4029 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 4030 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
Willy Tarreau | 8a90b8e | 2016-10-21 18:15:32 +0200 | [diff] [blame] | 4031 | stats[ST_F_DCON] = mkf_u64(FN_COUNTER, px->fe_counters.denied_conn); |
Willy Tarreau | a5bc36b | 2016-10-21 18:16:27 +0200 | [diff] [blame] | 4032 | stats[ST_F_DSES] = mkf_u64(FN_COUNTER, px->fe_counters.denied_sess); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4033 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); |
| 4034 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4035 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4036 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 4037 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 4038 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 4039 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 4040 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 4041 | |
| 4042 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4043 | if (px->mode == PR_MODE_HTTP) { |
| 4044 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 4045 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 4046 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 4047 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 4048 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 4049 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 4050 | stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->fe_counters.intercepted_req); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 4054 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 4055 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 4056 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 4057 | |
| 4058 | /* compression: in, out, bypassed, responses */ |
| 4059 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 4060 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 4061 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 4062 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 4063 | |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 4064 | /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */ |
| 4065 | stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 4066 | stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 4067 | stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 4068 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 4069 | return 1; |
| 4070 | } |
| 4071 | |
| 4072 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 4073 | * the state from stream interface <si>. The caller is responsible for clearing |
| 4074 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4075 | */ |
| 4076 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
| 4077 | { |
| 4078 | struct appctx *appctx = __objt_appctx(si->end); |
| 4079 | |
| 4080 | if (!(px->cap & PR_CAP_FE)) |
| 4081 | return 0; |
| 4082 | |
| 4083 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 4084 | return 0; |
| 4085 | |
| 4086 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS)) |
| 4087 | return 0; |
| 4088 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4089 | return stats_dump_one_line(stats, 0, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4090 | } |
| 4091 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4092 | /* Fill <stats> with the listener statistics. <stats> is |
| 4093 | * preallocated array of length <len>. The length of the array |
| 4094 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4095 | * then this value, the function returns 0, otherwise, it |
| 4096 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4097 | */ |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4098 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
| 4099 | struct field *stats, int len) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4100 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4101 | struct chunk *out = get_trash_chunk(); |
| 4102 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4103 | if (len < ST_F_TOTAL_FIELDS) |
| 4104 | return 0; |
| 4105 | |
Thierry Fournier | ac9d467 | 2016-03-25 08:43:46 +0100 | [diff] [blame] | 4106 | if (!l->counters) |
| 4107 | return 0; |
| 4108 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4109 | chunk_reset(out); |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4110 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4111 | |
| 4112 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4113 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, l->name); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4114 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4115 | stats[ST_F_SCUR] = mkf_u32(0, l->nbconn); |
| 4116 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max); |
| 4117 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn); |
| 4118 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 4119 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 4120 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 4121 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 4122 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 4123 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req); |
Willy Tarreau | 8a90b8e | 2016-10-21 18:15:32 +0200 | [diff] [blame] | 4124 | stats[ST_F_DCON] = mkf_u64(FN_COUNTER, l->counters->denied_conn); |
Willy Tarreau | a5bc36b | 2016-10-21 18:16:27 +0200 | [diff] [blame] | 4125 | stats[ST_F_DSES] = mkf_u64(FN_COUNTER, l->counters->denied_sess); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4126 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 4127 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4128 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4129 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 4130 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 4131 | |
| 4132 | if (flags & ST_SHLGNDS) { |
| 4133 | char str[INET6_ADDRSTRLEN]; |
| 4134 | int port; |
| 4135 | |
| 4136 | port = get_host_port(&l->addr); |
| 4137 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 4138 | case AF_INET: |
| 4139 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4140 | chunk_appendf(out, "%s:%d", str, port); |
| 4141 | break; |
| 4142 | case AF_INET6: |
| 4143 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4144 | chunk_appendf(out, "[%s]:%d", str, port); |
| 4145 | break; |
| 4146 | case AF_UNIX: |
| 4147 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4148 | break; |
| 4149 | case -1: |
| 4150 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4151 | chunk_strcat(out, strerror(errno)); |
| 4152 | break; |
| 4153 | default: /* address family not supported */ |
| 4154 | break; |
| 4155 | } |
| 4156 | } |
| 4157 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4158 | return 1; |
| 4159 | } |
| 4160 | |
| 4161 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 4162 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 4163 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 4164 | * otherwise. |
| 4165 | */ |
| 4166 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
| 4167 | { |
| 4168 | struct appctx *appctx = __objt_appctx(si->end); |
| 4169 | |
| 4170 | if (!stats_fill_li_stats(px, l, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4171 | return 0; |
| 4172 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4173 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | enum srv_stats_state { |
| 4177 | SRV_STATS_STATE_DOWN = 0, |
| 4178 | SRV_STATS_STATE_DOWN_AGENT, |
| 4179 | SRV_STATS_STATE_GOING_UP, |
| 4180 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 4181 | SRV_STATS_STATE_UP, |
| 4182 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4183 | SRV_STATS_STATE_NOLB, |
| 4184 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 4185 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4186 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4187 | SRV_STATS_STATE_NO_CHECK, |
| 4188 | |
| 4189 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 4190 | }; |
| 4191 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4192 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 4193 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 4194 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 4195 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 4196 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 4197 | [SRV_STATS_STATE_UP] = "UP", |
| 4198 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 4199 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 4200 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 4201 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 4202 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 4203 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 4204 | }; |
| 4205 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4206 | /* Fill <stats> with the server statistics. <stats> is |
| 4207 | * preallocated array of length <len>. The length of the array |
| 4208 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4209 | * then this value, the function returns 0, otherwise, it |
| 4210 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4211 | */ |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4212 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 4213 | struct field *stats, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4214 | { |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4215 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4216 | char str[INET6_ADDRSTRLEN]; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4217 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4218 | enum srv_stats_state state; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4219 | char *fld_status; |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4220 | |
| 4221 | if (len < ST_F_TOTAL_FIELDS) |
| 4222 | return 0; |
| 4223 | |
| 4224 | memset(stats, 0, sizeof(*stats) * len); |
| 4225 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4226 | /* we have "via" which is the tracked server as described in the configuration, |
| 4227 | * and "ref" which is the checked server and the end of the chain. |
| 4228 | */ |
| 4229 | via = sv->track ? sv->track : sv; |
| 4230 | ref = via; |
| 4231 | while (ref->track) |
| 4232 | ref = ref->track; |
| 4233 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4234 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 4235 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 4236 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
| 4237 | state = SRV_STATS_STATE_UP_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4238 | } else { |
| 4239 | state = SRV_STATS_STATE_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4240 | } |
| 4241 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4242 | if (sv->admin & SRV_ADMF_DRAIN) { |
| 4243 | if (ref->agent.state & CHK_ST_ENABLED) |
| 4244 | state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4245 | else if (state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 4246 | state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
| 4247 | else |
| 4248 | state = SRV_STATS_STATE_DRAIN; |
| 4249 | } |
| 4250 | |
| 4251 | if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 4252 | state = SRV_STATS_STATE_NO_CHECK; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4253 | } |
| 4254 | } |
| 4255 | else if (sv->state == SRV_ST_STOPPING) { |
| 4256 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 4257 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
| 4258 | state = SRV_STATS_STATE_NOLB; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4259 | } else { |
| 4260 | state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4261 | } |
| 4262 | } |
| 4263 | else { /* stopped */ |
| 4264 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
| 4265 | state = SRV_STATS_STATE_DOWN_AGENT; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4266 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
| 4267 | state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4268 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
| 4269 | state = SRV_STATS_STATE_GOING_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4270 | } else { |
| 4271 | state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4272 | } |
| 4273 | } |
| 4274 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4275 | chunk_reset(out); |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4276 | |
| 4277 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4278 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, sv->id); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4279 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4280 | stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend); |
| 4281 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 4282 | stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess); |
| 4283 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 4284 | |
| 4285 | if (sv->maxconn) |
| 4286 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 4287 | |
| 4288 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 4289 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 4290 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 4291 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu); |
| 4292 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 4293 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 4294 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 4295 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 4296 | |
| 4297 | /* status */ |
| 4298 | fld_status = chunk_newstr(out); |
Willy Tarreau | b96dd28 | 2016-11-09 14:45:51 +0100 | [diff] [blame] | 4299 | if (sv->admin & SRV_ADMF_RMAINT) |
| 4300 | chunk_appendf(out, "MAINT (resolution)"); |
| 4301 | else if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4302 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 4303 | else if (sv->admin & SRV_ADMF_MAINT) |
| 4304 | chunk_appendf(out, "MAINT"); |
| 4305 | else |
| 4306 | chunk_appendf(out, |
| 4307 | srv_hlt_st[state], |
| 4308 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 4309 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
| 4310 | |
| 4311 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4312 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 4313 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4314 | stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 4315 | stats[ST_F_BCK] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4316 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4317 | /* check failures: unique, fatal; last change, total downtime */ |
| 4318 | if (sv->check.state & CHK_ST_ENABLED) { |
| 4319 | stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 4320 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 4321 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 4322 | } |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4323 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4324 | if (sv->maxqueue) |
| 4325 | stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4326 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4327 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4328 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4329 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4330 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4331 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 4332 | stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4333 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4334 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4335 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4336 | if (sv->track) { |
| 4337 | char *fld_track = chunk_newstr(out); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4338 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4339 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 4340 | stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 4341 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4342 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4343 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 4344 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 4345 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, sv->counters.sps_max); |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4346 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4347 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4348 | const char *fld_chksts; |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4349 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4350 | fld_chksts = chunk_newstr(out); |
| 4351 | chunk_strcat(out, "* "); // for check in progress |
| 4352 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 4353 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 4354 | fld_chksts += 2; // skip "* " |
| 4355 | stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4356 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4357 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 4358 | stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4359 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4360 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 4361 | stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4362 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4363 | stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 4364 | stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc); |
| 4365 | stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 4366 | stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 4367 | stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 4368 | } |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4369 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4370 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4371 | const char *fld_chksts; |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4372 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4373 | fld_chksts = chunk_newstr(out); |
| 4374 | chunk_strcat(out, "* "); // for check in progress |
| 4375 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 4376 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 4377 | fld_chksts += 2; // skip "* " |
| 4378 | stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4379 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4380 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 4381 | stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4383 | if (sv->agent.status >= HCHK_STATUS_CHECKED) |
| 4384 | stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4385 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4386 | stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 4387 | stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 4388 | stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 4389 | stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 4390 | stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 4391 | } |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4392 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4393 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4394 | if (px->mode == PR_MODE_HTTP) { |
| 4395 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 4396 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 4397 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 4398 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 4399 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 4400 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 4401 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4402 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4403 | if (ref->observe) |
| 4404 | stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4405 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4406 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 4407 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 4408 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4409 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4410 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES)); |
| 4411 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES)); |
| 4412 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES)); |
| 4413 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4414 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4415 | if (flags & ST_SHLGNDS) { |
| 4416 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 4417 | case AF_INET: |
| 4418 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4419 | chunk_appendf(out, "%s:%d", str, get_host_port(&sv->addr)); |
| 4420 | break; |
| 4421 | case AF_INET6: |
| 4422 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4423 | chunk_appendf(out, "[%s]:%d", str, get_host_port(&sv->addr)); |
| 4424 | break; |
| 4425 | case AF_UNIX: |
| 4426 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4427 | break; |
| 4428 | case -1: |
| 4429 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4430 | chunk_strcat(out, strerror(errno)); |
| 4431 | break; |
| 4432 | default: /* address family not supported */ |
| 4433 | break; |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 4434 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4435 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4436 | if (sv->cookie) |
| 4437 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 4438 | } |
| 4439 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4440 | return 1; |
| 4441 | } |
| 4442 | |
| 4443 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 4444 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 4445 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 4446 | * if it emits anything, zero otherwise. |
| 4447 | */ |
| 4448 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv) |
| 4449 | { |
| 4450 | struct appctx *appctx = __objt_appctx(si->end); |
| 4451 | |
| 4452 | if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4453 | return 0; |
| 4454 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4455 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4456 | } |
| 4457 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4458 | /* Fill <stats> with the backend statistics. <stats> is |
| 4459 | * preallocated array of length <len>. The length of the array |
| 4460 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4461 | * then this value, the function returns 0, otherwise, it |
| 4462 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4463 | */ |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4464 | int stats_fill_be_stats(struct proxy *px, int flags, struct field *stats, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4465 | { |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4466 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4467 | return 0; |
| 4468 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4469 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4470 | |
| 4471 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4472 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "BACKEND"); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 4473 | stats[ST_F_MODE] = mkf_str(FO_CONFIG|FS_SERVICE, proxy_mode_str(px->mode)); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4474 | stats[ST_F_QCUR] = mkf_u32(0, px->nbpend); |
| 4475 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 4476 | stats[ST_F_SCUR] = mkf_u32(FO_CONFIG|FN_LIMIT, px->beconn); |
| 4477 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 4478 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 4479 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 4480 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 4481 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 4482 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 4483 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 4484 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 4485 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 4486 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 4487 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 4488 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 4489 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4490 | stats[ST_F_ACT] = mkf_u32(0, px->srv_act); |
| 4491 | stats[ST_F_BCK] = mkf_u32(0, px->srv_bck); |
| 4492 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans); |
| 4493 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - px->last_change); |
Willy Tarreau | 7344f47 | 2016-01-11 12:04:02 +0100 | [diff] [blame] | 4494 | if (px->srv) |
| 4495 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 4496 | |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4497 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4498 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4499 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 4500 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 4501 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 4502 | stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 4503 | stats[ST_F_RATE_MAX] = mkf_u32(0, px->be_counters.sps_max); |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 4504 | |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 4505 | if (flags & ST_SHLGNDS) { |
| 4506 | if (px->cookie_name) |
| 4507 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, px->cookie_name); |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 4508 | stats[ST_F_ALGO] = mkf_str(FO_CONFIG|FS_SERVICE, backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 4509 | } |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4510 | |
| 4511 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4512 | if (px->mode == PR_MODE_HTTP) { |
| 4513 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 4514 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 4515 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 4516 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 4517 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 4518 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 4519 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[0]); |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 4520 | stats[ST_F_INTERCEPTED] = mkf_u64(FN_COUNTER, px->be_counters.intercepted_req); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 4524 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 4525 | |
| 4526 | /* compression: in, out, bypassed, responses */ |
| 4527 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 4528 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 4529 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 4530 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 4531 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px)); |
| 4532 | |
| 4533 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES)); |
| 4534 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES)); |
| 4535 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); |
| 4536 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4537 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4538 | return 1; |
| 4539 | } |
| 4540 | |
| 4541 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 4542 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 4543 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4544 | */ |
| 4545 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 4546 | { |
| 4547 | struct appctx *appctx = __objt_appctx(si->end); |
| 4548 | |
| 4549 | if (!(px->cap & PR_CAP_BE)) |
| 4550 | return 0; |
| 4551 | |
| 4552 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 4553 | return 0; |
| 4554 | |
| 4555 | if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4556 | return 0; |
| 4557 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4558 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4559 | } |
| 4560 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4561 | /* Dumps the HTML table header for proxy <px> to the trash for and uses the state from |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4562 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4563 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4564 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4565 | static void stats_dump_html_px_hdr(struct stream_interface *si, struct proxy *px, struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4566 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4567 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4568 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4569 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4570 | if (px->cap & PR_CAP_BE && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4571 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4572 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4573 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4574 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4575 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4576 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4577 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4578 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4579 | } |
| 4580 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4581 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4582 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4583 | } |
| 4584 | |
| 4585 | /* print a new table */ |
| 4586 | chunk_appendf(&trash, |
| 4587 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4588 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4589 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4590 | |
| 4591 | chunk_appendf(&trash, |
| 4592 | "<a name=\"%s\"></a>%s" |
| 4593 | "<a class=px href=\"#%s\">%s</a>", |
| 4594 | px->id, |
| 4595 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4596 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4597 | |
| 4598 | if (uri->flags & ST_SHLGNDS) { |
| 4599 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4600 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4601 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4602 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4603 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4604 | } |
| 4605 | |
| 4606 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4607 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4608 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4609 | "</tr>\n" |
| 4610 | "</table>\n" |
| 4611 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4612 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4613 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4614 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4615 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4616 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4617 | /* Column heading for Enable or Disable server */ |
| 4618 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4619 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4620 | |
| 4621 | chunk_appendf(&trash, |
| 4622 | "<th rowspan=2></th>" |
| 4623 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4624 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4625 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4626 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4627 | "<th colspan=9>Server</th>" |
| 4628 | "</tr>\n" |
| 4629 | "<tr class=\"titre\">" |
| 4630 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4631 | "<th>Cur</th><th>Max</th><th>Limit</th><th>Cur</th><th>Max</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4632 | "<th>Limit</th><th>Total</th><th>LbTot</th><th>Last</th><th>In</th><th>Out</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4633 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4634 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4635 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4636 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4637 | "<th>Thrtle</th>\n" |
| 4638 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4639 | } |
| 4640 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4641 | /* Dumps the HTML table trailer for proxy <px> to the trash for and uses the state from |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4642 | * stream interface <si>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4643 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4644 | static void stats_dump_html_px_end(struct stream_interface *si, struct proxy *px) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4645 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4646 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4647 | chunk_appendf(&trash, "</table>"); |
| 4648 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4649 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4650 | /* close the form used to enable/disable this proxy servers */ |
| 4651 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4652 | "Choose the action to perform on the checked servers : " |
| 4653 | "<select name=action>" |
| 4654 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4655 | "<option value=\"ready\">Set state to READY</option>" |
| 4656 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4657 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4658 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4659 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4660 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4661 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4662 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4663 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4664 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4665 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4666 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4667 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4668 | "</select>" |
| 4669 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4670 | " <input type=\"submit\" value=\"Apply\">" |
| 4671 | "</form>", |
| 4672 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4676 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4677 | |
| 4678 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4679 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4680 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4681 | * buffer space, or non-zero if everything completed. This function is used |
| 4682 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4683 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4684 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4685 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4686 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4687 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4688 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4689 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4690 | struct server *sv, *svs; /* server and server-state, server-state=server or server->track */ |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4691 | struct listener *l; |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4692 | unsigned int flags; |
| 4693 | |
| 4694 | if (uri) |
| 4695 | flags = uri->flags; |
| 4696 | else if (strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) |
| 4697 | flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC; |
| 4698 | else |
| 4699 | flags = ST_SHNODE | ST_SHDESC; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4700 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4701 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4702 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4703 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4704 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4705 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4706 | if (uri && uri->scope) { |
| 4707 | /* we have a limited scope, we have to check the proxy name */ |
| 4708 | struct stat_scope *scope; |
| 4709 | int len; |
| 4710 | |
| 4711 | len = strlen(px->id); |
| 4712 | scope = uri->scope; |
| 4713 | |
| 4714 | while (scope) { |
| 4715 | /* match exact proxy name */ |
| 4716 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4717 | break; |
| 4718 | |
| 4719 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4720 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4721 | break; |
| 4722 | scope = scope->next; |
| 4723 | } |
| 4724 | |
| 4725 | /* proxy name not found : don't dump anything */ |
| 4726 | if (scope == NULL) |
| 4727 | return 1; |
| 4728 | } |
| 4729 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4730 | /* if the user has requested a limited output and the proxy |
| 4731 | * name does not match, skip it. |
| 4732 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4733 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4734 | strnistr(px->id, strlen(px->id), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len) == NULL) |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4735 | return 1; |
| 4736 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4737 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4738 | (appctx->ctx.stats.iid != -1) && |
| 4739 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4740 | return 1; |
| 4741 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4742 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4743 | /* fall through */ |
| 4744 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4745 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4746 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4747 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4748 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4749 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4750 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4751 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4752 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4753 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4754 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4755 | /* fall through */ |
| 4756 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4757 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4758 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4759 | if (stats_dump_fe_stats(si, px)) { |
| 4760 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4761 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4762 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4763 | } |
| 4764 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4765 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4766 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4767 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4768 | /* fall through */ |
| 4769 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4770 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4771 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4772 | for (; appctx->ctx.stats.l != &px->conf.listeners; appctx->ctx.stats.l = l->by_fe.n) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4773 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4774 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4775 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4776 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4777 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4778 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4779 | if (!l->counters) |
| 4780 | continue; |
| 4781 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4782 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4783 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4784 | break; |
| 4785 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4786 | if (appctx->ctx.stats.sid != -1 && l->luid != appctx->ctx.stats.sid) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4787 | continue; |
| 4788 | } |
| 4789 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4790 | /* print the frontend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4791 | if (stats_dump_li_stats(si, px, l, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4792 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4793 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4794 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4795 | } |
| 4796 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4797 | } |
| 4798 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4799 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4800 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4801 | /* fall through */ |
| 4802 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4803 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4804 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4805 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4806 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4807 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4808 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4809 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4810 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4811 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4812 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4813 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4814 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4815 | break; |
| 4816 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4817 | if (appctx->ctx.stats.sid != -1 && sv->puid != appctx->ctx.stats.sid) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4818 | continue; |
| 4819 | } |
| 4820 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4821 | svs = sv; |
| 4822 | while (svs->track) |
| 4823 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4824 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4825 | /* do not report servers which are DOWN and not changing state */ |
| 4826 | if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) && |
| 4827 | ((sv->admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 4828 | (sv->state == SRV_ST_STOPPED && /* server is down */ |
| 4829 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 4830 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 4831 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4832 | continue; |
| 4833 | } |
| 4834 | |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4835 | if (stats_dump_sv_stats(si, px, flags, sv)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4836 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4837 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4838 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4839 | } |
| 4840 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4841 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4842 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4843 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4844 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4845 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4846 | case STAT_PX_ST_BE: |
| 4847 | /* print the backend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4848 | if (stats_dump_be_stats(si, px, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4849 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4850 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4851 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4852 | } |
| 4853 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4854 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4855 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4856 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4857 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4858 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4859 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4860 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4861 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4862 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4863 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4864 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4865 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4866 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4867 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4868 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4869 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4870 | case STAT_PX_ST_FIN: |
| 4871 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4872 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4873 | default: |
| 4874 | /* unknown state, we should put an abort() here ! */ |
| 4875 | return 1; |
| 4876 | } |
| 4877 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4878 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4879 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4880 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4881 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4882 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4883 | { |
| 4884 | /* WARNING! This must fit in the first buffer !!! */ |
| 4885 | chunk_appendf(&trash, |
| 4886 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4887 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4888 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4889 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4890 | "<style type=\"text/css\"><!--\n" |
| 4891 | "body {" |
| 4892 | " font-family: arial, helvetica, sans-serif;" |
| 4893 | " font-size: 12px;" |
| 4894 | " font-weight: normal;" |
| 4895 | " color: black;" |
| 4896 | " background: white;" |
| 4897 | "}\n" |
| 4898 | "th,td {" |
| 4899 | " font-size: 10px;" |
| 4900 | "}\n" |
| 4901 | "h1 {" |
| 4902 | " font-size: x-large;" |
| 4903 | " margin-bottom: 0.5em;" |
| 4904 | "}\n" |
| 4905 | "h2 {" |
| 4906 | " font-family: helvetica, arial;" |
| 4907 | " font-size: x-large;" |
| 4908 | " font-weight: bold;" |
| 4909 | " font-style: italic;" |
| 4910 | " color: #6020a0;" |
| 4911 | " margin-top: 0em;" |
| 4912 | " margin-bottom: 0em;" |
| 4913 | "}\n" |
| 4914 | "h3 {" |
| 4915 | " font-family: helvetica, arial;" |
| 4916 | " font-size: 16px;" |
| 4917 | " font-weight: bold;" |
| 4918 | " color: #b00040;" |
| 4919 | " background: #e8e8d0;" |
| 4920 | " margin-top: 0em;" |
| 4921 | " margin-bottom: 0em;" |
| 4922 | "}\n" |
| 4923 | "li {" |
| 4924 | " margin-top: 0.25em;" |
| 4925 | " margin-right: 2em;" |
| 4926 | "}\n" |
| 4927 | ".hr {margin-top: 0.25em;" |
| 4928 | " border-color: black;" |
| 4929 | " border-bottom-style: solid;" |
| 4930 | "}\n" |
| 4931 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4932 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4933 | ".frontend {background: #e8e8d0;}\n" |
| 4934 | ".socket {background: #d0d0d0;}\n" |
| 4935 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4936 | ".active_down {background: #ff9090;}\n" |
| 4937 | ".active_going_up {background: #ffd020;}\n" |
| 4938 | ".active_going_down {background: #ffffa0;}\n" |
| 4939 | ".active_up {background: #c0ffc0;}\n" |
| 4940 | ".active_nolb {background: #20a0ff;}\n" |
| 4941 | ".active_draining {background: #20a0FF;}\n" |
| 4942 | ".active_no_check {background: #e0e0e0;}\n" |
| 4943 | ".backup_down {background: #ff9090;}\n" |
| 4944 | ".backup_going_up {background: #ff80ff;}\n" |
| 4945 | ".backup_going_down {background: #c060ff;}\n" |
| 4946 | ".backup_up {background: #b0d0ff;}\n" |
| 4947 | ".backup_nolb {background: #90b0e0;}\n" |
| 4948 | ".backup_draining {background: #cc9900;}\n" |
| 4949 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4950 | ".maintain {background: #c07820;}\n" |
| 4951 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4952 | "\n" |
| 4953 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4954 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4955 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4956 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4957 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4958 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4959 | "\n" |
| 4960 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4961 | "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" |
| 4962 | "table.tbl td.ac { text-align: center;}\n" |
| 4963 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4964 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4965 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4966 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4967 | "\n" |
| 4968 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4969 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4970 | "table.lgd td.noborder { border-style: none; padding: 2px; white-space: nowrap;}\n" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4971 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4972 | "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" |
Willy Tarreau | 6b9d3a8 | 2013-12-16 09:00:35 +0100 | [diff] [blame] | 4973 | "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" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4974 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4975 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4976 | " display:block;\n" |
| 4977 | " visibility:hidden;\n" |
| 4978 | " z-index:2147483647;\n" |
| 4979 | " position:absolute;\n" |
| 4980 | " padding:2px 4px 3px;\n" |
| 4981 | " background:#f0f060; color:#000000;\n" |
| 4982 | " border:1px solid #7040c0;\n" |
| 4983 | " white-space:nowrap;\n" |
| 4984 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4985 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4986 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4987 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4988 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4989 | "-->\n" |
| 4990 | "</style></head>\n", |
| 4991 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4992 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4993 | ); |
| 4994 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4995 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4996 | /* Dumps the HTML stats information block to the trash for and uses the state from |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4997 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4998 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4999 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5000 | static void stats_dump_html_info(struct stream_interface *si, struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5001 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5002 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5003 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5004 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 5005 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5006 | /* WARNING! this has to fit the first packet too. |
| 5007 | * We are around 3.5 kB, add adding entries will |
| 5008 | * become tricky if we want to support 4kB buffers ! |
| 5009 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5010 | chunk_appendf(&trash, |
| 5011 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 5012 | PRODUCT_NAME "%s</a></h1>\n" |
| 5013 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 5014 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 5015 | "<h3>> General process information</h3>\n" |
| 5016 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 5017 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 5018 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 5019 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 5020 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 5021 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 5022 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 5023 | "</td><td align=\"center\" nowrap>\n" |
| 5024 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5025 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 5026 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5027 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5028 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 5029 | "<td class=\"backup_going_down\"></td><td class=\"noborder\">backup UP, going down </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5030 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5031 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 5032 | "<td class=\"backup_going_up\"></td><td class=\"noborder\">backup DOWN, going up </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5033 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5034 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 5035 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5036 | "</tr><tr>\n" |
| 5037 | "<td class=\"maintain\"></td><td class=\"noborder\" colspan=\"3\">active or backup DOWN for maintenance (MAINT) </td>" |
Geoff Bucar | cc8bb92 | 2013-04-18 13:53:16 -0700 | [diff] [blame] | 5038 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5039 | "<td class=\"active_draining\"></td><td class=\"noborder\" colspan=\"3\">active or backup SOFT STOPPED for maintenance </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5040 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 5041 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5042 | "</td>" |
| 5043 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 5044 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 5045 | "", |
| 5046 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 5047 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 5048 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 5049 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 5050 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 5051 | pid, relative_pid, global.nbproc, |
| 5052 | up / 86400, (up % 86400) / 3600, |
| 5053 | (up % 3600) / 60, (up % 60), |
| 5054 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 5055 | global.rlimit_memmax ? " MB" : "", |
| 5056 | global.rlimit_nofile, |
| 5057 | global.maxsock, global.maxconn, global.maxpipes, |
| 5058 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 5059 | run_queue_cur, nb_tasks_cur, idle_pct |
| 5060 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5061 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5062 | /* scope_txt = search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5063 | memcpy(scope_txt, bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5064 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5065 | |
| 5066 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 5067 | "<li><form method=\"GET\">Scope : <input value=\"%s\" name=\"" STAT_SCOPE_INPUT_NAME "\" size=\"8\" maxlength=\"%d\" tabindex=\"1\"/></form>\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5068 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5069 | STAT_SCOPE_TXT_MAXLEN); |
| 5070 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5071 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5072 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5073 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5074 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5075 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5076 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5077 | } |
| 5078 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5079 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5080 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5081 | "<li><a href=\"%s%s%s%s\">Show all servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5082 | uri->uri_prefix, |
| 5083 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5084 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5085 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5086 | else |
| 5087 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5088 | "<li><a href=\"%s%s%s%s\">Hide 'DOWN' servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5089 | uri->uri_prefix, |
| 5090 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5091 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5092 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5093 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5094 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5095 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5096 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5097 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5098 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5099 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5100 | "", |
| 5101 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5102 | else |
| 5103 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5104 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5105 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5106 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5107 | ";norefresh", |
| 5108 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5109 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 5110 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5111 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5112 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5113 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5114 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5115 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5116 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 5117 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5118 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5119 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5120 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5121 | (uri->refresh > 0) ? ";norefresh" : "", |
| 5122 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5123 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5124 | chunk_appendf(&trash, |
| 5125 | "</ul></td>" |
| 5126 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 5127 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 5128 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 5129 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 5130 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 5131 | "</ul>" |
| 5132 | "</td>" |
| 5133 | "</tr></table>\n" |
| 5134 | "" |
| 5135 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5136 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5137 | if (appctx->ctx.stats.st_code) { |
| 5138 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5139 | case STAT_STATUS_DONE: |
| 5140 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5141 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5142 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5143 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5144 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5145 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5146 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5147 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5148 | break; |
| 5149 | case STAT_STATUS_NONE: |
| 5150 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5151 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5152 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5153 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5154 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5155 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5156 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5157 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5158 | break; |
| 5159 | case STAT_STATUS_PART: |
| 5160 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5161 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5162 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5163 | "Action partially processed.<br>" |
| 5164 | "Some server names are probably unknown or ambiguous (duplicated names in the backend)." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5165 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5166 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5167 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5168 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5169 | break; |
| 5170 | case STAT_STATUS_ERRP: |
| 5171 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5172 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5173 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5174 | "Action not processed because of invalid parameters." |
| 5175 | "<ul>" |
| 5176 | "<li>The action is maybe unknown.</li>" |
| 5177 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 5178 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 5179 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5180 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5181 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5182 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5183 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5184 | break; |
| 5185 | case STAT_STATUS_EXCD: |
| 5186 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5187 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5188 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5189 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 5190 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5191 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5192 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5193 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5194 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5195 | break; |
| 5196 | case STAT_STATUS_DENY: |
| 5197 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5198 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5199 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5200 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5201 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5202 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5203 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5204 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5205 | break; |
| 5206 | default: |
| 5207 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5208 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5209 | "<a class=lfsb href=\"%s%s%s%s\" title=\"Remove this message\">[X]</a> " |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5210 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5211 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5212 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5213 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5214 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5215 | } |
| 5216 | chunk_appendf(&trash, "<p>\n"); |
| 5217 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5218 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5219 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5220 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 5221 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5222 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5223 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5224 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5225 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5226 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5227 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5228 | /* This function dumps statistics onto the stream interface's read buffer in |
| 5229 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5230 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 5231 | * it had to stop writing data and an I/O is needed, 1 if the dump is finished |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5232 | * and the stream must be closed, or -1 in case of any error. This function is |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5233 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5234 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5235 | static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5236 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5237 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5238 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5239 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5240 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5241 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5242 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5243 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5244 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5245 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5246 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 5247 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5248 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5249 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5250 | stats_dump_html_head(uri); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 5251 | else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED)) |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 5252 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 5253 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5254 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5255 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5256 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5257 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5258 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5259 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5260 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5261 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5262 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5263 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5264 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5265 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5266 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5267 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5268 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5269 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5270 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5271 | appctx->ctx.stats.px = proxy; |
| 5272 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 5273 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5274 | /* fall through */ |
| 5275 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5276 | case STAT_ST_LIST: |
| 5277 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5278 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5279 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5280 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5281 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5282 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5283 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5284 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5285 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5286 | if (px->state != PR_STSTOPPED && px->uuid > 0 && (px->cap & (PR_CAP_FE | PR_CAP_BE))) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5287 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5288 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5289 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5290 | appctx->ctx.stats.px = px->next; |
| 5291 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5292 | } |
| 5293 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5294 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5295 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5296 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5297 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5298 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5299 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5300 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5301 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5302 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5303 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5304 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5305 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5306 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5307 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5308 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5309 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5310 | case STAT_ST_FIN: |
| 5311 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5312 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5313 | default: |
| 5314 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5315 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5316 | return -1; |
| 5317 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5318 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5319 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5320 | /* We reached the stats page through a POST request. The appctx is |
| 5321 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5322 | * Parse the posted data and enable/disable servers if necessary. |
| 5323 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5324 | */ |
| 5325 | static int stats_process_http_post(struct stream_interface *si) |
| 5326 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5327 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5328 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5329 | |
| 5330 | struct proxy *px = NULL; |
| 5331 | struct server *sv = NULL; |
| 5332 | |
| 5333 | char key[LINESIZE]; |
| 5334 | int action = ST_ADM_ACTION_NONE; |
| 5335 | int reprocess = 0; |
| 5336 | |
| 5337 | int total_servers = 0; |
| 5338 | int altered_servers = 0; |
| 5339 | |
| 5340 | char *first_param, *cur_param, *next_param, *end_params; |
| 5341 | char *st_cur_param = NULL; |
| 5342 | char *st_next_param = NULL; |
| 5343 | |
| 5344 | struct chunk *temp; |
| 5345 | int reql; |
| 5346 | |
| 5347 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5348 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5349 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5350 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5351 | goto out; |
| 5352 | } |
| 5353 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5354 | reql = bo_getblk(si_oc(si), temp->str, s->txn->req.body_len, s->txn->req.eoh + 2); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5355 | if (reql <= 0) { |
| 5356 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5357 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5358 | return 0; |
| 5359 | } |
| 5360 | |
| 5361 | first_param = temp->str; |
| 5362 | end_params = temp->str + reql; |
| 5363 | cur_param = next_param = end_params; |
| 5364 | *end_params = '\0'; |
| 5365 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5366 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5367 | |
| 5368 | /* |
| 5369 | * Parse the parameters in reverse order to only store the last value. |
| 5370 | * From the html form, the backend and the action are at the end. |
| 5371 | */ |
| 5372 | while (cur_param > first_param) { |
| 5373 | char *value; |
| 5374 | int poffset, plen; |
| 5375 | |
| 5376 | cur_param--; |
| 5377 | |
| 5378 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5379 | reprocess_servers: |
| 5380 | /* Parse the key */ |
| 5381 | poffset = (cur_param != first_param ? 1 : 0); |
| 5382 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5383 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5384 | strncpy(key, cur_param + poffset, plen); |
| 5385 | key[plen - 1] = '\0'; |
| 5386 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5387 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5388 | goto out; |
| 5389 | } |
| 5390 | |
| 5391 | /* Parse the value */ |
| 5392 | value = key; |
| 5393 | while (*value != '\0' && *value != '=') { |
| 5394 | value++; |
| 5395 | } |
| 5396 | if (*value == '=') { |
| 5397 | /* Ok, a value is found, we can mark the end of the key */ |
| 5398 | *value++ = '\0'; |
| 5399 | } |
| 5400 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5401 | break; |
| 5402 | |
| 5403 | /* Now we can check the key to see what to do */ |
| 5404 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5405 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5406 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5407 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5408 | goto out; |
| 5409 | } |
| 5410 | } |
| 5411 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5412 | if (strcmp(value, "ready") == 0) { |
| 5413 | action = ST_ADM_ACTION_READY; |
| 5414 | } |
| 5415 | else if (strcmp(value, "drain") == 0) { |
| 5416 | action = ST_ADM_ACTION_DRAIN; |
| 5417 | } |
| 5418 | else if (strcmp(value, "maint") == 0) { |
| 5419 | action = ST_ADM_ACTION_MAINT; |
| 5420 | } |
| 5421 | else if (strcmp(value, "shutdown") == 0) { |
| 5422 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5423 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5424 | else if (strcmp(value, "dhlth") == 0) { |
| 5425 | action = ST_ADM_ACTION_DHLTH; |
| 5426 | } |
| 5427 | else if (strcmp(value, "ehlth") == 0) { |
| 5428 | action = ST_ADM_ACTION_EHLTH; |
| 5429 | } |
| 5430 | else if (strcmp(value, "hrunn") == 0) { |
| 5431 | action = ST_ADM_ACTION_HRUNN; |
| 5432 | } |
| 5433 | else if (strcmp(value, "hnolb") == 0) { |
| 5434 | action = ST_ADM_ACTION_HNOLB; |
| 5435 | } |
| 5436 | else if (strcmp(value, "hdown") == 0) { |
| 5437 | action = ST_ADM_ACTION_HDOWN; |
| 5438 | } |
| 5439 | else if (strcmp(value, "dagent") == 0) { |
| 5440 | action = ST_ADM_ACTION_DAGENT; |
| 5441 | } |
| 5442 | else if (strcmp(value, "eagent") == 0) { |
| 5443 | action = ST_ADM_ACTION_EAGENT; |
| 5444 | } |
| 5445 | else if (strcmp(value, "arunn") == 0) { |
| 5446 | action = ST_ADM_ACTION_ARUNN; |
| 5447 | } |
| 5448 | else if (strcmp(value, "adown") == 0) { |
| 5449 | action = ST_ADM_ACTION_ADOWN; |
| 5450 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5451 | /* else these are the old supported methods */ |
| 5452 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5453 | action = ST_ADM_ACTION_DISABLE; |
| 5454 | } |
| 5455 | else if (strcmp(value, "enable") == 0) { |
| 5456 | action = ST_ADM_ACTION_ENABLE; |
| 5457 | } |
| 5458 | else if (strcmp(value, "stop") == 0) { |
| 5459 | action = ST_ADM_ACTION_STOP; |
| 5460 | } |
| 5461 | else if (strcmp(value, "start") == 0) { |
| 5462 | action = ST_ADM_ACTION_START; |
| 5463 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5464 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5465 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5466 | goto out; |
| 5467 | } |
| 5468 | } |
| 5469 | else if (strcmp(key, "s") == 0) { |
| 5470 | if (!(px && action)) { |
| 5471 | /* |
| 5472 | * Indicates that we'll need to reprocess the parameters |
| 5473 | * as soon as backend and action are known |
| 5474 | */ |
| 5475 | if (!reprocess) { |
| 5476 | st_cur_param = cur_param; |
| 5477 | st_next_param = next_param; |
| 5478 | } |
| 5479 | reprocess = 1; |
| 5480 | } |
| 5481 | else if ((sv = findserver(px, value)) != NULL) { |
| 5482 | switch (action) { |
| 5483 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5484 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5485 | altered_servers++; |
| 5486 | total_servers++; |
Willy Tarreau | 8b42848 | 2016-11-07 15:53:43 +0100 | [diff] [blame] | 5487 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT, "'disable' on stats page"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5488 | } |
| 5489 | break; |
| 5490 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5491 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5492 | altered_servers++; |
| 5493 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5494 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5495 | } |
| 5496 | break; |
| 5497 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5498 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
Willy Tarreau | 8b42848 | 2016-11-07 15:53:43 +0100 | [diff] [blame] | 5499 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN, "'stop' on stats page"); |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5500 | altered_servers++; |
| 5501 | total_servers++; |
| 5502 | } |
| 5503 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5504 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5505 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5506 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5507 | altered_servers++; |
| 5508 | total_servers++; |
| 5509 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5510 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5511 | case ST_ADM_ACTION_DHLTH: |
| 5512 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5513 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5514 | altered_servers++; |
| 5515 | total_servers++; |
| 5516 | } |
| 5517 | break; |
| 5518 | case ST_ADM_ACTION_EHLTH: |
| 5519 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5520 | sv->check.state |= CHK_ST_ENABLED; |
| 5521 | altered_servers++; |
| 5522 | total_servers++; |
| 5523 | } |
| 5524 | break; |
| 5525 | case ST_ADM_ACTION_HRUNN: |
| 5526 | if (!(sv->track)) { |
| 5527 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5528 | srv_set_running(sv, "changed from Web interface"); |
| 5529 | altered_servers++; |
| 5530 | total_servers++; |
| 5531 | } |
| 5532 | break; |
| 5533 | case ST_ADM_ACTION_HNOLB: |
| 5534 | if (!(sv->track)) { |
| 5535 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5536 | srv_set_stopping(sv, "changed from Web interface"); |
| 5537 | altered_servers++; |
| 5538 | total_servers++; |
| 5539 | } |
| 5540 | break; |
| 5541 | case ST_ADM_ACTION_HDOWN: |
| 5542 | if (!(sv->track)) { |
| 5543 | sv->check.health = 0; |
| 5544 | srv_set_stopped(sv, "changed from Web interface"); |
| 5545 | altered_servers++; |
| 5546 | total_servers++; |
| 5547 | } |
| 5548 | break; |
| 5549 | case ST_ADM_ACTION_DAGENT: |
| 5550 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5551 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5552 | altered_servers++; |
| 5553 | total_servers++; |
| 5554 | } |
| 5555 | break; |
| 5556 | case ST_ADM_ACTION_EAGENT: |
| 5557 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5558 | sv->agent.state |= CHK_ST_ENABLED; |
| 5559 | altered_servers++; |
| 5560 | total_servers++; |
| 5561 | } |
| 5562 | break; |
| 5563 | case ST_ADM_ACTION_ARUNN: |
| 5564 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5565 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5566 | srv_set_running(sv, "changed from Web interface"); |
| 5567 | altered_servers++; |
| 5568 | total_servers++; |
| 5569 | } |
| 5570 | break; |
| 5571 | case ST_ADM_ACTION_ADOWN: |
| 5572 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5573 | sv->agent.health = 0; |
| 5574 | srv_set_stopped(sv, "changed from Web interface"); |
| 5575 | altered_servers++; |
| 5576 | total_servers++; |
| 5577 | } |
| 5578 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5579 | case ST_ADM_ACTION_READY: |
| 5580 | srv_adm_set_ready(sv); |
| 5581 | altered_servers++; |
| 5582 | total_servers++; |
| 5583 | break; |
| 5584 | case ST_ADM_ACTION_DRAIN: |
| 5585 | srv_adm_set_drain(sv); |
| 5586 | altered_servers++; |
| 5587 | total_servers++; |
| 5588 | break; |
| 5589 | case ST_ADM_ACTION_MAINT: |
| 5590 | srv_adm_set_maint(sv); |
| 5591 | altered_servers++; |
| 5592 | total_servers++; |
| 5593 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5594 | case ST_ADM_ACTION_SHUTDOWN: |
| 5595 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5596 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5597 | |
| 5598 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5599 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5600 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5601 | |
| 5602 | altered_servers++; |
| 5603 | total_servers++; |
| 5604 | } |
| 5605 | break; |
| 5606 | } |
| 5607 | } else { |
| 5608 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5609 | total_servers++; |
| 5610 | } |
| 5611 | } |
| 5612 | if (reprocess && px && action) { |
| 5613 | /* Now, we know the backend and the action chosen by the user. |
| 5614 | * We can safely restart from the first server parameter |
| 5615 | * to reprocess them |
| 5616 | */ |
| 5617 | cur_param = st_cur_param; |
| 5618 | next_param = st_next_param; |
| 5619 | reprocess = 0; |
| 5620 | goto reprocess_servers; |
| 5621 | } |
| 5622 | |
| 5623 | next_param = cur_param; |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5628 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5629 | } |
| 5630 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5631 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5632 | } |
| 5633 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5634 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5635 | } |
| 5636 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5637 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5638 | } |
| 5639 | out: |
| 5640 | return 1; |
| 5641 | } |
| 5642 | |
| 5643 | |
| 5644 | static int stats_send_http_headers(struct stream_interface *si) |
| 5645 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5646 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5647 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5648 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5649 | |
| 5650 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5651 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5652 | "Cache-Control: no-cache\r\n" |
| 5653 | "Connection: close\r\n" |
| 5654 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5655 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5656 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5657 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5658 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5659 | uri->refresh); |
| 5660 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5661 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5662 | |
| 5663 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5664 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5665 | else |
| 5666 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5667 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5668 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5669 | s->logs.tv_request = now; |
| 5670 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5671 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5672 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5673 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5674 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5675 | |
| 5676 | return 1; |
| 5677 | } |
| 5678 | |
| 5679 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5680 | { |
| 5681 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5682 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5683 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5684 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5685 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5686 | /* scope_txt = search pattern + search query, appctx->ctx.stats.scope_len is always <= STAT_SCOPE_TXT_MAXLEN */ |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5687 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5688 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5689 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5690 | memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), bo_ptr(si_ob(si)) + appctx->ctx.stats.scope_str, appctx->ctx.stats.scope_len); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5691 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5692 | } |
| 5693 | |
| 5694 | /* We don't want to land on the posted stats page because a refresh will |
| 5695 | * repost the data. We don't want this to happen on accident so we redirect |
| 5696 | * the browse to the stats page with a GET. |
| 5697 | */ |
| 5698 | chunk_printf(&trash, |
| 5699 | "HTTP/1.1 303 See Other\r\n" |
| 5700 | "Cache-Control: no-cache\r\n" |
| 5701 | "Content-Type: text/plain\r\n" |
| 5702 | "Connection: close\r\n" |
| 5703 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5704 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5705 | "\r\n", |
| 5706 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5707 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5708 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5709 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5710 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5711 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5712 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5713 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5714 | scope_txt); |
| 5715 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5716 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5717 | s->logs.tv_request = now; |
| 5718 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5719 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5720 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5721 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5722 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5723 | |
| 5724 | return 1; |
| 5725 | } |
| 5726 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5727 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5728 | * used to send HTTP stats over a TCP socket. The mechanism is very simple. |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5729 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5730 | * automatically unregisters itself once transfer is complete. |
| 5731 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5732 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5733 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5734 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5735 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5736 | struct channel *req = si_oc(si); |
| 5737 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5738 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5739 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5740 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5741 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5742 | /* check that the output is not closed */ |
| 5743 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5744 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5745 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5746 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5747 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5748 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5749 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5750 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5751 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5752 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5753 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5754 | } |
| 5755 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5756 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5757 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5758 | unsigned int data_len; |
| 5759 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5760 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5761 | |
| 5762 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5763 | /* One difficulty we're facing is that we must prevent |
| 5764 | * the input data from being automatically forwarded to |
| 5765 | * the output area. For this, we temporarily disable |
| 5766 | * forwarding on the channel. |
| 5767 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5768 | last_fwd = si_ic(si)->to_forward; |
| 5769 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5770 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5771 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5772 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5773 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5774 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5775 | } |
| 5776 | } |
| 5777 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5778 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5779 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5780 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5781 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5782 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5783 | |
| 5784 | /* Now we must either adjust or remove the chunk size. This is |
| 5785 | * not easy because the chunk size might wrap at the end of the |
| 5786 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5787 | * the size, then restore the buffer's contents. Note that we can |
| 5788 | * only do that because no forwarding is scheduled on the stats |
| 5789 | * applet. |
| 5790 | */ |
| 5791 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5792 | si_ic(si)->total -= (last_len - prev_len); |
| 5793 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5794 | |
| 5795 | if (last_len != data_len) { |
| 5796 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5797 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5798 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5799 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5800 | si_ic(si)->total += (last_len - data_len); |
| 5801 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5802 | } |
| 5803 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5804 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5805 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5806 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5807 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5808 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5809 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5810 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5811 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5812 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5813 | } |
| 5814 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5815 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5816 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5817 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5818 | } |
| 5819 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5820 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5821 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5822 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5823 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5824 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5825 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5826 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5827 | } |
| 5828 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5829 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5830 | res->flags |= CF_READ_NULL; |
| 5831 | si_shutr(si); |
| 5832 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5833 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5834 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5835 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5837 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5838 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5839 | si_shutr(si); |
| 5840 | res->flags |= CF_READ_NULL; |
| 5841 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5842 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5843 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5844 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5845 | } |
| 5846 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5847 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5848 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5849 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5850 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5851 | return "NONE"; |
| 5852 | return conn->ctrl->name; |
| 5853 | } |
| 5854 | |
| 5855 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5856 | { |
| 5857 | static char ptr[17]; |
| 5858 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5859 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5860 | return "NONE"; |
| 5861 | |
| 5862 | if (conn->xprt == &raw_sock) |
| 5863 | return "RAW"; |
| 5864 | |
| 5865 | #ifdef USE_OPENSSL |
| 5866 | if (conn->xprt == &ssl_sock) |
| 5867 | return "SSL"; |
| 5868 | #endif |
| 5869 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5870 | return ptr; |
| 5871 | } |
| 5872 | |
| 5873 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5874 | { |
| 5875 | static char ptr[17]; |
| 5876 | |
| 5877 | if (!conn->data) |
| 5878 | return "NONE"; |
| 5879 | |
| 5880 | if (conn->data == &sess_conn_cb) |
| 5881 | return "SESS"; |
| 5882 | |
| 5883 | if (conn->data == &si_conn_cb) |
| 5884 | return "STRM"; |
| 5885 | |
| 5886 | if (conn->data == &check_conn_cb) |
| 5887 | return "CHCK"; |
| 5888 | |
| 5889 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5890 | return ptr; |
| 5891 | } |
| 5892 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5893 | /* This function dumps a complete stream state onto the stream interface's |
| 5894 | * read buffer. The stream has to be set in sess->target. It returns |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 5895 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5896 | * non-zero. It is designed to be called from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5897 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5898 | static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5899 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5900 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5901 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5902 | extern const char *monthname[12]; |
| 5903 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5904 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5905 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5906 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5907 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5908 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5909 | if (appctx->ctx.sess.section > 0 && appctx->ctx.sess.uid != sess->uniq_id) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5910 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5911 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5912 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5913 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5914 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5915 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5916 | appctx->ctx.sess.uid = 0; |
| 5917 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5918 | return 1; |
| 5919 | } |
| 5920 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5921 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5922 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5923 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5924 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5925 | /* fall through */ |
| 5926 | |
| 5927 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5928 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5929 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5930 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5931 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5932 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5933 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(sess->logs.accept_date.tv_usec), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5934 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5935 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5936 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5937 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5938 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5939 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5940 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5941 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5942 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5943 | break; |
| 5944 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5945 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5946 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5947 | default: |
| 5948 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5949 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5950 | break; |
| 5951 | } |
| 5952 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5953 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5954 | " flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p\n", |
Willy Tarreau | ee28de0 | 2010-06-01 09:51:00 +0200 | [diff] [blame] | 5955 | sess->flags, sess->si[1].conn_retries, sess->srv_conn, sess->pend_pos); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5956 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5957 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5958 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5959 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5960 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5961 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5962 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5963 | if (conn) |
| 5964 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5965 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5966 | switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5967 | case AF_INET: |
| 5968 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5969 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5970 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5971 | break; |
| 5972 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5973 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5974 | break; |
| 5975 | default: |
| 5976 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5977 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5978 | break; |
| 5979 | } |
| 5980 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5981 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5982 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5983 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5984 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5985 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5986 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5987 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5988 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5989 | conn = objt_conn(sess->si[1].end); |
| 5990 | if (conn) |
| 5991 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5992 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5993 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5994 | case AF_INET: |
| 5995 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5996 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5997 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5998 | break; |
| 5999 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6000 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6001 | break; |
| 6002 | default: |
| 6003 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6004 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6005 | break; |
| 6006 | } |
| 6007 | |
| 6008 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6009 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6010 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6011 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 6012 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6013 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6014 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6015 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6016 | if (conn) |
| 6017 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6018 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6019 | switch (conn ? addr_to_str(&conn->addr.to, pn, sizeof(pn)) : AF_UNSPEC) { |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6020 | case AF_INET: |
| 6021 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6022 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6023 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6024 | break; |
| 6025 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6026 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6027 | break; |
| 6028 | default: |
| 6029 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6030 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 6031 | break; |
| 6032 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6033 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6034 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6035 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6036 | sess->task, |
| 6037 | sess->task->state, |
| 6038 | sess->task->nice, sess->task->calls, |
| 6039 | sess->task->expire ? |
| 6040 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 6041 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 6042 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 6043 | task_in_rq(sess->task) ? ", running" : ""); |
| 6044 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6045 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6046 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6047 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 6048 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6049 | if (sess->txn) |
| 6050 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 6051 | " txn=%p flags=0x%x meth=%d status=%d req.st=%s rsp.st=%s waiting=%d\n", |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6052 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 6053 | http_msg_state_str(sess->txn->req.msg_state), http_msg_state_str(sess->txn->rsp.msg_state), !LIST_ISEMPTY(&sess->buffer_wait)); |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6054 | |
| 6055 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 6056 | " si[0]=%p (state=%s flags=0x%02x endp0=%s:%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6057 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6058 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6059 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6060 | obj_type_name(sess->si[0].end), |
| 6061 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6062 | sess->si[0].exp ? |
| 6063 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 6064 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 6065 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 6066 | sess->si[0].err_type); |
| 6067 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6068 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 6069 | " si[1]=%p (state=%s flags=0x%02x endp1=%s:%p exp=%s, et=0x%03x)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6070 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6071 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6072 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6073 | obj_type_name(sess->si[1].end), |
| 6074 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6075 | sess->si[1].exp ? |
| 6076 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 6077 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 6078 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 6079 | sess->si[1].err_type); |
| 6080 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6081 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6082 | chunk_appendf(&trash, |
| 6083 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6084 | conn, |
| 6085 | get_conn_ctrl_name(conn), |
| 6086 | get_conn_xprt_name(conn), |
| 6087 | get_conn_data_name(conn), |
| 6088 | obj_type_name(conn->target), |
| 6089 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6090 | |
Willy Tarreau | 733b132 | 2016-11-17 14:22:52 +0100 | [diff] [blame] | 6091 | chunk_appendf(&trash, " flags=0x%08x", conn->flags); |
| 6092 | |
| 6093 | if (conn->t.sock.fd >= 0) { |
| 6094 | chunk_appendf(&trash, " fd=%d fd.state=%02x fd.cache=%d updt=%d\n", |
| 6095 | conn->t.sock.fd, fdtab[conn->t.sock.fd].state, |
| 6096 | fdtab[conn->t.sock.fd].cache, fdtab[conn->t.sock.fd].updated); |
| 6097 | } |
| 6098 | else |
| 6099 | chunk_appendf(&trash, " fd=<dead>\n"); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6100 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6101 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 6102 | chunk_appendf(&trash, |
| 6103 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6104 | tmpctx, |
| 6105 | tmpctx->st0, |
| 6106 | tmpctx->st1, |
| 6107 | tmpctx->st2, |
| 6108 | tmpctx->applet->name); |
| 6109 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 6110 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6111 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6112 | chunk_appendf(&trash, |
| 6113 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6114 | conn, |
| 6115 | get_conn_ctrl_name(conn), |
| 6116 | get_conn_xprt_name(conn), |
| 6117 | get_conn_data_name(conn), |
| 6118 | obj_type_name(conn->target), |
| 6119 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6120 | |
Willy Tarreau | 733b132 | 2016-11-17 14:22:52 +0100 | [diff] [blame] | 6121 | chunk_appendf(&trash, " flags=0x%08x", conn->flags); |
| 6122 | |
| 6123 | if (conn->t.sock.fd >= 0) { |
| 6124 | chunk_appendf(&trash, " fd=%d fd.state=%02x fd.cache=%d updt=%d\n", |
| 6125 | conn->t.sock.fd, fdtab[conn->t.sock.fd].state, |
| 6126 | fdtab[conn->t.sock.fd].cache, fdtab[conn->t.sock.fd].updated); |
| 6127 | } |
| 6128 | else |
| 6129 | chunk_appendf(&trash, " fd=<dead>\n"); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6130 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6131 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 6132 | chunk_appendf(&trash, |
| 6133 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6134 | tmpctx, |
| 6135 | tmpctx->st0, |
| 6136 | tmpctx->st1, |
| 6137 | tmpctx->st2, |
| 6138 | tmpctx->applet->name); |
| 6139 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6140 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6141 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6142 | " req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6143 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6144 | &sess->req, |
| 6145 | sess->req.flags, sess->req.analysers, |
| 6146 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 6147 | sess->req.to_forward, sess->req.total, |
| 6148 | sess->req.analyse_exp ? |
| 6149 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6150 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6151 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6152 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6153 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6154 | sess->req.rex ? |
| 6155 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6156 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6157 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6158 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6159 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6160 | " buf=%p data=%p o=%d p=%d req.next=%d i=%d size=%d\n", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6161 | sess->req.wex ? |
| 6162 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6163 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6164 | sess->req.buf, |
| 6165 | sess->req.buf->data, sess->req.buf->o, |
| 6166 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6167 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6168 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6169 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6170 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6171 | " res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6172 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6173 | &sess->res, |
| 6174 | sess->res.flags, sess->res.analysers, |
| 6175 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 6176 | sess->res.to_forward, sess->res.total, |
| 6177 | sess->res.analyse_exp ? |
| 6178 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6179 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6180 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6181 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6182 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6183 | sess->res.rex ? |
| 6184 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6185 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6186 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6187 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6188 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6189 | " buf=%p data=%p o=%d p=%d rsp.next=%d i=%d size=%d\n", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6190 | sess->res.wex ? |
| 6191 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6192 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6193 | sess->res.buf, |
| 6194 | sess->res.buf->data, sess->res.buf->o, |
| 6195 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6196 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6197 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6198 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6199 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6200 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6201 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6202 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6203 | |
| 6204 | /* use other states to dump the contents */ |
| 6205 | } |
| 6206 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6207 | appctx->ctx.sess.uid = 0; |
| 6208 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6209 | return 1; |
| 6210 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6211 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6212 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 6213 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 6214 | struct appctx *appctx = __objt_appctx(si->end); |
| 6215 | |
| 6216 | switch (appctx->st2) { |
| 6217 | case STAT_ST_INIT: |
| 6218 | /* Display the column headers. If the message cannot be sent, |
| 6219 | * quit the fucntion with returning 0. The function is called |
| 6220 | * later and restart at the state "STAT_ST_INIT". |
| 6221 | */ |
| 6222 | chunk_reset(&trash); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6223 | |
| 6224 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT) |
| 6225 | chunk_appendf(&trash, "# id secret\n"); |
| 6226 | else |
| 6227 | chunk_appendf(&trash, "# id (file)\n"); |
| 6228 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6229 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6230 | si_applet_cant_put(si); |
| 6231 | return 0; |
| 6232 | } |
| 6233 | |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6234 | appctx->ctx.tlskeys.dump_keys_index = 0; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6235 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6236 | /* Now, we start the browsing of the references lists. |
| 6237 | * Note that the following call to LIST_ELEM return bad pointer. The only |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 6238 | * available field of this pointer is <list>. It is used with the function |
| 6239 | * tlskeys_list_get_next() for retruning the first available entry |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6240 | */ |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6241 | if (appctx->ctx.tlskeys.ref == NULL) { |
| 6242 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 6243 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6244 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6245 | |
| 6246 | appctx->st2 = STAT_ST_LIST; |
| 6247 | /* fall through */ |
| 6248 | |
| 6249 | case STAT_ST_LIST: |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6250 | while (appctx->ctx.tlskeys.ref) { |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6251 | int head = appctx->ctx.tlskeys.ref->tls_ticket_enc_index; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6252 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6253 | chunk_reset(&trash); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6254 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT && appctx->ctx.tlskeys.dump_keys_index == 0) |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6255 | chunk_appendf(&trash, "# "); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6256 | if (appctx->ctx.tlskeys.dump_keys_index == 0) |
| 6257 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 6258 | appctx->ctx.tlskeys.ref->filename); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6259 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT) { |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6260 | while (appctx->ctx.tlskeys.dump_keys_index < TLS_TICKETS_NO) { |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6261 | struct chunk *t2 = get_trash_chunk(); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6262 | |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6263 | chunk_reset(t2); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6264 | /* should never fail here because we dump only a key in the t2 buffer */ |
| 6265 | t2->len = a2base64((char *)(appctx->ctx.tlskeys.ref->tlskeys + (head + 2 + appctx->ctx.tlskeys.dump_keys_index) % TLS_TICKETS_NO), |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6266 | sizeof(struct tls_sess_key), t2->str, t2->size); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6267 | chunk_appendf(&trash, "%d.%d %s\n", appctx->ctx.tlskeys.ref->unique_id, appctx->ctx.tlskeys.dump_keys_index, t2->str); |
| 6268 | |
| 6269 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6270 | /* let's try again later from this stream. We add ourselves into |
| 6271 | * this stream's users so that it can remove us upon termination. |
| 6272 | */ |
| 6273 | si_applet_cant_put(si); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6274 | return 0; |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6275 | } |
| 6276 | appctx->ctx.tlskeys.dump_keys_index++; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6277 | } |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6278 | appctx->ctx.tlskeys.dump_keys_index = 0; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6279 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6280 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6281 | /* let's try again later from this stream. We add ourselves into |
| 6282 | * this stream's users so that it can remove us upon termination. |
| 6283 | */ |
| 6284 | si_applet_cant_put(si); |
| 6285 | return 0; |
| 6286 | } |
| 6287 | |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6288 | if (appctx->ctx.tlskeys.dump_all == 0) /* don't display everything if not necessary */ |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6289 | break; |
| 6290 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6291 | /* get next list entry and check the end of the list */ |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6292 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6293 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6294 | } |
| 6295 | |
| 6296 | appctx->st2 = STAT_ST_FIN; |
| 6297 | /* fall through */ |
| 6298 | |
| 6299 | default: |
| 6300 | appctx->st2 = STAT_ST_FIN; |
| 6301 | return 1; |
| 6302 | } |
| 6303 | return 0; |
| 6304 | } |
| 6305 | #endif |
| 6306 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6307 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6308 | { |
| 6309 | struct appctx *appctx = __objt_appctx(si->end); |
| 6310 | |
| 6311 | switch (appctx->st2) { |
| 6312 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6313 | /* Display the column headers. If the message cannot be sent, |
| 6314 | * quit the fucntion with returning 0. The function is called |
| 6315 | * later and restart at the state "STAT_ST_INIT". |
| 6316 | */ |
| 6317 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 6318 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6319 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6320 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6321 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6322 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6323 | |
| 6324 | /* Now, we start the browsing of the references lists. |
| 6325 | * Note that the following call to LIST_ELEM return bad pointer. The only |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 6326 | * available field of this pointer is <list>. It is used with the function |
| 6327 | * pat_list_get_next() for retruning the first available entry |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6328 | */ |
| 6329 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6330 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6331 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6332 | appctx->st2 = STAT_ST_LIST; |
| 6333 | /* fall through */ |
| 6334 | |
| 6335 | case STAT_ST_LIST: |
| 6336 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6337 | chunk_reset(&trash); |
| 6338 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6339 | /* Build messages. If the reference is used by another category than |
| 6340 | * the listed categorie, display the information in the massage. |
| 6341 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6342 | chunk_appendf(&trash, "%d (%s) %s\n", appctx->ctx.map.ref->unique_id, |
Thierry FOURNIER | 0d6ba51 | 2014-02-11 03:31:34 +0100 | [diff] [blame] | 6343 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6344 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6345 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6346 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6347 | /* let's try again later from this stream. We add ourselves into |
| 6348 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6349 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6350 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6351 | return 0; |
| 6352 | } |
| 6353 | |
| 6354 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6355 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6356 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6357 | } |
| 6358 | |
| 6359 | appctx->st2 = STAT_ST_FIN; |
| 6360 | /* fall through */ |
| 6361 | |
| 6362 | default: |
| 6363 | appctx->st2 = STAT_ST_FIN; |
| 6364 | return 1; |
| 6365 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6366 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6367 | } |
| 6368 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6369 | static int stats_map_lookup(struct stream_interface *si) |
| 6370 | { |
| 6371 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6372 | struct sample sample; |
| 6373 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6374 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6375 | |
| 6376 | switch (appctx->st2) { |
| 6377 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6378 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6379 | appctx->ctx.map.expr = LIST_ELEM(&appctx->ctx.map.ref->pat, struct pattern_expr *, list); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6380 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6381 | appctx->st2 = STAT_ST_LIST; |
| 6382 | /* fall through */ |
| 6383 | |
| 6384 | case STAT_ST_LIST: |
| 6385 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6386 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6387 | /* initialise chunk to build new message */ |
| 6388 | chunk_reset(&trash); |
| 6389 | |
| 6390 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6391 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6392 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6393 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6394 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6395 | if (appctx->ctx.map.expr->pat_head->match && |
| 6396 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6397 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6398 | else |
| 6399 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6400 | |
| 6401 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6402 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6403 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6404 | break; |
| 6405 | if (match_method >= PAT_MATCH_NUM) |
| 6406 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6407 | else |
| 6408 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6409 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6410 | /* case sensitive */ |
| 6411 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6412 | chunk_appendf(&trash, ", case=insensitive"); |
| 6413 | else |
| 6414 | chunk_appendf(&trash, ", case=sensitive"); |
| 6415 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6416 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6417 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6418 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6419 | chunk_appendf(&trash, ", found=no"); |
| 6420 | else |
| 6421 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6422 | } |
| 6423 | |
| 6424 | /* Display match and match info */ |
| 6425 | else { |
| 6426 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6427 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6428 | chunk_appendf(&trash, ", found=yes"); |
| 6429 | else |
| 6430 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6431 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6432 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6433 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6434 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6435 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6436 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6437 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6438 | /* display pattern */ |
| 6439 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6440 | if (pat->ref && pat->ref->pattern) |
| 6441 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6442 | else |
| 6443 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6444 | } |
| 6445 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6446 | if (pat->ref && pat->ref->pattern) |
| 6447 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6448 | else |
| 6449 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6450 | } |
| 6451 | |
| 6452 | /* display return value */ |
| 6453 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6454 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6455 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6456 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6457 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6458 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6459 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6460 | } |
| 6461 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6462 | chunk_appendf(&trash, "\n"); |
| 6463 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6464 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6465 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6466 | /* let's try again later from this stream. We add ourselves into |
| 6467 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6468 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6469 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6470 | return 0; |
| 6471 | } |
| 6472 | |
| 6473 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6474 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6475 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6476 | } |
| 6477 | |
| 6478 | appctx->st2 = STAT_ST_FIN; |
| 6479 | /* fall through */ |
| 6480 | |
| 6481 | default: |
| 6482 | appctx->st2 = STAT_ST_FIN; |
| 6483 | free(appctx->ctx.map.chunk.str); |
| 6484 | return 1; |
| 6485 | } |
| 6486 | } |
| 6487 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6488 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6489 | { |
| 6490 | struct appctx *appctx = __objt_appctx(si->end); |
| 6491 | |
| 6492 | switch (appctx->st2) { |
| 6493 | |
| 6494 | case STAT_ST_INIT: |
| 6495 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6496 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6497 | struct pat_ref_elt *, list); |
| 6498 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6499 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6500 | appctx->st2 = STAT_ST_LIST; |
| 6501 | /* fall through */ |
| 6502 | |
| 6503 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6504 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6505 | chunk_reset(&trash); |
| 6506 | |
| 6507 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6508 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6509 | chunk_appendf(&trash, "%p %s %s\n", |
| 6510 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6511 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6512 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6513 | chunk_appendf(&trash, "%p %s\n", |
| 6514 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6515 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6516 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6517 | /* let's try again later from this stream. We add ourselves into |
| 6518 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6519 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6520 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6521 | return 0; |
| 6522 | } |
| 6523 | |
| 6524 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6525 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6526 | struct pat_ref_elt *, list); |
| 6527 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6528 | break; |
| 6529 | } |
| 6530 | |
| 6531 | appctx->st2 = STAT_ST_FIN; |
| 6532 | /* fall through */ |
| 6533 | |
| 6534 | default: |
| 6535 | appctx->st2 = STAT_ST_FIN; |
| 6536 | return 1; |
| 6537 | } |
| 6538 | } |
| 6539 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6540 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6541 | * read buffer. It returns 0 if the output buffer is full and it needs |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 6542 | * to be called again, otherwise non-zero. It is designed to be called |
| 6543 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6544 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6545 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6546 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6547 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6548 | struct connection *conn; |
| 6549 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6550 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6551 | /* If we're forced to shut down, we might have to remove our |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6552 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6553 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6554 | if (appctx->st2 == STAT_ST_LIST) { |
| 6555 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6556 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6557 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6558 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6559 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6560 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6561 | } |
| 6562 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6563 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6564 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6565 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6566 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6567 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6568 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6569 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6570 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6571 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6572 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6573 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6574 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6575 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6576 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6577 | /* fall through */ |
| 6578 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6579 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6580 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6581 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6582 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6583 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6584 | } |
| 6585 | |
| 6586 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6587 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6588 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6589 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6590 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6591 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6592 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6593 | if (appctx->ctx.sess.target) { |
| 6594 | if (appctx->ctx.sess.target != (void *)-1 && appctx->ctx.sess.target != curr_sess) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6595 | goto next_sess; |
| 6596 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6597 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6598 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6599 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6600 | return 0; |
| 6601 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6602 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6603 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6604 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6605 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6606 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6607 | break; |
| 6608 | } |
| 6609 | else |
| 6610 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6611 | } |
| 6612 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6613 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6614 | "%p: proto=%s", |
| 6615 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6616 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6617 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6618 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6619 | switch (conn ? addr_to_str(&conn->addr.from, pn, sizeof(pn)) : AF_UNSPEC) { |
Willy Tarreau | 631f01c | 2011-09-05 00:36:48 +0200 | [diff] [blame] | 6620 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6621 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6622 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6623 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6624 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6625 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6626 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6627 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6628 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6629 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6630 | break; |
| 6631 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6632 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6633 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6634 | strm_li(curr_sess)->luid, |
| 6635 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6636 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6637 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6638 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6639 | break; |
| 6640 | } |
| 6641 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6642 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6643 | " ts=%02x age=%s calls=%d", |
| 6644 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6645 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6646 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6647 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6648 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6649 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6650 | curr_sess->req.flags, |
| 6651 | curr_sess->req.buf->i, |
| 6652 | curr_sess->req.analysers, |
| 6653 | curr_sess->req.rex ? |
| 6654 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6655 | TICKS_TO_MS(1000)) : ""); |
| 6656 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6657 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6658 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6659 | curr_sess->req.wex ? |
| 6660 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6661 | TICKS_TO_MS(1000)) : ""); |
| 6662 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6663 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6664 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6665 | curr_sess->req.analyse_exp ? |
| 6666 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6667 | TICKS_TO_MS(1000)) : ""); |
| 6668 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6669 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6670 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6671 | curr_sess->res.flags, |
| 6672 | curr_sess->res.buf->i, |
| 6673 | curr_sess->res.analysers, |
| 6674 | curr_sess->res.rex ? |
| 6675 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6676 | TICKS_TO_MS(1000)) : ""); |
| 6677 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6678 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6679 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6680 | curr_sess->res.wex ? |
| 6681 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6682 | TICKS_TO_MS(1000)) : ""); |
| 6683 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6684 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6685 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6686 | curr_sess->res.analyse_exp ? |
| 6687 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6688 | TICKS_TO_MS(1000)) : ""); |
| 6689 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6690 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6691 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6692 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6693 | curr_sess->si[0].state, |
| 6694 | curr_sess->si[0].flags, |
Willy Tarreau | 733b132 | 2016-11-17 14:22:52 +0100 | [diff] [blame] | 6695 | (conn && conn->t.sock.fd >= 0) ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6696 | curr_sess->si[0].exp ? |
| 6697 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6698 | TICKS_TO_MS(1000)) : ""); |
| 6699 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6700 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6701 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6702 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6703 | curr_sess->si[1].state, |
| 6704 | curr_sess->si[1].flags, |
Willy Tarreau | 733b132 | 2016-11-17 14:22:52 +0100 | [diff] [blame] | 6705 | (conn && conn->t.sock.fd >= 0) ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6706 | curr_sess->si[1].exp ? |
| 6707 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6708 | TICKS_TO_MS(1000)) : ""); |
| 6709 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6710 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6711 | " exp=%s", |
| 6712 | curr_sess->task->expire ? |
| 6713 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6714 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6715 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6716 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6717 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6718 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6719 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6720 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6721 | /* let's try again later from this stream. We add ourselves into |
| 6722 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6723 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6724 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6725 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6726 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6727 | } |
| 6728 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6729 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6730 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6731 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6732 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6733 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6734 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6735 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6736 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6737 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6738 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6739 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6740 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6741 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6742 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6743 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6744 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6745 | appctx->ctx.sess.target = NULL; |
| 6746 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6747 | return 1; |
| 6748 | } |
| 6749 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6750 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6751 | /* fall through */ |
| 6752 | |
| 6753 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6754 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6755 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6756 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6757 | } |
| 6758 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6759 | /* This is called when the stream interface is closed. For instance, upon an |
| 6760 | * external abort, we won't call the i/o handler anymore so we may need to |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6761 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6762 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6763 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6764 | { |
Thierry FOURNIER / OZON.IO | 6a22dcb | 2016-11-12 10:51:33 +0100 | [diff] [blame] | 6765 | if (appctx->io_release) { |
| 6766 | appctx->io_release(appctx); |
| 6767 | appctx->io_release = NULL; |
| 6768 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6769 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6770 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6771 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6772 | } |
Willy Tarreau | 2fe1b92 | 2016-11-18 19:17:40 +0100 | [diff] [blame] | 6773 | else if ((appctx->st0 == STAT_CLI_O_TAB || appctx->st0 == STAT_CLI_O_CLR) && |
| 6774 | appctx->st2 == STAT_ST_LIST) { |
| 6775 | appctx->ctx.table.entry->ref_cnt--; |
| 6776 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6777 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6778 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6779 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6780 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6781 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6782 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6783 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6784 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6785 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6786 | } |
| 6787 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6788 | /* This function is used to either dump tables states (when action is set |
| 6789 | * to STAT_CLI_O_TAB) or clear tables (when action is STAT_CLI_O_CLR). |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6790 | * It returns 0 if the output buffer is full and it needs to be called |
| 6791 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6792 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6793 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6794 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6795 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6796 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6797 | struct ebmb_node *eb; |
| 6798 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6799 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6800 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6801 | |
| 6802 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6803 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6804 | * - STAT_ST_INIT : the first call |
| 6805 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6806 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6807 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6808 | * and the entry pointer points to the next entry to be dumped, |
| 6809 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6810 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6811 | * data though. |
| 6812 | */ |
| 6813 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6814 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6815 | /* in case of abort, remove any refcount we might have set on an entry */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6816 | if (appctx->st2 == STAT_ST_LIST) { |
| 6817 | appctx->ctx.table.entry->ref_cnt--; |
| 6818 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Willy Tarreau | f6efda1 | 2010-08-03 20:34:06 +0200 | [diff] [blame] | 6819 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6820 | return 1; |
| 6821 | } |
| 6822 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6823 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6824 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6825 | while (appctx->st2 != STAT_ST_FIN) { |
| 6826 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6827 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6828 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6829 | if (!appctx->ctx.table.proxy) |
| 6830 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6831 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6832 | appctx->ctx.table.entry = NULL; |
| 6833 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6834 | break; |
| 6835 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6836 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6837 | if (!appctx->ctx.table.proxy || |
| 6838 | (appctx->ctx.table.target && |
| 6839 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6840 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6841 | break; |
| 6842 | } |
| 6843 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6844 | if (appctx->ctx.table.proxy->table.size) { |
| 6845 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6846 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6847 | return 0; |
| 6848 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6849 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6850 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6851 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6852 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6853 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6854 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6855 | appctx->ctx.table.entry->ref_cnt++; |
| 6856 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6857 | break; |
| 6858 | } |
| 6859 | } |
| 6860 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6861 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6862 | break; |
| 6863 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6864 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6865 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6866 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6867 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6868 | /* we're filtering on some data contents */ |
| 6869 | void *ptr; |
| 6870 | long long data; |
| 6871 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6872 | dt = appctx->ctx.table.data_type; |
| 6873 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6874 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6875 | dt); |
| 6876 | |
| 6877 | data = 0; |
| 6878 | switch (stktable_data_types[dt].std_type) { |
| 6879 | case STD_T_SINT: |
| 6880 | data = stktable_data_cast(ptr, std_t_sint); |
| 6881 | break; |
| 6882 | case STD_T_UINT: |
| 6883 | data = stktable_data_cast(ptr, std_t_uint); |
| 6884 | break; |
| 6885 | case STD_T_ULL: |
| 6886 | data = stktable_data_cast(ptr, std_t_ull); |
| 6887 | break; |
| 6888 | case STD_T_FRQP: |
| 6889 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6890 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6891 | break; |
| 6892 | } |
| 6893 | |
| 6894 | /* skip the entry if the data does not match the test and the value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6895 | if ((data < appctx->ctx.table.value && |
| 6896 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6897 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6898 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6899 | (data == appctx->ctx.table.value && |
| 6900 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6901 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6902 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6903 | (data > appctx->ctx.table.value && |
| 6904 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6905 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6906 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6907 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6908 | } |
| 6909 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6910 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6911 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6912 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6913 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6914 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6915 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6916 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6917 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6918 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6919 | struct stksess *old = appctx->ctx.table.entry; |
| 6920 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6921 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6922 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6923 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6924 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6925 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6926 | break; |
| 6927 | } |
| 6928 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6929 | |
| 6930 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6931 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6932 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6933 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6934 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6935 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6936 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6937 | break; |
| 6938 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6939 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6940 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6941 | break; |
| 6942 | } |
| 6943 | } |
| 6944 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6945 | } |
| 6946 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6947 | /* print a line of text buffer (limited to 70 bytes) to <out>. The format is : |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6948 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6949 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6950 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6951 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6952 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6953 | * after the offset. The new pointer is returned. |
| 6954 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6955 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6956 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6957 | { |
| 6958 | int end; |
| 6959 | unsigned char c; |
| 6960 | |
| 6961 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6962 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6963 | return ptr; |
| 6964 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6965 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6966 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6967 | while (ptr < len && ptr < bsize) { |
| 6968 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6969 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6970 | if (out->len > end - 2) |
| 6971 | break; |
| 6972 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6973 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6974 | if (out->len > end - 3) |
| 6975 | break; |
| 6976 | out->str[out->len++] = '\\'; |
| 6977 | switch (c) { |
| 6978 | case '\t': c = 't'; break; |
| 6979 | case '\n': c = 'n'; break; |
| 6980 | case '\r': c = 'r'; break; |
| 6981 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6982 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6983 | } |
| 6984 | out->str[out->len++] = c; |
| 6985 | } else { |
| 6986 | if (out->len > end - 5) |
| 6987 | break; |
| 6988 | out->str[out->len++] = '\\'; |
| 6989 | out->str[out->len++] = 'x'; |
| 6990 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6991 | out->str[out->len++] = hextab[c & 0xF]; |
| 6992 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6993 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6994 | /* we had a line break, let's return now */ |
| 6995 | out->str[out->len++] = '\n'; |
| 6996 | *line = ptr; |
| 6997 | return ptr; |
| 6998 | } |
| 6999 | } |
| 7000 | /* we have an incomplete line, we return it as-is */ |
| 7001 | out->str[out->len++] = '\n'; |
| 7002 | return ptr; |
| 7003 | } |
| 7004 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 7005 | /* This function dumps counters from all resolvers section and associated name servers. |
| 7006 | * It returns 0 if the output buffer is full and it needs |
| 7007 | * to be called again, otherwise non-zero. |
| 7008 | */ |
| 7009 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 7010 | { |
| 7011 | struct appctx *appctx = __objt_appctx(si->end); |
| 7012 | struct dns_resolvers *presolvers; |
| 7013 | struct dns_nameserver *pnameserver; |
| 7014 | |
| 7015 | chunk_reset(&trash); |
| 7016 | |
| 7017 | switch (appctx->st2) { |
| 7018 | case STAT_ST_INIT: |
| 7019 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 7020 | /* fall through */ |
| 7021 | |
| 7022 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 7023 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 7024 | chunk_appendf(&trash, "No resolvers found\n"); |
| 7025 | } |
| 7026 | else { |
| 7027 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 7028 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 7029 | continue; |
| 7030 | |
| 7031 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 7032 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 7033 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 7034 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 7035 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 7036 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 7037 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 7038 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 7039 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 7040 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 7041 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 7042 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 7043 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 7044 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 7045 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 7046 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 7047 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 7048 | } |
| 7049 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 7050 | } |
| 7051 | |
| 7052 | /* display response */ |
| 7053 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 7054 | /* let's try again later from this session. We add ourselves into |
| 7055 | * this session's users so that it can remove us upon termination. |
| 7056 | */ |
| 7057 | si->flags |= SI_FL_WAIT_ROOM; |
| 7058 | return 0; |
| 7059 | } |
| 7060 | |
| 7061 | appctx->st2 = STAT_ST_FIN; |
| 7062 | /* fall through */ |
| 7063 | |
| 7064 | default: |
| 7065 | appctx->st2 = STAT_ST_FIN; |
| 7066 | return 1; |
| 7067 | } |
| 7068 | } |
| 7069 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 7070 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 7071 | * read buffer. It returns 0 if the output buffer is full and it needs |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 7072 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7073 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 7074 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7075 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7076 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7077 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7078 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7079 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7080 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7081 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7082 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7083 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7084 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7085 | /* the function had not been called yet, let's prepare the |
| 7086 | * buffer for a response. |
| 7087 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7088 | struct tm tm; |
| 7089 | |
| 7090 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7091 | chunk_appendf(&trash, "Total events captured on [%02d/%s/%04d:%02d:%02d:%02d.%03d] : %u\n", |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7092 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 7093 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 7094 | error_snapshot_id); |
| 7095 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7096 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7097 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7098 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7099 | return 0; |
| 7100 | } |
| 7101 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7102 | appctx->ctx.errors.px = proxy; |
| 7103 | appctx->ctx.errors.buf = 0; |
| 7104 | appctx->ctx.errors.bol = 0; |
| 7105 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7106 | } |
| 7107 | |
| 7108 | /* we have two inner loops here, one for the proxy, the other one for |
| 7109 | * the buffer. |
| 7110 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7111 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7112 | struct error_snapshot *es; |
| 7113 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7114 | if (appctx->ctx.errors.buf == 0) |
| 7115 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7116 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7117 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7118 | |
| 7119 | if (!es->when.tv_sec) |
| 7120 | goto next; |
| 7121 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7122 | if (appctx->ctx.errors.iid >= 0 && |
| 7123 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 7124 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7125 | goto next; |
| 7126 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7127 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7128 | /* just print headers now */ |
| 7129 | |
| 7130 | char pn[INET6_ADDRSTRLEN]; |
| 7131 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7132 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7133 | |
| 7134 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7135 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7136 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 7137 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(es->when.tv_usec/1000)); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7138 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7139 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 7140 | case AF_INET: |
| 7141 | case AF_INET6: |
| 7142 | port = get_host_port(&es->src); |
| 7143 | break; |
| 7144 | default: |
| 7145 | port = 0; |
| 7146 | } |
| 7147 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7148 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7149 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7150 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7151 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7152 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7153 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7154 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 7155 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7156 | break; |
| 7157 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7158 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 7159 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7160 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7161 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7162 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7163 | break; |
| 7164 | } |
| 7165 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7166 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7167 | ", server %s (#%d), event #%u\n" |
| 7168 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 7169 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 7170 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 7171 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 7172 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 7173 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 7174 | es->ev_id, |
| 7175 | pn, port, es->sid, es->s_flags, |
| 7176 | es->state, es->m_flags, es->t_flags, |
| 7177 | es->m_clen, es->m_blen, |
| 7178 | es->b_flags, es->b_out, es->b_tot, |
| 7179 | es->len, es->b_wrap, es->pos); |
| 7180 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7181 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7182 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7183 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7184 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7185 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7186 | appctx->ctx.errors.ptr = 0; |
| 7187 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7188 | } |
| 7189 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7190 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7191 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7192 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7193 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7194 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7195 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7196 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7197 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7198 | goto next; |
| 7199 | } |
| 7200 | |
| 7201 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7202 | while (es->buf && appctx->ctx.errors.ptr < es->len && appctx->ctx.errors.ptr < global.tune.bufsize) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7203 | int newptr; |
| 7204 | int newline; |
| 7205 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7206 | newline = appctx->ctx.errors.bol; |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7207 | newptr = dump_text_line(&trash, es->buf, global.tune.bufsize, es->len, &newline, appctx->ctx.errors.ptr); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7208 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7209 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7210 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7211 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7212 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7213 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7214 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7215 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7216 | appctx->ctx.errors.ptr = newptr; |
| 7217 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7218 | }; |
| 7219 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7220 | appctx->ctx.errors.bol = 0; |
| 7221 | appctx->ctx.errors.ptr = -1; |
| 7222 | appctx->ctx.errors.buf++; |
| 7223 | if (appctx->ctx.errors.buf > 1) { |
| 7224 | appctx->ctx.errors.buf = 0; |
| 7225 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7226 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 7227 | } |
| 7228 | |
| 7229 | /* dump complete */ |
| 7230 | return 1; |
| 7231 | } |
| 7232 | |
| 7233 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 7234 | * if the output buffer is full and it needs to be called again, otherwise |
| 7235 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 7236 | */ |
| 7237 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 7238 | { |
| 7239 | struct appctx *appctx = __objt_appctx(si->end); |
| 7240 | |
| 7241 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 7242 | return 1; |
| 7243 | |
| 7244 | chunk_reset(&trash); |
| 7245 | |
| 7246 | /* we have two inner loops here, one for the proxy, the other one for |
| 7247 | * the buffer. |
| 7248 | */ |
| 7249 | while (*appctx->ctx.env.var) { |
| 7250 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 7251 | |
| 7252 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 7253 | si_applet_cant_put(si); |
| 7254 | return 0; |
| 7255 | } |
| 7256 | if (appctx->st2 == STAT_ST_END) |
| 7257 | break; |
| 7258 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7259 | } |
| 7260 | |
| 7261 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7262 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7263 | } |
| 7264 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7265 | /* parse the "level" argument on the bind lines */ |
| 7266 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 7267 | { |
| 7268 | if (!*args[cur_arg + 1]) { |
| 7269 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 7270 | return ERR_ALERT | ERR_FATAL; |
| 7271 | } |
| 7272 | |
| 7273 | if (!strcmp(args[cur_arg+1], "user")) |
| 7274 | conf->level = ACCESS_LVL_USER; |
| 7275 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 7276 | conf->level = ACCESS_LVL_OPER; |
| 7277 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 7278 | conf->level = ACCESS_LVL_ADMIN; |
| 7279 | else { |
| 7280 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 7281 | args[cur_arg], args[cur_arg+1]); |
| 7282 | return ERR_ALERT | ERR_FATAL; |
| 7283 | } |
| 7284 | |
| 7285 | return 0; |
| 7286 | } |
| 7287 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7288 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7289 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7290 | .name = "<STATS>", /* used for logging */ |
| 7291 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 7292 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7293 | }; |
| 7294 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7295 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7296 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7297 | .name = "<CLI>", /* used for logging */ |
| 7298 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 7299 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7300 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 7301 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 7302 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7303 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 7304 | { 0, NULL, NULL }, |
| 7305 | }}; |
| 7306 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7307 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 7308 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 7309 | { NULL, NULL, 0 }, |
| 7310 | }}; |
| 7311 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7312 | __attribute__((constructor)) |
| 7313 | static void __dumpstats_module_init(void) |
| 7314 | { |
| 7315 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7316 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7317 | } |
| 7318 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 7319 | /* |
| 7320 | * Local variables: |
| 7321 | * c-indent-level: 8 |
| 7322 | * c-basic-offset: 8 |
| 7323 | * End: |
| 7324 | */ |