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 | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 73 | /* stats socket states */ |
| 74 | enum { |
| 75 | STAT_CLI_INIT = 0, /* initial state, must leave to zero ! */ |
| 76 | STAT_CLI_END, /* final state, let's close */ |
| 77 | STAT_CLI_GETREQ, /* wait for a request */ |
| 78 | STAT_CLI_OUTPUT, /* all states after this one are responses */ |
| 79 | STAT_CLI_PROMPT, /* display the prompt (first output, same code) */ |
| 80 | STAT_CLI_PRINT, /* display message in cli->msg */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 81 | STAT_CLI_PRINT_FREE, /* display message in cli->msg. After the display, free the pointer */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 82 | STAT_CLI_O_INFO, /* dump info */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 83 | STAT_CLI_O_SESS, /* dump streams */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 84 | STAT_CLI_O_ERR, /* dump errors */ |
| 85 | STAT_CLI_O_TAB, /* dump tables */ |
| 86 | STAT_CLI_O_CLR, /* clear tables */ |
| 87 | STAT_CLI_O_SET, /* set entries in tables */ |
| 88 | STAT_CLI_O_STAT, /* dump stats */ |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 89 | STAT_CLI_O_PATS, /* list all pattern reference available */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 90 | STAT_CLI_O_PAT, /* list all entries of a pattern */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 91 | STAT_CLI_O_MLOOK, /* lookup a map entry */ |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 92 | STAT_CLI_O_POOLS, /* dump memory pools */ |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 93 | STAT_CLI_O_TLSK, /* list all TLS ticket keys references */ |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 94 | STAT_CLI_O_TLSK_ENT, /* list all TLS ticket keys entries for a reference */ |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 95 | STAT_CLI_O_RESOLVERS,/* dump a resolver's section nameservers counters */ |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 96 | STAT_CLI_O_SERVERS_STATE, /* dump server state and changing information */ |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 97 | STAT_CLI_O_BACKEND, /* dump backend list */ |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 98 | STAT_CLI_O_ENV, /* dump environment */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 101 | /* Actions available for the stats admin forms */ |
| 102 | enum { |
| 103 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 104 | |
| 105 | /* enable/disable health checks */ |
| 106 | ST_ADM_ACTION_DHLTH, |
| 107 | ST_ADM_ACTION_EHLTH, |
| 108 | |
| 109 | /* force health check status */ |
| 110 | ST_ADM_ACTION_HRUNN, |
| 111 | ST_ADM_ACTION_HNOLB, |
| 112 | ST_ADM_ACTION_HDOWN, |
| 113 | |
| 114 | /* enable/disable agent checks */ |
| 115 | ST_ADM_ACTION_DAGENT, |
| 116 | ST_ADM_ACTION_EAGENT, |
| 117 | |
| 118 | /* force agent check status */ |
| 119 | ST_ADM_ACTION_ARUNN, |
| 120 | ST_ADM_ACTION_ADOWN, |
| 121 | |
| 122 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 123 | ST_ADM_ACTION_READY, |
| 124 | ST_ADM_ACTION_DRAIN, |
| 125 | ST_ADM_ACTION_MAINT, |
| 126 | ST_ADM_ACTION_SHUTDOWN, |
| 127 | /* these are the ancient actions, still available for compatibility */ |
| 128 | ST_ADM_ACTION_DISABLE, |
| 129 | ST_ADM_ACTION_ENABLE, |
| 130 | ST_ADM_ACTION_STOP, |
| 131 | ST_ADM_ACTION_START, |
| 132 | }; |
| 133 | |
Willy Tarreau | c4832de | 2016-01-11 18:12:26 +0100 | [diff] [blame] | 134 | |
Willy Tarreau | c4832de | 2016-01-11 18:12:26 +0100 | [diff] [blame] | 135 | /* These are the field names for each INF_* field position. Please pay attention |
| 136 | * to always use the exact same name except that the strings for new names must |
| 137 | * be lower case or CamelCase while the enum entries must be upper case. |
| 138 | */ |
| 139 | const char *info_field_names[INF_TOTAL_FIELDS] = { |
| 140 | [INF_NAME] = "Name", |
| 141 | [INF_VERSION] = "Version", |
| 142 | [INF_RELEASE_DATE] = "Release_date", |
| 143 | [INF_NBPROC] = "Nbproc", |
| 144 | [INF_PROCESS_NUM] = "Process_num", |
| 145 | [INF_PID] = "Pid", |
| 146 | [INF_UPTIME] = "Uptime", |
| 147 | [INF_UPTIME_SEC] = "Uptime_sec", |
| 148 | [INF_MEMMAX_MB] = "Memmax_MB", |
| 149 | [INF_POOL_ALLOC_MB] = "PoolAlloc_MB", |
| 150 | [INF_POOL_USED_MB] = "PoolUsed_MB", |
| 151 | [INF_POOL_FAILED] = "PoolFailed", |
| 152 | [INF_ULIMIT_N] = "Ulimit-n", |
| 153 | [INF_MAXSOCK] = "Maxsock", |
| 154 | [INF_MAXCONN] = "Maxconn", |
| 155 | [INF_HARD_MAXCONN] = "Hard_maxconn", |
| 156 | [INF_CURR_CONN] = "CurrConns", |
| 157 | [INF_CUM_CONN] = "CumConns", |
| 158 | [INF_CUM_REQ] = "CumReq", |
| 159 | [INF_MAX_SSL_CONNS] = "MaxSslConns", |
| 160 | [INF_CURR_SSL_CONNS] = "CurrSslConns", |
| 161 | [INF_CUM_SSL_CONNS] = "CumSslConns", |
| 162 | [INF_MAXPIPES] = "Maxpipes", |
| 163 | [INF_PIPES_USED] = "PipesUsed", |
| 164 | [INF_PIPES_FREE] = "PipesFree", |
| 165 | [INF_CONN_RATE] = "ConnRate", |
| 166 | [INF_CONN_RATE_LIMIT] = "ConnRateLimit", |
| 167 | [INF_MAX_CONN_RATE] = "MaxConnRate", |
| 168 | [INF_SESS_RATE] = "SessRate", |
| 169 | [INF_SESS_RATE_LIMIT] = "SessRateLimit", |
| 170 | [INF_MAX_SESS_RATE] = "MaxSessRate", |
| 171 | [INF_SSL_RATE] = "SslRate", |
| 172 | [INF_SSL_RATE_LIMIT] = "SslRateLimit", |
| 173 | [INF_MAX_SSL_RATE] = "MaxSslRate", |
| 174 | [INF_SSL_FRONTEND_KEY_RATE] = "SslFrontendKeyRate", |
| 175 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = "SslFrontendMaxKeyRate", |
| 176 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = "SslFrontendSessionReuse_pct", |
| 177 | [INF_SSL_BACKEND_KEY_RATE] = "SslBackendKeyRate", |
| 178 | [INF_SSL_BACKEND_MAX_KEY_RATE] = "SslBackendMaxKeyRate", |
| 179 | [INF_SSL_CACHE_LOOKUPS] = "SslCacheLookups", |
| 180 | [INF_SSL_CACHE_MISSES] = "SslCacheMisses", |
| 181 | [INF_COMPRESS_BPS_IN] = "CompressBpsIn", |
| 182 | [INF_COMPRESS_BPS_OUT] = "CompressBpsOut", |
| 183 | [INF_COMPRESS_BPS_RATE_LIM] = "CompressBpsRateLim", |
| 184 | [INF_ZLIB_MEM_USAGE] = "ZlibMemUsage", |
| 185 | [INF_MAX_ZLIB_MEM_USAGE] = "MaxZlibMemUsage", |
| 186 | [INF_TASKS] = "Tasks", |
| 187 | [INF_RUN_QUEUE] = "Run_queue", |
| 188 | [INF_IDLE_PCT] = "Idle_pct", |
| 189 | [INF_NODE] = "node", |
| 190 | [INF_DESCRIPTION] = "description", |
| 191 | }; |
| 192 | |
| 193 | /* one line of stats */ |
| 194 | static struct field info[INF_TOTAL_FIELDS]; |
| 195 | |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 196 | /* These are the field names for each ST_F_* field position. Please pay attention |
| 197 | * to always use the exact same name except that the strings must be lower case |
| 198 | * while the enum entries must be upper case. |
| 199 | */ |
| 200 | const char *stat_field_names[ST_F_TOTAL_FIELDS] = { |
| 201 | [ST_F_PXNAME] = "pxname", |
| 202 | [ST_F_SVNAME] = "svname", |
| 203 | [ST_F_QCUR] = "qcur", |
| 204 | [ST_F_QMAX] = "qmax", |
| 205 | [ST_F_SCUR] = "scur", |
| 206 | [ST_F_SMAX] = "smax", |
| 207 | [ST_F_SLIM] = "slim", |
| 208 | [ST_F_STOT] = "stot", |
| 209 | [ST_F_BIN] = "bin", |
| 210 | [ST_F_BOUT] = "bout", |
| 211 | [ST_F_DREQ] = "dreq", |
| 212 | [ST_F_DRESP] = "dresp", |
| 213 | [ST_F_EREQ] = "ereq", |
| 214 | [ST_F_ECON] = "econ", |
| 215 | [ST_F_ERESP] = "eresp", |
| 216 | [ST_F_WRETR] = "wretr", |
| 217 | [ST_F_WREDIS] = "wredis", |
| 218 | [ST_F_STATUS] = "status", |
| 219 | [ST_F_WEIGHT] = "weight", |
| 220 | [ST_F_ACT] = "act", |
| 221 | [ST_F_BCK] = "bck", |
| 222 | [ST_F_CHKFAIL] = "chkfail", |
| 223 | [ST_F_CHKDOWN] = "chkdown", |
| 224 | [ST_F_LASTCHG] = "lastchg", |
| 225 | [ST_F_DOWNTIME] = "downtime", |
| 226 | [ST_F_QLIMIT] = "qlimit", |
| 227 | [ST_F_PID] = "pid", |
| 228 | [ST_F_IID] = "iid", |
| 229 | [ST_F_SID] = "sid", |
| 230 | [ST_F_THROTTLE] = "throttle", |
| 231 | [ST_F_LBTOT] = "lbtot", |
| 232 | [ST_F_TRACKED] = "tracked", |
| 233 | [ST_F_TYPE] = "type", |
| 234 | [ST_F_RATE] = "rate", |
| 235 | [ST_F_RATE_LIM] = "rate_lim", |
| 236 | [ST_F_RATE_MAX] = "rate_max", |
| 237 | [ST_F_CHECK_STATUS] = "check_status", |
| 238 | [ST_F_CHECK_CODE] = "check_code", |
| 239 | [ST_F_CHECK_DURATION] = "check_duration", |
| 240 | [ST_F_HRSP_1XX] = "hrsp_1xx", |
| 241 | [ST_F_HRSP_2XX] = "hrsp_2xx", |
| 242 | [ST_F_HRSP_3XX] = "hrsp_3xx", |
| 243 | [ST_F_HRSP_4XX] = "hrsp_4xx", |
| 244 | [ST_F_HRSP_5XX] = "hrsp_5xx", |
| 245 | [ST_F_HRSP_OTHER] = "hrsp_other", |
| 246 | [ST_F_HANAFAIL] = "hanafail", |
| 247 | [ST_F_REQ_RATE] = "req_rate", |
| 248 | [ST_F_REQ_RATE_MAX] = "req_rate_max", |
| 249 | [ST_F_REQ_TOT] = "req_tot", |
| 250 | [ST_F_CLI_ABRT] = "cli_abrt", |
| 251 | [ST_F_SRV_ABRT] = "srv_abrt", |
| 252 | [ST_F_COMP_IN] = "comp_in", |
| 253 | [ST_F_COMP_OUT] = "comp_out", |
| 254 | [ST_F_COMP_BYP] = "comp_byp", |
| 255 | [ST_F_COMP_RSP] = "comp_rsp", |
| 256 | [ST_F_LASTSESS] = "lastsess", |
| 257 | [ST_F_LAST_CHK] = "last_chk", |
| 258 | [ST_F_LAST_AGT] = "last_agt", |
| 259 | [ST_F_QTIME] = "qtime", |
| 260 | [ST_F_CTIME] = "ctime", |
| 261 | [ST_F_RTIME] = "rtime", |
| 262 | [ST_F_TTIME] = "ttime", |
Willy Tarreau | 7f61884 | 2016-01-08 11:40:03 +0100 | [diff] [blame] | 263 | [ST_F_AGENT_STATUS] = "agent_status", |
| 264 | [ST_F_AGENT_CODE] = "agent_code", |
| 265 | [ST_F_AGENT_DURATION] = "agent_duration", |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 266 | [ST_F_CHECK_DESC] = "check_desc", |
| 267 | [ST_F_AGENT_DESC] = "agent_desc", |
Willy Tarreau | 3141f59 | 2016-01-08 14:25:28 +0100 | [diff] [blame] | 268 | [ST_F_CHECK_RISE] = "check_rise", |
| 269 | [ST_F_CHECK_FALL] = "check_fall", |
| 270 | [ST_F_CHECK_HEALTH] = "check_health", |
| 271 | [ST_F_AGENT_RISE] = "agent_rise", |
| 272 | [ST_F_AGENT_FALL] = "agent_fall", |
| 273 | [ST_F_AGENT_HEALTH] = "agent_health", |
Willy Tarreau | 3a4ec3a | 2016-01-08 15:35:43 +0100 | [diff] [blame] | 274 | [ST_F_ADDR] = "addr", |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 275 | [ST_F_COOKIE] = "cookie", |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 276 | [ST_F_MODE] = "mode", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 277 | [ST_F_ALGO] = "algo", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 278 | [ST_F_CONN_RATE] = "conn_rate", |
| 279 | [ST_F_CONN_RATE_MAX] = "conn_rate_max", |
| 280 | [ST_F_CONN_TOT] = "conn_tot", |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 281 | [ST_F_INTERCEPTED] = "intercepted", |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 282 | }; |
| 283 | |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 284 | /* one line of stats */ |
| 285 | static struct field stats[ST_F_TOTAL_FIELDS]; |
| 286 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 287 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 288 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 289 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 290 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 291 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 292 | 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] | 293 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 294 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 295 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 296 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 297 | 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] | 298 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 299 | static int stats_pats_list(struct stream_interface *si); |
| 300 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 301 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 302 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 303 | static int stats_tlskeys_list(struct stream_interface *si); |
| 304 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 305 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 306 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 307 | static int dump_servers_state(struct stream_interface *si, struct chunk *buf); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 308 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 309 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 310 | * cli_io_handler() |
| 311 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 312 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 313 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 314 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 315 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 316 | * -> stats_dump_stat_to_buffer() // "show stat" |
Cyril Bonté | a8322f9 | 2016-05-06 12:18:51 +0200 | [diff] [blame] | 317 | * -> stats_dump_resolvers_to_buffer() // "show stat resolvers <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 318 | * -> stats_dump_csv_header() |
| 319 | * -> stats_dump_proxy_to_buffer() |
| 320 | * -> stats_dump_fe_stats() |
| 321 | * -> stats_dump_li_stats() |
| 322 | * -> stats_dump_sv_stats() |
| 323 | * -> stats_dump_be_stats() |
| 324 | * |
| 325 | * http_stats_io_handler() |
| 326 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 327 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 328 | * -> stats_dump_html_head() // emits the HTML headers |
| 329 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 330 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 331 | * -> stats_dump_html_px_hdr() |
| 332 | * -> stats_dump_fe_stats() |
| 333 | * -> stats_dump_li_stats() |
| 334 | * -> stats_dump_sv_stats() |
| 335 | * -> stats_dump_be_stats() |
| 336 | * -> stats_dump_html_px_end() |
| 337 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 338 | */ |
| 339 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 340 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 341 | |
| 342 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 343 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 344 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 345 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 346 | " help : this message\n" |
| 347 | " prompt : toggle interactive mode with prompt\n" |
| 348 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 349 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 350 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 351 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 352 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 353 | " show stat : report counters for each proxy and server\n" |
Cyril Bonté | a8322f9 | 2016-05-06 12:18:51 +0200 | [diff] [blame] | 354 | " show stat resolvers [id]: dumps counters from all resolvers section and\n" |
| 355 | " associated name servers\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 356 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 357 | " 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] | 358 | " 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] | 359 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 360 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 361 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 362 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 363 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 364 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 365 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 366 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 367 | " disable : put a server or frontend in maintenance mode\n" |
| 368 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 369 | " 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] | 370 | " 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] | 371 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 372 | " add acl : add acl entry\n" |
| 373 | " del acl : delete acl entry\n" |
| 374 | " clear acl <id> : clear the content of this acl\n" |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 375 | " 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] | 376 | " get map : reports the keys and values matching a sample for a map\n" |
| 377 | " set map : modify map entry\n" |
| 378 | " add map : add map entry\n" |
| 379 | " del map : delete map entry\n" |
| 380 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 381 | " set ssl <stmt> : set statement for ssl\n" |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 382 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 383 | " show tls-keys [id|*]: show tls keys references or dump tls ticket keys when id specified\n" |
| 384 | #endif |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 385 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 386 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 387 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 388 | "Permission denied\n" |
| 389 | ""; |
| 390 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 391 | /* data transmission states for the stats responses */ |
| 392 | enum { |
| 393 | STAT_ST_INIT = 0, |
| 394 | STAT_ST_HEAD, |
| 395 | STAT_ST_INFO, |
| 396 | STAT_ST_LIST, |
| 397 | STAT_ST_END, |
| 398 | STAT_ST_FIN, |
| 399 | }; |
| 400 | |
| 401 | /* data transmission states for the stats responses inside a proxy */ |
| 402 | enum { |
| 403 | STAT_PX_ST_INIT = 0, |
| 404 | STAT_PX_ST_TH, |
| 405 | STAT_PX_ST_FE, |
| 406 | STAT_PX_ST_LI, |
| 407 | STAT_PX_ST_SV, |
| 408 | STAT_PX_ST_BE, |
| 409 | STAT_PX_ST_END, |
| 410 | STAT_PX_ST_FIN, |
| 411 | }; |
| 412 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 413 | extern const char *stat_status_codes[]; |
| 414 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 415 | /* allocate a new stats frontend named <name>, and return it |
| 416 | * (or NULL in case of lack of memory). |
| 417 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 418 | 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] | 419 | { |
| 420 | struct proxy *fe; |
| 421 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 422 | fe = calloc(1, sizeof(*fe)); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 423 | if (!fe) |
| 424 | return NULL; |
| 425 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 426 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 427 | fe->next = proxy; |
| 428 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 429 | fe->last_change = now.tv_sec; |
| 430 | fe->id = strdup("GLOBAL"); |
| 431 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 432 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 433 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 434 | fe->conf.file = strdup(file); |
| 435 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 436 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 437 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 438 | |
| 439 | /* the stats frontend is the only one able to assign ID #0 */ |
| 440 | fe->conf.id.key = fe->uuid = 0; |
| 441 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 442 | return fe; |
| 443 | } |
| 444 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 445 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 446 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 447 | * error message into the <err> buffer which will be preallocated. The trailing |
| 448 | * '\n' must not be written. The function must be called with <args> pointing to |
| 449 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 450 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 451 | 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] | 452 | struct proxy *defpx, const char *file, int line, |
| 453 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 454 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 455 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 456 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 457 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 458 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 459 | int cur_arg; |
| 460 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 461 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 462 | 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] | 463 | return -1; |
| 464 | } |
| 465 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 466 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 467 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 468 | 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] | 469 | return -1; |
| 470 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 471 | } |
| 472 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 473 | 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] | 474 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 475 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 476 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 477 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 478 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 479 | return -1; |
| 480 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 481 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 482 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 483 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 484 | static int bind_dumped; |
| 485 | struct bind_kw *kw; |
| 486 | |
| 487 | kw = bind_find_kw(args[cur_arg]); |
| 488 | if (kw) { |
| 489 | if (!kw->parse) { |
| 490 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 491 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 492 | return -1; |
| 493 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 494 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 495 | 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] | 496 | if (err && *err) |
| 497 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 498 | else |
| 499 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 500 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 501 | return -1; |
| 502 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 503 | |
| 504 | cur_arg += 1 + kw->skip; |
| 505 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 506 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 507 | |
| 508 | if (!bind_dumped) { |
| 509 | bind_dump_kws(err); |
| 510 | indent_msg(err, 4); |
| 511 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 512 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 513 | |
| 514 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 515 | args[0], args[1], args[cur_arg], |
| 516 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 517 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 518 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 519 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 520 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 521 | l->maxconn = global.stats_fe->maxconn; |
| 522 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 523 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 524 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 525 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 526 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 527 | l->nice = -64; /* we want to boost priority for local stats */ |
| 528 | global.maxsock += l->maxconn; |
| 529 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 530 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 531 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 532 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 533 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 534 | |
| 535 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 536 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 537 | return -1; |
| 538 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 539 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 540 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 541 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 542 | return -1; |
| 543 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 544 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 545 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 546 | 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] | 547 | return -1; |
| 548 | } |
| 549 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 550 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 551 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 552 | else if (!strcmp(args[1], "maxconn")) { |
| 553 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 554 | |
| 555 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 556 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 557 | return -1; |
| 558 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 559 | |
| 560 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 561 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 562 | 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] | 563 | return -1; |
| 564 | } |
| 565 | } |
| 566 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 567 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 568 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 569 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 570 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 571 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 572 | if (!global.stats_fe) { |
| 573 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 574 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 575 | return -1; |
| 576 | } |
| 577 | } |
| 578 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 579 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 580 | unsigned int low, high; |
| 581 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 582 | if (strcmp(args[cur_arg], "all") == 0) { |
| 583 | set = 0; |
| 584 | break; |
| 585 | } |
| 586 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 587 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 588 | } |
| 589 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 590 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 591 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 592 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 593 | char *dash = strchr(args[cur_arg], '-'); |
| 594 | |
| 595 | low = high = str2uic(args[cur_arg]); |
| 596 | if (dash) |
| 597 | high = str2uic(dash + 1); |
| 598 | |
| 599 | if (high < low) { |
| 600 | unsigned int swap = low; |
| 601 | low = high; |
| 602 | high = swap; |
| 603 | } |
| 604 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 605 | if (low < 1 || high > LONGBITS) { |
| 606 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 607 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 608 | return -1; |
| 609 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 610 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 611 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 612 | } |
| 613 | else { |
| 614 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 615 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 616 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 617 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 618 | } |
| 619 | cur_arg++; |
| 620 | } |
| 621 | global.stats_fe->bind_proc = set; |
| 622 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 623 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 624 | 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] | 625 | return -1; |
| 626 | } |
| 627 | return 0; |
| 628 | } |
| 629 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 630 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 631 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 632 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 633 | * 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] | 634 | */ |
| 635 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 636 | { |
Willy Tarreau | f614229 | 2016-01-04 17:24:29 +0100 | [diff] [blame] | 637 | int field; |
| 638 | |
| 639 | chunk_appendf(&trash, "# "); |
| 640 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) |
| 641 | chunk_appendf(&trash, "%s,", stat_field_names[field]); |
| 642 | |
| 643 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 644 | } |
| 645 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 646 | /* print a string of text buffer to <out>. The format is : |
| 647 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 648 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 649 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 650 | */ |
| 651 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 652 | { |
| 653 | unsigned char c; |
| 654 | int ptr = 0; |
| 655 | |
| 656 | while (buf[ptr] && ptr < bsize) { |
| 657 | c = buf[ptr]; |
| 658 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 659 | if (out->len > out->size - 1) |
| 660 | break; |
| 661 | out->str[out->len++] = c; |
| 662 | } |
| 663 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 664 | if (out->len > out->size - 2) |
| 665 | break; |
| 666 | out->str[out->len++] = '\\'; |
| 667 | switch (c) { |
| 668 | case ' ': c = ' '; break; |
| 669 | case '\t': c = 't'; break; |
| 670 | case '\n': c = 'n'; break; |
| 671 | case '\r': c = 'r'; break; |
| 672 | case '\e': c = 'e'; break; |
| 673 | case '\\': c = '\\'; break; |
| 674 | } |
| 675 | out->str[out->len++] = c; |
| 676 | } |
| 677 | else { |
| 678 | if (out->len > out->size - 4) |
| 679 | break; |
| 680 | out->str[out->len++] = '\\'; |
| 681 | out->str[out->len++] = 'x'; |
| 682 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 683 | out->str[out->len++] = hextab[c & 0xF]; |
| 684 | } |
| 685 | ptr++; |
| 686 | } |
| 687 | |
| 688 | return ptr; |
| 689 | } |
| 690 | |
| 691 | /* print a buffer in hexa. |
| 692 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 693 | */ |
| 694 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 695 | { |
| 696 | unsigned char c; |
| 697 | int ptr = 0; |
| 698 | |
| 699 | while (ptr < bsize) { |
| 700 | c = buf[ptr]; |
| 701 | |
| 702 | if (out->len > out->size - 2) |
| 703 | break; |
| 704 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 705 | out->str[out->len++] = hextab[c & 0xF]; |
| 706 | |
| 707 | ptr++; |
| 708 | } |
| 709 | return ptr; |
| 710 | } |
| 711 | |
| 712 | /* Dump the status of a table to a stream interface's |
| 713 | * read buffer. It returns 0 if the output buffer is full |
| 714 | * and needs to be called again, otherwise non-zero. |
| 715 | */ |
| 716 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 717 | struct proxy *proxy, struct proxy *target) |
| 718 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 719 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 720 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 721 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 722 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 723 | |
| 724 | /* any other information should be dumped here */ |
| 725 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 726 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 727 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 728 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 729 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 730 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 731 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 732 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 733 | |
| 734 | return 1; |
| 735 | } |
| 736 | |
| 737 | /* Dump the a table entry to a stream interface's |
| 738 | * read buffer. It returns 0 if the output buffer is full |
| 739 | * and needs to be called again, otherwise non-zero. |
| 740 | */ |
| 741 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 742 | struct proxy *proxy, struct stksess *entry) |
| 743 | { |
| 744 | int dt; |
| 745 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 746 | chunk_appendf(msg, "%p:", entry); |
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 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 749 | char addr[INET_ADDRSTRLEN]; |
| 750 | inet_ntop(AF_INET, (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_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 754 | char addr[INET6_ADDRSTRLEN]; |
| 755 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 756 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 757 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 758 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 759 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 760 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 761 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 762 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 763 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 764 | } |
| 765 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 766 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 767 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 768 | } |
| 769 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 770 | 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] | 771 | |
| 772 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 773 | void *ptr; |
| 774 | |
| 775 | if (proxy->table.data_ofs[dt] == 0) |
| 776 | continue; |
| 777 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 778 | 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] | 779 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 780 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 781 | |
| 782 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 783 | switch (stktable_data_types[dt].std_type) { |
| 784 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 785 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 786 | break; |
| 787 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 788 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 789 | break; |
| 790 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 791 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 792 | break; |
| 793 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 794 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 795 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 796 | proxy->table.data_arg[dt].u)); |
| 797 | break; |
| 798 | } |
| 799 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 800 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 801 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 802 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 803 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 804 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 805 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 806 | |
| 807 | return 1; |
| 808 | } |
| 809 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 810 | 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] | 811 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 812 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 813 | struct appctx *appctx = __objt_appctx(si->end); |
| 814 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 815 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 816 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 817 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 818 | long long value; |
| 819 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 820 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 821 | void *ptr; |
| 822 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 823 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 824 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 825 | |
| 826 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 827 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 828 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 829 | return; |
| 830 | } |
| 831 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 832 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 833 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 834 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 835 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 836 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 837 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 838 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 839 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 840 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 841 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 842 | { |
| 843 | char *endptr; |
| 844 | unsigned long val; |
| 845 | errno = 0; |
| 846 | val = strtoul(args[4], &endptr, 10); |
| 847 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 848 | (errno != 0 && val == 0) || endptr == args[4] || |
| 849 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 850 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 851 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 852 | return; |
| 853 | } |
| 854 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 855 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 856 | break; |
| 857 | } |
| 858 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 859 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 860 | static_table_key->key = args[4]; |
| 861 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 862 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 863 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 864 | switch (action) { |
| 865 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 866 | 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] | 867 | break; |
| 868 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 869 | 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] | 870 | break; |
| 871 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 872 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 873 | break; |
| 874 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 875 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 876 | return; |
| 877 | } |
| 878 | |
| 879 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 880 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 881 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 882 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 883 | return; |
| 884 | } |
| 885 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 886 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 887 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 888 | switch (action) { |
| 889 | case STAT_CLI_O_TAB: |
| 890 | if (!ts) |
| 891 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 892 | chunk_reset(&trash); |
| 893 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 894 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 895 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 896 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 897 | |
| 898 | case STAT_CLI_O_CLR: |
| 899 | if (!ts) |
| 900 | return; |
| 901 | if (ts->ref_cnt) { |
| 902 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 903 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 904 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 905 | return; |
| 906 | } |
| 907 | stksess_kill(&px->table, ts); |
| 908 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 909 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 910 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 911 | if (ts) |
| 912 | stktable_touch(&px->table, ts, 1); |
| 913 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 914 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 915 | if (!ts) { |
| 916 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 917 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 918 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 919 | return; |
| 920 | } |
| 921 | stktable_store(&px->table, ts, 1); |
| 922 | } |
| 923 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 924 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 925 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 926 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 927 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 928 | return; |
| 929 | } |
| 930 | |
| 931 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 932 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 933 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 934 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 935 | return; |
| 936 | } |
| 937 | |
| 938 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 939 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 940 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 941 | return; |
| 942 | } |
| 943 | |
| 944 | 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] | 945 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 946 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 947 | return; |
| 948 | } |
| 949 | |
| 950 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 951 | |
| 952 | switch (stktable_data_types[data_type].std_type) { |
| 953 | case STD_T_SINT: |
| 954 | stktable_data_cast(ptr, std_t_sint) = value; |
| 955 | break; |
| 956 | case STD_T_UINT: |
| 957 | stktable_data_cast(ptr, std_t_uint) = value; |
| 958 | break; |
| 959 | case STD_T_ULL: |
| 960 | stktable_data_cast(ptr, std_t_ull) = value; |
| 961 | break; |
| 962 | case STD_T_FRQP: |
| 963 | /* We set both the current and previous values. That way |
| 964 | * the reported frequency is stable during all the period |
| 965 | * then slowly fades out. This allows external tools to |
| 966 | * push measures without having to update them too often. |
| 967 | */ |
| 968 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 969 | frqp->curr_tick = now_ms; |
| 970 | frqp->prev_ctr = 0; |
| 971 | frqp->curr_ctr = value; |
| 972 | break; |
| 973 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 974 | } |
| 975 | break; |
| 976 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 977 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 978 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 979 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 980 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 981 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 982 | } |
| 983 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 984 | 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] | 985 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 986 | struct appctx *appctx = __objt_appctx(si->end); |
| 987 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 988 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 989 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 990 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 991 | return; |
| 992 | } |
| 993 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 994 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 995 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 996 | if (appctx->ctx.table.data_type < 0) { |
| 997 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 998 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 999 | return; |
| 1000 | } |
| 1001 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1002 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 1003 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 1004 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1005 | return; |
| 1006 | } |
| 1007 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1008 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 1009 | if (appctx->ctx.table.data_op < 0) { |
| 1010 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 1011 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1012 | return; |
| 1013 | } |
| 1014 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1015 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 1016 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 1017 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1018 | return; |
| 1019 | } |
| 1020 | } |
| 1021 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1022 | 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] | 1023 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1024 | struct appctx *appctx = __objt_appctx(si->end); |
| 1025 | |
| 1026 | appctx->ctx.table.data_type = -1; |
| 1027 | appctx->st2 = STAT_ST_INIT; |
| 1028 | appctx->ctx.table.target = NULL; |
| 1029 | appctx->ctx.table.proxy = NULL; |
| 1030 | appctx->ctx.table.entry = NULL; |
| 1031 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1032 | |
| 1033 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 1034 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1035 | if (!appctx->ctx.table.target) { |
| 1036 | appctx->ctx.cli.msg = "No such table\n"; |
| 1037 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1038 | return; |
| 1039 | } |
| 1040 | } |
| 1041 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1042 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1043 | goto err_args; |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1048 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1049 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1050 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1051 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1052 | goto err_args; |
| 1053 | |
| 1054 | return; |
| 1055 | |
| 1056 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1057 | switch (action) { |
| 1058 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1059 | 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] | 1060 | break; |
| 1061 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1062 | 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] | 1063 | break; |
| 1064 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1065 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1066 | break; |
| 1067 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1068 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1069 | } |
| 1070 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1071 | /* 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] | 1072 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1073 | * level to be admin. |
| 1074 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1075 | 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] | 1076 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1077 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1078 | struct proxy *px; |
| 1079 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1080 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1081 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1082 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1083 | return NULL; |
| 1084 | } |
| 1085 | |
| 1086 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1087 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 1088 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1089 | return NULL; |
| 1090 | } |
| 1091 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 1092 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1093 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1094 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 1095 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1096 | return NULL; |
| 1097 | } |
| 1098 | return px; |
| 1099 | } |
| 1100 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1101 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 1102 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1103 | * 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] | 1104 | * the <arg> is modified to remove the '/'. |
| 1105 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1106 | 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] | 1107 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1108 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1109 | struct proxy *px; |
| 1110 | struct server *sv; |
| 1111 | char *line; |
| 1112 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1113 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1114 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1115 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1116 | return NULL; |
| 1117 | } |
| 1118 | |
| 1119 | /* split "backend/server" and make <line> point to server */ |
| 1120 | for (line = arg; *line; line++) |
| 1121 | if (*line == '/') { |
| 1122 | *line++ = '\0'; |
| 1123 | break; |
| 1124 | } |
| 1125 | |
| 1126 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1127 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1128 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1129 | return NULL; |
| 1130 | } |
| 1131 | |
| 1132 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1133 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1134 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1135 | return NULL; |
| 1136 | } |
| 1137 | |
| 1138 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1139 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 1140 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1141 | return NULL; |
| 1142 | } |
| 1143 | |
| 1144 | return sv; |
| 1145 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1146 | |
| 1147 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1148 | * each reference. The variable <getnext> must contain the current node, |
| 1149 | * <end> point to the root node. |
| 1150 | */ |
| 1151 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1152 | static inline |
| 1153 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1154 | { |
| 1155 | struct tls_keys_ref *ref = getnext; |
| 1156 | |
| 1157 | while (1) { |
| 1158 | |
| 1159 | /* Get next list entry. */ |
| 1160 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1161 | |
| 1162 | /* If the entry is the last of the list, return NULL. */ |
| 1163 | if (&ref->list == end) |
| 1164 | return NULL; |
| 1165 | |
| 1166 | return ref; |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | static inline |
| 1171 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1172 | { |
| 1173 | int id; |
| 1174 | char *error; |
| 1175 | |
| 1176 | /* If the reference starts by a '#', this is numeric id. */ |
| 1177 | if (reference[0] == '#') { |
| 1178 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1179 | id = strtol(reference + 1, &error, 10); |
| 1180 | if (*error != '\0') |
| 1181 | return NULL; |
| 1182 | |
| 1183 | /* Perform the unique id lookup. */ |
| 1184 | return tlskeys_ref_lookupid(id); |
| 1185 | } |
| 1186 | |
| 1187 | /* Perform the string lookup. */ |
| 1188 | return tlskeys_ref_lookup(reference); |
| 1189 | } |
| 1190 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1191 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1192 | /* This function is used with map and acl management. It permits to browse |
| 1193 | * each reference. The variable <getnext> must contain the current node, |
| 1194 | * <end> point to the root node and the <flags> permit to filter required |
| 1195 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1196 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1197 | static inline |
| 1198 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1199 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1200 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1201 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1202 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1203 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1204 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1205 | /* Get next list entry. */ |
| 1206 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1207 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1208 | /* If the entry is the last of the list, return NULL. */ |
| 1209 | if (&ref->list == end) |
| 1210 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1211 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1212 | /* If the entry match the flag, return it. */ |
| 1213 | if (ref->flags & flags) |
| 1214 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1215 | } |
| 1216 | } |
| 1217 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1218 | static inline |
| 1219 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1220 | { |
| 1221 | int id; |
| 1222 | char *error; |
| 1223 | |
| 1224 | /* If the reference starts by a '#', this is numeric id. */ |
| 1225 | if (reference[0] == '#') { |
| 1226 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1227 | id = strtol(reference + 1, &error, 10); |
| 1228 | if (*error != '\0') |
| 1229 | return NULL; |
| 1230 | |
| 1231 | /* Perform the unique id lookup. */ |
| 1232 | return pat_ref_lookupid(id); |
| 1233 | } |
| 1234 | |
| 1235 | /* Perform the string lookup. */ |
| 1236 | return pat_ref_lookup(reference); |
| 1237 | } |
| 1238 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1239 | /* This function is used with map and acl management. It permits to browse |
| 1240 | * each reference. |
| 1241 | */ |
| 1242 | static inline |
| 1243 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1244 | { |
| 1245 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1246 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1247 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1248 | return NULL; |
| 1249 | return expr; |
| 1250 | } |
| 1251 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1252 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1253 | * 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] | 1254 | * 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] | 1255 | * designating the function which will have to process the request, which can |
| 1256 | * 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] | 1257 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1258 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1259 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1260 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1261 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1262 | char *args[MAX_STATS_ARGS + 1]; |
| 1263 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1264 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1265 | |
| 1266 | while (isspace((unsigned char)*line)) |
| 1267 | line++; |
| 1268 | |
| 1269 | arg = 0; |
| 1270 | args[arg] = line; |
| 1271 | |
| 1272 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1273 | if (*line == '\\') { |
| 1274 | line++; |
| 1275 | if (*line == '\0') |
| 1276 | break; |
| 1277 | } |
| 1278 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1279 | *line++ = '\0'; |
| 1280 | |
| 1281 | while (isspace((unsigned char)*line)) |
| 1282 | line++; |
| 1283 | |
| 1284 | args[++arg] = line; |
| 1285 | continue; |
| 1286 | } |
| 1287 | |
| 1288 | line++; |
| 1289 | } |
| 1290 | |
| 1291 | while (++arg <= MAX_STATS_ARGS) |
| 1292 | args[arg] = line; |
| 1293 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1294 | /* remove \ */ |
| 1295 | arg = 0; |
| 1296 | while (*args[arg] != '\0') { |
| 1297 | j = 0; |
| 1298 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1299 | if (args[arg][i] == '\\') |
| 1300 | continue; |
| 1301 | args[arg][j] = args[arg][i]; |
| 1302 | j++; |
| 1303 | } |
| 1304 | args[arg][j] = '\0'; |
| 1305 | arg++; |
| 1306 | } |
| 1307 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1308 | appctx->ctx.stats.scope_str = 0; |
| 1309 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1310 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1311 | if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1312 | if (strcmp(args[1], "backend") == 0) { |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 1313 | appctx->ctx.be.px = NULL; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1314 | appctx->st2 = STAT_ST_INIT; |
| 1315 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1316 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1317 | else if (strcmp(args[1], "env") == 0) { |
| 1318 | extern char **environ; |
| 1319 | |
| 1320 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1321 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1322 | appctx->st0 = STAT_CLI_PRINT; |
| 1323 | return 1; |
| 1324 | } |
| 1325 | appctx->ctx.env.var = environ; |
| 1326 | appctx->st2 = STAT_ST_INIT; |
| 1327 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1328 | |
| 1329 | if (*args[2]) { |
| 1330 | int len = strlen(args[2]); |
| 1331 | |
| 1332 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1333 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1334 | (*appctx->ctx.env.var)[len] == '=') |
| 1335 | break; |
| 1336 | } |
| 1337 | if (!*appctx->ctx.env.var) { |
| 1338 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1339 | appctx->st0 = STAT_CLI_PRINT; |
| 1340 | return 1; |
| 1341 | } |
| 1342 | appctx->st2 = STAT_ST_END; |
| 1343 | } |
| 1344 | } |
| 1345 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1346 | if (strcmp(args[2], "resolvers") == 0) { |
| 1347 | struct dns_resolvers *presolvers; |
| 1348 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1349 | if (*args[3]) { |
| 1350 | appctx->ctx.resolvers.ptr = NULL; |
| 1351 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1352 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1353 | appctx->ctx.resolvers.ptr = presolvers; |
| 1354 | break; |
| 1355 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1356 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1357 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1358 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1359 | appctx->st0 = STAT_CLI_PRINT; |
| 1360 | return 1; |
| 1361 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | appctx->st2 = STAT_ST_INIT; |
| 1365 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1366 | return 1; |
| 1367 | } |
| 1368 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1369 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1370 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1371 | appctx->ctx.stats.type = atoi(args[3]); |
| 1372 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1373 | if (strcmp(args[5], "typed") == 0) |
| 1374 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1375 | } |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1376 | else if (strcmp(args[2], "typed") == 0) |
| 1377 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1378 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1379 | appctx->st2 = STAT_ST_INIT; |
| 1380 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1381 | } |
| 1382 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 1383 | if (strcmp(args[2], "typed") == 0) |
| 1384 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1385 | appctx->st2 = STAT_ST_INIT; |
| 1386 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1387 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1388 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1389 | appctx->ctx.server_state.iid = 0; |
| 1390 | appctx->ctx.server_state.px = NULL; |
| 1391 | appctx->ctx.server_state.sv = NULL; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1392 | |
| 1393 | /* check if a backend name has been provided */ |
| 1394 | if (*args[3]) { |
| 1395 | /* read server state from local file */ |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1396 | appctx->ctx.server_state.px = proxy_be_by_name(args[3]); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1397 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1398 | if (!appctx->ctx.server_state.px) { |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1399 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1400 | appctx->st0 = STAT_CLI_PRINT; |
| 1401 | return 1; |
| 1402 | } |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 1403 | appctx->ctx.server_state.iid = appctx->ctx.server_state.px->uuid; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1404 | } |
| 1405 | appctx->st2 = STAT_ST_INIT; |
| 1406 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1407 | return 1; |
| 1408 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1409 | else if (strcmp(args[1], "pools") == 0) { |
| 1410 | appctx->st2 = STAT_ST_INIT; |
| 1411 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1412 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1413 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1414 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1415 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1416 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1417 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1418 | return 1; |
| 1419 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1420 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1421 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1422 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1423 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1424 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1425 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1426 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1427 | appctx->ctx.sess.pos = 0; |
| 1428 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1429 | } |
| 1430 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1431 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1432 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1433 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1434 | return 1; |
| 1435 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1436 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1437 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1438 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1439 | appctx->ctx.errors.iid = -1; |
| 1440 | appctx->ctx.errors.px = NULL; |
| 1441 | appctx->st2 = STAT_ST_INIT; |
| 1442 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1443 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1444 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1445 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1446 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1447 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1448 | #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] | 1449 | appctx->ctx.tlskeys.dump_all = 0; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1450 | /* no parameter, shows only file list */ |
| 1451 | if (!*args[2]) { |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 1452 | appctx->ctx.tlskeys.dump_all = 1; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1453 | appctx->st2 = STAT_ST_INIT; |
| 1454 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1455 | return 1; |
| 1456 | } |
| 1457 | |
| 1458 | if (args[2][0] == '*') { |
| 1459 | /* list every TLS ticket keys */ |
| 1460 | appctx->ctx.tlskeys.ref = NULL; |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 1461 | appctx->ctx.tlskeys.dump_all = 1; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1462 | } else { |
| 1463 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[2]); |
| 1464 | if(!appctx->ctx.tlskeys.ref) { |
| 1465 | appctx->ctx.cli.msg = "'show tls-keys' unable to locate referenced filename\n"; |
| 1466 | appctx->st0 = STAT_CLI_PRINT; |
| 1467 | return 1; |
| 1468 | } |
| 1469 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1470 | appctx->st2 = STAT_ST_INIT; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 1471 | appctx->st0 = STAT_CLI_O_TLSK_ENT; |
| 1472 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1473 | #else |
| 1474 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1475 | "that doesn't support specifying TLS ticket keys\n"; |
| 1476 | appctx->st0 = STAT_CLI_PRINT; |
| 1477 | #endif |
| 1478 | return 1; |
| 1479 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1480 | else if (strcmp(args[1], "map") == 0 || |
| 1481 | strcmp(args[1], "acl") == 0) { |
| 1482 | |
| 1483 | /* Set ACL or MAP flags. */ |
| 1484 | if (args[1][0] == 'm') |
| 1485 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1486 | else |
| 1487 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1488 | |
Cyril Bonté | db98eb3 | 2016-05-06 12:18:50 +0200 | [diff] [blame] | 1489 | /* no parameter: display all map available */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1490 | if (!*args[2]) { |
| 1491 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1492 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1493 | return 1; |
| 1494 | } |
| 1495 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1496 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1497 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1498 | if (!appctx->ctx.map.ref || |
| 1499 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1500 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1501 | 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] | 1502 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1503 | 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] | 1504 | appctx->st0 = STAT_CLI_PRINT; |
| 1505 | return 1; |
| 1506 | } |
| 1507 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1508 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1509 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1510 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1511 | return 0; |
| 1512 | } |
| 1513 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1514 | else if (strcmp(args[0], "clear") == 0) { |
| 1515 | if (strcmp(args[1], "counters") == 0) { |
| 1516 | struct proxy *px; |
| 1517 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1518 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1519 | int clrall = 0; |
| 1520 | |
| 1521 | if (strcmp(args[2], "all") == 0) |
| 1522 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1523 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1524 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1525 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1526 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1527 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1528 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1529 | return 1; |
| 1530 | } |
| 1531 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1532 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1533 | if (clrall) { |
| 1534 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1535 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1536 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1537 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1538 | px->be_counters.conn_max = 0; |
| 1539 | px->be_counters.p.http.rps_max = 0; |
| 1540 | px->be_counters.sps_max = 0; |
| 1541 | px->be_counters.cps_max = 0; |
| 1542 | px->be_counters.nbpend_max = 0; |
| 1543 | |
| 1544 | px->fe_counters.conn_max = 0; |
| 1545 | px->fe_counters.p.http.rps_max = 0; |
| 1546 | px->fe_counters.sps_max = 0; |
| 1547 | px->fe_counters.cps_max = 0; |
| 1548 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1549 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1550 | |
| 1551 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1552 | if (clrall) |
| 1553 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1554 | else { |
| 1555 | sv->counters.cur_sess_max = 0; |
| 1556 | sv->counters.nbpend_max = 0; |
| 1557 | sv->counters.sps_max = 0; |
| 1558 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1559 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1560 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1561 | if (li->counters) { |
| 1562 | if (clrall) |
| 1563 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1564 | else |
| 1565 | li->counters->conn_max = 0; |
| 1566 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1567 | } |
| 1568 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1569 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1570 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1571 | return 1; |
| 1572 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1573 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1574 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1575 | /* end of processing */ |
| 1576 | return 1; |
| 1577 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1578 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1579 | /* Set ACL or MAP flags. */ |
| 1580 | if (args[1][0] == 'm') |
| 1581 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1582 | else |
| 1583 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1584 | |
| 1585 | /* no parameter */ |
| 1586 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1587 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1588 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1589 | else |
| 1590 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1591 | appctx->st0 = STAT_CLI_PRINT; |
| 1592 | return 1; |
| 1593 | } |
| 1594 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1595 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1596 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1597 | if (!appctx->ctx.map.ref || |
| 1598 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1599 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1600 | 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] | 1601 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1602 | 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] | 1603 | appctx->st0 = STAT_CLI_PRINT; |
| 1604 | return 1; |
| 1605 | } |
| 1606 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1607 | /* Clear all. */ |
| 1608 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1609 | |
| 1610 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1611 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1612 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1613 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1614 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1615 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1616 | return 0; |
| 1617 | } |
| 1618 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1619 | else if (strcmp(args[0], "get") == 0) { |
| 1620 | if (strcmp(args[1], "weight") == 0) { |
| 1621 | struct proxy *px; |
| 1622 | struct server *sv; |
| 1623 | |
| 1624 | /* split "backend/server" and make <line> point to server */ |
| 1625 | for (line = args[2]; *line; line++) |
| 1626 | if (*line == '/') { |
| 1627 | *line++ = '\0'; |
| 1628 | break; |
| 1629 | } |
| 1630 | |
| 1631 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1632 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1633 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1634 | return 1; |
| 1635 | } |
| 1636 | |
| 1637 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1638 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1639 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1640 | return 1; |
| 1641 | } |
| 1642 | |
| 1643 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1644 | 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] | 1645 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1646 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1647 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1648 | return 1; |
| 1649 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1650 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1651 | /* Set flags. */ |
| 1652 | if (args[1][0] == 'm') |
| 1653 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1654 | else |
| 1655 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1656 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1657 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1658 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1659 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1660 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1661 | else |
| 1662 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1663 | appctx->st0 = STAT_CLI_PRINT; |
| 1664 | return 1; |
| 1665 | } |
| 1666 | |
| 1667 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1668 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1669 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1670 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1671 | 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] | 1672 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1673 | 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] | 1674 | appctx->st0 = STAT_CLI_PRINT; |
| 1675 | return 1; |
| 1676 | } |
| 1677 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1678 | /* copy input string. The string must be allocated because |
| 1679 | * it may be used over multiple iterations. It's released |
| 1680 | * at the end and upon abort anyway. |
| 1681 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1682 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1683 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1684 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1685 | if (!appctx->ctx.map.chunk.str) { |
| 1686 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1687 | appctx->st0 = STAT_CLI_PRINT; |
| 1688 | return 1; |
| 1689 | } |
| 1690 | |
| 1691 | /* prepare response */ |
| 1692 | appctx->st2 = STAT_ST_INIT; |
| 1693 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1694 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1695 | else { /* not "get weight" */ |
| 1696 | return 0; |
| 1697 | } |
| 1698 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1699 | else if (strcmp(args[0], "set") == 0) { |
| 1700 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1701 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1702 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1703 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1704 | sv = expect_server_admin(s, si, args[2]); |
| 1705 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1706 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1707 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1708 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1709 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1710 | appctx->ctx.cli.msg = warning; |
| 1711 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1712 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1713 | return 1; |
| 1714 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1715 | else if (strcmp(args[1], "server") == 0) { |
| 1716 | struct server *sv; |
| 1717 | const char *warning; |
| 1718 | |
| 1719 | sv = expect_server_admin(s, si, args[2]); |
| 1720 | if (!sv) |
| 1721 | return 1; |
| 1722 | |
| 1723 | if (strcmp(args[3], "weight") == 0) { |
| 1724 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1725 | if (warning) { |
| 1726 | appctx->ctx.cli.msg = warning; |
| 1727 | appctx->st0 = STAT_CLI_PRINT; |
| 1728 | } |
| 1729 | } |
| 1730 | else if (strcmp(args[3], "state") == 0) { |
| 1731 | if (strcmp(args[4], "ready") == 0) |
| 1732 | srv_adm_set_ready(sv); |
| 1733 | else if (strcmp(args[4], "drain") == 0) |
| 1734 | srv_adm_set_drain(sv); |
| 1735 | else if (strcmp(args[4], "maint") == 0) |
| 1736 | srv_adm_set_maint(sv); |
| 1737 | else { |
| 1738 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1739 | appctx->st0 = STAT_CLI_PRINT; |
| 1740 | } |
| 1741 | } |
| 1742 | else if (strcmp(args[3], "health") == 0) { |
| 1743 | if (sv->track) { |
| 1744 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1745 | appctx->st0 = STAT_CLI_PRINT; |
| 1746 | } |
| 1747 | else if (strcmp(args[4], "up") == 0) { |
| 1748 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1749 | srv_set_running(sv, "changed from CLI"); |
| 1750 | } |
| 1751 | else if (strcmp(args[4], "stopping") == 0) { |
| 1752 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1753 | srv_set_stopping(sv, "changed from CLI"); |
| 1754 | } |
| 1755 | else if (strcmp(args[4], "down") == 0) { |
| 1756 | sv->check.health = 0; |
| 1757 | srv_set_stopped(sv, "changed from CLI"); |
| 1758 | } |
| 1759 | else { |
| 1760 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1761 | appctx->st0 = STAT_CLI_PRINT; |
| 1762 | } |
| 1763 | } |
| 1764 | else if (strcmp(args[3], "agent") == 0) { |
| 1765 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1766 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1767 | appctx->st0 = STAT_CLI_PRINT; |
| 1768 | } |
| 1769 | else if (strcmp(args[4], "up") == 0) { |
| 1770 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1771 | srv_set_running(sv, "changed from CLI"); |
| 1772 | } |
| 1773 | else if (strcmp(args[4], "down") == 0) { |
| 1774 | sv->agent.health = 0; |
| 1775 | srv_set_stopped(sv, "changed from CLI"); |
| 1776 | } |
| 1777 | else { |
| 1778 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1779 | appctx->st0 = STAT_CLI_PRINT; |
| 1780 | } |
| 1781 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1782 | else if (strcmp(args[3], "addr") == 0) { |
Thierry Fournier | 09a9178 | 2016-02-24 08:25:39 +0100 | [diff] [blame] | 1783 | warning = server_parse_addr_change_request(sv, args[4], "stats command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1784 | if (warning) { |
| 1785 | appctx->ctx.cli.msg = warning; |
| 1786 | appctx->st0 = STAT_CLI_PRINT; |
| 1787 | } |
| 1788 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1789 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1790 | appctx->ctx.cli.msg = "'set server <srv>' only supports 'agent', 'health', 'state', 'weight' and 'addr'.\n"; |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1791 | appctx->st0 = STAT_CLI_PRINT; |
| 1792 | } |
| 1793 | return 1; |
| 1794 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1795 | else if (strcmp(args[1], "timeout") == 0) { |
| 1796 | if (strcmp(args[2], "cli") == 0) { |
| 1797 | unsigned timeout; |
| 1798 | const char *res; |
| 1799 | |
| 1800 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1801 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1802 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1803 | return 1; |
| 1804 | } |
| 1805 | |
| 1806 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1807 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1808 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1809 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1810 | return 1; |
| 1811 | } |
| 1812 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1813 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1814 | return 1; |
| 1815 | } |
| 1816 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1817 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1818 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1819 | return 1; |
| 1820 | } |
| 1821 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1822 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1823 | if (strcmp(args[2], "frontend") == 0) { |
| 1824 | struct proxy *px; |
| 1825 | struct listener *l; |
| 1826 | int v; |
| 1827 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1828 | px = expect_frontend_admin(s, si, args[3]); |
| 1829 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1830 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1831 | |
| 1832 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1833 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1834 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1835 | return 1; |
| 1836 | } |
| 1837 | |
| 1838 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1839 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1840 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1841 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1842 | return 1; |
| 1843 | } |
| 1844 | |
| 1845 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1846 | * its listeners. The blocked ones will be dequeued. |
| 1847 | */ |
| 1848 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1849 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1850 | l->maxconn = v; |
| 1851 | if (l->state == LI_FULL) |
| 1852 | resume_listener(l); |
| 1853 | } |
| 1854 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1855 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1856 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1857 | |
| 1858 | return 1; |
| 1859 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1860 | else if (strcmp(args[2], "server") == 0) { |
| 1861 | struct server *sv; |
Nenad Merdanovic | 5c3ed34 | 2016-04-24 23:10:07 +0200 | [diff] [blame] | 1862 | const char *warning; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1863 | |
| 1864 | sv = expect_server_admin(s, si, args[3]); |
| 1865 | if (!sv) |
| 1866 | return 1; |
| 1867 | |
Nenad Merdanovic | 5c3ed34 | 2016-04-24 23:10:07 +0200 | [diff] [blame] | 1868 | warning = server_parse_maxconn_change_request(sv, args[4]); |
| 1869 | if (warning) { |
| 1870 | appctx->ctx.cli.msg = warning; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1871 | appctx->st0 = STAT_CLI_PRINT; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1874 | return 1; |
| 1875 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1876 | else if (strcmp(args[2], "global") == 0) { |
| 1877 | int v; |
| 1878 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1879 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1880 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1881 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1882 | return 1; |
| 1883 | } |
| 1884 | |
| 1885 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1886 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1887 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1888 | return 1; |
| 1889 | } |
| 1890 | |
| 1891 | v = atoi(args[3]); |
| 1892 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1893 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1894 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1895 | return 1; |
| 1896 | } |
| 1897 | |
| 1898 | /* check for unlimited values */ |
| 1899 | if (v <= 0) |
| 1900 | v = global.hardmaxconn; |
| 1901 | |
| 1902 | global.maxconn = v; |
| 1903 | |
| 1904 | /* Dequeues all of the listeners waiting for a resource */ |
| 1905 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1906 | dequeue_all_listeners(&global_listener_queue); |
| 1907 | |
| 1908 | return 1; |
| 1909 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1910 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1911 | 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] | 1912 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1913 | return 1; |
| 1914 | } |
| 1915 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1916 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1917 | if (strcmp(args[2], "connections") == 0) { |
| 1918 | if (strcmp(args[3], "global") == 0) { |
| 1919 | int v; |
| 1920 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1921 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1922 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1923 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1924 | return 1; |
| 1925 | } |
| 1926 | |
| 1927 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1928 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1929 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1930 | return 1; |
| 1931 | } |
| 1932 | |
| 1933 | v = atoi(args[4]); |
| 1934 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1935 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1936 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1937 | return 1; |
| 1938 | } |
| 1939 | |
| 1940 | global.cps_lim = 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 | } |
| 1948 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1949 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1950 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1951 | return 1; |
| 1952 | } |
| 1953 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1954 | else if (strcmp(args[2], "sessions") == 0) { |
| 1955 | if (strcmp(args[3], "global") == 0) { |
| 1956 | int v; |
| 1957 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1958 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1959 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1960 | appctx->st0 = STAT_CLI_PRINT; |
| 1961 | return 1; |
| 1962 | } |
| 1963 | |
| 1964 | if (!*args[4]) { |
| 1965 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1966 | appctx->st0 = STAT_CLI_PRINT; |
| 1967 | return 1; |
| 1968 | } |
| 1969 | |
| 1970 | v = atoi(args[4]); |
| 1971 | if (v < 0) { |
| 1972 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1973 | appctx->st0 = STAT_CLI_PRINT; |
| 1974 | return 1; |
| 1975 | } |
| 1976 | |
| 1977 | global.sps_lim = v; |
| 1978 | |
| 1979 | /* Dequeues all of the listeners waiting for a resource */ |
| 1980 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1981 | dequeue_all_listeners(&global_listener_queue); |
| 1982 | |
| 1983 | return 1; |
| 1984 | } |
| 1985 | else { |
| 1986 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1987 | appctx->st0 = STAT_CLI_PRINT; |
| 1988 | return 1; |
| 1989 | } |
| 1990 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1991 | #ifdef USE_OPENSSL |
| 1992 | else if (strcmp(args[2], "ssl-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 | e43d532 | 2013-10-07 20:01:52 +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.ssl_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 ssl-sessions' only supports 'global'.\n"; |
| 2025 | appctx->st0 = STAT_CLI_PRINT; |
| 2026 | return 1; |
| 2027 | } |
| 2028 | } |
| 2029 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2030 | else if (strcmp(args[2], "http-compression") == 0) { |
| 2031 | if (strcmp(args[3], "global") == 0) { |
| 2032 | int v; |
| 2033 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 2034 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 2035 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2036 | appctx->st0 = STAT_CLI_PRINT; |
| 2037 | return 1; |
| 2038 | } |
| 2039 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2040 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2041 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 2042 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2043 | return 1; |
| 2044 | } |
| 2045 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2046 | v = atoi(args[4]); |
| 2047 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 2048 | } |
| 2049 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2050 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 2051 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2052 | return 1; |
| 2053 | } |
| 2054 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2055 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2056 | 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] | 2057 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2058 | return 1; |
| 2059 | } |
| 2060 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 2061 | else if (strcmp(args[1], "table") == 0) { |
| 2062 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 2063 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2064 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2065 | char *err; |
| 2066 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2067 | /* Set flags. */ |
| 2068 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2069 | |
| 2070 | /* Expect three parameters: map name, key and new value. */ |
| 2071 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 2072 | 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] | 2073 | appctx->st0 = STAT_CLI_PRINT; |
| 2074 | return 1; |
| 2075 | } |
| 2076 | |
| 2077 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2078 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2079 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2080 | 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] | 2081 | appctx->st0 = STAT_CLI_PRINT; |
| 2082 | return 1; |
| 2083 | } |
| 2084 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2085 | /* If the entry identifier start with a '#', it is considered as |
| 2086 | * pointer id |
| 2087 | */ |
| 2088 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2089 | struct pat_ref_elt *ref; |
| 2090 | long long int conv; |
| 2091 | char *error; |
| 2092 | |
| 2093 | /* Convert argument to integer value. */ |
| 2094 | conv = strtoll(&args[3][1], &error, 16); |
| 2095 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2096 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2097 | appctx->st0 = STAT_CLI_PRINT; |
| 2098 | return 1; |
| 2099 | } |
| 2100 | |
| 2101 | /* Convert and check integer to pointer. */ |
| 2102 | ref = (struct pat_ref_elt *)(long)conv; |
| 2103 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2104 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2105 | appctx->st0 = STAT_CLI_PRINT; |
| 2106 | return 1; |
| 2107 | } |
| 2108 | |
| 2109 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2110 | err = NULL; |
| 2111 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 2112 | if (err) |
| 2113 | memprintf(&err, "%s.\n", err); |
| 2114 | appctx->ctx.cli.err = err; |
| 2115 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2116 | return 1; |
| 2117 | } |
| 2118 | } |
| 2119 | else { |
| 2120 | /* Else, use the entry identifier as pattern |
| 2121 | * string, and update the value. |
| 2122 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2123 | err = NULL; |
| 2124 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 2125 | if (err) |
| 2126 | memprintf(&err, "%s.\n", err); |
| 2127 | appctx->ctx.cli.err = err; |
| 2128 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2129 | return 1; |
| 2130 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2133 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2134 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2135 | return 1; |
| 2136 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2137 | #ifdef USE_OPENSSL |
| 2138 | else if (strcmp(args[1], "ssl") == 0) { |
| 2139 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 2140 | #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] | 2141 | char *err = NULL; |
| 2142 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 2143 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2144 | if (!*args[3]) { |
| 2145 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 2146 | appctx->st0 = STAT_CLI_PRINT; |
| 2147 | return 1; |
| 2148 | } |
| 2149 | |
| 2150 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 2151 | if (trash.len < 0) { |
| 2152 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 2153 | appctx->st0 = STAT_CLI_PRINT; |
| 2154 | return 1; |
| 2155 | } |
| 2156 | |
| 2157 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 2158 | if (err) { |
| 2159 | memprintf(&err, "%s.\n", err); |
| 2160 | appctx->ctx.cli.err = err; |
| 2161 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 2162 | } |
| 2163 | return 1; |
| 2164 | } |
| 2165 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2166 | appctx->st0 = STAT_CLI_PRINT; |
| 2167 | return 1; |
| 2168 | #else |
| 2169 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2170 | appctx->st0 = STAT_CLI_PRINT; |
| 2171 | return 1; |
| 2172 | #endif |
| 2173 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2174 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2175 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2176 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2177 | if (!*args[3] || !*args[4]) { |
| 2178 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2179 | appctx->st0 = STAT_CLI_PRINT; |
| 2180 | return 1; |
| 2181 | } |
| 2182 | |
| 2183 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2184 | if(!appctx->ctx.tlskeys.ref) { |
| 2185 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2186 | appctx->st0 = STAT_CLI_PRINT; |
| 2187 | return 1; |
| 2188 | } |
| 2189 | |
| 2190 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2191 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2192 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2193 | appctx->st0 = STAT_CLI_PRINT; |
| 2194 | return 1; |
| 2195 | } |
| 2196 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2197 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2198 | 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] | 2199 | |
| 2200 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2201 | appctx->st0 = STAT_CLI_PRINT; |
| 2202 | return 1; |
| 2203 | #else |
| 2204 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2205 | "that doesn't support specifying TLS ticket keys\n"; |
| 2206 | appctx->st0 = STAT_CLI_PRINT; |
| 2207 | return 1; |
| 2208 | #endif |
| 2209 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2210 | else { |
| 2211 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2212 | appctx->st0 = STAT_CLI_PRINT; |
| 2213 | return 1; |
| 2214 | } |
| 2215 | } |
| 2216 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2217 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2218 | return 0; |
| 2219 | } |
| 2220 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2221 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2222 | if (strcmp(args[1], "agent") == 0) { |
| 2223 | struct server *sv; |
| 2224 | |
| 2225 | sv = expect_server_admin(s, si, args[2]); |
| 2226 | if (!sv) |
| 2227 | return 1; |
| 2228 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2229 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2230 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2231 | appctx->st0 = STAT_CLI_PRINT; |
| 2232 | return 1; |
| 2233 | } |
| 2234 | |
| 2235 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2236 | return 1; |
| 2237 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2238 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2239 | struct server *sv; |
| 2240 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2241 | sv = expect_server_admin(s, si, args[2]); |
| 2242 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2243 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2244 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2245 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2246 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2247 | appctx->st0 = STAT_CLI_PRINT; |
| 2248 | return 1; |
| 2249 | } |
| 2250 | |
| 2251 | sv->check.state |= CHK_ST_ENABLED; |
| 2252 | return 1; |
| 2253 | } |
| 2254 | else if (strcmp(args[1], "server") == 0) { |
| 2255 | struct server *sv; |
| 2256 | |
| 2257 | sv = expect_server_admin(s, si, args[2]); |
| 2258 | if (!sv) |
| 2259 | return 1; |
| 2260 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2261 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2262 | return 1; |
| 2263 | } |
| 2264 | else if (strcmp(args[1], "frontend") == 0) { |
| 2265 | struct proxy *px; |
| 2266 | |
| 2267 | px = expect_frontend_admin(s, si, args[2]); |
| 2268 | if (!px) |
| 2269 | return 1; |
| 2270 | |
| 2271 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2272 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2273 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2274 | return 1; |
| 2275 | } |
| 2276 | |
| 2277 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2278 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2279 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2280 | return 1; |
| 2281 | } |
| 2282 | |
| 2283 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2284 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2285 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2286 | return 1; |
| 2287 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2288 | return 1; |
| 2289 | } |
| 2290 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2291 | 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] | 2292 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2293 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2294 | } |
| 2295 | } |
| 2296 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2297 | if (strcmp(args[1], "agent") == 0) { |
| 2298 | struct server *sv; |
| 2299 | |
| 2300 | sv = expect_server_admin(s, si, args[2]); |
| 2301 | if (!sv) |
| 2302 | return 1; |
| 2303 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2304 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2305 | return 1; |
| 2306 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2307 | else if (strcmp(args[1], "health") == 0) { |
| 2308 | struct server *sv; |
| 2309 | |
| 2310 | sv = expect_server_admin(s, si, args[2]); |
| 2311 | if (!sv) |
| 2312 | return 1; |
| 2313 | |
| 2314 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2315 | return 1; |
| 2316 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2317 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2318 | struct server *sv; |
| 2319 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2320 | sv = expect_server_admin(s, si, args[2]); |
| 2321 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2322 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2323 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2324 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2325 | return 1; |
| 2326 | } |
| 2327 | else if (strcmp(args[1], "frontend") == 0) { |
| 2328 | struct proxy *px; |
| 2329 | |
| 2330 | px = expect_frontend_admin(s, si, args[2]); |
| 2331 | if (!px) |
| 2332 | return 1; |
| 2333 | |
| 2334 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2335 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2336 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2337 | return 1; |
| 2338 | } |
| 2339 | |
| 2340 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2341 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2342 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2343 | return 1; |
| 2344 | } |
| 2345 | |
| 2346 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2347 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2348 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2349 | return 1; |
| 2350 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2351 | return 1; |
| 2352 | } |
| 2353 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2354 | 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] | 2355 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2356 | return 1; |
| 2357 | } |
| 2358 | } |
| 2359 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2360 | if (strcmp(args[1], "frontend") == 0) { |
| 2361 | struct proxy *px; |
| 2362 | |
| 2363 | px = expect_frontend_admin(s, si, args[2]); |
| 2364 | if (!px) |
| 2365 | return 1; |
| 2366 | |
| 2367 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2368 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2369 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2370 | return 1; |
| 2371 | } |
| 2372 | |
| 2373 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2374 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2375 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2376 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2377 | stop_proxy(px); |
| 2378 | return 1; |
| 2379 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2380 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2381 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2382 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2383 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2384 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2385 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2386 | return 1; |
| 2387 | } |
| 2388 | |
| 2389 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2390 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2391 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2392 | return 1; |
| 2393 | } |
| 2394 | |
| 2395 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2396 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2397 | /* first, look for the requested stream in the stream table */ |
| 2398 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2399 | if (sess == ptr) |
| 2400 | break; |
| 2401 | } |
| 2402 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2403 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2404 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2405 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2406 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2407 | return 1; |
| 2408 | } |
| 2409 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2410 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2411 | return 1; |
| 2412 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2413 | else if (strcmp(args[1], "sessions") == 0) { |
| 2414 | if (strcmp(args[2], "server") == 0) { |
| 2415 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2416 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2417 | |
| 2418 | sv = expect_server_admin(s, si, args[3]); |
| 2419 | if (!sv) |
| 2420 | return 1; |
| 2421 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2422 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2423 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2424 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2425 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2426 | |
| 2427 | return 1; |
| 2428 | } |
| 2429 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2430 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2431 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2432 | return 1; |
| 2433 | } |
| 2434 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2435 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2436 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2437 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2438 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2439 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2440 | } |
| 2441 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2442 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2443 | if (args[1][0] == 'm') |
| 2444 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2445 | else |
| 2446 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2447 | |
| 2448 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2449 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2450 | if (!*args[2] || !*args[3]) { |
| 2451 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2452 | appctx->st0 = STAT_CLI_PRINT; |
| 2453 | return 1; |
| 2454 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2455 | } |
| 2456 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2457 | else { |
| 2458 | if (!*args[2] || !*args[3]) { |
| 2459 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2460 | appctx->st0 = STAT_CLI_PRINT; |
| 2461 | return 1; |
| 2462 | } |
| 2463 | } |
| 2464 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2465 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2466 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2467 | if (!appctx->ctx.map.ref || |
| 2468 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2469 | 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] | 2470 | appctx->st0 = STAT_CLI_PRINT; |
| 2471 | return 1; |
| 2472 | } |
| 2473 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2474 | /* If the entry identifier start with a '#', it is considered as |
| 2475 | * pointer id |
| 2476 | */ |
| 2477 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2478 | struct pat_ref_elt *ref; |
| 2479 | long long int conv; |
| 2480 | char *error; |
| 2481 | |
| 2482 | /* Convert argument to integer value. */ |
| 2483 | conv = strtoll(&args[3][1], &error, 16); |
| 2484 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2485 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2486 | appctx->st0 = STAT_CLI_PRINT; |
| 2487 | return 1; |
| 2488 | } |
| 2489 | |
| 2490 | /* Convert and check integer to pointer. */ |
| 2491 | ref = (struct pat_ref_elt *)(long)conv; |
| 2492 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2493 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2494 | appctx->st0 = STAT_CLI_PRINT; |
| 2495 | return 1; |
| 2496 | } |
| 2497 | |
| 2498 | /* Try to delete the entry. */ |
| 2499 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2500 | /* The entry is not found, send message. */ |
| 2501 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2502 | appctx->st0 = STAT_CLI_PRINT; |
| 2503 | return 1; |
| 2504 | } |
| 2505 | } |
| 2506 | else { |
| 2507 | /* Else, use the entry identifier as pattern |
| 2508 | * string and try to delete the entry. |
| 2509 | */ |
| 2510 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2511 | /* The entry is not found, send message. */ |
| 2512 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2513 | appctx->st0 = STAT_CLI_PRINT; |
| 2514 | return 1; |
| 2515 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2516 | } |
| 2517 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2518 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2519 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2520 | return 1; |
| 2521 | } |
| 2522 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2523 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2524 | appctx->st0 = STAT_CLI_PRINT; |
| 2525 | return 1; |
| 2526 | } |
| 2527 | } |
| 2528 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2529 | if (strcmp(args[1], "map") == 0 || |
| 2530 | strcmp(args[1], "acl") == 0) { |
| 2531 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2532 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2533 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2534 | /* Set flags. */ |
| 2535 | if (args[1][0] == 'm') |
| 2536 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2537 | else |
| 2538 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2539 | |
| 2540 | /* If the keywork is "map", we expect three parameters, if it |
| 2541 | * is "acl", we expect only two parameters |
| 2542 | */ |
| 2543 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2544 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2545 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2546 | appctx->st0 = STAT_CLI_PRINT; |
| 2547 | return 1; |
| 2548 | } |
| 2549 | } |
| 2550 | else { |
| 2551 | if (!*args[2] || !*args[3]) { |
| 2552 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2553 | appctx->st0 = STAT_CLI_PRINT; |
| 2554 | return 1; |
| 2555 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2556 | } |
| 2557 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2558 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2559 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2560 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2561 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2562 | 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] | 2563 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2564 | 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] | 2565 | appctx->st0 = STAT_CLI_PRINT; |
| 2566 | return 1; |
| 2567 | } |
| 2568 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2569 | /* The command "add acl" is prohibited if the reference |
| 2570 | * use samples. |
| 2571 | */ |
| 2572 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2573 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2574 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2575 | "You must use the command 'add map' to add values.\n"; |
| 2576 | appctx->st0 = STAT_CLI_PRINT; |
| 2577 | return 1; |
| 2578 | } |
| 2579 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2580 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2581 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2582 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2583 | 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] | 2584 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2585 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2586 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2587 | if (err) |
| 2588 | memprintf(&err, "%s.\n", err); |
| 2589 | appctx->ctx.cli.err = err; |
| 2590 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2591 | return 1; |
| 2592 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2593 | |
| 2594 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2595 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2596 | return 1; |
| 2597 | } |
| 2598 | else { /* unknown "del" parameter */ |
| 2599 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2600 | appctx->st0 = STAT_CLI_PRINT; |
| 2601 | return 1; |
| 2602 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2603 | } |
| 2604 | 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] | 2605 | return 0; |
| 2606 | } |
| 2607 | return 1; |
| 2608 | } |
| 2609 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2610 | /* 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] | 2611 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2612 | * state machine handling requests and various responses. We read a request, |
| 2613 | * 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] | 2614 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2615 | * 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] | 2616 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2617 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2618 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2619 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2620 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2621 | struct channel *req = si_oc(si); |
| 2622 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2623 | int reql; |
| 2624 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2625 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2626 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2627 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2628 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2629 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2630 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2631 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2632 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2633 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2634 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2635 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2636 | /* Let's close for real now. We just close the request |
| 2637 | * side, the conditions below will complete if needed. |
| 2638 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2639 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2640 | break; |
| 2641 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2642 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2643 | /* ensure we have some output room left in the event we |
| 2644 | * would want to return some info right after parsing. |
| 2645 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2646 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2647 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2648 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2649 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2650 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2651 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2652 | if (reql <= 0) { /* closed or EOL not found */ |
| 2653 | if (reql == 0) |
| 2654 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2655 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2656 | continue; |
| 2657 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2658 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2659 | /* seek for a possible semi-colon. If we find one, we |
| 2660 | * replace it with an LF and skip only this part. |
| 2661 | */ |
| 2662 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2663 | if (trash.str[len] == ';') { |
| 2664 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2665 | reql = len + 1; |
| 2666 | break; |
| 2667 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2668 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2669 | /* now it is time to check that we have a full line, |
| 2670 | * remove the trailing \n and possibly \r, then cut the |
| 2671 | * line. |
| 2672 | */ |
| 2673 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2674 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2675 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2676 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2677 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2678 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2679 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2680 | len--; |
| 2681 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2682 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2683 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2684 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2685 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2686 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2687 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2688 | continue; |
| 2689 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2690 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2691 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2692 | else if (strcmp(trash.str, "help") == 0 || |
| 2693 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2694 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2695 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2696 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2697 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2698 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2699 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2700 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2701 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2702 | /* if prompt is disabled, print help on empty lines, |
| 2703 | * so that the user at least knows how to enable |
| 2704 | * prompt and find help. |
| 2705 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2706 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2707 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2711 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2712 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2713 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2714 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2715 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2716 | case STAT_CLI_PROMPT: |
| 2717 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2718 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2719 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2720 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2721 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2722 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2723 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2724 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2725 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2726 | free(appctx->ctx.cli.err); |
| 2727 | appctx->st0 = STAT_CLI_PROMPT; |
| 2728 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2729 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2730 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2731 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2732 | case STAT_CLI_O_BACKEND: |
| 2733 | if (stats_dump_backend_to_buffer(si)) |
| 2734 | appctx->st0 = STAT_CLI_PROMPT; |
| 2735 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2736 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2737 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2738 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2739 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2740 | case STAT_CLI_O_SERVERS_STATE: |
| 2741 | if (stats_dump_servers_state_to_buffer(si)) |
| 2742 | appctx->st0 = STAT_CLI_PROMPT; |
| 2743 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2744 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2745 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2746 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2747 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2748 | case STAT_CLI_O_RESOLVERS: |
| 2749 | if (stats_dump_resolvers_to_buffer(si)) |
| 2750 | appctx->st0 = STAT_CLI_PROMPT; |
| 2751 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2752 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2753 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2754 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2755 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2756 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2757 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2758 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2759 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2760 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2761 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2762 | if (stats_table_request(si, appctx->st0)) |
| 2763 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2764 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2765 | case STAT_CLI_O_PATS: |
| 2766 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2767 | appctx->st0 = STAT_CLI_PROMPT; |
| 2768 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2769 | case STAT_CLI_O_PAT: |
| 2770 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2771 | appctx->st0 = STAT_CLI_PROMPT; |
| 2772 | break; |
| 2773 | case STAT_CLI_O_MLOOK: |
| 2774 | if (stats_map_lookup(si)) |
| 2775 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2776 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2777 | case STAT_CLI_O_POOLS: |
| 2778 | if (stats_dump_pools_to_buffer(si)) |
| 2779 | appctx->st0 = STAT_CLI_PROMPT; |
| 2780 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2781 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2782 | case STAT_CLI_O_TLSK: |
| 2783 | if (stats_tlskeys_list(si)) |
| 2784 | appctx->st0 = STAT_CLI_PROMPT; |
| 2785 | break; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 2786 | case STAT_CLI_O_TLSK_ENT: |
| 2787 | if (stats_tlskeys_list(si)) |
| 2788 | appctx->st0 = STAT_CLI_PROMPT; |
| 2789 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2790 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2791 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2792 | if (stats_dump_env_to_buffer(si)) |
| 2793 | appctx->st0 = STAT_CLI_PROMPT; |
| 2794 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2795 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2796 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2797 | break; |
| 2798 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2799 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2800 | /* 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] | 2801 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2802 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2803 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2804 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2805 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2806 | } |
| 2807 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2808 | /* 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] | 2809 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2810 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2811 | |
| 2812 | /* Now we close the output if one of the writers did so, |
| 2813 | * or if we're not in interactive mode and the request |
| 2814 | * buffer is empty. This still allows pipelined requests |
| 2815 | * to be sent in non-interactive mode. |
| 2816 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2817 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2818 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2819 | continue; |
| 2820 | } |
| 2821 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2822 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2823 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2824 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2825 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2826 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2827 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2828 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2829 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2830 | /* 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] | 2831 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2832 | * we forward the close to the request side so that it flows upstream to |
| 2833 | * the client. |
| 2834 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2835 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2836 | } |
| 2837 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2838 | 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] | 2839 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2840 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2841 | /* We have no more processing to do, and nothing more to send, and |
| 2842 | * the client side has closed. So we'll forward this state downstream |
| 2843 | * on the response buffer. |
| 2844 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2845 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2846 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2847 | } |
| 2848 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2849 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2850 | 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] | 2851 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2852 | 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] | 2853 | } |
| 2854 | |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2855 | /* Emits a stats field without any surrounding element and properly encoded to |
| 2856 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 2857 | */ |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 2858 | 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] | 2859 | { |
| 2860 | switch (field_format(f, 0)) { |
| 2861 | case FF_EMPTY: return 1; |
| 2862 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 2863 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 2864 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 2865 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 2866 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 2867 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 2868 | } |
| 2869 | } |
| 2870 | |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 2871 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 2872 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 2873 | * if the buffer is full. |
| 2874 | */ |
| 2875 | int stats_emit_typed_data_field(struct chunk *out, const struct field *f) |
| 2876 | { |
| 2877 | switch (field_format(f, 0)) { |
| 2878 | case FF_EMPTY: return 1; |
| 2879 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 2880 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 2881 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 2882 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
| 2883 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 2884 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 2889 | * Returns non-zero on success, 0 if the buffer is full. |
| 2890 | */ |
| 2891 | int stats_emit_field_tags(struct chunk *out, const struct field *f, char delim) |
| 2892 | { |
| 2893 | char origin, nature, scope; |
| 2894 | |
| 2895 | switch (field_origin(f, 0)) { |
| 2896 | case FO_METRIC: origin = 'M'; break; |
| 2897 | case FO_STATUS: origin = 'S'; break; |
| 2898 | case FO_KEY: origin = 'K'; break; |
| 2899 | case FO_CONFIG: origin = 'C'; break; |
| 2900 | case FO_PRODUCT: origin = 'P'; break; |
| 2901 | default: origin = '?'; break; |
| 2902 | } |
| 2903 | |
| 2904 | switch (field_nature(f, 0)) { |
| 2905 | case FN_GAUGE: nature = 'G'; break; |
| 2906 | case FN_LIMIT: nature = 'L'; break; |
| 2907 | case FN_MIN: nature = 'm'; break; |
| 2908 | case FN_MAX: nature = 'M'; break; |
| 2909 | case FN_RATE: nature = 'R'; break; |
| 2910 | case FN_COUNTER: nature = 'C'; break; |
| 2911 | case FN_DURATION: nature = 'D'; break; |
| 2912 | case FN_AGE: nature = 'A'; break; |
| 2913 | case FN_TIME: nature = 'T'; break; |
| 2914 | case FN_NAME: nature = 'N'; break; |
| 2915 | case FN_OUTPUT: nature = 'O'; break; |
| 2916 | case FN_AVG: nature = 'a'; break; |
| 2917 | default: nature = '?'; break; |
| 2918 | } |
| 2919 | |
| 2920 | switch (field_scope(f, 0)) { |
| 2921 | case FS_PROCESS: scope = 'P'; break; |
| 2922 | case FS_SERVICE: scope = 'S'; break; |
| 2923 | case FS_SYSTEM: scope = 's'; break; |
| 2924 | case FS_CLUSTER: scope = 'C'; break; |
| 2925 | default: scope = '?'; break; |
| 2926 | } |
| 2927 | |
| 2928 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 2929 | } |
| 2930 | |
Willy Tarreau | bf95cba | 2016-01-11 18:27:29 +0100 | [diff] [blame] | 2931 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
| 2932 | static int stats_dump_info_fields(struct chunk *out, const struct field *info) |
| 2933 | { |
| 2934 | int field; |
| 2935 | |
| 2936 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 2937 | if (!field_format(info, field)) |
| 2938 | continue; |
| 2939 | |
| 2940 | if (!chunk_appendf(out, "%s: ", info_field_names[field])) |
| 2941 | return 0; |
| 2942 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 2943 | return 0; |
| 2944 | if (!chunk_strcat(out, "\n")) |
| 2945 | return 0; |
| 2946 | } |
| 2947 | return 1; |
| 2948 | } |
| 2949 | |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 2950 | /* Dump all fields from <info> into <out> using the "show info typed" format */ |
| 2951 | static int stats_dump_typed_info_fields(struct chunk *out, const struct field *info) |
| 2952 | { |
| 2953 | int field; |
| 2954 | |
| 2955 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 2956 | if (!field_format(info, field)) |
| 2957 | continue; |
| 2958 | |
| 2959 | if (!chunk_appendf(out, "%d.%s.%u:", field, info_field_names[field], info[INF_PROCESS_NUM].u.u32)) |
| 2960 | return 0; |
| 2961 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 2962 | return 0; |
| 2963 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 2964 | return 0; |
| 2965 | if (!chunk_strcat(out, "\n")) |
| 2966 | return 0; |
| 2967 | } |
| 2968 | return 1; |
| 2969 | } |
| 2970 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2971 | /* Fill <info> with HAProxy global info. <info> is preallocated |
| 2972 | * array of length <len>. The length of the aray must be |
| 2973 | * INF_TOTAL_FIELDS. If this length is less then this value, the |
| 2974 | * function returns 0, otherwise, it returns 1. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2975 | */ |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2976 | int stats_fill_info(struct field *info, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2977 | { |
| 2978 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2979 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2980 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2981 | #ifdef USE_OPENSSL |
| 2982 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2983 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2984 | int ssl_reuse = 0; |
| 2985 | |
| 2986 | if (ssl_key_rate < ssl_sess_rate) { |
| 2987 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2988 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2989 | } |
| 2990 | #endif |
| 2991 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2992 | if (len < INF_TOTAL_FIELDS) |
| 2993 | return 0; |
| 2994 | |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2995 | chunk_reset(out); |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2996 | memset(info, 0, sizeof(*info) * len); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2997 | |
| 2998 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
| 2999 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION); |
| 3000 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE); |
| 3001 | |
| 3002 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 3003 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 3004 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 3005 | |
| 3006 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 3007 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 3008 | |
| 3009 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 3010 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 3011 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 3012 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 3013 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 3014 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 3015 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 3016 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 3017 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 3018 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 3019 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 3020 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 3021 | #ifdef USE_OPENSSL |
| 3022 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 3023 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 3024 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 3025 | #endif |
| 3026 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 3027 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 3028 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 3029 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 3030 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 3031 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 3032 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 3033 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 3034 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 3035 | |
| 3036 | #ifdef USE_OPENSSL |
| 3037 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3038 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3039 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3040 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3041 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3042 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3043 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3044 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3045 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3046 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3047 | #endif |
| 3048 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3049 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3050 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3051 | #ifdef USE_ZLIB |
| 3052 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3053 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3054 | #endif |
| 3055 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
| 3056 | info[INF_RUN_QUEUE] = mkf_u32(0, run_queue_cur); |
| 3057 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct); |
| 3058 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3059 | if (global.desc) |
| 3060 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
| 3061 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 3062 | return 1; |
| 3063 | } |
| 3064 | |
| 3065 | /* This function dumps information onto the stream interface's read buffer. |
| 3066 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3067 | * No state is used. |
| 3068 | */ |
| 3069 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
| 3070 | { |
| 3071 | struct appctx *appctx = __objt_appctx(si->end); |
| 3072 | |
| 3073 | if (!stats_fill_info(info, INF_TOTAL_FIELDS)) |
| 3074 | return 0; |
| 3075 | |
Willy Tarreau | 1b4ba1e | 2016-01-11 18:29:04 +0100 | [diff] [blame] | 3076 | chunk_reset(&trash); |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 3077 | |
| 3078 | if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3079 | stats_dump_typed_info_fields(&trash, info); |
| 3080 | else |
| 3081 | stats_dump_info_fields(&trash, info); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3082 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3083 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3084 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3085 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3086 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3087 | |
| 3088 | return 1; |
| 3089 | } |
| 3090 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3091 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 3092 | * These information are all the parameters which may change during HAProxy runtime. |
| 3093 | * By default, we only export to the last known server state file format. |
| 3094 | * These information can be used at next startup to recover same level of server state. |
| 3095 | */ |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3096 | static int dump_servers_state(struct stream_interface *si, struct chunk *buf) |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3097 | { |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3098 | struct appctx *appctx = __objt_appctx(si->end); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3099 | struct server *srv; |
| 3100 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 3101 | time_t srv_time_since_last_change; |
| 3102 | int bk_f_forced_id, srv_f_forced_id; |
| 3103 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3104 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3105 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 3106 | if (appctx->ctx.server_state.px->bind_proc && !(appctx->ctx.server_state.px->bind_proc & (1UL << (relative_pid - 1)))) |
| 3107 | return 1; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3108 | |
Cyril Bonté | d55bd7a | 2016-05-27 00:06:45 +0200 | [diff] [blame] | 3109 | if (!appctx->ctx.server_state.sv) |
| 3110 | appctx->ctx.server_state.sv = appctx->ctx.server_state.px->srv; |
| 3111 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3112 | for (; appctx->ctx.server_state.sv != NULL; appctx->ctx.server_state.sv = srv->next) { |
| 3113 | srv = appctx->ctx.server_state.sv; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3114 | srv_addr[0] = '\0'; |
| 3115 | srv_time_since_last_change = 0; |
| 3116 | bk_f_forced_id = 0; |
| 3117 | srv_f_forced_id = 0; |
| 3118 | |
| 3119 | switch (srv->addr.ss_family) { |
| 3120 | case AF_INET: |
| 3121 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 3122 | srv_addr, INET_ADDRSTRLEN + 1); |
| 3123 | break; |
| 3124 | case AF_INET6: |
| 3125 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 3126 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 3127 | break; |
| 3128 | } |
| 3129 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3130 | 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] | 3131 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 3132 | |
| 3133 | chunk_appendf(buf, |
| 3134 | "%d %s " |
| 3135 | "%d %s %s " |
| 3136 | "%d %d %d %d %ld " |
| 3137 | "%d %d %d %d %d " |
| 3138 | "%d %d" |
| 3139 | "\n", |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3140 | appctx->ctx.server_state.px->uuid, appctx->ctx.server_state.px->id, |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3141 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 3142 | 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] | 3143 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 3144 | bk_f_forced_id, srv_f_forced_id); |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3145 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3146 | si_applet_cant_put(si); |
| 3147 | return 0; |
| 3148 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3149 | } |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3150 | return 1; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3151 | } |
| 3152 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3153 | /* Parses backend list and simply report backend names */ |
| 3154 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 3155 | { |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 3156 | struct appctx *appctx = __objt_appctx(si->end); |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3157 | extern struct proxy *proxy; |
| 3158 | struct proxy *curproxy; |
| 3159 | |
| 3160 | chunk_reset(&trash); |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3161 | |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 3162 | if (!appctx->ctx.be.px) { |
| 3163 | chunk_printf(&trash, "# name\n"); |
| 3164 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3165 | si_applet_cant_put(si); |
| 3166 | return 0; |
| 3167 | } |
| 3168 | appctx->ctx.be.px = proxy; |
| 3169 | } |
| 3170 | |
| 3171 | for (; appctx->ctx.be.px != NULL; appctx->ctx.be.px = curproxy->next) { |
| 3172 | curproxy = appctx->ctx.be.px; |
| 3173 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3174 | /* looking for backends only */ |
| 3175 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3176 | continue; |
| 3177 | |
| 3178 | /* we don't want to list a backend which is bound to this process */ |
| 3179 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 3180 | continue; |
| 3181 | |
| 3182 | chunk_appendf(&trash, "%s\n", curproxy->id); |
Cyril Bonté | 6ca9e01 | 2016-05-06 12:18:49 +0200 | [diff] [blame] | 3183 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3184 | si_applet_cant_put(si); |
| 3185 | return 0; |
| 3186 | } |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | return 1; |
| 3190 | } |
| 3191 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3192 | /* Parses backend list or simply use backend name provided by the user to return |
| 3193 | * states of servers to stdout. |
| 3194 | */ |
| 3195 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 3196 | { |
| 3197 | struct appctx *appctx = __objt_appctx(si->end); |
| 3198 | extern struct proxy *proxy; |
| 3199 | struct proxy *curproxy; |
| 3200 | |
| 3201 | chunk_reset(&trash); |
| 3202 | |
Willy Tarreau | a58c435 | 2016-06-22 14:51:40 +0200 | [diff] [blame] | 3203 | if (appctx->st2 == STAT_ST_INIT) { |
| 3204 | if (!appctx->ctx.server_state.px) |
| 3205 | appctx->ctx.server_state.px = proxy; |
| 3206 | appctx->st2 = STAT_ST_HEAD; |
| 3207 | } |
| 3208 | |
| 3209 | if (appctx->st2 == STAT_ST_HEAD) { |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3210 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3211 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3212 | si_applet_cant_put(si); |
| 3213 | return 0; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3214 | } |
Willy Tarreau | a58c435 | 2016-06-22 14:51:40 +0200 | [diff] [blame] | 3215 | appctx->st2 = STAT_ST_INFO; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3216 | } |
| 3217 | |
Willy Tarreau | a58c435 | 2016-06-22 14:51:40 +0200 | [diff] [blame] | 3218 | /* STAT_ST_INFO */ |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3219 | for (; appctx->ctx.server_state.px != NULL; appctx->ctx.server_state.px = curproxy->next) { |
| 3220 | curproxy = appctx->ctx.server_state.px; |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3221 | /* servers are only in backends */ |
| 3222 | if (curproxy->cap & PR_CAP_BE) { |
| 3223 | if (!dump_servers_state(si, &trash)) |
| 3224 | return 0; |
| 3225 | |
| 3226 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3227 | si_applet_cant_put(si); |
| 3228 | return 0; |
| 3229 | } |
| 3230 | } |
| 3231 | /* only the selected proxy is dumped */ |
| 3232 | if (appctx->ctx.server_state.iid) |
| 3233 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | return 1; |
| 3237 | } |
| 3238 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3239 | /* This function dumps memory usage information onto the stream interface's |
| 3240 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3241 | * completion. No state is used. |
| 3242 | */ |
| 3243 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3244 | { |
| 3245 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3246 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3247 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3248 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3249 | } |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 3250 | return 1; |
| 3251 | } |
| 3252 | |
| 3253 | /* Dump all fields from <stats> into <out> using CSV format */ |
| 3254 | static int stats_dump_fields_csv(struct chunk *out, const struct field *stats) |
| 3255 | { |
| 3256 | int field; |
| 3257 | |
| 3258 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3259 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 3260 | return 0; |
| 3261 | if (!chunk_strcat(out, ",")) |
| 3262 | return 0; |
| 3263 | } |
Conrad Hoffmann | 692c938 | 2016-04-01 20:40:58 +0200 | [diff] [blame] | 3264 | chunk_strcat(out, "\n"); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3265 | return 1; |
| 3266 | } |
| 3267 | |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3268 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
| 3269 | static int stats_dump_fields_typed(struct chunk *out, const struct field *stats) |
| 3270 | { |
| 3271 | int field; |
| 3272 | |
| 3273 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3274 | if (!stats[field].type) |
| 3275 | continue; |
| 3276 | |
| 3277 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 3278 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 3279 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 3280 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 3281 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 3282 | '?', |
| 3283 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 3284 | field, stat_field_names[field], stats[ST_F_PID].u.u32); |
| 3285 | |
| 3286 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 3287 | return 0; |
| 3288 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 3289 | return 0; |
| 3290 | if (!chunk_strcat(out, "\n")) |
| 3291 | return 0; |
| 3292 | } |
| 3293 | return 1; |
| 3294 | } |
| 3295 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3296 | /* 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] | 3297 | * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info |
| 3298 | * are provided if ST_SHLGNDS is present in <flags>. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3299 | */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3300 | 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] | 3301 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3302 | struct chunk src; |
| 3303 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3304 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3305 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3306 | /* name, queue */ |
| 3307 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3308 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3309 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3310 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3311 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3312 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3313 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3314 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3315 | "<td class=ac>" |
| 3316 | "<a name=\"%s/Frontend\"></a>" |
| 3317 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3318 | "<td colspan=3></td>" |
| 3319 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3320 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3321 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3322 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3323 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3324 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3325 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3326 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3327 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3328 | U2H(stats[ST_F_RATE].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3329 | U2H(stats[ST_F_CONN_RATE].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3330 | U2H(stats[ST_F_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3331 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3332 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3333 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3334 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3335 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3336 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3337 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3338 | "</table></div></u></td>" |
| 3339 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3340 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3341 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3342 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3343 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3344 | U2H(stats[ST_F_RATE_MAX].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3345 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3346 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3347 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3348 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3349 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3350 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3351 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3352 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3353 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3354 | "</table></div></u></td>" |
| 3355 | /* sessions rate : limit */ |
| 3356 | "<td>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3357 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3358 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3359 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3360 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3361 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3362 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3363 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3364 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3365 | "", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3366 | 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] | 3367 | U2H(stats[ST_F_STOT].u.u64), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3368 | U2H(stats[ST_F_CONN_TOT].u.u64), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3369 | U2H(stats[ST_F_STOT].u.u64)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3370 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3371 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3372 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3373 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3374 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3375 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3376 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3377 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3378 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3379 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3380 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3381 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3382 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3383 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3384 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3385 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3386 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3387 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3388 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3389 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3390 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3391 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3392 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3393 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3394 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3395 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3396 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3397 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3398 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3399 | /* sessions: lbtot, lastsess */ |
| 3400 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3401 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3402 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3404 | U2H(stats[ST_F_BIN].u.u64)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3405 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3406 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3407 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3408 | "<td>%s%s<div class=tips><table class=det>" |
| 3409 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3410 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3411 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3412 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3413 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3414 | "</table></div>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3415 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3416 | U2H(stats[ST_F_BOUT].u.u64), |
| 3417 | U2H(stats[ST_F_BOUT].u.u64), |
| 3418 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3419 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3420 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3421 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 3422 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 3423 | 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, |
| 3424 | (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] | 3425 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3426 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3427 | /* denied: req, resp */ |
| 3428 | "<td>%s</td><td>%s</td>" |
| 3429 | /* errors : request, connect, response */ |
| 3430 | "<td>%s</td><td></td><td></td>" |
| 3431 | /* warnings: retries, redispatches */ |
| 3432 | "<td></td><td></td>" |
| 3433 | /* server status : reflect frontend status */ |
| 3434 | "<td class=ac>%s</td>" |
| 3435 | /* rest of server: nothing */ |
| 3436 | "<td class=ac colspan=8></td></tr>" |
| 3437 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3438 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3439 | U2H(stats[ST_F_EREQ].u.u64), |
| 3440 | field_str(stats, ST_F_STATUS)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3441 | } |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3442 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3443 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3444 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3445 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3446 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3447 | } |
| 3448 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3449 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3450 | /* frontend name, listener name */ |
| 3451 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3452 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3453 | "", |
| 3454 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3455 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3456 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 3457 | |
| 3458 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3459 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3460 | |
| 3461 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3462 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3463 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3464 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3465 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3466 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3467 | |
| 3468 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3469 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3470 | } |
| 3471 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3472 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3473 | /* queue */ |
| 3474 | "%s</td><td colspan=3></td>" |
| 3475 | /* sessions rate: current, max, limit */ |
| 3476 | "<td colspan=3> </td>" |
| 3477 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 3478 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3479 | "<td>%s</td><td> </td><td> </td>" |
| 3480 | /* bytes: in, out */ |
| 3481 | "<td>%s</td><td>%s</td>" |
| 3482 | "", |
| 3483 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3484 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3485 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 3486 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3487 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3488 | /* denied: req, resp */ |
| 3489 | "<td>%s</td><td>%s</td>" |
| 3490 | /* errors: request, connect, response */ |
| 3491 | "<td>%s</td><td></td><td></td>" |
| 3492 | /* warnings: retries, redispatches */ |
| 3493 | "<td></td><td></td>" |
| 3494 | /* server status: reflect listener status */ |
| 3495 | "<td class=ac>%s</td>" |
| 3496 | /* rest of server: nothing */ |
| 3497 | "<td class=ac colspan=8></td></tr>" |
| 3498 | "", |
| 3499 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3500 | U2H(stats[ST_F_EREQ].u.u64), |
| 3501 | field_str(stats, ST_F_STATUS)); |
| 3502 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3503 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 3504 | const char *style; |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3505 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3506 | /* determine the style to use depending on the server's state, |
| 3507 | * its health and weight. There isn't a 1-to-1 mapping between |
| 3508 | * state and styles for the cases where the server is (still) |
| 3509 | * up. The reason is that we don't want to report nolb and |
| 3510 | * drain with the same color. |
| 3511 | */ |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3512 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3513 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 3514 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 3515 | style = "down"; |
| 3516 | } |
| 3517 | else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) { |
| 3518 | style = "going_up"; |
| 3519 | } |
| 3520 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) { |
| 3521 | style = "going_down"; |
| 3522 | } |
| 3523 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 3524 | style = "nolb"; |
| 3525 | } |
| 3526 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 3527 | style = "no_check"; |
| 3528 | } |
| 3529 | else if (!stats[ST_F_CHKFAIL].type || |
| 3530 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 3531 | /* no check or max health = UP */ |
| 3532 | if (stats[ST_F_WEIGHT].u.u32) |
| 3533 | style = "up"; |
| 3534 | else |
| 3535 | style = "draining"; |
| 3536 | } |
| 3537 | else { |
| 3538 | style = "going_down"; |
| 3539 | } |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3540 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3541 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3542 | chunk_appendf(out, "<tr class=\"maintain\">"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3543 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3544 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3545 | "<tr class=\"%s_%s\">", |
| 3546 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3547 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3548 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3549 | if (flags & ST_SHOWADMIN) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3550 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3551 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3552 | field_str(stats, ST_F_SVNAME)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3553 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3554 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3555 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3556 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3557 | "", |
| 3558 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3559 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3560 | 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] | 3561 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3562 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3563 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3564 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3565 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3566 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3567 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3568 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3569 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3570 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3571 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3572 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3573 | chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3574 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3575 | /* cookie */ |
| 3576 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3577 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3578 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3579 | chunk_htmlencode(out, &src); |
| 3580 | chunk_appendf(out, "'"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3581 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3582 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3583 | chunk_appendf(out, "</div>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3584 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3585 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3586 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3587 | /* queue : current, max, limit */ |
| 3588 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 3589 | /* sessions rate : current, max, limit */ |
| 3590 | "<td>%s</td><td>%s</td><td></td>" |
| 3591 | "", |
| 3592 | (flags & ST_SHLGNDS) ? "</u>" : "", |
| 3593 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 3594 | 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] | 3595 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3596 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3597 | /* sessions: current, max, limit, total */ |
| 3598 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3599 | "<td><u>%s<div class=tips><table class=det>" |
| 3600 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3601 | "", |
| 3602 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 3603 | U2H(stats[ST_F_STOT].u.u64), |
| 3604 | U2H(stats[ST_F_STOT].u.u64)); |
Willy Tarreau | 4607fad | 2016-01-06 15:41:29 +0100 | [diff] [blame] | 3605 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3606 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3607 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3608 | unsigned long long tot; |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3609 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3610 | tot = stats[ST_F_HRSP_OTHER].u.u64; |
| 3611 | tot += stats[ST_F_HRSP_1XX].u.u64; |
| 3612 | tot += stats[ST_F_HRSP_2XX].u.u64; |
| 3613 | tot += stats[ST_F_HRSP_3XX].u.u64; |
| 3614 | tot += stats[ST_F_HRSP_4XX].u.u64; |
| 3615 | tot += stats[ST_F_HRSP_5XX].u.u64; |
| 3616 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3617 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3618 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3619 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3620 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3621 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3622 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3623 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3624 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3625 | "", |
| 3626 | U2H(tot), |
| 3627 | U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0, |
| 3628 | U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0, |
| 3629 | U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0, |
| 3630 | U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0, |
| 3631 | U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0, |
| 3632 | 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] | 3633 | } |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3634 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3635 | chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3636 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3637 | 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] | 3638 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3639 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3640 | 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] | 3641 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3642 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3643 | "</table></div></u></td>" |
| 3644 | /* sessions: lbtot, last */ |
| 3645 | "<td>%s</td><td>%s</td>", |
| 3646 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3647 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3648 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3649 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3650 | /* bytes : in, out */ |
| 3651 | "<td>%s</td><td>%s</td>" |
| 3652 | /* denied: req, resp */ |
| 3653 | "<td></td><td>%s</td>" |
| 3654 | /* errors : request, connect */ |
| 3655 | "<td></td><td>%s</td>" |
| 3656 | /* errors : response */ |
| 3657 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3658 | /* warnings: retries, redispatches */ |
| 3659 | "<td>%lld</td><td>%lld</td>" |
| 3660 | "", |
| 3661 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 3662 | U2H(stats[ST_F_DRESP].u.u64), |
| 3663 | U2H(stats[ST_F_ECON].u.u64), |
| 3664 | U2H(stats[ST_F_ERESP].u.u64), |
| 3665 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3666 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3667 | (long long)stats[ST_F_WRETR].u.u64, |
| 3668 | (long long)stats[ST_F_WREDIS].u.u64); |
| 3669 | |
| 3670 | /* status, last change */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3671 | chunk_appendf(out, "<td class=ac>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3672 | |
| 3673 | /* FIXME!!!! |
| 3674 | * LASTCHG should contain the last change for *this* server and must be computed |
| 3675 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 3676 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 3677 | */ |
| 3678 | |
| 3679 | |
| 3680 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3681 | 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] | 3682 | } |
| 3683 | 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] | 3684 | chunk_strcat(out, "<i>no check</i>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3685 | } |
| 3686 | else { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3687 | 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] | 3688 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
| 3689 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3690 | chunk_strcat(out, " ↑"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3691 | } |
| 3692 | 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] | 3693 | chunk_strcat(out, " ↓"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
| 3697 | 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] | 3698 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3699 | "</td><td class=ac><u> %s", |
| 3700 | field_str(stats, ST_F_AGENT_STATUS)); |
| 3701 | |
| 3702 | if (stats[ST_F_AGENT_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3703 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3704 | |
| 3705 | if (stats[ST_F_AGENT_DURATION].type && stats[ST_F_AGENT_DURATION].u.u64 >= 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3706 | 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] | 3707 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3708 | 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] | 3709 | |
| 3710 | if (*field_str(stats, ST_F_LAST_AGT)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3711 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3712 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3713 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3714 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3715 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3716 | } |
| 3717 | else if (stats[ST_F_CHECK_STATUS].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3718 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3719 | "</td><td class=ac><u> %s", |
| 3720 | field_str(stats, ST_F_CHECK_STATUS)); |
| 3721 | |
| 3722 | if (stats[ST_F_CHECK_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3723 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3724 | |
| 3725 | if (stats[ST_F_CHECK_DURATION].type && stats[ST_F_CHECK_DURATION].u.u64 >= 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3726 | 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] | 3727 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3728 | 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] | 3729 | |
| 3730 | if (*field_str(stats, ST_F_LAST_CHK)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3731 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3732 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3733 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3734 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3735 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3736 | } |
| 3737 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3738 | chunk_appendf(out, "</td><td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3739 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3740 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3741 | /* weight */ |
| 3742 | "</td><td class=ac>%d</td>" |
| 3743 | /* act, bck */ |
| 3744 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3745 | "", |
| 3746 | stats[ST_F_WEIGHT].u.u32, |
| 3747 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 3748 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 3749 | |
| 3750 | /* check failures: unique, fatal, down time */ |
| 3751 | if (stats[ST_F_CHKFAIL].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3752 | 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] | 3753 | |
| 3754 | if (stats[ST_F_HANAFAIL].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3755 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3756 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3757 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3758 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 3759 | "<td>%lld</td><td>%s</td>" |
| 3760 | "", |
| 3761 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 3762 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 3763 | } |
| 3764 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 3765 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3766 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3767 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 3768 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 3769 | } |
| 3770 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3771 | chunk_appendf(out, "<td colspan=3></td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3772 | |
| 3773 | /* throttle */ |
| 3774 | if (stats[ST_F_THROTTLE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3775 | 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] | 3776 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3777 | chunk_appendf(out, "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3778 | } |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3779 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3780 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3781 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3782 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3783 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3784 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3785 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3786 | "<td class=ac>" |
| 3787 | /* name */ |
| 3788 | "%s<a name=\"%s/Backend\"></a>" |
| 3789 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3790 | "", |
| 3791 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3792 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 3793 | |
| 3794 | if (flags & ST_SHLGNDS) { |
| 3795 | /* balancing */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3796 | chunk_appendf(out, "<div class=tips>balancing: %s", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 3797 | field_str(stats, ST_F_ALGO)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3798 | |
| 3799 | /* cookie */ |
| 3800 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3801 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3802 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3803 | chunk_htmlencode(out, &src); |
| 3804 | chunk_appendf(out, "'"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3805 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3806 | chunk_appendf(out, "</div>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3807 | } |
| 3808 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3809 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3810 | "%s</td>" |
| 3811 | /* queue : current, max */ |
| 3812 | "<td>%s</td><td>%s</td><td></td>" |
| 3813 | /* sessions rate : current, max, limit */ |
| 3814 | "<td>%s</td><td>%s</td><td></td>" |
| 3815 | "", |
| 3816 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3817 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 3818 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 3819 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3820 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3821 | /* sessions: current, max, limit, total */ |
| 3822 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3823 | "<td><u>%s<div class=tips><table class=det>" |
| 3824 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3825 | "", |
| 3826 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3827 | U2H(stats[ST_F_STOT].u.u64), |
| 3828 | U2H(stats[ST_F_STOT].u.u64)); |
| 3829 | |
| 3830 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3831 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3832 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3833 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3834 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3835 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3836 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3837 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3838 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3839 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3840 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3841 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3842 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
| 3843 | "", |
| 3844 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3845 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3846 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3847 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3848 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3849 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3850 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3851 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3852 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3853 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3854 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3855 | } |
| 3856 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3857 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3858 | chunk_appendf(out, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3859 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3860 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3861 | 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] | 3862 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3863 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3864 | "</table></div></u></td>" |
| 3865 | /* sessions: lbtot, last */ |
| 3866 | "<td>%s</td><td>%s</td>" |
| 3867 | /* bytes: in */ |
| 3868 | "<td>%s</td>" |
| 3869 | "", |
| 3870 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3871 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 3872 | U2H(stats[ST_F_BIN].u.u64)); |
| 3873 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3874 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3875 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 3876 | "<td>%s%s<div class=tips><table class=det>" |
| 3877 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3878 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3879 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3880 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3881 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3882 | "</table></div>%s</td>", |
| 3883 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3884 | U2H(stats[ST_F_BOUT].u.u64), |
| 3885 | U2H(stats[ST_F_BOUT].u.u64), |
| 3886 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3887 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3888 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3889 | U2H(stats[ST_F_COMP_BYP].u.u64), |
Christopher Faulet | 0b64f62 | 2016-04-28 15:09:31 +0200 | [diff] [blame] | 3890 | 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] | 3891 | 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, |
| 3892 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 3893 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3894 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3895 | /* denied: req, resp */ |
| 3896 | "<td>%s</td><td>%s</td>" |
| 3897 | /* errors : request, connect */ |
| 3898 | "<td></td><td>%s</td>" |
| 3899 | /* errors : response */ |
| 3900 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3901 | /* warnings: retries, redispatches */ |
| 3902 | "<td>%lld</td><td>%lld</td>" |
| 3903 | /* backend status: reflect backend status (up/down): we display UP |
| 3904 | * if the backend has known working servers or if it has no server at |
| 3905 | * all (eg: for stats). Then we display the total weight, number of |
| 3906 | * active and backups. */ |
| 3907 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3908 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3909 | "", |
| 3910 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3911 | U2H(stats[ST_F_ECON].u.u64), |
| 3912 | U2H(stats[ST_F_ERESP].u.u64), |
| 3913 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3914 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3915 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 3916 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 3917 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
| 3918 | stats[ST_F_WEIGHT].u.u32, |
| 3919 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 3920 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3921 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3922 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3923 | "<td class=ac> </td><td>%d</td>" |
| 3924 | "<td>%s</td>" |
| 3925 | "<td></td>" |
| 3926 | "</tr>", |
| 3927 | stats[ST_F_CHKDOWN].u.u32, |
| 3928 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
| 3929 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3930 | return 1; |
| 3931 | } |
| 3932 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3933 | static int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx) |
| 3934 | { |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3935 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
| 3936 | flags |= ST_SHOWADMIN; |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3937 | |
| 3938 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3939 | return stats_dump_fields_html(&trash, stats, flags); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3940 | else if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3941 | return stats_dump_fields_typed(&trash, stats); |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3942 | else |
| 3943 | return stats_dump_fields_csv(&trash, stats); |
| 3944 | } |
| 3945 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3946 | /* Fill <stats> with the frontend statistics. <stats> is |
| 3947 | * preallocated array of length <len>. The length of the array |
| 3948 | * must be at least ST_F_TOTAL_FIELDS. If this length is less then |
| 3949 | * this value, the function returns 0, otherwise, it returns 1. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3950 | */ |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3951 | 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] | 3952 | { |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3953 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3954 | return 0; |
| 3955 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3956 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3957 | |
| 3958 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 3959 | 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] | 3960 | 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] | 3961 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 3962 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 3963 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 3964 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 3965 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 3966 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 3967 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 3968 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 3969 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 3970 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); |
| 3971 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 3972 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 3973 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 3974 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 3975 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 3976 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 3977 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 3978 | |
| 3979 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3980 | if (px->mode == PR_MODE_HTTP) { |
| 3981 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 3982 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 3983 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 3984 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 3985 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 3986 | 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] | 3987 | 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] | 3988 | } |
| 3989 | |
| 3990 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3991 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 3992 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 3993 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 3994 | |
| 3995 | /* compression: in, out, bypassed, responses */ |
| 3996 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 3997 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 3998 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 3999 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 4000 | |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 4001 | /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */ |
| 4002 | stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 4003 | stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 4004 | stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 4005 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 4006 | return 1; |
| 4007 | } |
| 4008 | |
| 4009 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 4010 | * the state from stream interface <si>. The caller is responsible for clearing |
| 4011 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4012 | */ |
| 4013 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
| 4014 | { |
| 4015 | struct appctx *appctx = __objt_appctx(si->end); |
| 4016 | |
| 4017 | if (!(px->cap & PR_CAP_FE)) |
| 4018 | return 0; |
| 4019 | |
| 4020 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 4021 | return 0; |
| 4022 | |
| 4023 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS)) |
| 4024 | return 0; |
| 4025 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4026 | return stats_dump_one_line(stats, 0, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4027 | } |
| 4028 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4029 | /* Fill <stats> with the listener statistics. <stats> is |
| 4030 | * preallocated array of length <len>. The length of the array |
| 4031 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4032 | * then this value, the function returns 0, otherwise, it |
| 4033 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4034 | */ |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4035 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
| 4036 | struct field *stats, int len) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4037 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4038 | struct chunk *out = get_trash_chunk(); |
| 4039 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4040 | if (len < ST_F_TOTAL_FIELDS) |
| 4041 | return 0; |
| 4042 | |
Thierry Fournier | ac9d467 | 2016-03-25 08:43:46 +0100 | [diff] [blame] | 4043 | if (!l->counters) |
| 4044 | return 0; |
| 4045 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4046 | chunk_reset(out); |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4047 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4048 | |
| 4049 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4050 | 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] | 4051 | 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] | 4052 | stats[ST_F_SCUR] = mkf_u32(0, l->nbconn); |
| 4053 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max); |
| 4054 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn); |
| 4055 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 4056 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 4057 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 4058 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 4059 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 4060 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 4061 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 4062 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4063 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4064 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 4065 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 4066 | |
| 4067 | if (flags & ST_SHLGNDS) { |
| 4068 | char str[INET6_ADDRSTRLEN]; |
| 4069 | int port; |
| 4070 | |
| 4071 | port = get_host_port(&l->addr); |
| 4072 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 4073 | case AF_INET: |
| 4074 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4075 | chunk_appendf(out, "%s:%d", str, port); |
| 4076 | break; |
| 4077 | case AF_INET6: |
| 4078 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4079 | chunk_appendf(out, "[%s]:%d", str, port); |
| 4080 | break; |
| 4081 | case AF_UNIX: |
| 4082 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4083 | break; |
| 4084 | case -1: |
| 4085 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4086 | chunk_strcat(out, strerror(errno)); |
| 4087 | break; |
| 4088 | default: /* address family not supported */ |
| 4089 | break; |
| 4090 | } |
| 4091 | } |
| 4092 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4093 | return 1; |
| 4094 | } |
| 4095 | |
| 4096 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 4097 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 4098 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 4099 | * otherwise. |
| 4100 | */ |
| 4101 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
| 4102 | { |
| 4103 | struct appctx *appctx = __objt_appctx(si->end); |
| 4104 | |
| 4105 | if (!stats_fill_li_stats(px, l, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4106 | return 0; |
| 4107 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4108 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | enum srv_stats_state { |
| 4112 | SRV_STATS_STATE_DOWN = 0, |
| 4113 | SRV_STATS_STATE_DOWN_AGENT, |
| 4114 | SRV_STATS_STATE_GOING_UP, |
| 4115 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 4116 | SRV_STATS_STATE_UP, |
| 4117 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4118 | SRV_STATS_STATE_NOLB, |
| 4119 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 4120 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4121 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4122 | SRV_STATS_STATE_NO_CHECK, |
| 4123 | |
| 4124 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 4125 | }; |
| 4126 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4127 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 4128 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 4129 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 4130 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 4131 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 4132 | [SRV_STATS_STATE_UP] = "UP", |
| 4133 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 4134 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 4135 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 4136 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 4137 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 4138 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 4139 | }; |
| 4140 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4141 | /* Fill <stats> with the server statistics. <stats> is |
| 4142 | * preallocated array of length <len>. The length of the array |
| 4143 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4144 | * then this value, the function returns 0, otherwise, it |
| 4145 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4146 | */ |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4147 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 4148 | struct field *stats, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4149 | { |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4150 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4151 | char str[INET6_ADDRSTRLEN]; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4152 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4153 | enum srv_stats_state state; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4154 | char *fld_status; |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4155 | |
| 4156 | if (len < ST_F_TOTAL_FIELDS) |
| 4157 | return 0; |
| 4158 | |
| 4159 | memset(stats, 0, sizeof(*stats) * len); |
| 4160 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4161 | /* we have "via" which is the tracked server as described in the configuration, |
| 4162 | * and "ref" which is the checked server and the end of the chain. |
| 4163 | */ |
| 4164 | via = sv->track ? sv->track : sv; |
| 4165 | ref = via; |
| 4166 | while (ref->track) |
| 4167 | ref = ref->track; |
| 4168 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4169 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 4170 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 4171 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
| 4172 | state = SRV_STATS_STATE_UP_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4173 | } else { |
| 4174 | state = SRV_STATS_STATE_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4175 | } |
| 4176 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4177 | if (sv->admin & SRV_ADMF_DRAIN) { |
| 4178 | if (ref->agent.state & CHK_ST_ENABLED) |
| 4179 | state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4180 | else if (state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 4181 | state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
| 4182 | else |
| 4183 | state = SRV_STATS_STATE_DRAIN; |
| 4184 | } |
| 4185 | |
| 4186 | if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 4187 | state = SRV_STATS_STATE_NO_CHECK; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4188 | } |
| 4189 | } |
| 4190 | else if (sv->state == SRV_ST_STOPPING) { |
| 4191 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 4192 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
| 4193 | state = SRV_STATS_STATE_NOLB; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4194 | } else { |
| 4195 | state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4196 | } |
| 4197 | } |
| 4198 | else { /* stopped */ |
| 4199 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
| 4200 | state = SRV_STATS_STATE_DOWN_AGENT; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4201 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
| 4202 | state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4203 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
| 4204 | state = SRV_STATS_STATE_GOING_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4205 | } else { |
| 4206 | state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4207 | } |
| 4208 | } |
| 4209 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4210 | chunk_reset(out); |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4211 | |
| 4212 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4213 | 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] | 4214 | 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] | 4215 | stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend); |
| 4216 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 4217 | stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess); |
| 4218 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 4219 | |
| 4220 | if (sv->maxconn) |
| 4221 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 4222 | |
| 4223 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 4224 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 4225 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 4226 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu); |
| 4227 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 4228 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 4229 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 4230 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 4231 | |
| 4232 | /* status */ |
| 4233 | fld_status = chunk_newstr(out); |
| 4234 | if (sv->admin & SRV_ADMF_IMAINT) |
| 4235 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 4236 | else if (sv->admin & SRV_ADMF_MAINT) |
| 4237 | chunk_appendf(out, "MAINT"); |
| 4238 | else |
| 4239 | chunk_appendf(out, |
| 4240 | srv_hlt_st[state], |
| 4241 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 4242 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
| 4243 | |
| 4244 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4245 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 4246 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4247 | stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 4248 | 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] | 4249 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4250 | /* check failures: unique, fatal; last change, total downtime */ |
| 4251 | if (sv->check.state & CHK_ST_ENABLED) { |
| 4252 | stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 4253 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 4254 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 4255 | } |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4256 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4257 | if (sv->maxqueue) |
| 4258 | stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4259 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4260 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4261 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4262 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4263 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4264 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 4265 | stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4266 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4267 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4268 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4269 | if (sv->track) { |
| 4270 | char *fld_track = chunk_newstr(out); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4271 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4272 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 4273 | stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 4274 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4275 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4276 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 4277 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 4278 | 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] | 4279 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4280 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4281 | const char *fld_chksts; |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4282 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4283 | fld_chksts = chunk_newstr(out); |
| 4284 | chunk_strcat(out, "* "); // for check in progress |
| 4285 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 4286 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 4287 | fld_chksts += 2; // skip "* " |
| 4288 | stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4289 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4290 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 4291 | stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4292 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4293 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 4294 | stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4295 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4296 | stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 4297 | stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc); |
| 4298 | stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 4299 | stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 4300 | stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 4301 | } |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4302 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4303 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4304 | const char *fld_chksts; |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4305 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4306 | fld_chksts = chunk_newstr(out); |
| 4307 | chunk_strcat(out, "* "); // for check in progress |
| 4308 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 4309 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 4310 | fld_chksts += 2; // skip "* " |
| 4311 | stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4312 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4313 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 4314 | stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4315 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4316 | if (sv->agent.status >= HCHK_STATUS_CHECKED) |
| 4317 | stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4318 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4319 | stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 4320 | stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 4321 | stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 4322 | stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 4323 | stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 4324 | } |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4325 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4326 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4327 | if (px->mode == PR_MODE_HTTP) { |
| 4328 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 4329 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 4330 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 4331 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 4332 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 4333 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 4334 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4335 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4336 | if (ref->observe) |
| 4337 | stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4338 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4339 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 4340 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 4341 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv)); |
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_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES)); |
| 4344 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES)); |
| 4345 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES)); |
| 4346 | 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] | 4347 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4348 | if (flags & ST_SHLGNDS) { |
| 4349 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 4350 | case AF_INET: |
| 4351 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4352 | chunk_appendf(out, "%s:%d", str, get_host_port(&sv->addr)); |
| 4353 | break; |
| 4354 | case AF_INET6: |
| 4355 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4356 | chunk_appendf(out, "[%s]:%d", str, get_host_port(&sv->addr)); |
| 4357 | break; |
| 4358 | case AF_UNIX: |
| 4359 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4360 | break; |
| 4361 | case -1: |
| 4362 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4363 | chunk_strcat(out, strerror(errno)); |
| 4364 | break; |
| 4365 | default: /* address family not supported */ |
| 4366 | break; |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 4367 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4368 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4369 | if (sv->cookie) |
| 4370 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 4371 | } |
| 4372 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4373 | return 1; |
| 4374 | } |
| 4375 | |
| 4376 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 4377 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 4378 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 4379 | * if it emits anything, zero otherwise. |
| 4380 | */ |
| 4381 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv) |
| 4382 | { |
| 4383 | struct appctx *appctx = __objt_appctx(si->end); |
| 4384 | |
| 4385 | if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4386 | return 0; |
| 4387 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4388 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4389 | } |
| 4390 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4391 | /* Fill <stats> with the backend statistics. <stats> is |
| 4392 | * preallocated array of length <len>. The length of the array |
| 4393 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4394 | * then this value, the function returns 0, otherwise, it |
| 4395 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4396 | */ |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4397 | 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] | 4398 | { |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4399 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4400 | return 0; |
| 4401 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4402 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4403 | |
| 4404 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4405 | 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] | 4406 | 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] | 4407 | stats[ST_F_QCUR] = mkf_u32(0, px->nbpend); |
| 4408 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 4409 | stats[ST_F_SCUR] = mkf_u32(FO_CONFIG|FN_LIMIT, px->beconn); |
| 4410 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 4411 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 4412 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 4413 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 4414 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 4415 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 4416 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 4417 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 4418 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 4419 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 4420 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 4421 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 4422 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4423 | stats[ST_F_ACT] = mkf_u32(0, px->srv_act); |
| 4424 | stats[ST_F_BCK] = mkf_u32(0, px->srv_bck); |
| 4425 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans); |
| 4426 | 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] | 4427 | if (px->srv) |
| 4428 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 4429 | |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4430 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4431 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4432 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 4433 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 4434 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 4435 | stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 4436 | 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] | 4437 | |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 4438 | if (flags & ST_SHLGNDS) { |
| 4439 | if (px->cookie_name) |
| 4440 | 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] | 4441 | 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] | 4442 | } |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4443 | |
| 4444 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4445 | if (px->mode == PR_MODE_HTTP) { |
| 4446 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 4447 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 4448 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 4449 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 4450 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 4451 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 4452 | 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] | 4453 | 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] | 4454 | } |
| 4455 | |
| 4456 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 4457 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 4458 | |
| 4459 | /* compression: in, out, bypassed, responses */ |
| 4460 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 4461 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 4462 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 4463 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 4464 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px)); |
| 4465 | |
| 4466 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES)); |
| 4467 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES)); |
| 4468 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); |
| 4469 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4470 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4471 | return 1; |
| 4472 | } |
| 4473 | |
| 4474 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 4475 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 4476 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4477 | */ |
| 4478 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 4479 | { |
| 4480 | struct appctx *appctx = __objt_appctx(si->end); |
| 4481 | |
| 4482 | if (!(px->cap & PR_CAP_BE)) |
| 4483 | return 0; |
| 4484 | |
| 4485 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 4486 | return 0; |
| 4487 | |
| 4488 | if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4489 | return 0; |
| 4490 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4491 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4492 | } |
| 4493 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4494 | /* 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] | 4495 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4496 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4497 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4498 | 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] | 4499 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4500 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4501 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4503 | 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] | 4504 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4505 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4506 | /* 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] | 4507 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4508 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4509 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4510 | 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] | 4511 | 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] | 4512 | } |
| 4513 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4514 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4515 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | /* print a new table */ |
| 4519 | chunk_appendf(&trash, |
| 4520 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4521 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4522 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4523 | |
| 4524 | chunk_appendf(&trash, |
| 4525 | "<a name=\"%s\"></a>%s" |
| 4526 | "<a class=px href=\"#%s\">%s</a>", |
| 4527 | px->id, |
| 4528 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4529 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4530 | |
| 4531 | if (uri->flags & ST_SHLGNDS) { |
| 4532 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4533 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4534 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4535 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4536 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4540 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4541 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4542 | "</tr>\n" |
| 4543 | "</table>\n" |
| 4544 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4545 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4546 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4547 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4548 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4549 | 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] | 4550 | /* Column heading for Enable or Disable server */ |
| 4551 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4552 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4553 | |
| 4554 | chunk_appendf(&trash, |
| 4555 | "<th rowspan=2></th>" |
| 4556 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4557 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4558 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4559 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4560 | "<th colspan=9>Server</th>" |
| 4561 | "</tr>\n" |
| 4562 | "<tr class=\"titre\">" |
| 4563 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4564 | "<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] | 4565 | "<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] | 4566 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4567 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4568 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4569 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4570 | "<th>Thrtle</th>\n" |
| 4571 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4572 | } |
| 4573 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4574 | /* 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] | 4575 | * 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] | 4576 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4577 | 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] | 4578 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4579 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4580 | chunk_appendf(&trash, "</table>"); |
| 4581 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4582 | 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] | 4583 | /* close the form used to enable/disable this proxy servers */ |
| 4584 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4585 | "Choose the action to perform on the checked servers : " |
| 4586 | "<select name=action>" |
| 4587 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4588 | "<option value=\"ready\">Set state to READY</option>" |
| 4589 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4590 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4591 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4592 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4593 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4594 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4595 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4596 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4597 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4598 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4599 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4600 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4601 | "</select>" |
| 4602 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4603 | " <input type=\"submit\" value=\"Apply\">" |
| 4604 | "</form>", |
| 4605 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4606 | } |
| 4607 | |
| 4608 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4609 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4610 | |
| 4611 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4612 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4613 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4614 | * buffer space, or non-zero if everything completed. This function is used |
| 4615 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4616 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4617 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4618 | 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] | 4619 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4620 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4621 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4622 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4623 | 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] | 4624 | struct listener *l; |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4625 | unsigned int flags; |
| 4626 | |
| 4627 | if (uri) |
| 4628 | flags = uri->flags; |
| 4629 | else if (strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) |
| 4630 | flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC; |
| 4631 | else |
| 4632 | flags = ST_SHNODE | ST_SHDESC; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4633 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4634 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4635 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4636 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4637 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4638 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4639 | if (uri && uri->scope) { |
| 4640 | /* we have a limited scope, we have to check the proxy name */ |
| 4641 | struct stat_scope *scope; |
| 4642 | int len; |
| 4643 | |
| 4644 | len = strlen(px->id); |
| 4645 | scope = uri->scope; |
| 4646 | |
| 4647 | while (scope) { |
| 4648 | /* match exact proxy name */ |
| 4649 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4650 | break; |
| 4651 | |
| 4652 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4653 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4654 | break; |
| 4655 | scope = scope->next; |
| 4656 | } |
| 4657 | |
| 4658 | /* proxy name not found : don't dump anything */ |
| 4659 | if (scope == NULL) |
| 4660 | return 1; |
| 4661 | } |
| 4662 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4663 | /* if the user has requested a limited output and the proxy |
| 4664 | * name does not match, skip it. |
| 4665 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4666 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4667 | 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] | 4668 | return 1; |
| 4669 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4670 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4671 | (appctx->ctx.stats.iid != -1) && |
| 4672 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4673 | return 1; |
| 4674 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4675 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4676 | /* fall through */ |
| 4677 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4678 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4679 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4680 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4681 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4682 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4683 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4684 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4685 | } |
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 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4688 | /* fall through */ |
| 4689 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4690 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4691 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4692 | if (stats_dump_fe_stats(si, px)) { |
| 4693 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4694 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4695 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4696 | } |
| 4697 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4698 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4699 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4700 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4701 | /* fall through */ |
| 4702 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4703 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4704 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4705 | 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] | 4706 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4707 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4708 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4709 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4710 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4711 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4712 | if (!l->counters) |
| 4713 | continue; |
| 4714 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4715 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4716 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4717 | break; |
| 4718 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4719 | 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] | 4720 | continue; |
| 4721 | } |
| 4722 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4723 | /* print the frontend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4724 | if (stats_dump_li_stats(si, px, l, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4725 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4726 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4727 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4728 | } |
| 4729 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4730 | } |
| 4731 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4732 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4733 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4734 | /* fall through */ |
| 4735 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4736 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4737 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4738 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4739 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4740 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4741 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4742 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4743 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4744 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4745 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4746 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4747 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4748 | break; |
| 4749 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4750 | 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] | 4751 | continue; |
| 4752 | } |
| 4753 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4754 | svs = sv; |
| 4755 | while (svs->track) |
| 4756 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4757 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4758 | /* do not report servers which are DOWN and not changing state */ |
| 4759 | if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) && |
| 4760 | ((sv->admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 4761 | (sv->state == SRV_ST_STOPPED && /* server is down */ |
| 4762 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 4763 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 4764 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4765 | continue; |
| 4766 | } |
| 4767 | |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4768 | if (stats_dump_sv_stats(si, px, flags, sv)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4769 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4770 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4771 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4772 | } |
| 4773 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4774 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4775 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4776 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4777 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4778 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4779 | case STAT_PX_ST_BE: |
| 4780 | /* print the backend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4781 | if (stats_dump_be_stats(si, px, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4782 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4783 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4784 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4785 | } |
| 4786 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4787 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4788 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4789 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4790 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4791 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4792 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4793 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4794 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4795 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4796 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4797 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4798 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4799 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4800 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4801 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4802 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4803 | case STAT_PX_ST_FIN: |
| 4804 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4805 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4806 | default: |
| 4807 | /* unknown state, we should put an abort() here ! */ |
| 4808 | return 1; |
| 4809 | } |
| 4810 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4811 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4812 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4813 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4814 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4815 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4816 | { |
| 4817 | /* WARNING! This must fit in the first buffer !!! */ |
| 4818 | chunk_appendf(&trash, |
| 4819 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4820 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4821 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4822 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4823 | "<style type=\"text/css\"><!--\n" |
| 4824 | "body {" |
| 4825 | " font-family: arial, helvetica, sans-serif;" |
| 4826 | " font-size: 12px;" |
| 4827 | " font-weight: normal;" |
| 4828 | " color: black;" |
| 4829 | " background: white;" |
| 4830 | "}\n" |
| 4831 | "th,td {" |
| 4832 | " font-size: 10px;" |
| 4833 | "}\n" |
| 4834 | "h1 {" |
| 4835 | " font-size: x-large;" |
| 4836 | " margin-bottom: 0.5em;" |
| 4837 | "}\n" |
| 4838 | "h2 {" |
| 4839 | " font-family: helvetica, arial;" |
| 4840 | " font-size: x-large;" |
| 4841 | " font-weight: bold;" |
| 4842 | " font-style: italic;" |
| 4843 | " color: #6020a0;" |
| 4844 | " margin-top: 0em;" |
| 4845 | " margin-bottom: 0em;" |
| 4846 | "}\n" |
| 4847 | "h3 {" |
| 4848 | " font-family: helvetica, arial;" |
| 4849 | " font-size: 16px;" |
| 4850 | " font-weight: bold;" |
| 4851 | " color: #b00040;" |
| 4852 | " background: #e8e8d0;" |
| 4853 | " margin-top: 0em;" |
| 4854 | " margin-bottom: 0em;" |
| 4855 | "}\n" |
| 4856 | "li {" |
| 4857 | " margin-top: 0.25em;" |
| 4858 | " margin-right: 2em;" |
| 4859 | "}\n" |
| 4860 | ".hr {margin-top: 0.25em;" |
| 4861 | " border-color: black;" |
| 4862 | " border-bottom-style: solid;" |
| 4863 | "}\n" |
| 4864 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4865 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4866 | ".frontend {background: #e8e8d0;}\n" |
| 4867 | ".socket {background: #d0d0d0;}\n" |
| 4868 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4869 | ".active_down {background: #ff9090;}\n" |
| 4870 | ".active_going_up {background: #ffd020;}\n" |
| 4871 | ".active_going_down {background: #ffffa0;}\n" |
| 4872 | ".active_up {background: #c0ffc0;}\n" |
| 4873 | ".active_nolb {background: #20a0ff;}\n" |
| 4874 | ".active_draining {background: #20a0FF;}\n" |
| 4875 | ".active_no_check {background: #e0e0e0;}\n" |
| 4876 | ".backup_down {background: #ff9090;}\n" |
| 4877 | ".backup_going_up {background: #ff80ff;}\n" |
| 4878 | ".backup_going_down {background: #c060ff;}\n" |
| 4879 | ".backup_up {background: #b0d0ff;}\n" |
| 4880 | ".backup_nolb {background: #90b0e0;}\n" |
| 4881 | ".backup_draining {background: #cc9900;}\n" |
| 4882 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4883 | ".maintain {background: #c07820;}\n" |
| 4884 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4885 | "\n" |
| 4886 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4887 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4888 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4889 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4890 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4891 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4892 | "\n" |
| 4893 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4894 | "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" |
| 4895 | "table.tbl td.ac { text-align: center;}\n" |
| 4896 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4897 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4898 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4899 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4900 | "\n" |
| 4901 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4902 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4903 | "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] | 4904 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4905 | "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] | 4906 | "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] | 4907 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4908 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4909 | " display:block;\n" |
| 4910 | " visibility:hidden;\n" |
| 4911 | " z-index:2147483647;\n" |
| 4912 | " position:absolute;\n" |
| 4913 | " padding:2px 4px 3px;\n" |
| 4914 | " background:#f0f060; color:#000000;\n" |
| 4915 | " border:1px solid #7040c0;\n" |
| 4916 | " white-space:nowrap;\n" |
| 4917 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4918 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4919 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4920 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4921 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4922 | "-->\n" |
| 4923 | "</style></head>\n", |
| 4924 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4925 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4926 | ); |
| 4927 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4928 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4929 | /* 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] | 4930 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4931 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4932 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4933 | 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] | 4934 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4935 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4936 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4937 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4938 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4939 | /* WARNING! this has to fit the first packet too. |
| 4940 | * We are around 3.5 kB, add adding entries will |
| 4941 | * become tricky if we want to support 4kB buffers ! |
| 4942 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4943 | chunk_appendf(&trash, |
| 4944 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4945 | PRODUCT_NAME "%s</a></h1>\n" |
| 4946 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4947 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4948 | "<h3>> General process information</h3>\n" |
| 4949 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4950 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4951 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4952 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4953 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4954 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4955 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4956 | "</td><td align=\"center\" nowrap>\n" |
| 4957 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4958 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4959 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4960 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4961 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4962 | "<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] | 4963 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4964 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4965 | "<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] | 4966 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4967 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4968 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4969 | "</tr><tr>\n" |
| 4970 | "<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] | 4971 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4972 | "<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] | 4973 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4974 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4975 | "</td>" |
| 4976 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4977 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4978 | "", |
| 4979 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4980 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4981 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4982 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4983 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4984 | pid, relative_pid, global.nbproc, |
| 4985 | up / 86400, (up % 86400) / 3600, |
| 4986 | (up % 3600) / 60, (up % 60), |
| 4987 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4988 | global.rlimit_memmax ? " MB" : "", |
| 4989 | global.rlimit_nofile, |
| 4990 | global.maxsock, global.maxconn, global.maxpipes, |
| 4991 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4992 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4993 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4994 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4995 | /* 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] | 4996 | 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] | 4997 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4998 | |
| 4999 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 5000 | "<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] | 5001 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5002 | STAT_SCOPE_TXT_MAXLEN); |
| 5003 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5004 | /* 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] | 5005 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5006 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5007 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5008 | 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] | 5009 | 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] | 5010 | } |
| 5011 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5012 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5013 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5014 | "<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] | 5015 | uri->uri_prefix, |
| 5016 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5017 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5018 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5019 | else |
| 5020 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5021 | "<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] | 5022 | uri->uri_prefix, |
| 5023 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5024 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5025 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5026 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5027 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5028 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5029 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5030 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5031 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5032 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5033 | "", |
| 5034 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5035 | else |
| 5036 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5037 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5038 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5039 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5040 | ";norefresh", |
| 5041 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5042 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 5043 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5044 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5045 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5046 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5047 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5048 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5049 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 5050 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5051 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5052 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5053 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5054 | (uri->refresh > 0) ? ";norefresh" : "", |
| 5055 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5056 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5057 | chunk_appendf(&trash, |
| 5058 | "</ul></td>" |
| 5059 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 5060 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 5061 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 5062 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 5063 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 5064 | "</ul>" |
| 5065 | "</td>" |
| 5066 | "</tr></table>\n" |
| 5067 | "" |
| 5068 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5069 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5070 | if (appctx->ctx.stats.st_code) { |
| 5071 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5072 | case STAT_STATUS_DONE: |
| 5073 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5074 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5075 | "<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] | 5076 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5077 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5078 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5079 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5080 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5081 | break; |
| 5082 | case STAT_STATUS_NONE: |
| 5083 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5084 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5085 | "<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] | 5086 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5087 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5088 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5089 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5090 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5091 | break; |
| 5092 | case STAT_STATUS_PART: |
| 5093 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5094 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5095 | "<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] | 5096 | "Action partially processed.<br>" |
| 5097 | "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] | 5098 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5099 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5100 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5101 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5102 | break; |
| 5103 | case STAT_STATUS_ERRP: |
| 5104 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5105 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5106 | "<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] | 5107 | "Action not processed because of invalid parameters." |
| 5108 | "<ul>" |
| 5109 | "<li>The action is maybe unknown.</li>" |
| 5110 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 5111 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 5112 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5113 | "</div>\n", 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" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5116 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5117 | break; |
| 5118 | case STAT_STATUS_EXCD: |
| 5119 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5120 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5121 | "<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] | 5122 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 5123 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5124 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5125 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5126 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5127 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5128 | break; |
| 5129 | case STAT_STATUS_DENY: |
| 5130 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5131 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5132 | "<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] | 5133 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5134 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5135 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5136 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5137 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5138 | break; |
| 5139 | default: |
| 5140 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5141 | "<p><div class=active_no_check>" |
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 | "Unexpected result." |
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 | } |
| 5149 | chunk_appendf(&trash, "<p>\n"); |
| 5150 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5151 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5152 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5153 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 5154 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5155 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5156 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5157 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5158 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5159 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5160 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5161 | /* This function dumps statistics onto the stream interface's read buffer in |
| 5162 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5163 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 5164 | * 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] | 5165 | * 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] | 5166 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5167 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5168 | 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] | 5169 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5170 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5171 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5172 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5173 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5174 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5175 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5176 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5177 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5178 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5179 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 5180 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5181 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5182 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5183 | stats_dump_html_head(uri); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 5184 | else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED)) |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 5185 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 5186 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5187 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5188 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5189 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5190 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5191 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5192 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5193 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5194 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5195 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5196 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5197 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5198 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5199 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5200 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5201 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5202 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5203 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5204 | appctx->ctx.stats.px = proxy; |
| 5205 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 5206 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5207 | /* fall through */ |
| 5208 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5209 | case STAT_ST_LIST: |
| 5210 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5211 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5212 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5213 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5214 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5215 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5216 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5217 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5218 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5219 | 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] | 5220 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5221 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5222 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5223 | appctx->ctx.stats.px = px->next; |
| 5224 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5225 | } |
| 5226 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5227 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5228 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5229 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5230 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5231 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5232 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5233 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5234 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5235 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5236 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5237 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5238 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5239 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5240 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5241 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5242 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5243 | case STAT_ST_FIN: |
| 5244 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5245 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5246 | default: |
| 5247 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5248 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5249 | return -1; |
| 5250 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5251 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5252 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5253 | /* We reached the stats page through a POST request. The appctx is |
| 5254 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5255 | * Parse the posted data and enable/disable servers if necessary. |
| 5256 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5257 | */ |
| 5258 | static int stats_process_http_post(struct stream_interface *si) |
| 5259 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5260 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5261 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5262 | |
| 5263 | struct proxy *px = NULL; |
| 5264 | struct server *sv = NULL; |
| 5265 | |
| 5266 | char key[LINESIZE]; |
| 5267 | int action = ST_ADM_ACTION_NONE; |
| 5268 | int reprocess = 0; |
| 5269 | |
| 5270 | int total_servers = 0; |
| 5271 | int altered_servers = 0; |
| 5272 | |
| 5273 | char *first_param, *cur_param, *next_param, *end_params; |
| 5274 | char *st_cur_param = NULL; |
| 5275 | char *st_next_param = NULL; |
| 5276 | |
| 5277 | struct chunk *temp; |
| 5278 | int reql; |
| 5279 | |
| 5280 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5281 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5282 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5283 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5284 | goto out; |
| 5285 | } |
| 5286 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5287 | 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] | 5288 | if (reql <= 0) { |
| 5289 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5290 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5291 | return 0; |
| 5292 | } |
| 5293 | |
| 5294 | first_param = temp->str; |
| 5295 | end_params = temp->str + reql; |
| 5296 | cur_param = next_param = end_params; |
| 5297 | *end_params = '\0'; |
| 5298 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5299 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5300 | |
| 5301 | /* |
| 5302 | * Parse the parameters in reverse order to only store the last value. |
| 5303 | * From the html form, the backend and the action are at the end. |
| 5304 | */ |
| 5305 | while (cur_param > first_param) { |
| 5306 | char *value; |
| 5307 | int poffset, plen; |
| 5308 | |
| 5309 | cur_param--; |
| 5310 | |
| 5311 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5312 | reprocess_servers: |
| 5313 | /* Parse the key */ |
| 5314 | poffset = (cur_param != first_param ? 1 : 0); |
| 5315 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5316 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5317 | strncpy(key, cur_param + poffset, plen); |
| 5318 | key[plen - 1] = '\0'; |
| 5319 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5320 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5321 | goto out; |
| 5322 | } |
| 5323 | |
| 5324 | /* Parse the value */ |
| 5325 | value = key; |
| 5326 | while (*value != '\0' && *value != '=') { |
| 5327 | value++; |
| 5328 | } |
| 5329 | if (*value == '=') { |
| 5330 | /* Ok, a value is found, we can mark the end of the key */ |
| 5331 | *value++ = '\0'; |
| 5332 | } |
| 5333 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5334 | break; |
| 5335 | |
| 5336 | /* Now we can check the key to see what to do */ |
| 5337 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5338 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5339 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5340 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5341 | goto out; |
| 5342 | } |
| 5343 | } |
| 5344 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5345 | if (strcmp(value, "ready") == 0) { |
| 5346 | action = ST_ADM_ACTION_READY; |
| 5347 | } |
| 5348 | else if (strcmp(value, "drain") == 0) { |
| 5349 | action = ST_ADM_ACTION_DRAIN; |
| 5350 | } |
| 5351 | else if (strcmp(value, "maint") == 0) { |
| 5352 | action = ST_ADM_ACTION_MAINT; |
| 5353 | } |
| 5354 | else if (strcmp(value, "shutdown") == 0) { |
| 5355 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5356 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5357 | else if (strcmp(value, "dhlth") == 0) { |
| 5358 | action = ST_ADM_ACTION_DHLTH; |
| 5359 | } |
| 5360 | else if (strcmp(value, "ehlth") == 0) { |
| 5361 | action = ST_ADM_ACTION_EHLTH; |
| 5362 | } |
| 5363 | else if (strcmp(value, "hrunn") == 0) { |
| 5364 | action = ST_ADM_ACTION_HRUNN; |
| 5365 | } |
| 5366 | else if (strcmp(value, "hnolb") == 0) { |
| 5367 | action = ST_ADM_ACTION_HNOLB; |
| 5368 | } |
| 5369 | else if (strcmp(value, "hdown") == 0) { |
| 5370 | action = ST_ADM_ACTION_HDOWN; |
| 5371 | } |
| 5372 | else if (strcmp(value, "dagent") == 0) { |
| 5373 | action = ST_ADM_ACTION_DAGENT; |
| 5374 | } |
| 5375 | else if (strcmp(value, "eagent") == 0) { |
| 5376 | action = ST_ADM_ACTION_EAGENT; |
| 5377 | } |
| 5378 | else if (strcmp(value, "arunn") == 0) { |
| 5379 | action = ST_ADM_ACTION_ARUNN; |
| 5380 | } |
| 5381 | else if (strcmp(value, "adown") == 0) { |
| 5382 | action = ST_ADM_ACTION_ADOWN; |
| 5383 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5384 | /* else these are the old supported methods */ |
| 5385 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5386 | action = ST_ADM_ACTION_DISABLE; |
| 5387 | } |
| 5388 | else if (strcmp(value, "enable") == 0) { |
| 5389 | action = ST_ADM_ACTION_ENABLE; |
| 5390 | } |
| 5391 | else if (strcmp(value, "stop") == 0) { |
| 5392 | action = ST_ADM_ACTION_STOP; |
| 5393 | } |
| 5394 | else if (strcmp(value, "start") == 0) { |
| 5395 | action = ST_ADM_ACTION_START; |
| 5396 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5397 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5398 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5399 | goto out; |
| 5400 | } |
| 5401 | } |
| 5402 | else if (strcmp(key, "s") == 0) { |
| 5403 | if (!(px && action)) { |
| 5404 | /* |
| 5405 | * Indicates that we'll need to reprocess the parameters |
| 5406 | * as soon as backend and action are known |
| 5407 | */ |
| 5408 | if (!reprocess) { |
| 5409 | st_cur_param = cur_param; |
| 5410 | st_next_param = next_param; |
| 5411 | } |
| 5412 | reprocess = 1; |
| 5413 | } |
| 5414 | else if ((sv = findserver(px, value)) != NULL) { |
| 5415 | switch (action) { |
| 5416 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5417 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5418 | altered_servers++; |
| 5419 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5420 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5421 | } |
| 5422 | break; |
| 5423 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5424 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5425 | altered_servers++; |
| 5426 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5427 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5428 | } |
| 5429 | break; |
| 5430 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5431 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5432 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5433 | altered_servers++; |
| 5434 | total_servers++; |
| 5435 | } |
| 5436 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5437 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5438 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5439 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5440 | altered_servers++; |
| 5441 | total_servers++; |
| 5442 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5443 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5444 | case ST_ADM_ACTION_DHLTH: |
| 5445 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5446 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5447 | altered_servers++; |
| 5448 | total_servers++; |
| 5449 | } |
| 5450 | break; |
| 5451 | case ST_ADM_ACTION_EHLTH: |
| 5452 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5453 | sv->check.state |= CHK_ST_ENABLED; |
| 5454 | altered_servers++; |
| 5455 | total_servers++; |
| 5456 | } |
| 5457 | break; |
| 5458 | case ST_ADM_ACTION_HRUNN: |
| 5459 | if (!(sv->track)) { |
| 5460 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5461 | srv_set_running(sv, "changed from Web interface"); |
| 5462 | altered_servers++; |
| 5463 | total_servers++; |
| 5464 | } |
| 5465 | break; |
| 5466 | case ST_ADM_ACTION_HNOLB: |
| 5467 | if (!(sv->track)) { |
| 5468 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5469 | srv_set_stopping(sv, "changed from Web interface"); |
| 5470 | altered_servers++; |
| 5471 | total_servers++; |
| 5472 | } |
| 5473 | break; |
| 5474 | case ST_ADM_ACTION_HDOWN: |
| 5475 | if (!(sv->track)) { |
| 5476 | sv->check.health = 0; |
| 5477 | srv_set_stopped(sv, "changed from Web interface"); |
| 5478 | altered_servers++; |
| 5479 | total_servers++; |
| 5480 | } |
| 5481 | break; |
| 5482 | case ST_ADM_ACTION_DAGENT: |
| 5483 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5484 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5485 | altered_servers++; |
| 5486 | total_servers++; |
| 5487 | } |
| 5488 | break; |
| 5489 | case ST_ADM_ACTION_EAGENT: |
| 5490 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5491 | sv->agent.state |= CHK_ST_ENABLED; |
| 5492 | altered_servers++; |
| 5493 | total_servers++; |
| 5494 | } |
| 5495 | break; |
| 5496 | case ST_ADM_ACTION_ARUNN: |
| 5497 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5498 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5499 | srv_set_running(sv, "changed from Web interface"); |
| 5500 | altered_servers++; |
| 5501 | total_servers++; |
| 5502 | } |
| 5503 | break; |
| 5504 | case ST_ADM_ACTION_ADOWN: |
| 5505 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5506 | sv->agent.health = 0; |
| 5507 | srv_set_stopped(sv, "changed from Web interface"); |
| 5508 | altered_servers++; |
| 5509 | total_servers++; |
| 5510 | } |
| 5511 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5512 | case ST_ADM_ACTION_READY: |
| 5513 | srv_adm_set_ready(sv); |
| 5514 | altered_servers++; |
| 5515 | total_servers++; |
| 5516 | break; |
| 5517 | case ST_ADM_ACTION_DRAIN: |
| 5518 | srv_adm_set_drain(sv); |
| 5519 | altered_servers++; |
| 5520 | total_servers++; |
| 5521 | break; |
| 5522 | case ST_ADM_ACTION_MAINT: |
| 5523 | srv_adm_set_maint(sv); |
| 5524 | altered_servers++; |
| 5525 | total_servers++; |
| 5526 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5527 | case ST_ADM_ACTION_SHUTDOWN: |
| 5528 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5529 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5530 | |
| 5531 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5532 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5533 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5534 | |
| 5535 | altered_servers++; |
| 5536 | total_servers++; |
| 5537 | } |
| 5538 | break; |
| 5539 | } |
| 5540 | } else { |
| 5541 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5542 | total_servers++; |
| 5543 | } |
| 5544 | } |
| 5545 | if (reprocess && px && action) { |
| 5546 | /* Now, we know the backend and the action chosen by the user. |
| 5547 | * We can safely restart from the first server parameter |
| 5548 | * to reprocess them |
| 5549 | */ |
| 5550 | cur_param = st_cur_param; |
| 5551 | next_param = st_next_param; |
| 5552 | reprocess = 0; |
| 5553 | goto reprocess_servers; |
| 5554 | } |
| 5555 | |
| 5556 | next_param = cur_param; |
| 5557 | } |
| 5558 | } |
| 5559 | |
| 5560 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5561 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5562 | } |
| 5563 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5564 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5565 | } |
| 5566 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5567 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5568 | } |
| 5569 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5570 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5571 | } |
| 5572 | out: |
| 5573 | return 1; |
| 5574 | } |
| 5575 | |
| 5576 | |
| 5577 | static int stats_send_http_headers(struct stream_interface *si) |
| 5578 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5579 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5580 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5581 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5582 | |
| 5583 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5584 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5585 | "Cache-Control: no-cache\r\n" |
| 5586 | "Connection: close\r\n" |
| 5587 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5588 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5589 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5590 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5591 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5592 | uri->refresh); |
| 5593 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5594 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5595 | |
| 5596 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5597 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5598 | else |
| 5599 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5600 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5601 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5602 | s->logs.tv_request = now; |
| 5603 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5604 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5605 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5606 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5607 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5608 | |
| 5609 | return 1; |
| 5610 | } |
| 5611 | |
| 5612 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5613 | { |
| 5614 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5615 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5616 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5617 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5618 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5619 | /* 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] | 5620 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5621 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5622 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5623 | 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] | 5624 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5625 | } |
| 5626 | |
| 5627 | /* We don't want to land on the posted stats page because a refresh will |
| 5628 | * repost the data. We don't want this to happen on accident so we redirect |
| 5629 | * the browse to the stats page with a GET. |
| 5630 | */ |
| 5631 | chunk_printf(&trash, |
| 5632 | "HTTP/1.1 303 See Other\r\n" |
| 5633 | "Cache-Control: no-cache\r\n" |
| 5634 | "Content-Type: text/plain\r\n" |
| 5635 | "Connection: close\r\n" |
| 5636 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5637 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5638 | "\r\n", |
| 5639 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5640 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5641 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5642 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5643 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5644 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5645 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5646 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5647 | scope_txt); |
| 5648 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5649 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5650 | s->logs.tv_request = now; |
| 5651 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5652 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5653 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5654 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5655 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5656 | |
| 5657 | return 1; |
| 5658 | } |
| 5659 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5660 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5661 | * 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] | 5662 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5663 | * automatically unregisters itself once transfer is complete. |
| 5664 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5665 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5666 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5667 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5668 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5669 | struct channel *req = si_oc(si); |
| 5670 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5671 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5672 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5673 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5674 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5675 | /* check that the output is not closed */ |
| 5676 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5677 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5678 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5679 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5680 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5681 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5682 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5683 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5684 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5685 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5686 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5687 | } |
| 5688 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5689 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5690 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5691 | unsigned int data_len; |
| 5692 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5693 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5694 | |
| 5695 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5696 | /* One difficulty we're facing is that we must prevent |
| 5697 | * the input data from being automatically forwarded to |
| 5698 | * the output area. For this, we temporarily disable |
| 5699 | * forwarding on the channel. |
| 5700 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5701 | last_fwd = si_ic(si)->to_forward; |
| 5702 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5703 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5704 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5705 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5706 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5707 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5708 | } |
| 5709 | } |
| 5710 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5711 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5712 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5713 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5714 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5715 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5716 | |
| 5717 | /* Now we must either adjust or remove the chunk size. This is |
| 5718 | * not easy because the chunk size might wrap at the end of the |
| 5719 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5720 | * the size, then restore the buffer's contents. Note that we can |
| 5721 | * only do that because no forwarding is scheduled on the stats |
| 5722 | * applet. |
| 5723 | */ |
| 5724 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5725 | si_ic(si)->total -= (last_len - prev_len); |
| 5726 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5727 | |
| 5728 | if (last_len != data_len) { |
| 5729 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5730 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5731 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5732 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5733 | si_ic(si)->total += (last_len - data_len); |
| 5734 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5735 | } |
| 5736 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5737 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5738 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5739 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5740 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5741 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5742 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5743 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5744 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5745 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5746 | } |
| 5747 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5748 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5749 | if (stats_send_http_redirect(si)) |
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 | } |
| 5752 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5753 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5754 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5755 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5756 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5757 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5758 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5759 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5760 | } |
| 5761 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5762 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5763 | res->flags |= CF_READ_NULL; |
| 5764 | si_shutr(si); |
| 5765 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5766 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5767 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5768 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5769 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5770 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5771 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5772 | si_shutr(si); |
| 5773 | res->flags |= CF_READ_NULL; |
| 5774 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5775 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5776 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5777 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5778 | } |
| 5779 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5780 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5781 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5782 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5783 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5784 | return "NONE"; |
| 5785 | return conn->ctrl->name; |
| 5786 | } |
| 5787 | |
| 5788 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5789 | { |
| 5790 | static char ptr[17]; |
| 5791 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5792 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5793 | return "NONE"; |
| 5794 | |
| 5795 | if (conn->xprt == &raw_sock) |
| 5796 | return "RAW"; |
| 5797 | |
| 5798 | #ifdef USE_OPENSSL |
| 5799 | if (conn->xprt == &ssl_sock) |
| 5800 | return "SSL"; |
| 5801 | #endif |
| 5802 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5803 | return ptr; |
| 5804 | } |
| 5805 | |
| 5806 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5807 | { |
| 5808 | static char ptr[17]; |
| 5809 | |
| 5810 | if (!conn->data) |
| 5811 | return "NONE"; |
| 5812 | |
| 5813 | if (conn->data == &sess_conn_cb) |
| 5814 | return "SESS"; |
| 5815 | |
| 5816 | if (conn->data == &si_conn_cb) |
| 5817 | return "STRM"; |
| 5818 | |
| 5819 | if (conn->data == &check_conn_cb) |
| 5820 | return "CHCK"; |
| 5821 | |
| 5822 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5823 | return ptr; |
| 5824 | } |
| 5825 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5826 | /* This function dumps a complete stream state onto the stream interface's |
| 5827 | * 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] | 5828 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5829 | * 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] | 5830 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5831 | 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] | 5832 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5833 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5834 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5835 | extern const char *monthname[12]; |
| 5836 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5837 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5838 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5839 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5840 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5841 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5842 | 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] | 5843 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5844 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5845 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5846 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5847 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5848 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5849 | appctx->ctx.sess.uid = 0; |
| 5850 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5851 | return 1; |
| 5852 | } |
| 5853 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5854 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5855 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5856 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5857 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5858 | /* fall through */ |
| 5859 | |
| 5860 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5861 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5862 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5863 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5864 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5865 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5866 | 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] | 5867 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5868 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5869 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5870 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5871 | 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] | 5872 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5873 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5874 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5875 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5876 | break; |
| 5877 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5878 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5879 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5880 | default: |
| 5881 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5882 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5883 | break; |
| 5884 | } |
| 5885 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5886 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5887 | " 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] | 5888 | 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] | 5889 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5890 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5891 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5892 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5893 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5894 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5895 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5896 | if (conn) |
| 5897 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5898 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5899 | 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] | 5900 | case AF_INET: |
| 5901 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5902 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5903 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5904 | break; |
| 5905 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5906 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5907 | break; |
| 5908 | default: |
| 5909 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5910 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5911 | break; |
| 5912 | } |
| 5913 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5914 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5915 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5916 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5917 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5918 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5919 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5920 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5921 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5922 | conn = objt_conn(sess->si[1].end); |
| 5923 | if (conn) |
| 5924 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5925 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5926 | 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] | 5927 | case AF_INET: |
| 5928 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5929 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5930 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5931 | break; |
| 5932 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5933 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5934 | break; |
| 5935 | default: |
| 5936 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5937 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5938 | break; |
| 5939 | } |
| 5940 | |
| 5941 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5942 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5943 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5944 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5945 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5946 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5947 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5948 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5949 | if (conn) |
| 5950 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5951 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5952 | 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] | 5953 | case AF_INET: |
| 5954 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5955 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5956 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5957 | break; |
| 5958 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5959 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5960 | break; |
| 5961 | default: |
| 5962 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5963 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5964 | break; |
| 5965 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5966 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5967 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5968 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5969 | sess->task, |
| 5970 | sess->task->state, |
| 5971 | sess->task->nice, sess->task->calls, |
| 5972 | sess->task->expire ? |
| 5973 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5974 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5975 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5976 | task_in_rq(sess->task) ? ", running" : ""); |
| 5977 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5978 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5979 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5980 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5981 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5982 | if (sess->txn) |
| 5983 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5984 | " 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] | 5985 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5986 | 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] | 5987 | |
| 5988 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5989 | " 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] | 5990 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5991 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5992 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5993 | obj_type_name(sess->si[0].end), |
| 5994 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5995 | sess->si[0].exp ? |
| 5996 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5997 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5998 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5999 | sess->si[0].err_type); |
| 6000 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6001 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 6002 | " 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] | 6003 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 6004 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6005 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6006 | obj_type_name(sess->si[1].end), |
| 6007 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6008 | sess->si[1].exp ? |
| 6009 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 6010 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 6011 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 6012 | sess->si[1].err_type); |
| 6013 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6014 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6015 | chunk_appendf(&trash, |
| 6016 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6017 | conn, |
| 6018 | get_conn_ctrl_name(conn), |
| 6019 | get_conn_xprt_name(conn), |
| 6020 | get_conn_data_name(conn), |
| 6021 | obj_type_name(conn->target), |
| 6022 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6023 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6024 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 6025 | " flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6026 | conn->flags, |
| 6027 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 6028 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 6029 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6030 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6031 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6032 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 6033 | chunk_appendf(&trash, |
| 6034 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6035 | tmpctx, |
| 6036 | tmpctx->st0, |
| 6037 | tmpctx->st1, |
| 6038 | tmpctx->st2, |
| 6039 | tmpctx->applet->name); |
| 6040 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 6041 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6042 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6043 | chunk_appendf(&trash, |
| 6044 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6045 | conn, |
| 6046 | get_conn_ctrl_name(conn), |
| 6047 | get_conn_xprt_name(conn), |
| 6048 | get_conn_data_name(conn), |
| 6049 | obj_type_name(conn->target), |
| 6050 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6051 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6052 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 6053 | " flags=0x%08x fd=%d fd.state=%02x fd.cache=%d updt=%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6054 | conn->flags, |
| 6055 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 6056 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 6057 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6058 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6059 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6060 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 6061 | chunk_appendf(&trash, |
| 6062 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6063 | tmpctx, |
| 6064 | tmpctx->st0, |
| 6065 | tmpctx->st1, |
| 6066 | tmpctx->st2, |
| 6067 | tmpctx->applet->name); |
| 6068 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6069 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6070 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6071 | " 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] | 6072 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6073 | &sess->req, |
| 6074 | sess->req.flags, sess->req.analysers, |
| 6075 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 6076 | sess->req.to_forward, sess->req.total, |
| 6077 | sess->req.analyse_exp ? |
| 6078 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6079 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6080 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6081 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6082 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6083 | sess->req.rex ? |
| 6084 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6085 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6086 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6087 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6088 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6089 | " 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] | 6090 | sess->req.wex ? |
| 6091 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6092 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6093 | sess->req.buf, |
| 6094 | sess->req.buf->data, sess->req.buf->o, |
| 6095 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6096 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6097 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6098 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6099 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6100 | " 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] | 6101 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6102 | &sess->res, |
| 6103 | sess->res.flags, sess->res.analysers, |
| 6104 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 6105 | sess->res.to_forward, sess->res.total, |
| 6106 | sess->res.analyse_exp ? |
| 6107 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6108 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6109 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6110 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6111 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6112 | sess->res.rex ? |
| 6113 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6114 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6115 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6116 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6117 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6118 | " 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] | 6119 | sess->res.wex ? |
| 6120 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6121 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6122 | sess->res.buf, |
| 6123 | sess->res.buf->data, sess->res.buf->o, |
| 6124 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6125 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6126 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6127 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6128 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6129 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6130 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6131 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6132 | |
| 6133 | /* use other states to dump the contents */ |
| 6134 | } |
| 6135 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6136 | appctx->ctx.sess.uid = 0; |
| 6137 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6138 | return 1; |
| 6139 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6140 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6141 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 6142 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 6143 | struct appctx *appctx = __objt_appctx(si->end); |
| 6144 | |
| 6145 | switch (appctx->st2) { |
| 6146 | case STAT_ST_INIT: |
| 6147 | /* Display the column headers. If the message cannot be sent, |
| 6148 | * quit the fucntion with returning 0. The function is called |
| 6149 | * later and restart at the state "STAT_ST_INIT". |
| 6150 | */ |
| 6151 | chunk_reset(&trash); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6152 | |
| 6153 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT) |
| 6154 | chunk_appendf(&trash, "# id secret\n"); |
| 6155 | else |
| 6156 | chunk_appendf(&trash, "# id (file)\n"); |
| 6157 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6158 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6159 | si_applet_cant_put(si); |
| 6160 | return 0; |
| 6161 | } |
| 6162 | |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6163 | appctx->ctx.tlskeys.dump_keys_index = 0; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6164 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6165 | /* Now, we start the browsing of the references lists. |
| 6166 | * 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] | 6167 | * available field of this pointer is <list>. It is used with the function |
| 6168 | * tlskeys_list_get_next() for retruning the first available entry |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6169 | */ |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6170 | if (appctx->ctx.tlskeys.ref == NULL) { |
| 6171 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 6172 | 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] | 6173 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6174 | |
| 6175 | appctx->st2 = STAT_ST_LIST; |
| 6176 | /* fall through */ |
| 6177 | |
| 6178 | case STAT_ST_LIST: |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6179 | while (appctx->ctx.tlskeys.ref) { |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6180 | int head = appctx->ctx.tlskeys.ref->tls_ticket_enc_index; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6181 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6182 | chunk_reset(&trash); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6183 | 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] | 6184 | chunk_appendf(&trash, "# "); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6185 | if (appctx->ctx.tlskeys.dump_keys_index == 0) |
| 6186 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 6187 | appctx->ctx.tlskeys.ref->filename); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6188 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT) { |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6189 | while (appctx->ctx.tlskeys.dump_keys_index < TLS_TICKETS_NO) { |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6190 | struct chunk *t2 = get_trash_chunk(); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6191 | |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6192 | chunk_reset(t2); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6193 | /* should never fail here because we dump only a key in the t2 buffer */ |
| 6194 | 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] | 6195 | sizeof(struct tls_sess_key), t2->str, t2->size); |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6196 | chunk_appendf(&trash, "%d.%d %s\n", appctx->ctx.tlskeys.ref->unique_id, appctx->ctx.tlskeys.dump_keys_index, t2->str); |
| 6197 | |
| 6198 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6199 | /* let's try again later from this stream. We add ourselves into |
| 6200 | * this stream's users so that it can remove us upon termination. |
| 6201 | */ |
| 6202 | si_applet_cant_put(si); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6203 | return 0; |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6204 | } |
| 6205 | appctx->ctx.tlskeys.dump_keys_index++; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6206 | } |
William Lallemand | 72a8a18 | 2016-06-14 18:58:55 +0200 | [diff] [blame] | 6207 | appctx->ctx.tlskeys.dump_keys_index = 0; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6208 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6209 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6210 | /* let's try again later from this stream. We add ourselves into |
| 6211 | * this stream's users so that it can remove us upon termination. |
| 6212 | */ |
| 6213 | si_applet_cant_put(si); |
| 6214 | return 0; |
| 6215 | } |
| 6216 | |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6217 | 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] | 6218 | break; |
| 6219 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6220 | /* get next list entry and check the end of the list */ |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame] | 6221 | 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] | 6222 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | appctx->st2 = STAT_ST_FIN; |
| 6226 | /* fall through */ |
| 6227 | |
| 6228 | default: |
| 6229 | appctx->st2 = STAT_ST_FIN; |
| 6230 | return 1; |
| 6231 | } |
| 6232 | return 0; |
| 6233 | } |
| 6234 | #endif |
| 6235 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6236 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6237 | { |
| 6238 | struct appctx *appctx = __objt_appctx(si->end); |
| 6239 | |
| 6240 | switch (appctx->st2) { |
| 6241 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6242 | /* Display the column headers. If the message cannot be sent, |
| 6243 | * quit the fucntion with returning 0. The function is called |
| 6244 | * later and restart at the state "STAT_ST_INIT". |
| 6245 | */ |
| 6246 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 6247 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6248 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6249 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6250 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6251 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6252 | |
| 6253 | /* Now, we start the browsing of the references lists. |
| 6254 | * 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] | 6255 | * available field of this pointer is <list>. It is used with the function |
| 6256 | * pat_list_get_next() for retruning the first available entry |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6257 | */ |
| 6258 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6259 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6260 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6261 | appctx->st2 = STAT_ST_LIST; |
| 6262 | /* fall through */ |
| 6263 | |
| 6264 | case STAT_ST_LIST: |
| 6265 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6266 | chunk_reset(&trash); |
| 6267 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6268 | /* Build messages. If the reference is used by another category than |
| 6269 | * the listed categorie, display the information in the massage. |
| 6270 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6271 | 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] | 6272 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6273 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6274 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6275 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6276 | /* let's try again later from this stream. We add ourselves into |
| 6277 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6278 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6279 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6280 | return 0; |
| 6281 | } |
| 6282 | |
| 6283 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6284 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6285 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | appctx->st2 = STAT_ST_FIN; |
| 6289 | /* fall through */ |
| 6290 | |
| 6291 | default: |
| 6292 | appctx->st2 = STAT_ST_FIN; |
| 6293 | return 1; |
| 6294 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6295 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6296 | } |
| 6297 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6298 | static int stats_map_lookup(struct stream_interface *si) |
| 6299 | { |
| 6300 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6301 | struct sample sample; |
| 6302 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6303 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6304 | |
| 6305 | switch (appctx->st2) { |
| 6306 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6307 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6308 | 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] | 6309 | 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] | 6310 | appctx->st2 = STAT_ST_LIST; |
| 6311 | /* fall through */ |
| 6312 | |
| 6313 | case STAT_ST_LIST: |
| 6314 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6315 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6316 | /* initialise chunk to build new message */ |
| 6317 | chunk_reset(&trash); |
| 6318 | |
| 6319 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6320 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6321 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6322 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6323 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6324 | if (appctx->ctx.map.expr->pat_head->match && |
| 6325 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6326 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6327 | else |
| 6328 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6329 | |
| 6330 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6331 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6332 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6333 | break; |
| 6334 | if (match_method >= PAT_MATCH_NUM) |
| 6335 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6336 | else |
| 6337 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6338 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6339 | /* case sensitive */ |
| 6340 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6341 | chunk_appendf(&trash, ", case=insensitive"); |
| 6342 | else |
| 6343 | chunk_appendf(&trash, ", case=sensitive"); |
| 6344 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6345 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6346 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6347 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6348 | chunk_appendf(&trash, ", found=no"); |
| 6349 | else |
| 6350 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | /* Display match and match info */ |
| 6354 | else { |
| 6355 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6356 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6357 | chunk_appendf(&trash, ", found=yes"); |
| 6358 | else |
| 6359 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6360 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6361 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6362 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6363 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6364 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6365 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6366 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6367 | /* display pattern */ |
| 6368 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6369 | if (pat->ref && pat->ref->pattern) |
| 6370 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6371 | else |
| 6372 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6373 | } |
| 6374 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6375 | if (pat->ref && pat->ref->pattern) |
| 6376 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6377 | else |
| 6378 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6379 | } |
| 6380 | |
| 6381 | /* display return value */ |
| 6382 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6383 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6384 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6385 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6386 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6387 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6388 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6389 | } |
| 6390 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6391 | chunk_appendf(&trash, "\n"); |
| 6392 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6393 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6394 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6395 | /* let's try again later from this stream. We add ourselves into |
| 6396 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6397 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6398 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6399 | return 0; |
| 6400 | } |
| 6401 | |
| 6402 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6403 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6404 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6405 | } |
| 6406 | |
| 6407 | appctx->st2 = STAT_ST_FIN; |
| 6408 | /* fall through */ |
| 6409 | |
| 6410 | default: |
| 6411 | appctx->st2 = STAT_ST_FIN; |
| 6412 | free(appctx->ctx.map.chunk.str); |
| 6413 | return 1; |
| 6414 | } |
| 6415 | } |
| 6416 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6417 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6418 | { |
| 6419 | struct appctx *appctx = __objt_appctx(si->end); |
| 6420 | |
| 6421 | switch (appctx->st2) { |
| 6422 | |
| 6423 | case STAT_ST_INIT: |
| 6424 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6425 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6426 | struct pat_ref_elt *, list); |
| 6427 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6428 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6429 | appctx->st2 = STAT_ST_LIST; |
| 6430 | /* fall through */ |
| 6431 | |
| 6432 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6433 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6434 | chunk_reset(&trash); |
| 6435 | |
| 6436 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6437 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6438 | chunk_appendf(&trash, "%p %s %s\n", |
| 6439 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6440 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6441 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6442 | chunk_appendf(&trash, "%p %s\n", |
| 6443 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6444 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6445 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6446 | /* let's try again later from this stream. We add ourselves into |
| 6447 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6448 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6449 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6450 | return 0; |
| 6451 | } |
| 6452 | |
| 6453 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6454 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6455 | struct pat_ref_elt *, list); |
| 6456 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6457 | break; |
| 6458 | } |
| 6459 | |
| 6460 | appctx->st2 = STAT_ST_FIN; |
| 6461 | /* fall through */ |
| 6462 | |
| 6463 | default: |
| 6464 | appctx->st2 = STAT_ST_FIN; |
| 6465 | return 1; |
| 6466 | } |
| 6467 | } |
| 6468 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6469 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6470 | * 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] | 6471 | * to be called again, otherwise non-zero. It is designed to be called |
| 6472 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6473 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6474 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6475 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6476 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6477 | struct connection *conn; |
| 6478 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6479 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6480 | /* 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] | 6481 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6482 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6483 | if (appctx->st2 == STAT_ST_LIST) { |
| 6484 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6485 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6486 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6487 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6488 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6489 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6490 | } |
| 6491 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6492 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6493 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6494 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6495 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6496 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6497 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6498 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6499 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6500 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6501 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6502 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6503 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6504 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6505 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6506 | /* fall through */ |
| 6507 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6508 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6509 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6510 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6511 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6512 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6516 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6517 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6518 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6519 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6520 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6521 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6522 | if (appctx->ctx.sess.target) { |
| 6523 | 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] | 6524 | goto next_sess; |
| 6525 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6526 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6527 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6528 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6529 | return 0; |
| 6530 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6531 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6532 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6533 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6534 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6535 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6536 | break; |
| 6537 | } |
| 6538 | else |
| 6539 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6540 | } |
| 6541 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6542 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6543 | "%p: proto=%s", |
| 6544 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6545 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6546 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6547 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6548 | 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] | 6549 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6550 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6551 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6552 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6553 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6554 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6555 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6556 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6557 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6558 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6559 | break; |
| 6560 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6561 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6562 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6563 | strm_li(curr_sess)->luid, |
| 6564 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6565 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6566 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6567 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6568 | break; |
| 6569 | } |
| 6570 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6571 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6572 | " ts=%02x age=%s calls=%d", |
| 6573 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6574 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6575 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6576 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6577 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6578 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6579 | curr_sess->req.flags, |
| 6580 | curr_sess->req.buf->i, |
| 6581 | curr_sess->req.analysers, |
| 6582 | curr_sess->req.rex ? |
| 6583 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6584 | TICKS_TO_MS(1000)) : ""); |
| 6585 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6586 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6587 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6588 | curr_sess->req.wex ? |
| 6589 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6590 | TICKS_TO_MS(1000)) : ""); |
| 6591 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6592 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6593 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6594 | curr_sess->req.analyse_exp ? |
| 6595 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6596 | TICKS_TO_MS(1000)) : ""); |
| 6597 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6598 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6599 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6600 | curr_sess->res.flags, |
| 6601 | curr_sess->res.buf->i, |
| 6602 | curr_sess->res.analysers, |
| 6603 | curr_sess->res.rex ? |
| 6604 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6605 | TICKS_TO_MS(1000)) : ""); |
| 6606 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6607 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6608 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6609 | curr_sess->res.wex ? |
| 6610 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6611 | TICKS_TO_MS(1000)) : ""); |
| 6612 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6613 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6614 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6615 | curr_sess->res.analyse_exp ? |
| 6616 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6617 | TICKS_TO_MS(1000)) : ""); |
| 6618 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6619 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6620 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6621 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6622 | curr_sess->si[0].state, |
| 6623 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6624 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6625 | curr_sess->si[0].exp ? |
| 6626 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6627 | TICKS_TO_MS(1000)) : ""); |
| 6628 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6629 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6630 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6631 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6632 | curr_sess->si[1].state, |
| 6633 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6634 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6635 | curr_sess->si[1].exp ? |
| 6636 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6637 | TICKS_TO_MS(1000)) : ""); |
| 6638 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6639 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6640 | " exp=%s", |
| 6641 | curr_sess->task->expire ? |
| 6642 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6643 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6644 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6645 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6646 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6647 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6648 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6649 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6650 | /* let's try again later from this stream. We add ourselves into |
| 6651 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6652 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6653 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6654 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6655 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6656 | } |
| 6657 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6658 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6659 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6660 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6661 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6662 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6663 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6664 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6665 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6666 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6667 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6668 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6669 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6670 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6671 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6672 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6673 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6674 | appctx->ctx.sess.target = NULL; |
| 6675 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6676 | return 1; |
| 6677 | } |
| 6678 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6679 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6680 | /* fall through */ |
| 6681 | |
| 6682 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6683 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6684 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6685 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6686 | } |
| 6687 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6688 | /* This is called when the stream interface is closed. For instance, upon an |
| 6689 | * 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] | 6690 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6691 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6692 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6693 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6694 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6695 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6696 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6697 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6698 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6699 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6700 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6701 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6702 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6703 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6704 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6705 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6706 | } |
| 6707 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6708 | /* This function is used to either dump tables states (when action is set |
| 6709 | * 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] | 6710 | * It returns 0 if the output buffer is full and it needs to be called |
| 6711 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6712 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6713 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6714 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6715 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6716 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6717 | struct ebmb_node *eb; |
| 6718 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6719 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6720 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6721 | |
| 6722 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6723 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6724 | * - STAT_ST_INIT : the first call |
| 6725 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6726 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6727 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6728 | * and the entry pointer points to the next entry to be dumped, |
| 6729 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6730 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6731 | * data though. |
| 6732 | */ |
| 6733 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6734 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6735 | /* 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] | 6736 | if (appctx->st2 == STAT_ST_LIST) { |
| 6737 | appctx->ctx.table.entry->ref_cnt--; |
| 6738 | 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] | 6739 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6740 | return 1; |
| 6741 | } |
| 6742 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6743 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6744 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6745 | while (appctx->st2 != STAT_ST_FIN) { |
| 6746 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6747 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6748 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6749 | if (!appctx->ctx.table.proxy) |
| 6750 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6751 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6752 | appctx->ctx.table.entry = NULL; |
| 6753 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6754 | break; |
| 6755 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6756 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6757 | if (!appctx->ctx.table.proxy || |
| 6758 | (appctx->ctx.table.target && |
| 6759 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6760 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6761 | break; |
| 6762 | } |
| 6763 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6764 | if (appctx->ctx.table.proxy->table.size) { |
| 6765 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6766 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6767 | return 0; |
| 6768 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6769 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6770 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6771 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6772 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6773 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6774 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6775 | appctx->ctx.table.entry->ref_cnt++; |
| 6776 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6777 | break; |
| 6778 | } |
| 6779 | } |
| 6780 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6781 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6782 | break; |
| 6783 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6784 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6785 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6786 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6787 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6788 | /* we're filtering on some data contents */ |
| 6789 | void *ptr; |
| 6790 | long long data; |
| 6791 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6792 | dt = appctx->ctx.table.data_type; |
| 6793 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6794 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6795 | dt); |
| 6796 | |
| 6797 | data = 0; |
| 6798 | switch (stktable_data_types[dt].std_type) { |
| 6799 | case STD_T_SINT: |
| 6800 | data = stktable_data_cast(ptr, std_t_sint); |
| 6801 | break; |
| 6802 | case STD_T_UINT: |
| 6803 | data = stktable_data_cast(ptr, std_t_uint); |
| 6804 | break; |
| 6805 | case STD_T_ULL: |
| 6806 | data = stktable_data_cast(ptr, std_t_ull); |
| 6807 | break; |
| 6808 | case STD_T_FRQP: |
| 6809 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6810 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6811 | break; |
| 6812 | } |
| 6813 | |
| 6814 | /* 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] | 6815 | if ((data < appctx->ctx.table.value && |
| 6816 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6817 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6818 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6819 | (data == appctx->ctx.table.value && |
| 6820 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6821 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6822 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6823 | (data > appctx->ctx.table.value && |
| 6824 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6825 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6826 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6827 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6828 | } |
| 6829 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6830 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6831 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6832 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6833 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6834 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6835 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6837 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6838 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6839 | struct stksess *old = appctx->ctx.table.entry; |
| 6840 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6841 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6842 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6843 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6844 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6845 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6846 | break; |
| 6847 | } |
| 6848 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6849 | |
| 6850 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6851 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6852 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6853 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6854 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6855 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6856 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6857 | break; |
| 6858 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6859 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6860 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6861 | break; |
| 6862 | } |
| 6863 | } |
| 6864 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6865 | } |
| 6866 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6867 | /* 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] | 6868 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6869 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6870 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6871 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6872 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6873 | * after the offset. The new pointer is returned. |
| 6874 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6875 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6876 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6877 | { |
| 6878 | int end; |
| 6879 | unsigned char c; |
| 6880 | |
| 6881 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6882 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6883 | return ptr; |
| 6884 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6885 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6886 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6887 | while (ptr < len && ptr < bsize) { |
| 6888 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6889 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6890 | if (out->len > end - 2) |
| 6891 | break; |
| 6892 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6893 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6894 | if (out->len > end - 3) |
| 6895 | break; |
| 6896 | out->str[out->len++] = '\\'; |
| 6897 | switch (c) { |
| 6898 | case '\t': c = 't'; break; |
| 6899 | case '\n': c = 'n'; break; |
| 6900 | case '\r': c = 'r'; break; |
| 6901 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6902 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6903 | } |
| 6904 | out->str[out->len++] = c; |
| 6905 | } else { |
| 6906 | if (out->len > end - 5) |
| 6907 | break; |
| 6908 | out->str[out->len++] = '\\'; |
| 6909 | out->str[out->len++] = 'x'; |
| 6910 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6911 | out->str[out->len++] = hextab[c & 0xF]; |
| 6912 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6913 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6914 | /* we had a line break, let's return now */ |
| 6915 | out->str[out->len++] = '\n'; |
| 6916 | *line = ptr; |
| 6917 | return ptr; |
| 6918 | } |
| 6919 | } |
| 6920 | /* we have an incomplete line, we return it as-is */ |
| 6921 | out->str[out->len++] = '\n'; |
| 6922 | return ptr; |
| 6923 | } |
| 6924 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6925 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6926 | * It returns 0 if the output buffer is full and it needs |
| 6927 | * to be called again, otherwise non-zero. |
| 6928 | */ |
| 6929 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6930 | { |
| 6931 | struct appctx *appctx = __objt_appctx(si->end); |
| 6932 | struct dns_resolvers *presolvers; |
| 6933 | struct dns_nameserver *pnameserver; |
| 6934 | |
| 6935 | chunk_reset(&trash); |
| 6936 | |
| 6937 | switch (appctx->st2) { |
| 6938 | case STAT_ST_INIT: |
| 6939 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6940 | /* fall through */ |
| 6941 | |
| 6942 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6943 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6944 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6945 | } |
| 6946 | else { |
| 6947 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6948 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6949 | continue; |
| 6950 | |
| 6951 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6952 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6953 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6954 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6955 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6956 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6957 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6958 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6959 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6960 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6961 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6962 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6963 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6964 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6965 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6966 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6967 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6968 | } |
| 6969 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6970 | } |
| 6971 | |
| 6972 | /* display response */ |
| 6973 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6974 | /* let's try again later from this session. We add ourselves into |
| 6975 | * this session's users so that it can remove us upon termination. |
| 6976 | */ |
| 6977 | si->flags |= SI_FL_WAIT_ROOM; |
| 6978 | return 0; |
| 6979 | } |
| 6980 | |
| 6981 | appctx->st2 = STAT_ST_FIN; |
| 6982 | /* fall through */ |
| 6983 | |
| 6984 | default: |
| 6985 | appctx->st2 = STAT_ST_FIN; |
| 6986 | return 1; |
| 6987 | } |
| 6988 | } |
| 6989 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6990 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6991 | * 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] | 6992 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6993 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6994 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6995 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6996 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6997 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6998 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6999 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7000 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7001 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7002 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7003 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7004 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7005 | /* the function had not been called yet, let's prepare the |
| 7006 | * buffer for a response. |
| 7007 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7008 | struct tm tm; |
| 7009 | |
| 7010 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7011 | 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] | 7012 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 7013 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 7014 | error_snapshot_id); |
| 7015 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7016 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7017 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7018 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7019 | return 0; |
| 7020 | } |
| 7021 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7022 | appctx->ctx.errors.px = proxy; |
| 7023 | appctx->ctx.errors.buf = 0; |
| 7024 | appctx->ctx.errors.bol = 0; |
| 7025 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7026 | } |
| 7027 | |
| 7028 | /* we have two inner loops here, one for the proxy, the other one for |
| 7029 | * the buffer. |
| 7030 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7031 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7032 | struct error_snapshot *es; |
| 7033 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7034 | if (appctx->ctx.errors.buf == 0) |
| 7035 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7036 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7037 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7038 | |
| 7039 | if (!es->when.tv_sec) |
| 7040 | goto next; |
| 7041 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7042 | if (appctx->ctx.errors.iid >= 0 && |
| 7043 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 7044 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7045 | goto next; |
| 7046 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7047 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7048 | /* just print headers now */ |
| 7049 | |
| 7050 | char pn[INET6_ADDRSTRLEN]; |
| 7051 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7052 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7053 | |
| 7054 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7055 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7056 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 7057 | 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] | 7058 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7059 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 7060 | case AF_INET: |
| 7061 | case AF_INET6: |
| 7062 | port = get_host_port(&es->src); |
| 7063 | break; |
| 7064 | default: |
| 7065 | port = 0; |
| 7066 | } |
| 7067 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7068 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7069 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7070 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7071 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7072 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7073 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7074 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 7075 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7076 | break; |
| 7077 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7078 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 7079 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7080 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7081 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7082 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7083 | break; |
| 7084 | } |
| 7085 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7086 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7087 | ", server %s (#%d), event #%u\n" |
| 7088 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 7089 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 7090 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 7091 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 7092 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 7093 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 7094 | es->ev_id, |
| 7095 | pn, port, es->sid, es->s_flags, |
| 7096 | es->state, es->m_flags, es->t_flags, |
| 7097 | es->m_clen, es->m_blen, |
| 7098 | es->b_flags, es->b_out, es->b_tot, |
| 7099 | es->len, es->b_wrap, es->pos); |
| 7100 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7101 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7102 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7103 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7104 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7105 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7106 | appctx->ctx.errors.ptr = 0; |
| 7107 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7108 | } |
| 7109 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7110 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7111 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7112 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7113 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7114 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7115 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7116 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7117 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7118 | goto next; |
| 7119 | } |
| 7120 | |
| 7121 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7122 | 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] | 7123 | int newptr; |
| 7124 | int newline; |
| 7125 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7126 | newline = appctx->ctx.errors.bol; |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7127 | 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] | 7128 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7129 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7130 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7131 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7132 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7133 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7134 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7135 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7136 | appctx->ctx.errors.ptr = newptr; |
| 7137 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7138 | }; |
| 7139 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7140 | appctx->ctx.errors.bol = 0; |
| 7141 | appctx->ctx.errors.ptr = -1; |
| 7142 | appctx->ctx.errors.buf++; |
| 7143 | if (appctx->ctx.errors.buf > 1) { |
| 7144 | appctx->ctx.errors.buf = 0; |
| 7145 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7146 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 7147 | } |
| 7148 | |
| 7149 | /* dump complete */ |
| 7150 | return 1; |
| 7151 | } |
| 7152 | |
| 7153 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 7154 | * if the output buffer is full and it needs to be called again, otherwise |
| 7155 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 7156 | */ |
| 7157 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 7158 | { |
| 7159 | struct appctx *appctx = __objt_appctx(si->end); |
| 7160 | |
| 7161 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 7162 | return 1; |
| 7163 | |
| 7164 | chunk_reset(&trash); |
| 7165 | |
| 7166 | /* we have two inner loops here, one for the proxy, the other one for |
| 7167 | * the buffer. |
| 7168 | */ |
| 7169 | while (*appctx->ctx.env.var) { |
| 7170 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 7171 | |
| 7172 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 7173 | si_applet_cant_put(si); |
| 7174 | return 0; |
| 7175 | } |
| 7176 | if (appctx->st2 == STAT_ST_END) |
| 7177 | break; |
| 7178 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7179 | } |
| 7180 | |
| 7181 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7182 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7183 | } |
| 7184 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7185 | /* parse the "level" argument on the bind lines */ |
| 7186 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 7187 | { |
| 7188 | if (!*args[cur_arg + 1]) { |
| 7189 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 7190 | return ERR_ALERT | ERR_FATAL; |
| 7191 | } |
| 7192 | |
| 7193 | if (!strcmp(args[cur_arg+1], "user")) |
| 7194 | conf->level = ACCESS_LVL_USER; |
| 7195 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 7196 | conf->level = ACCESS_LVL_OPER; |
| 7197 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 7198 | conf->level = ACCESS_LVL_ADMIN; |
| 7199 | else { |
| 7200 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 7201 | args[cur_arg], args[cur_arg+1]); |
| 7202 | return ERR_ALERT | ERR_FATAL; |
| 7203 | } |
| 7204 | |
| 7205 | return 0; |
| 7206 | } |
| 7207 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7208 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7209 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7210 | .name = "<STATS>", /* used for logging */ |
| 7211 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 7212 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7213 | }; |
| 7214 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7215 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7216 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7217 | .name = "<CLI>", /* used for logging */ |
| 7218 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 7219 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7220 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 7221 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 7222 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7223 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 7224 | { 0, NULL, NULL }, |
| 7225 | }}; |
| 7226 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7227 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 7228 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 7229 | { NULL, NULL, 0 }, |
| 7230 | }}; |
| 7231 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7232 | __attribute__((constructor)) |
| 7233 | static void __dumpstats_module_init(void) |
| 7234 | { |
| 7235 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7236 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7237 | } |
| 7238 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 7239 | /* |
| 7240 | * Local variables: |
| 7241 | * c-indent-level: 8 |
| 7242 | * c-basic-offset: 8 |
| 7243 | * End: |
| 7244 | */ |