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 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3203 | if (!appctx->ctx.server_state.px) { |
| 3204 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3205 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3206 | si_applet_cant_put(si); |
| 3207 | return 0; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3208 | } |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3209 | appctx->ctx.server_state.px = proxy; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3210 | } |
| 3211 | |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3212 | for (; appctx->ctx.server_state.px != NULL; appctx->ctx.server_state.px = curproxy->next) { |
| 3213 | curproxy = appctx->ctx.server_state.px; |
Cyril Bonté | 76a9978 | 2016-05-06 12:18:48 +0200 | [diff] [blame] | 3214 | /* servers are only in backends */ |
| 3215 | if (curproxy->cap & PR_CAP_BE) { |
| 3216 | if (!dump_servers_state(si, &trash)) |
| 3217 | return 0; |
| 3218 | |
| 3219 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3220 | si_applet_cant_put(si); |
| 3221 | return 0; |
| 3222 | } |
| 3223 | } |
| 3224 | /* only the selected proxy is dumped */ |
| 3225 | if (appctx->ctx.server_state.iid) |
| 3226 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | return 1; |
| 3230 | } |
| 3231 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3232 | /* This function dumps memory usage information onto the stream interface's |
| 3233 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3234 | * completion. No state is used. |
| 3235 | */ |
| 3236 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3237 | { |
| 3238 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3239 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3240 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3241 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3242 | } |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 3243 | return 1; |
| 3244 | } |
| 3245 | |
| 3246 | /* Dump all fields from <stats> into <out> using CSV format */ |
| 3247 | static int stats_dump_fields_csv(struct chunk *out, const struct field *stats) |
| 3248 | { |
| 3249 | int field; |
| 3250 | |
| 3251 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3252 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 3253 | return 0; |
| 3254 | if (!chunk_strcat(out, ",")) |
| 3255 | return 0; |
| 3256 | } |
Conrad Hoffmann | 692c938 | 2016-04-01 20:40:58 +0200 | [diff] [blame] | 3257 | chunk_strcat(out, "\n"); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3258 | return 1; |
| 3259 | } |
| 3260 | |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3261 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
| 3262 | static int stats_dump_fields_typed(struct chunk *out, const struct field *stats) |
| 3263 | { |
| 3264 | int field; |
| 3265 | |
| 3266 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3267 | if (!stats[field].type) |
| 3268 | continue; |
| 3269 | |
| 3270 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 3271 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 3272 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 3273 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 3274 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 3275 | '?', |
| 3276 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 3277 | field, stat_field_names[field], stats[ST_F_PID].u.u32); |
| 3278 | |
| 3279 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 3280 | return 0; |
| 3281 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 3282 | return 0; |
| 3283 | if (!chunk_strcat(out, "\n")) |
| 3284 | return 0; |
| 3285 | } |
| 3286 | return 1; |
| 3287 | } |
| 3288 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3289 | /* 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] | 3290 | * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info |
| 3291 | * are provided if ST_SHLGNDS is present in <flags>. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3292 | */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3293 | 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] | 3294 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3295 | struct chunk src; |
| 3296 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3297 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3298 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3299 | /* name, queue */ |
| 3300 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3301 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3302 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3303 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3304 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3305 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3306 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3307 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3308 | "<td class=ac>" |
| 3309 | "<a name=\"%s/Frontend\"></a>" |
| 3310 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3311 | "<td colspan=3></td>" |
| 3312 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3313 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3314 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3315 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3316 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3317 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3318 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3319 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3320 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3321 | U2H(stats[ST_F_RATE].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3322 | U2H(stats[ST_F_CONN_RATE].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3323 | U2H(stats[ST_F_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3324 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3325 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3326 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3327 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3328 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3329 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3330 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3331 | "</table></div></u></td>" |
| 3332 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3333 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3334 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3335 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3336 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3337 | U2H(stats[ST_F_RATE_MAX].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3338 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3339 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3340 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3341 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3342 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3343 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3344 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3345 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3346 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3347 | "</table></div></u></td>" |
| 3348 | /* sessions rate : limit */ |
| 3349 | "<td>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3350 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3351 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3352 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3353 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3354 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3355 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3356 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3357 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3358 | "", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3359 | 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] | 3360 | U2H(stats[ST_F_STOT].u.u64), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3361 | U2H(stats[ST_F_CONN_TOT].u.u64), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3362 | U2H(stats[ST_F_STOT].u.u64)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3363 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3364 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3365 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3366 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3367 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3368 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3369 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3370 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3371 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3372 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3373 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3374 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3375 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3376 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3377 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3378 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3379 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3380 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3381 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3382 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3383 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3384 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3385 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3386 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3387 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3388 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3389 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3390 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3391 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3392 | /* sessions: lbtot, lastsess */ |
| 3393 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3394 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3395 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3396 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3397 | U2H(stats[ST_F_BIN].u.u64)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3398 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3399 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3400 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3401 | "<td>%s%s<div class=tips><table class=det>" |
| 3402 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3403 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3404 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3405 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3406 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3407 | "</table></div>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3408 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3409 | U2H(stats[ST_F_BOUT].u.u64), |
| 3410 | U2H(stats[ST_F_BOUT].u.u64), |
| 3411 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3412 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3413 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3414 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 3415 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 3416 | 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, |
| 3417 | (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] | 3418 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3419 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3420 | /* denied: req, resp */ |
| 3421 | "<td>%s</td><td>%s</td>" |
| 3422 | /* errors : request, connect, response */ |
| 3423 | "<td>%s</td><td></td><td></td>" |
| 3424 | /* warnings: retries, redispatches */ |
| 3425 | "<td></td><td></td>" |
| 3426 | /* server status : reflect frontend status */ |
| 3427 | "<td class=ac>%s</td>" |
| 3428 | /* rest of server: nothing */ |
| 3429 | "<td class=ac colspan=8></td></tr>" |
| 3430 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3431 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3432 | U2H(stats[ST_F_EREQ].u.u64), |
| 3433 | field_str(stats, ST_F_STATUS)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3434 | } |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3435 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3436 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3437 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3438 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3439 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3440 | } |
| 3441 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3442 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3443 | /* frontend name, listener name */ |
| 3444 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3445 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3446 | "", |
| 3447 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3448 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3449 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 3450 | |
| 3451 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3452 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3453 | |
| 3454 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3455 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3456 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3457 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3458 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3459 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3460 | |
| 3461 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3462 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3463 | } |
| 3464 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3465 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3466 | /* queue */ |
| 3467 | "%s</td><td colspan=3></td>" |
| 3468 | /* sessions rate: current, max, limit */ |
| 3469 | "<td colspan=3> </td>" |
| 3470 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 3471 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3472 | "<td>%s</td><td> </td><td> </td>" |
| 3473 | /* bytes: in, out */ |
| 3474 | "<td>%s</td><td>%s</td>" |
| 3475 | "", |
| 3476 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3477 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3478 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 3479 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3480 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3481 | /* denied: req, resp */ |
| 3482 | "<td>%s</td><td>%s</td>" |
| 3483 | /* errors: request, connect, response */ |
| 3484 | "<td>%s</td><td></td><td></td>" |
| 3485 | /* warnings: retries, redispatches */ |
| 3486 | "<td></td><td></td>" |
| 3487 | /* server status: reflect listener status */ |
| 3488 | "<td class=ac>%s</td>" |
| 3489 | /* rest of server: nothing */ |
| 3490 | "<td class=ac colspan=8></td></tr>" |
| 3491 | "", |
| 3492 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3493 | U2H(stats[ST_F_EREQ].u.u64), |
| 3494 | field_str(stats, ST_F_STATUS)); |
| 3495 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3496 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 3497 | const char *style; |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3498 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3499 | /* determine the style to use depending on the server's state, |
| 3500 | * its health and weight. There isn't a 1-to-1 mapping between |
| 3501 | * state and styles for the cases where the server is (still) |
| 3502 | * up. The reason is that we don't want to report nolb and |
| 3503 | * drain with the same color. |
| 3504 | */ |
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 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 3507 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 3508 | style = "down"; |
| 3509 | } |
| 3510 | else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) { |
| 3511 | style = "going_up"; |
| 3512 | } |
| 3513 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) { |
| 3514 | style = "going_down"; |
| 3515 | } |
| 3516 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 3517 | style = "nolb"; |
| 3518 | } |
| 3519 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 3520 | style = "no_check"; |
| 3521 | } |
| 3522 | else if (!stats[ST_F_CHKFAIL].type || |
| 3523 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 3524 | /* no check or max health = UP */ |
| 3525 | if (stats[ST_F_WEIGHT].u.u32) |
| 3526 | style = "up"; |
| 3527 | else |
| 3528 | style = "draining"; |
| 3529 | } |
| 3530 | else { |
| 3531 | style = "going_down"; |
| 3532 | } |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3533 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3534 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3535 | chunk_appendf(out, "<tr class=\"maintain\">"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3536 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3537 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3538 | "<tr class=\"%s_%s\">", |
| 3539 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3540 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3541 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3542 | if (flags & ST_SHOWADMIN) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3543 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3544 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3545 | field_str(stats, ST_F_SVNAME)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3546 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3547 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3548 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3549 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3550 | "", |
| 3551 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3552 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3553 | 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] | 3554 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3555 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3556 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3557 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3558 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3559 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3560 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3561 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3562 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3563 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
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 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3566 | chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3567 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3568 | /* cookie */ |
| 3569 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3570 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3571 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3572 | chunk_htmlencode(out, &src); |
| 3573 | chunk_appendf(out, "'"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3574 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3575 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3576 | chunk_appendf(out, "</div>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3577 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3578 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3579 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3580 | /* queue : current, max, limit */ |
| 3581 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 3582 | /* sessions rate : current, max, limit */ |
| 3583 | "<td>%s</td><td>%s</td><td></td>" |
| 3584 | "", |
| 3585 | (flags & ST_SHLGNDS) ? "</u>" : "", |
| 3586 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 3587 | 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] | 3588 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3589 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3590 | /* sessions: current, max, limit, total */ |
| 3591 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3592 | "<td><u>%s<div class=tips><table class=det>" |
| 3593 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3594 | "", |
| 3595 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 3596 | U2H(stats[ST_F_STOT].u.u64), |
| 3597 | U2H(stats[ST_F_STOT].u.u64)); |
Willy Tarreau | 4607fad | 2016-01-06 15:41:29 +0100 | [diff] [blame] | 3598 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3599 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3600 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3601 | unsigned long long tot; |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3602 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3603 | tot = stats[ST_F_HRSP_OTHER].u.u64; |
| 3604 | tot += stats[ST_F_HRSP_1XX].u.u64; |
| 3605 | tot += stats[ST_F_HRSP_2XX].u.u64; |
| 3606 | tot += stats[ST_F_HRSP_3XX].u.u64; |
| 3607 | tot += stats[ST_F_HRSP_4XX].u.u64; |
| 3608 | tot += stats[ST_F_HRSP_5XX].u.u64; |
| 3609 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3610 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3611 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3612 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3613 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3614 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3615 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3616 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3617 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3618 | "", |
| 3619 | U2H(tot), |
| 3620 | U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0, |
| 3621 | U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0, |
| 3622 | U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0, |
| 3623 | U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0, |
| 3624 | U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0, |
| 3625 | 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] | 3626 | } |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3627 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3628 | chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3629 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3630 | 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] | 3631 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3632 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3633 | 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] | 3634 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3635 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3636 | "</table></div></u></td>" |
| 3637 | /* sessions: lbtot, last */ |
| 3638 | "<td>%s</td><td>%s</td>", |
| 3639 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3640 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +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 | /* bytes : in, out */ |
| 3644 | "<td>%s</td><td>%s</td>" |
| 3645 | /* denied: req, resp */ |
| 3646 | "<td></td><td>%s</td>" |
| 3647 | /* errors : request, connect */ |
| 3648 | "<td></td><td>%s</td>" |
| 3649 | /* errors : response */ |
| 3650 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3651 | /* warnings: retries, redispatches */ |
| 3652 | "<td>%lld</td><td>%lld</td>" |
| 3653 | "", |
| 3654 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 3655 | U2H(stats[ST_F_DRESP].u.u64), |
| 3656 | U2H(stats[ST_F_ECON].u.u64), |
| 3657 | U2H(stats[ST_F_ERESP].u.u64), |
| 3658 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3659 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3660 | (long long)stats[ST_F_WRETR].u.u64, |
| 3661 | (long long)stats[ST_F_WREDIS].u.u64); |
| 3662 | |
| 3663 | /* status, last change */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3664 | chunk_appendf(out, "<td class=ac>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3665 | |
| 3666 | /* FIXME!!!! |
| 3667 | * LASTCHG should contain the last change for *this* server and must be computed |
| 3668 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 3669 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 3670 | */ |
| 3671 | |
| 3672 | |
| 3673 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3674 | 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] | 3675 | } |
| 3676 | 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] | 3677 | chunk_strcat(out, "<i>no check</i>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3678 | } |
| 3679 | else { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3680 | 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] | 3681 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
| 3682 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3683 | chunk_strcat(out, " ↑"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3684 | } |
| 3685 | 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] | 3686 | chunk_strcat(out, " ↓"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
| 3690 | 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] | 3691 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3692 | "</td><td class=ac><u> %s", |
| 3693 | field_str(stats, ST_F_AGENT_STATUS)); |
| 3694 | |
| 3695 | if (stats[ST_F_AGENT_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3696 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3697 | |
| 3698 | 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] | 3699 | 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] | 3700 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3701 | 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] | 3702 | |
| 3703 | if (*field_str(stats, ST_F_LAST_AGT)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3704 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3705 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3706 | chunk_htmlencode(out, &src); |
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></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3709 | } |
| 3710 | else if (stats[ST_F_CHECK_STATUS].type) { |
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 | "</td><td class=ac><u> %s", |
| 3713 | field_str(stats, ST_F_CHECK_STATUS)); |
| 3714 | |
| 3715 | if (stats[ST_F_CHECK_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3716 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3717 | |
| 3718 | 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] | 3719 | 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] | 3720 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3721 | 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] | 3722 | |
| 3723 | if (*field_str(stats, ST_F_LAST_CHK)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3724 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3725 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3726 | chunk_htmlencode(out, &src); |
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></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3729 | } |
| 3730 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3731 | chunk_appendf(out, "</td><td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3732 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3733 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3734 | /* weight */ |
| 3735 | "</td><td class=ac>%d</td>" |
| 3736 | /* act, bck */ |
| 3737 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3738 | "", |
| 3739 | stats[ST_F_WEIGHT].u.u32, |
| 3740 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 3741 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 3742 | |
| 3743 | /* check failures: unique, fatal, down time */ |
| 3744 | if (stats[ST_F_CHKFAIL].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3745 | 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] | 3746 | |
| 3747 | if (stats[ST_F_HANAFAIL].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3748 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3749 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3750 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3751 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 3752 | "<td>%lld</td><td>%s</td>" |
| 3753 | "", |
| 3754 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 3755 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 3756 | } |
| 3757 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 3758 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3759 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3760 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 3761 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 3762 | } |
| 3763 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3764 | chunk_appendf(out, "<td colspan=3></td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3765 | |
| 3766 | /* throttle */ |
| 3767 | if (stats[ST_F_THROTTLE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3768 | 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] | 3769 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3770 | chunk_appendf(out, "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3771 | } |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3772 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3773 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3774 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3775 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3776 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3777 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3778 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3779 | "<td class=ac>" |
| 3780 | /* name */ |
| 3781 | "%s<a name=\"%s/Backend\"></a>" |
| 3782 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3783 | "", |
| 3784 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3785 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 3786 | |
| 3787 | if (flags & ST_SHLGNDS) { |
| 3788 | /* balancing */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3789 | chunk_appendf(out, "<div class=tips>balancing: %s", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 3790 | field_str(stats, ST_F_ALGO)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3791 | |
| 3792 | /* cookie */ |
| 3793 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3794 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3795 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3796 | chunk_htmlencode(out, &src); |
| 3797 | chunk_appendf(out, "'"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3798 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3799 | chunk_appendf(out, "</div>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3800 | } |
| 3801 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3802 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3803 | "%s</td>" |
| 3804 | /* queue : current, max */ |
| 3805 | "<td>%s</td><td>%s</td><td></td>" |
| 3806 | /* sessions rate : current, max, limit */ |
| 3807 | "<td>%s</td><td>%s</td><td></td>" |
| 3808 | "", |
| 3809 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3810 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 3811 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 3812 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3813 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3814 | /* sessions: current, max, limit, total */ |
| 3815 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3816 | "<td><u>%s<div class=tips><table class=det>" |
| 3817 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3818 | "", |
| 3819 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3820 | U2H(stats[ST_F_STOT].u.u64), |
| 3821 | U2H(stats[ST_F_STOT].u.u64)); |
| 3822 | |
| 3823 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3824 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3825 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3826 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3827 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3828 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3829 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3830 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3831 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3832 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3833 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3834 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3835 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
| 3836 | "", |
| 3837 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3838 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3839 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3840 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3841 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3842 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3843 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3844 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3845 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3846 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3847 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3848 | } |
| 3849 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3850 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3851 | 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] | 3852 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3853 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3854 | 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] | 3855 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3856 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3857 | "</table></div></u></td>" |
| 3858 | /* sessions: lbtot, last */ |
| 3859 | "<td>%s</td><td>%s</td>" |
| 3860 | /* bytes: in */ |
| 3861 | "<td>%s</td>" |
| 3862 | "", |
| 3863 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3864 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 3865 | U2H(stats[ST_F_BIN].u.u64)); |
| 3866 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3867 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3868 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 3869 | "<td>%s%s<div class=tips><table class=det>" |
| 3870 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3871 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3872 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3873 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3874 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3875 | "</table></div>%s</td>", |
| 3876 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3877 | U2H(stats[ST_F_BOUT].u.u64), |
| 3878 | U2H(stats[ST_F_BOUT].u.u64), |
| 3879 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3880 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3881 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3882 | U2H(stats[ST_F_COMP_BYP].u.u64), |
Christopher Faulet | 0b64f62 | 2016-04-28 15:09:31 +0200 | [diff] [blame] | 3883 | 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] | 3884 | 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, |
| 3885 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 3886 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3887 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3888 | /* denied: req, resp */ |
| 3889 | "<td>%s</td><td>%s</td>" |
| 3890 | /* errors : request, connect */ |
| 3891 | "<td></td><td>%s</td>" |
| 3892 | /* errors : response */ |
| 3893 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3894 | /* warnings: retries, redispatches */ |
| 3895 | "<td>%lld</td><td>%lld</td>" |
| 3896 | /* backend status: reflect backend status (up/down): we display UP |
| 3897 | * if the backend has known working servers or if it has no server at |
| 3898 | * all (eg: for stats). Then we display the total weight, number of |
| 3899 | * active and backups. */ |
| 3900 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3901 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3902 | "", |
| 3903 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3904 | U2H(stats[ST_F_ECON].u.u64), |
| 3905 | U2H(stats[ST_F_ERESP].u.u64), |
| 3906 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3907 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3908 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 3909 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 3910 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
| 3911 | stats[ST_F_WEIGHT].u.u32, |
| 3912 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 3913 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3914 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3915 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3916 | "<td class=ac> </td><td>%d</td>" |
| 3917 | "<td>%s</td>" |
| 3918 | "<td></td>" |
| 3919 | "</tr>", |
| 3920 | stats[ST_F_CHKDOWN].u.u32, |
| 3921 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
| 3922 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3923 | return 1; |
| 3924 | } |
| 3925 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3926 | static int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx) |
| 3927 | { |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3928 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
| 3929 | flags |= ST_SHOWADMIN; |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3930 | |
| 3931 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3932 | return stats_dump_fields_html(&trash, stats, flags); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3933 | else if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3934 | return stats_dump_fields_typed(&trash, stats); |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3935 | else |
| 3936 | return stats_dump_fields_csv(&trash, stats); |
| 3937 | } |
| 3938 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3939 | /* Fill <stats> with the frontend statistics. <stats> is |
| 3940 | * preallocated array of length <len>. The length of the array |
| 3941 | * must be at least ST_F_TOTAL_FIELDS. If this length is less then |
| 3942 | * this value, the function returns 0, otherwise, it returns 1. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3943 | */ |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3944 | 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] | 3945 | { |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3946 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3947 | return 0; |
| 3948 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3949 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3950 | |
| 3951 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 3952 | 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] | 3953 | 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] | 3954 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 3955 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 3956 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 3957 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 3958 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 3959 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 3960 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 3961 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 3962 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 3963 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); |
| 3964 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 3965 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 3966 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 3967 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 3968 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 3969 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 3970 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 3971 | |
| 3972 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3973 | if (px->mode == PR_MODE_HTTP) { |
| 3974 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 3975 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 3976 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 3977 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 3978 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 3979 | 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] | 3980 | 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] | 3981 | } |
| 3982 | |
| 3983 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3984 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 3985 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 3986 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 3987 | |
| 3988 | /* compression: in, out, bypassed, responses */ |
| 3989 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 3990 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 3991 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 3992 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 3993 | |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3994 | /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */ |
| 3995 | stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 3996 | stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 3997 | stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 3998 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3999 | return 1; |
| 4000 | } |
| 4001 | |
| 4002 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 4003 | * the state from stream interface <si>. The caller is responsible for clearing |
| 4004 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4005 | */ |
| 4006 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
| 4007 | { |
| 4008 | struct appctx *appctx = __objt_appctx(si->end); |
| 4009 | |
| 4010 | if (!(px->cap & PR_CAP_FE)) |
| 4011 | return 0; |
| 4012 | |
| 4013 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 4014 | return 0; |
| 4015 | |
| 4016 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS)) |
| 4017 | return 0; |
| 4018 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4019 | return stats_dump_one_line(stats, 0, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4020 | } |
| 4021 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4022 | /* Fill <stats> with the listener statistics. <stats> is |
| 4023 | * preallocated array of length <len>. The length of the array |
| 4024 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4025 | * then this value, the function returns 0, otherwise, it |
| 4026 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4027 | */ |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4028 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
| 4029 | struct field *stats, int len) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4030 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4031 | struct chunk *out = get_trash_chunk(); |
| 4032 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4033 | if (len < ST_F_TOTAL_FIELDS) |
| 4034 | return 0; |
| 4035 | |
Thierry Fournier | ac9d467 | 2016-03-25 08:43:46 +0100 | [diff] [blame] | 4036 | if (!l->counters) |
| 4037 | return 0; |
| 4038 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4039 | chunk_reset(out); |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4040 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4041 | |
| 4042 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4043 | 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] | 4044 | 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] | 4045 | stats[ST_F_SCUR] = mkf_u32(0, l->nbconn); |
| 4046 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max); |
| 4047 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn); |
| 4048 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 4049 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 4050 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 4051 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 4052 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 4053 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 4054 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 4055 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4056 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4057 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 4058 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 4059 | |
| 4060 | if (flags & ST_SHLGNDS) { |
| 4061 | char str[INET6_ADDRSTRLEN]; |
| 4062 | int port; |
| 4063 | |
| 4064 | port = get_host_port(&l->addr); |
| 4065 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 4066 | case AF_INET: |
| 4067 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4068 | chunk_appendf(out, "%s:%d", str, port); |
| 4069 | break; |
| 4070 | case AF_INET6: |
| 4071 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4072 | chunk_appendf(out, "[%s]:%d", str, port); |
| 4073 | break; |
| 4074 | case AF_UNIX: |
| 4075 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4076 | break; |
| 4077 | case -1: |
| 4078 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4079 | chunk_strcat(out, strerror(errno)); |
| 4080 | break; |
| 4081 | default: /* address family not supported */ |
| 4082 | break; |
| 4083 | } |
| 4084 | } |
| 4085 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4086 | return 1; |
| 4087 | } |
| 4088 | |
| 4089 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 4090 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 4091 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 4092 | * otherwise. |
| 4093 | */ |
| 4094 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
| 4095 | { |
| 4096 | struct appctx *appctx = __objt_appctx(si->end); |
| 4097 | |
| 4098 | if (!stats_fill_li_stats(px, l, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4099 | return 0; |
| 4100 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4101 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4102 | } |
| 4103 | |
| 4104 | enum srv_stats_state { |
| 4105 | SRV_STATS_STATE_DOWN = 0, |
| 4106 | SRV_STATS_STATE_DOWN_AGENT, |
| 4107 | SRV_STATS_STATE_GOING_UP, |
| 4108 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 4109 | SRV_STATS_STATE_UP, |
| 4110 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4111 | SRV_STATS_STATE_NOLB, |
| 4112 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 4113 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4114 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4115 | SRV_STATS_STATE_NO_CHECK, |
| 4116 | |
| 4117 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 4118 | }; |
| 4119 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4120 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 4121 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 4122 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 4123 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 4124 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 4125 | [SRV_STATS_STATE_UP] = "UP", |
| 4126 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 4127 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 4128 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 4129 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 4130 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 4131 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 4132 | }; |
| 4133 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4134 | /* Fill <stats> with the server statistics. <stats> is |
| 4135 | * preallocated array of length <len>. The length of the array |
| 4136 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4137 | * then this value, the function returns 0, otherwise, it |
| 4138 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4139 | */ |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4140 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 4141 | struct field *stats, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4142 | { |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4143 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4144 | char str[INET6_ADDRSTRLEN]; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4145 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4146 | enum srv_stats_state state; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4147 | char *fld_status; |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4148 | |
| 4149 | if (len < ST_F_TOTAL_FIELDS) |
| 4150 | return 0; |
| 4151 | |
| 4152 | memset(stats, 0, sizeof(*stats) * len); |
| 4153 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4154 | /* we have "via" which is the tracked server as described in the configuration, |
| 4155 | * and "ref" which is the checked server and the end of the chain. |
| 4156 | */ |
| 4157 | via = sv->track ? sv->track : sv; |
| 4158 | ref = via; |
| 4159 | while (ref->track) |
| 4160 | ref = ref->track; |
| 4161 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4162 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 4163 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 4164 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
| 4165 | state = SRV_STATS_STATE_UP_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4166 | } else { |
| 4167 | state = SRV_STATS_STATE_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4168 | } |
| 4169 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4170 | if (sv->admin & SRV_ADMF_DRAIN) { |
| 4171 | if (ref->agent.state & CHK_ST_ENABLED) |
| 4172 | state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4173 | else if (state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 4174 | state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
| 4175 | else |
| 4176 | state = SRV_STATS_STATE_DRAIN; |
| 4177 | } |
| 4178 | |
| 4179 | if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 4180 | state = SRV_STATS_STATE_NO_CHECK; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4181 | } |
| 4182 | } |
| 4183 | else if (sv->state == SRV_ST_STOPPING) { |
| 4184 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 4185 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
| 4186 | state = SRV_STATS_STATE_NOLB; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4187 | } else { |
| 4188 | state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4189 | } |
| 4190 | } |
| 4191 | else { /* stopped */ |
| 4192 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
| 4193 | state = SRV_STATS_STATE_DOWN_AGENT; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4194 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
| 4195 | state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4196 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
| 4197 | state = SRV_STATS_STATE_GOING_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4198 | } else { |
| 4199 | state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4200 | } |
| 4201 | } |
| 4202 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4203 | chunk_reset(out); |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4204 | |
| 4205 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4206 | 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] | 4207 | 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] | 4208 | stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend); |
| 4209 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 4210 | stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess); |
| 4211 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 4212 | |
| 4213 | if (sv->maxconn) |
| 4214 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 4215 | |
| 4216 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 4217 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 4218 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 4219 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu); |
| 4220 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 4221 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 4222 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 4223 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 4224 | |
| 4225 | /* status */ |
| 4226 | fld_status = chunk_newstr(out); |
| 4227 | if (sv->admin & SRV_ADMF_IMAINT) |
| 4228 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 4229 | else if (sv->admin & SRV_ADMF_MAINT) |
| 4230 | chunk_appendf(out, "MAINT"); |
| 4231 | else |
| 4232 | chunk_appendf(out, |
| 4233 | srv_hlt_st[state], |
| 4234 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 4235 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
| 4236 | |
| 4237 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4238 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 4239 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4240 | stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 4241 | 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] | 4242 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4243 | /* check failures: unique, fatal; last change, total downtime */ |
| 4244 | if (sv->check.state & CHK_ST_ENABLED) { |
| 4245 | stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 4246 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 4247 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 4248 | } |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4249 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4250 | if (sv->maxqueue) |
| 4251 | stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4252 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4253 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4254 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4255 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4256 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4257 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 4258 | stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4259 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4260 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4261 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4262 | if (sv->track) { |
| 4263 | char *fld_track = chunk_newstr(out); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4264 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4265 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 4266 | stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 4267 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4268 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4269 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 4270 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 4271 | 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] | 4272 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4273 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4274 | const char *fld_chksts; |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4275 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4276 | fld_chksts = chunk_newstr(out); |
| 4277 | chunk_strcat(out, "* "); // for check in progress |
| 4278 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 4279 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 4280 | fld_chksts += 2; // skip "* " |
| 4281 | stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4282 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4283 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 4284 | stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4285 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4286 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 4287 | stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4288 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4289 | stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 4290 | stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc); |
| 4291 | stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 4292 | stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 4293 | stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 4294 | } |
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 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4297 | const char *fld_chksts; |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4298 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4299 | fld_chksts = chunk_newstr(out); |
| 4300 | chunk_strcat(out, "* "); // for check in progress |
| 4301 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 4302 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 4303 | fld_chksts += 2; // skip "* " |
| 4304 | stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4305 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4306 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 4307 | stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4308 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4309 | if (sv->agent.status >= HCHK_STATUS_CHECKED) |
| 4310 | stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4311 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4312 | stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 4313 | stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 4314 | stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 4315 | stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 4316 | stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 4317 | } |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4318 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4319 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4320 | if (px->mode == PR_MODE_HTTP) { |
| 4321 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 4322 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 4323 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 4324 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 4325 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 4326 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 4327 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4328 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4329 | if (ref->observe) |
| 4330 | stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4331 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4332 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 4333 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 4334 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv)); |
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 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES)); |
| 4337 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES)); |
| 4338 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES)); |
| 4339 | 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] | 4340 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4341 | if (flags & ST_SHLGNDS) { |
| 4342 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 4343 | case AF_INET: |
| 4344 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4345 | chunk_appendf(out, "%s:%d", str, get_host_port(&sv->addr)); |
| 4346 | break; |
| 4347 | case AF_INET6: |
| 4348 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4349 | chunk_appendf(out, "[%s]:%d", str, get_host_port(&sv->addr)); |
| 4350 | break; |
| 4351 | case AF_UNIX: |
| 4352 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4353 | break; |
| 4354 | case -1: |
| 4355 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4356 | chunk_strcat(out, strerror(errno)); |
| 4357 | break; |
| 4358 | default: /* address family not supported */ |
| 4359 | break; |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 4360 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4361 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4362 | if (sv->cookie) |
| 4363 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 4364 | } |
| 4365 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4366 | return 1; |
| 4367 | } |
| 4368 | |
| 4369 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 4370 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 4371 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 4372 | * if it emits anything, zero otherwise. |
| 4373 | */ |
| 4374 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv) |
| 4375 | { |
| 4376 | struct appctx *appctx = __objt_appctx(si->end); |
| 4377 | |
| 4378 | if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4379 | return 0; |
| 4380 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4381 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4382 | } |
| 4383 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4384 | /* Fill <stats> with the backend statistics. <stats> is |
| 4385 | * preallocated array of length <len>. The length of the array |
| 4386 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4387 | * then this value, the function returns 0, otherwise, it |
| 4388 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4389 | */ |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4390 | 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] | 4391 | { |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4392 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4393 | return 0; |
| 4394 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4395 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4396 | |
| 4397 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4398 | 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] | 4399 | 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] | 4400 | stats[ST_F_QCUR] = mkf_u32(0, px->nbpend); |
| 4401 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 4402 | stats[ST_F_SCUR] = mkf_u32(FO_CONFIG|FN_LIMIT, px->beconn); |
| 4403 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 4404 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 4405 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 4406 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 4407 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 4408 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 4409 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 4410 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 4411 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 4412 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 4413 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 4414 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 4415 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4416 | stats[ST_F_ACT] = mkf_u32(0, px->srv_act); |
| 4417 | stats[ST_F_BCK] = mkf_u32(0, px->srv_bck); |
| 4418 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans); |
| 4419 | 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] | 4420 | if (px->srv) |
| 4421 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 4422 | |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4423 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4424 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4425 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 4426 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 4427 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 4428 | stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 4429 | 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] | 4430 | |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 4431 | if (flags & ST_SHLGNDS) { |
| 4432 | if (px->cookie_name) |
| 4433 | 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] | 4434 | 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] | 4435 | } |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4436 | |
| 4437 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4438 | if (px->mode == PR_MODE_HTTP) { |
| 4439 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 4440 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 4441 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 4442 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 4443 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 4444 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 4445 | 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] | 4446 | 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] | 4447 | } |
| 4448 | |
| 4449 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 4450 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 4451 | |
| 4452 | /* compression: in, out, bypassed, responses */ |
| 4453 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 4454 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 4455 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 4456 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 4457 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px)); |
| 4458 | |
| 4459 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES)); |
| 4460 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES)); |
| 4461 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); |
| 4462 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4463 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4464 | return 1; |
| 4465 | } |
| 4466 | |
| 4467 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 4468 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 4469 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4470 | */ |
| 4471 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 4472 | { |
| 4473 | struct appctx *appctx = __objt_appctx(si->end); |
| 4474 | |
| 4475 | if (!(px->cap & PR_CAP_BE)) |
| 4476 | return 0; |
| 4477 | |
| 4478 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 4479 | return 0; |
| 4480 | |
| 4481 | if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4482 | return 0; |
| 4483 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4484 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4485 | } |
| 4486 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4487 | /* 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] | 4488 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4489 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4490 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4491 | 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] | 4492 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4493 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4494 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4495 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4496 | 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] | 4497 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4498 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4499 | /* 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] | 4500 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4501 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4502 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4503 | 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] | 4504 | 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] | 4505 | } |
| 4506 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4507 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4508 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4509 | } |
| 4510 | |
| 4511 | /* print a new table */ |
| 4512 | chunk_appendf(&trash, |
| 4513 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4514 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4515 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4516 | |
| 4517 | chunk_appendf(&trash, |
| 4518 | "<a name=\"%s\"></a>%s" |
| 4519 | "<a class=px href=\"#%s\">%s</a>", |
| 4520 | px->id, |
| 4521 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4522 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4523 | |
| 4524 | if (uri->flags & ST_SHLGNDS) { |
| 4525 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4526 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4527 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4528 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4529 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4530 | } |
| 4531 | |
| 4532 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4533 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4534 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4535 | "</tr>\n" |
| 4536 | "</table>\n" |
| 4537 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4538 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4539 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4540 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4541 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4542 | 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] | 4543 | /* Column heading for Enable or Disable server */ |
| 4544 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4545 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4546 | |
| 4547 | chunk_appendf(&trash, |
| 4548 | "<th rowspan=2></th>" |
| 4549 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4550 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4551 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4552 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4553 | "<th colspan=9>Server</th>" |
| 4554 | "</tr>\n" |
| 4555 | "<tr class=\"titre\">" |
| 4556 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4557 | "<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] | 4558 | "<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] | 4559 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4560 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4561 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4562 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4563 | "<th>Thrtle</th>\n" |
| 4564 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4565 | } |
| 4566 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4567 | /* 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] | 4568 | * 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] | 4569 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4570 | 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] | 4571 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4572 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4573 | chunk_appendf(&trash, "</table>"); |
| 4574 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4575 | 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] | 4576 | /* close the form used to enable/disable this proxy servers */ |
| 4577 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4578 | "Choose the action to perform on the checked servers : " |
| 4579 | "<select name=action>" |
| 4580 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4581 | "<option value=\"ready\">Set state to READY</option>" |
| 4582 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4583 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4584 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4585 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4586 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4587 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4588 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4589 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4590 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4591 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4592 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4593 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4594 | "</select>" |
| 4595 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4596 | " <input type=\"submit\" value=\"Apply\">" |
| 4597 | "</form>", |
| 4598 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4599 | } |
| 4600 | |
| 4601 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4602 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4603 | |
| 4604 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4605 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4606 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4607 | * buffer space, or non-zero if everything completed. This function is used |
| 4608 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4609 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4610 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4611 | 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] | 4612 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4613 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4614 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4615 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4616 | 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] | 4617 | struct listener *l; |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4618 | unsigned int flags; |
| 4619 | |
| 4620 | if (uri) |
| 4621 | flags = uri->flags; |
| 4622 | else if (strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) |
| 4623 | flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC; |
| 4624 | else |
| 4625 | flags = ST_SHNODE | ST_SHDESC; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4626 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4627 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4628 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4629 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4630 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4631 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4632 | if (uri && uri->scope) { |
| 4633 | /* we have a limited scope, we have to check the proxy name */ |
| 4634 | struct stat_scope *scope; |
| 4635 | int len; |
| 4636 | |
| 4637 | len = strlen(px->id); |
| 4638 | scope = uri->scope; |
| 4639 | |
| 4640 | while (scope) { |
| 4641 | /* match exact proxy name */ |
| 4642 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4643 | break; |
| 4644 | |
| 4645 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4646 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4647 | break; |
| 4648 | scope = scope->next; |
| 4649 | } |
| 4650 | |
| 4651 | /* proxy name not found : don't dump anything */ |
| 4652 | if (scope == NULL) |
| 4653 | return 1; |
| 4654 | } |
| 4655 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4656 | /* if the user has requested a limited output and the proxy |
| 4657 | * name does not match, skip it. |
| 4658 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4659 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4660 | 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] | 4661 | return 1; |
| 4662 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4663 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4664 | (appctx->ctx.stats.iid != -1) && |
| 4665 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4666 | return 1; |
| 4667 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4668 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4669 | /* fall through */ |
| 4670 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4671 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4672 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4673 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4674 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4675 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4676 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4677 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4678 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4679 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4680 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4681 | /* fall through */ |
| 4682 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4683 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4684 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4685 | if (stats_dump_fe_stats(si, px)) { |
| 4686 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4687 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4688 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4689 | } |
| 4690 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4691 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4692 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4693 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4694 | /* fall through */ |
| 4695 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4696 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4697 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4698 | 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] | 4699 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4700 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4701 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4702 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4703 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4704 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4705 | if (!l->counters) |
| 4706 | continue; |
| 4707 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4708 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4709 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4710 | break; |
| 4711 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4712 | 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] | 4713 | continue; |
| 4714 | } |
| 4715 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4716 | /* print the frontend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4717 | if (stats_dump_li_stats(si, px, l, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4718 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4719 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4720 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4721 | } |
| 4722 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4723 | } |
| 4724 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4725 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4726 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4727 | /* fall through */ |
| 4728 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4729 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4730 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4731 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4732 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4733 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4734 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4735 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4736 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4737 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4738 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4739 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4740 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4741 | break; |
| 4742 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4743 | 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] | 4744 | continue; |
| 4745 | } |
| 4746 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4747 | svs = sv; |
| 4748 | while (svs->track) |
| 4749 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4750 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4751 | /* do not report servers which are DOWN and not changing state */ |
| 4752 | if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) && |
| 4753 | ((sv->admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 4754 | (sv->state == SRV_ST_STOPPED && /* server is down */ |
| 4755 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 4756 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 4757 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4758 | continue; |
| 4759 | } |
| 4760 | |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4761 | if (stats_dump_sv_stats(si, px, flags, sv)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4762 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4763 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4764 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4765 | } |
| 4766 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4767 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4768 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4769 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4770 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4771 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4772 | case STAT_PX_ST_BE: |
| 4773 | /* print the backend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4774 | if (stats_dump_be_stats(si, px, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4775 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4776 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4777 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4778 | } |
| 4779 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4780 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4781 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4782 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4783 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4784 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4785 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4786 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4787 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4788 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4789 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4790 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4791 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4792 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4793 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4794 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4795 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4796 | case STAT_PX_ST_FIN: |
| 4797 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4798 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4799 | default: |
| 4800 | /* unknown state, we should put an abort() here ! */ |
| 4801 | return 1; |
| 4802 | } |
| 4803 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4804 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4805 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4806 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4807 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4808 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4809 | { |
| 4810 | /* WARNING! This must fit in the first buffer !!! */ |
| 4811 | chunk_appendf(&trash, |
| 4812 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4813 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4814 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4815 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4816 | "<style type=\"text/css\"><!--\n" |
| 4817 | "body {" |
| 4818 | " font-family: arial, helvetica, sans-serif;" |
| 4819 | " font-size: 12px;" |
| 4820 | " font-weight: normal;" |
| 4821 | " color: black;" |
| 4822 | " background: white;" |
| 4823 | "}\n" |
| 4824 | "th,td {" |
| 4825 | " font-size: 10px;" |
| 4826 | "}\n" |
| 4827 | "h1 {" |
| 4828 | " font-size: x-large;" |
| 4829 | " margin-bottom: 0.5em;" |
| 4830 | "}\n" |
| 4831 | "h2 {" |
| 4832 | " font-family: helvetica, arial;" |
| 4833 | " font-size: x-large;" |
| 4834 | " font-weight: bold;" |
| 4835 | " font-style: italic;" |
| 4836 | " color: #6020a0;" |
| 4837 | " margin-top: 0em;" |
| 4838 | " margin-bottom: 0em;" |
| 4839 | "}\n" |
| 4840 | "h3 {" |
| 4841 | " font-family: helvetica, arial;" |
| 4842 | " font-size: 16px;" |
| 4843 | " font-weight: bold;" |
| 4844 | " color: #b00040;" |
| 4845 | " background: #e8e8d0;" |
| 4846 | " margin-top: 0em;" |
| 4847 | " margin-bottom: 0em;" |
| 4848 | "}\n" |
| 4849 | "li {" |
| 4850 | " margin-top: 0.25em;" |
| 4851 | " margin-right: 2em;" |
| 4852 | "}\n" |
| 4853 | ".hr {margin-top: 0.25em;" |
| 4854 | " border-color: black;" |
| 4855 | " border-bottom-style: solid;" |
| 4856 | "}\n" |
| 4857 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4858 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4859 | ".frontend {background: #e8e8d0;}\n" |
| 4860 | ".socket {background: #d0d0d0;}\n" |
| 4861 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4862 | ".active_down {background: #ff9090;}\n" |
| 4863 | ".active_going_up {background: #ffd020;}\n" |
| 4864 | ".active_going_down {background: #ffffa0;}\n" |
| 4865 | ".active_up {background: #c0ffc0;}\n" |
| 4866 | ".active_nolb {background: #20a0ff;}\n" |
| 4867 | ".active_draining {background: #20a0FF;}\n" |
| 4868 | ".active_no_check {background: #e0e0e0;}\n" |
| 4869 | ".backup_down {background: #ff9090;}\n" |
| 4870 | ".backup_going_up {background: #ff80ff;}\n" |
| 4871 | ".backup_going_down {background: #c060ff;}\n" |
| 4872 | ".backup_up {background: #b0d0ff;}\n" |
| 4873 | ".backup_nolb {background: #90b0e0;}\n" |
| 4874 | ".backup_draining {background: #cc9900;}\n" |
| 4875 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4876 | ".maintain {background: #c07820;}\n" |
| 4877 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4878 | "\n" |
| 4879 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4880 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4881 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4882 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4883 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4884 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4885 | "\n" |
| 4886 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4887 | "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" |
| 4888 | "table.tbl td.ac { text-align: center;}\n" |
| 4889 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4890 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4891 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4892 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4893 | "\n" |
| 4894 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4895 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4896 | "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] | 4897 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4898 | "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] | 4899 | "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] | 4900 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4901 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4902 | " display:block;\n" |
| 4903 | " visibility:hidden;\n" |
| 4904 | " z-index:2147483647;\n" |
| 4905 | " position:absolute;\n" |
| 4906 | " padding:2px 4px 3px;\n" |
| 4907 | " background:#f0f060; color:#000000;\n" |
| 4908 | " border:1px solid #7040c0;\n" |
| 4909 | " white-space:nowrap;\n" |
| 4910 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4911 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4912 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4913 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4914 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4915 | "-->\n" |
| 4916 | "</style></head>\n", |
| 4917 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4918 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4919 | ); |
| 4920 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4921 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4922 | /* 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] | 4923 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4924 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4925 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4926 | 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] | 4927 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4928 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4929 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4930 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4931 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4932 | /* WARNING! this has to fit the first packet too. |
| 4933 | * We are around 3.5 kB, add adding entries will |
| 4934 | * become tricky if we want to support 4kB buffers ! |
| 4935 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4936 | chunk_appendf(&trash, |
| 4937 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4938 | PRODUCT_NAME "%s</a></h1>\n" |
| 4939 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4940 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4941 | "<h3>> General process information</h3>\n" |
| 4942 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4943 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4944 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4945 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4946 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4947 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4948 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4949 | "</td><td align=\"center\" nowrap>\n" |
| 4950 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4951 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4952 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4953 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4954 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4955 | "<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] | 4956 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4957 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4958 | "<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] | 4959 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4960 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4961 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4962 | "</tr><tr>\n" |
| 4963 | "<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] | 4964 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4965 | "<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] | 4966 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4967 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4968 | "</td>" |
| 4969 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4970 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4971 | "", |
| 4972 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4973 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4974 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4975 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4976 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4977 | pid, relative_pid, global.nbproc, |
| 4978 | up / 86400, (up % 86400) / 3600, |
| 4979 | (up % 3600) / 60, (up % 60), |
| 4980 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4981 | global.rlimit_memmax ? " MB" : "", |
| 4982 | global.rlimit_nofile, |
| 4983 | global.maxsock, global.maxconn, global.maxpipes, |
| 4984 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4985 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4986 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4987 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4988 | /* 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] | 4989 | 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] | 4990 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4991 | |
| 4992 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4993 | "<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] | 4994 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4995 | STAT_SCOPE_TXT_MAXLEN); |
| 4996 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4997 | /* 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] | 4998 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4999 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5000 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5001 | 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] | 5002 | 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] | 5003 | } |
| 5004 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5005 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5006 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5007 | "<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] | 5008 | uri->uri_prefix, |
| 5009 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5010 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5011 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5012 | else |
| 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\">Hide 'DOWN' servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5015 | uri->uri_prefix, |
| 5016 | ";up", |
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 | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5019 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5020 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5021 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5022 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5023 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5024 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5025 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5026 | "", |
| 5027 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5028 | else |
| 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\">Disable 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 | ";norefresh", |
| 5034 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5035 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 5036 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5037 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5038 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5039 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5040 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5041 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5042 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +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;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5046 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 5047 | (uri->refresh > 0) ? ";norefresh" : "", |
| 5048 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5049 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5050 | chunk_appendf(&trash, |
| 5051 | "</ul></td>" |
| 5052 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 5053 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 5054 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 5055 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 5056 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 5057 | "</ul>" |
| 5058 | "</td>" |
| 5059 | "</tr></table>\n" |
| 5060 | "" |
| 5061 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5062 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5063 | if (appctx->ctx.stats.st_code) { |
| 5064 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5065 | case STAT_STATUS_DONE: |
| 5066 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5067 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5068 | "<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] | 5069 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5070 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5071 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5072 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5073 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5074 | break; |
| 5075 | case STAT_STATUS_NONE: |
| 5076 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5077 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5078 | "<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] | 5079 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5080 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5081 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5082 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5083 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5084 | break; |
| 5085 | case STAT_STATUS_PART: |
| 5086 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5087 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5088 | "<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] | 5089 | "Action partially processed.<br>" |
| 5090 | "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] | 5091 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5092 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5093 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5094 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5095 | break; |
| 5096 | case STAT_STATUS_ERRP: |
| 5097 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5098 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5099 | "<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] | 5100 | "Action not processed because of invalid parameters." |
| 5101 | "<ul>" |
| 5102 | "<li>The action is maybe unknown.</li>" |
| 5103 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 5104 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 5105 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5106 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5107 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5108 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5109 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5110 | break; |
| 5111 | case STAT_STATUS_EXCD: |
| 5112 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5113 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5114 | "<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] | 5115 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 5116 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5117 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5118 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5119 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5120 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5121 | break; |
| 5122 | case STAT_STATUS_DENY: |
| 5123 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5124 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5125 | "<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] | 5126 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5127 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5128 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5129 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5130 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5131 | break; |
| 5132 | default: |
| 5133 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5134 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5135 | "<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] | 5136 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5137 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5138 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5139 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5140 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5141 | } |
| 5142 | chunk_appendf(&trash, "<p>\n"); |
| 5143 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5144 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5145 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5146 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 5147 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5148 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5149 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5150 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5151 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5152 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5153 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5154 | /* This function dumps statistics onto the stream interface's read buffer in |
| 5155 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5156 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 5157 | * 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] | 5158 | * 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] | 5159 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5160 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5161 | 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] | 5162 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5163 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5164 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5165 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5166 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5167 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5168 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5169 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5170 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5171 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5172 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 5173 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5174 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5175 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5176 | stats_dump_html_head(uri); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 5177 | else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED)) |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 5178 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 5179 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5180 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5181 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5182 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5183 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5184 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5185 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5186 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5187 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5188 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5189 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5190 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5191 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5192 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5193 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5194 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5195 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5196 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5197 | appctx->ctx.stats.px = proxy; |
| 5198 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 5199 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5200 | /* fall through */ |
| 5201 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5202 | case STAT_ST_LIST: |
| 5203 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5204 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5205 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5206 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5207 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5208 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5209 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5210 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5211 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5212 | 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] | 5213 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5214 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5215 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5216 | appctx->ctx.stats.px = px->next; |
| 5217 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5218 | } |
| 5219 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5220 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5221 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5222 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5223 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5224 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5225 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5226 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5227 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5228 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5229 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5230 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5231 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5232 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5233 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5234 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5235 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5236 | case STAT_ST_FIN: |
| 5237 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5238 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5239 | default: |
| 5240 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5241 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5242 | return -1; |
| 5243 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5244 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5245 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5246 | /* We reached the stats page through a POST request. The appctx is |
| 5247 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5248 | * Parse the posted data and enable/disable servers if necessary. |
| 5249 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5250 | */ |
| 5251 | static int stats_process_http_post(struct stream_interface *si) |
| 5252 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5253 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5254 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5255 | |
| 5256 | struct proxy *px = NULL; |
| 5257 | struct server *sv = NULL; |
| 5258 | |
| 5259 | char key[LINESIZE]; |
| 5260 | int action = ST_ADM_ACTION_NONE; |
| 5261 | int reprocess = 0; |
| 5262 | |
| 5263 | int total_servers = 0; |
| 5264 | int altered_servers = 0; |
| 5265 | |
| 5266 | char *first_param, *cur_param, *next_param, *end_params; |
| 5267 | char *st_cur_param = NULL; |
| 5268 | char *st_next_param = NULL; |
| 5269 | |
| 5270 | struct chunk *temp; |
| 5271 | int reql; |
| 5272 | |
| 5273 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5274 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5275 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5276 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5277 | goto out; |
| 5278 | } |
| 5279 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5280 | 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] | 5281 | if (reql <= 0) { |
| 5282 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5283 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5284 | return 0; |
| 5285 | } |
| 5286 | |
| 5287 | first_param = temp->str; |
| 5288 | end_params = temp->str + reql; |
| 5289 | cur_param = next_param = end_params; |
| 5290 | *end_params = '\0'; |
| 5291 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5292 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5293 | |
| 5294 | /* |
| 5295 | * Parse the parameters in reverse order to only store the last value. |
| 5296 | * From the html form, the backend and the action are at the end. |
| 5297 | */ |
| 5298 | while (cur_param > first_param) { |
| 5299 | char *value; |
| 5300 | int poffset, plen; |
| 5301 | |
| 5302 | cur_param--; |
| 5303 | |
| 5304 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5305 | reprocess_servers: |
| 5306 | /* Parse the key */ |
| 5307 | poffset = (cur_param != first_param ? 1 : 0); |
| 5308 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5309 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5310 | strncpy(key, cur_param + poffset, plen); |
| 5311 | key[plen - 1] = '\0'; |
| 5312 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5313 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5314 | goto out; |
| 5315 | } |
| 5316 | |
| 5317 | /* Parse the value */ |
| 5318 | value = key; |
| 5319 | while (*value != '\0' && *value != '=') { |
| 5320 | value++; |
| 5321 | } |
| 5322 | if (*value == '=') { |
| 5323 | /* Ok, a value is found, we can mark the end of the key */ |
| 5324 | *value++ = '\0'; |
| 5325 | } |
| 5326 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5327 | break; |
| 5328 | |
| 5329 | /* Now we can check the key to see what to do */ |
| 5330 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5331 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5332 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5333 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5334 | goto out; |
| 5335 | } |
| 5336 | } |
| 5337 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5338 | if (strcmp(value, "ready") == 0) { |
| 5339 | action = ST_ADM_ACTION_READY; |
| 5340 | } |
| 5341 | else if (strcmp(value, "drain") == 0) { |
| 5342 | action = ST_ADM_ACTION_DRAIN; |
| 5343 | } |
| 5344 | else if (strcmp(value, "maint") == 0) { |
| 5345 | action = ST_ADM_ACTION_MAINT; |
| 5346 | } |
| 5347 | else if (strcmp(value, "shutdown") == 0) { |
| 5348 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5349 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5350 | else if (strcmp(value, "dhlth") == 0) { |
| 5351 | action = ST_ADM_ACTION_DHLTH; |
| 5352 | } |
| 5353 | else if (strcmp(value, "ehlth") == 0) { |
| 5354 | action = ST_ADM_ACTION_EHLTH; |
| 5355 | } |
| 5356 | else if (strcmp(value, "hrunn") == 0) { |
| 5357 | action = ST_ADM_ACTION_HRUNN; |
| 5358 | } |
| 5359 | else if (strcmp(value, "hnolb") == 0) { |
| 5360 | action = ST_ADM_ACTION_HNOLB; |
| 5361 | } |
| 5362 | else if (strcmp(value, "hdown") == 0) { |
| 5363 | action = ST_ADM_ACTION_HDOWN; |
| 5364 | } |
| 5365 | else if (strcmp(value, "dagent") == 0) { |
| 5366 | action = ST_ADM_ACTION_DAGENT; |
| 5367 | } |
| 5368 | else if (strcmp(value, "eagent") == 0) { |
| 5369 | action = ST_ADM_ACTION_EAGENT; |
| 5370 | } |
| 5371 | else if (strcmp(value, "arunn") == 0) { |
| 5372 | action = ST_ADM_ACTION_ARUNN; |
| 5373 | } |
| 5374 | else if (strcmp(value, "adown") == 0) { |
| 5375 | action = ST_ADM_ACTION_ADOWN; |
| 5376 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5377 | /* else these are the old supported methods */ |
| 5378 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5379 | action = ST_ADM_ACTION_DISABLE; |
| 5380 | } |
| 5381 | else if (strcmp(value, "enable") == 0) { |
| 5382 | action = ST_ADM_ACTION_ENABLE; |
| 5383 | } |
| 5384 | else if (strcmp(value, "stop") == 0) { |
| 5385 | action = ST_ADM_ACTION_STOP; |
| 5386 | } |
| 5387 | else if (strcmp(value, "start") == 0) { |
| 5388 | action = ST_ADM_ACTION_START; |
| 5389 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5390 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5391 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5392 | goto out; |
| 5393 | } |
| 5394 | } |
| 5395 | else if (strcmp(key, "s") == 0) { |
| 5396 | if (!(px && action)) { |
| 5397 | /* |
| 5398 | * Indicates that we'll need to reprocess the parameters |
| 5399 | * as soon as backend and action are known |
| 5400 | */ |
| 5401 | if (!reprocess) { |
| 5402 | st_cur_param = cur_param; |
| 5403 | st_next_param = next_param; |
| 5404 | } |
| 5405 | reprocess = 1; |
| 5406 | } |
| 5407 | else if ((sv = findserver(px, value)) != NULL) { |
| 5408 | switch (action) { |
| 5409 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5410 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5411 | altered_servers++; |
| 5412 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5413 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5414 | } |
| 5415 | break; |
| 5416 | case ST_ADM_ACTION_ENABLE: |
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_clr_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_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5424 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5425 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5426 | altered_servers++; |
| 5427 | total_servers++; |
| 5428 | } |
| 5429 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5430 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5431 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5432 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5433 | altered_servers++; |
| 5434 | total_servers++; |
| 5435 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5436 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5437 | case ST_ADM_ACTION_DHLTH: |
| 5438 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5439 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5440 | altered_servers++; |
| 5441 | total_servers++; |
| 5442 | } |
| 5443 | break; |
| 5444 | case ST_ADM_ACTION_EHLTH: |
| 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_HRUNN: |
| 5452 | if (!(sv->track)) { |
| 5453 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5454 | srv_set_running(sv, "changed from Web interface"); |
| 5455 | altered_servers++; |
| 5456 | total_servers++; |
| 5457 | } |
| 5458 | break; |
| 5459 | case ST_ADM_ACTION_HNOLB: |
| 5460 | if (!(sv->track)) { |
| 5461 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5462 | srv_set_stopping(sv, "changed from Web interface"); |
| 5463 | altered_servers++; |
| 5464 | total_servers++; |
| 5465 | } |
| 5466 | break; |
| 5467 | case ST_ADM_ACTION_HDOWN: |
| 5468 | if (!(sv->track)) { |
| 5469 | sv->check.health = 0; |
| 5470 | srv_set_stopped(sv, "changed from Web interface"); |
| 5471 | altered_servers++; |
| 5472 | total_servers++; |
| 5473 | } |
| 5474 | break; |
| 5475 | case ST_ADM_ACTION_DAGENT: |
| 5476 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5477 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5478 | altered_servers++; |
| 5479 | total_servers++; |
| 5480 | } |
| 5481 | break; |
| 5482 | case ST_ADM_ACTION_EAGENT: |
| 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_ARUNN: |
| 5490 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5491 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5492 | srv_set_running(sv, "changed from Web interface"); |
| 5493 | altered_servers++; |
| 5494 | total_servers++; |
| 5495 | } |
| 5496 | break; |
| 5497 | case ST_ADM_ACTION_ADOWN: |
| 5498 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5499 | sv->agent.health = 0; |
| 5500 | srv_set_stopped(sv, "changed from Web interface"); |
| 5501 | altered_servers++; |
| 5502 | total_servers++; |
| 5503 | } |
| 5504 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5505 | case ST_ADM_ACTION_READY: |
| 5506 | srv_adm_set_ready(sv); |
| 5507 | altered_servers++; |
| 5508 | total_servers++; |
| 5509 | break; |
| 5510 | case ST_ADM_ACTION_DRAIN: |
| 5511 | srv_adm_set_drain(sv); |
| 5512 | altered_servers++; |
| 5513 | total_servers++; |
| 5514 | break; |
| 5515 | case ST_ADM_ACTION_MAINT: |
| 5516 | srv_adm_set_maint(sv); |
| 5517 | altered_servers++; |
| 5518 | total_servers++; |
| 5519 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5520 | case ST_ADM_ACTION_SHUTDOWN: |
| 5521 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5522 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5523 | |
| 5524 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5525 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5526 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5527 | |
| 5528 | altered_servers++; |
| 5529 | total_servers++; |
| 5530 | } |
| 5531 | break; |
| 5532 | } |
| 5533 | } else { |
| 5534 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5535 | total_servers++; |
| 5536 | } |
| 5537 | } |
| 5538 | if (reprocess && px && action) { |
| 5539 | /* Now, we know the backend and the action chosen by the user. |
| 5540 | * We can safely restart from the first server parameter |
| 5541 | * to reprocess them |
| 5542 | */ |
| 5543 | cur_param = st_cur_param; |
| 5544 | next_param = st_next_param; |
| 5545 | reprocess = 0; |
| 5546 | goto reprocess_servers; |
| 5547 | } |
| 5548 | |
| 5549 | next_param = cur_param; |
| 5550 | } |
| 5551 | } |
| 5552 | |
| 5553 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5554 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5555 | } |
| 5556 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5557 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5558 | } |
| 5559 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5560 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5561 | } |
| 5562 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5563 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5564 | } |
| 5565 | out: |
| 5566 | return 1; |
| 5567 | } |
| 5568 | |
| 5569 | |
| 5570 | static int stats_send_http_headers(struct stream_interface *si) |
| 5571 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5572 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5573 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5574 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5575 | |
| 5576 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5577 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5578 | "Cache-Control: no-cache\r\n" |
| 5579 | "Connection: close\r\n" |
| 5580 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5581 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5582 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5583 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5584 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5585 | uri->refresh); |
| 5586 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5587 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5588 | |
| 5589 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5590 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5591 | else |
| 5592 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5593 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5594 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5595 | s->logs.tv_request = now; |
| 5596 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5597 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5598 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5599 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5600 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5601 | |
| 5602 | return 1; |
| 5603 | } |
| 5604 | |
| 5605 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5606 | { |
| 5607 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5608 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5609 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5610 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5611 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5612 | /* 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] | 5613 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5614 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5615 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5616 | 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] | 5617 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5618 | } |
| 5619 | |
| 5620 | /* We don't want to land on the posted stats page because a refresh will |
| 5621 | * repost the data. We don't want this to happen on accident so we redirect |
| 5622 | * the browse to the stats page with a GET. |
| 5623 | */ |
| 5624 | chunk_printf(&trash, |
| 5625 | "HTTP/1.1 303 See Other\r\n" |
| 5626 | "Cache-Control: no-cache\r\n" |
| 5627 | "Content-Type: text/plain\r\n" |
| 5628 | "Connection: close\r\n" |
| 5629 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5630 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5631 | "\r\n", |
| 5632 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5633 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5634 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5635 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5636 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5637 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5638 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5639 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5640 | scope_txt); |
| 5641 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5642 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5643 | s->logs.tv_request = now; |
| 5644 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5645 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5646 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5647 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5648 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5649 | |
| 5650 | return 1; |
| 5651 | } |
| 5652 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5653 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5654 | * 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] | 5655 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5656 | * automatically unregisters itself once transfer is complete. |
| 5657 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5658 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5659 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5660 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5661 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5662 | struct channel *req = si_oc(si); |
| 5663 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5664 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5665 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5666 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5667 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5668 | /* check that the output is not closed */ |
| 5669 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5670 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5671 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5672 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5673 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5674 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5675 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5676 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5677 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5678 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5679 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5680 | } |
| 5681 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5682 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5683 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5684 | unsigned int data_len; |
| 5685 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5686 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5687 | |
| 5688 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5689 | /* One difficulty we're facing is that we must prevent |
| 5690 | * the input data from being automatically forwarded to |
| 5691 | * the output area. For this, we temporarily disable |
| 5692 | * forwarding on the channel. |
| 5693 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5694 | last_fwd = si_ic(si)->to_forward; |
| 5695 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5696 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5697 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5698 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5699 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5700 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5701 | } |
| 5702 | } |
| 5703 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5704 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5705 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5706 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5707 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5708 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5709 | |
| 5710 | /* Now we must either adjust or remove the chunk size. This is |
| 5711 | * not easy because the chunk size might wrap at the end of the |
| 5712 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5713 | * the size, then restore the buffer's contents. Note that we can |
| 5714 | * only do that because no forwarding is scheduled on the stats |
| 5715 | * applet. |
| 5716 | */ |
| 5717 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5718 | si_ic(si)->total -= (last_len - prev_len); |
| 5719 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5720 | |
| 5721 | if (last_len != data_len) { |
| 5722 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5723 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5724 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5725 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5726 | si_ic(si)->total += (last_len - data_len); |
| 5727 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5728 | } |
| 5729 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5730 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5731 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5732 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5733 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5734 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5735 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5736 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5737 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5738 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5739 | } |
| 5740 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5741 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5742 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5743 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5744 | } |
| 5745 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5746 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5747 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5748 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5749 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5750 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5751 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5752 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5753 | } |
| 5754 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5755 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5756 | res->flags |= CF_READ_NULL; |
| 5757 | si_shutr(si); |
| 5758 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5759 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5760 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5761 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5762 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5763 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5764 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5765 | si_shutr(si); |
| 5766 | res->flags |= CF_READ_NULL; |
| 5767 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5768 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5769 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5770 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5771 | } |
| 5772 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5773 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5774 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5775 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5776 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5777 | return "NONE"; |
| 5778 | return conn->ctrl->name; |
| 5779 | } |
| 5780 | |
| 5781 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5782 | { |
| 5783 | static char ptr[17]; |
| 5784 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5785 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5786 | return "NONE"; |
| 5787 | |
| 5788 | if (conn->xprt == &raw_sock) |
| 5789 | return "RAW"; |
| 5790 | |
| 5791 | #ifdef USE_OPENSSL |
| 5792 | if (conn->xprt == &ssl_sock) |
| 5793 | return "SSL"; |
| 5794 | #endif |
| 5795 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5796 | return ptr; |
| 5797 | } |
| 5798 | |
| 5799 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5800 | { |
| 5801 | static char ptr[17]; |
| 5802 | |
| 5803 | if (!conn->data) |
| 5804 | return "NONE"; |
| 5805 | |
| 5806 | if (conn->data == &sess_conn_cb) |
| 5807 | return "SESS"; |
| 5808 | |
| 5809 | if (conn->data == &si_conn_cb) |
| 5810 | return "STRM"; |
| 5811 | |
| 5812 | if (conn->data == &check_conn_cb) |
| 5813 | return "CHCK"; |
| 5814 | |
| 5815 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5816 | return ptr; |
| 5817 | } |
| 5818 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5819 | /* This function dumps a complete stream state onto the stream interface's |
| 5820 | * 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] | 5821 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5822 | * 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] | 5823 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5824 | 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] | 5825 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5826 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5827 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5828 | extern const char *monthname[12]; |
| 5829 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5830 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5831 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5832 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5833 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5834 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5835 | 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] | 5836 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5837 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5838 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5839 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5840 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5841 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5842 | appctx->ctx.sess.uid = 0; |
| 5843 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5844 | return 1; |
| 5845 | } |
| 5846 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5847 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5848 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5849 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5850 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5851 | /* fall through */ |
| 5852 | |
| 5853 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5854 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5855 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5856 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5857 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5858 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5859 | 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] | 5860 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5861 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5862 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5863 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5864 | 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] | 5865 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5866 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5867 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5868 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5869 | break; |
| 5870 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5871 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5872 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5873 | default: |
| 5874 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5875 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5876 | break; |
| 5877 | } |
| 5878 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5879 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5880 | " 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] | 5881 | 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] | 5882 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5883 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5884 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5885 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5886 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5887 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5888 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5889 | if (conn) |
| 5890 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5891 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5892 | 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] | 5893 | case AF_INET: |
| 5894 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5895 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5896 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5897 | break; |
| 5898 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5899 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5900 | break; |
| 5901 | default: |
| 5902 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5903 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5904 | break; |
| 5905 | } |
| 5906 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5907 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5908 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5909 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5910 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5911 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5912 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5913 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5914 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5915 | conn = objt_conn(sess->si[1].end); |
| 5916 | if (conn) |
| 5917 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5918 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5919 | 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] | 5920 | case AF_INET: |
| 5921 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5922 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5923 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5924 | break; |
| 5925 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5926 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5927 | break; |
| 5928 | default: |
| 5929 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5930 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5931 | break; |
| 5932 | } |
| 5933 | |
| 5934 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5935 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5936 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5937 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5938 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5939 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5940 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5941 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5942 | if (conn) |
| 5943 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5944 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5945 | 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] | 5946 | case AF_INET: |
| 5947 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5948 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5949 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5950 | break; |
| 5951 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5952 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5953 | break; |
| 5954 | default: |
| 5955 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5956 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5957 | break; |
| 5958 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5959 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5960 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5961 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5962 | sess->task, |
| 5963 | sess->task->state, |
| 5964 | sess->task->nice, sess->task->calls, |
| 5965 | sess->task->expire ? |
| 5966 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5967 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5968 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5969 | task_in_rq(sess->task) ? ", running" : ""); |
| 5970 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5971 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5972 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5973 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5974 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5975 | if (sess->txn) |
| 5976 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5977 | " 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] | 5978 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5979 | 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] | 5980 | |
| 5981 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5982 | " 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] | 5983 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5984 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5985 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5986 | obj_type_name(sess->si[0].end), |
| 5987 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5988 | sess->si[0].exp ? |
| 5989 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5990 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5991 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5992 | sess->si[0].err_type); |
| 5993 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5994 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5995 | " 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] | 5996 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5997 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5998 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5999 | obj_type_name(sess->si[1].end), |
| 6000 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6001 | sess->si[1].exp ? |
| 6002 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 6003 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 6004 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 6005 | sess->si[1].err_type); |
| 6006 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6007 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6008 | chunk_appendf(&trash, |
| 6009 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6010 | conn, |
| 6011 | get_conn_ctrl_name(conn), |
| 6012 | get_conn_xprt_name(conn), |
| 6013 | get_conn_data_name(conn), |
| 6014 | obj_type_name(conn->target), |
| 6015 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6016 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6017 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 6018 | " 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] | 6019 | conn->flags, |
| 6020 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 6021 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 6022 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6023 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6024 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6025 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 6026 | chunk_appendf(&trash, |
| 6027 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6028 | tmpctx, |
| 6029 | tmpctx->st0, |
| 6030 | tmpctx->st1, |
| 6031 | tmpctx->st2, |
| 6032 | tmpctx->applet->name); |
| 6033 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 6034 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6035 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6036 | chunk_appendf(&trash, |
| 6037 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6038 | conn, |
| 6039 | get_conn_ctrl_name(conn), |
| 6040 | get_conn_xprt_name(conn), |
| 6041 | get_conn_data_name(conn), |
| 6042 | obj_type_name(conn->target), |
| 6043 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6044 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6045 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 6046 | " 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] | 6047 | conn->flags, |
| 6048 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 6049 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 6050 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6051 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 6052 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 6053 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 6054 | chunk_appendf(&trash, |
| 6055 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 6056 | tmpctx, |
| 6057 | tmpctx->st0, |
| 6058 | tmpctx->st1, |
| 6059 | tmpctx->st2, |
| 6060 | tmpctx->applet->name); |
| 6061 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6062 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6063 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6064 | " 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] | 6065 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6066 | &sess->req, |
| 6067 | sess->req.flags, sess->req.analysers, |
| 6068 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 6069 | sess->req.to_forward, sess->req.total, |
| 6070 | sess->req.analyse_exp ? |
| 6071 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6072 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6073 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6074 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6075 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6076 | sess->req.rex ? |
| 6077 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6078 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6079 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6080 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6081 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6082 | " 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] | 6083 | sess->req.wex ? |
| 6084 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6085 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6086 | sess->req.buf, |
| 6087 | sess->req.buf->data, sess->req.buf->o, |
| 6088 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6089 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6090 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6091 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6092 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6093 | " 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] | 6094 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6095 | &sess->res, |
| 6096 | sess->res.flags, sess->res.analysers, |
| 6097 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 6098 | sess->res.to_forward, sess->res.total, |
| 6099 | sess->res.analyse_exp ? |
| 6100 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6101 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6102 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6103 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6104 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6105 | sess->res.rex ? |
| 6106 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6107 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6108 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6109 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6110 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6111 | " 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] | 6112 | sess->res.wex ? |
| 6113 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6114 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6115 | sess->res.buf, |
| 6116 | sess->res.buf->data, sess->res.buf->o, |
| 6117 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6118 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6119 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6120 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6121 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6122 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6123 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6124 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6125 | |
| 6126 | /* use other states to dump the contents */ |
| 6127 | } |
| 6128 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6129 | appctx->ctx.sess.uid = 0; |
| 6130 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6131 | return 1; |
| 6132 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6133 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6134 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 6135 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 6136 | struct appctx *appctx = __objt_appctx(si->end); |
| 6137 | |
| 6138 | switch (appctx->st2) { |
| 6139 | case STAT_ST_INIT: |
| 6140 | /* Display the column headers. If the message cannot be sent, |
| 6141 | * quit the fucntion with returning 0. The function is called |
| 6142 | * later and restart at the state "STAT_ST_INIT". |
| 6143 | */ |
| 6144 | chunk_reset(&trash); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6145 | |
| 6146 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT) |
| 6147 | chunk_appendf(&trash, "# id secret\n"); |
| 6148 | else |
| 6149 | chunk_appendf(&trash, "# id (file)\n"); |
| 6150 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6151 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6152 | si_applet_cant_put(si); |
| 6153 | return 0; |
| 6154 | } |
| 6155 | |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6156 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6157 | /* Now, we start the browsing of the references lists. |
| 6158 | * 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] | 6159 | * available field of this pointer is <list>. It is used with the function |
| 6160 | * tlskeys_list_get_next() for retruning the first available entry |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6161 | */ |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6162 | if (appctx->ctx.tlskeys.ref == NULL) { |
| 6163 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 6164 | 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] | 6165 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6166 | |
| 6167 | appctx->st2 = STAT_ST_LIST; |
| 6168 | /* fall through */ |
| 6169 | |
| 6170 | case STAT_ST_LIST: |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6171 | while (appctx->ctx.tlskeys.ref) { |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6172 | int i; |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6173 | int head = appctx->ctx.tlskeys.ref->tls_ticket_enc_index; |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6174 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6175 | chunk_reset(&trash); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6176 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT) |
| 6177 | chunk_appendf(&trash, "# "); |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6178 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 6179 | appctx->ctx.tlskeys.ref->filename); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6180 | if (appctx->st0 == STAT_CLI_O_TLSK_ENT) { |
| 6181 | for (i = 0; i < TLS_TICKETS_NO; i++) { |
| 6182 | struct chunk *t2 = get_trash_chunk(); |
| 6183 | int b64_len; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6184 | |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6185 | chunk_reset(t2); |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6186 | b64_len = a2base64((char *)(appctx->ctx.tlskeys.ref->tlskeys + (head + 2 + i) % TLS_TICKETS_NO), |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6187 | sizeof(struct tls_sess_key), t2->str, t2->size); |
| 6188 | if (b64_len < 0) |
| 6189 | return 0; |
| 6190 | t2->len = b64_len; |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6191 | chunk_appendf(&trash, "%d.%d %s\n", appctx->ctx.tlskeys.ref->unique_id, i, t2->str); |
William Lallemand | 1d0b36a | 2016-05-20 17:40:26 +0200 | [diff] [blame] | 6192 | } |
| 6193 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6194 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6195 | /* let's try again later from this stream. We add ourselves into |
| 6196 | * this stream's users so that it can remove us upon termination. |
| 6197 | */ |
| 6198 | si_applet_cant_put(si); |
| 6199 | return 0; |
| 6200 | } |
| 6201 | |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6202 | 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] | 6203 | break; |
| 6204 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6205 | /* get next list entry and check the end of the list */ |
William Lallemand | cf9e788 | 2016-06-14 17:45:18 +0200 | [diff] [blame^] | 6206 | 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] | 6207 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6208 | } |
| 6209 | |
| 6210 | appctx->st2 = STAT_ST_FIN; |
| 6211 | /* fall through */ |
| 6212 | |
| 6213 | default: |
| 6214 | appctx->st2 = STAT_ST_FIN; |
| 6215 | return 1; |
| 6216 | } |
| 6217 | return 0; |
| 6218 | } |
| 6219 | #endif |
| 6220 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6221 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6222 | { |
| 6223 | struct appctx *appctx = __objt_appctx(si->end); |
| 6224 | |
| 6225 | switch (appctx->st2) { |
| 6226 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6227 | /* Display the column headers. If the message cannot be sent, |
| 6228 | * quit the fucntion with returning 0. The function is called |
| 6229 | * later and restart at the state "STAT_ST_INIT". |
| 6230 | */ |
| 6231 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 6232 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6233 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6234 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6235 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6236 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6237 | |
| 6238 | /* Now, we start the browsing of the references lists. |
| 6239 | * 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] | 6240 | * available field of this pointer is <list>. It is used with the function |
| 6241 | * pat_list_get_next() for retruning the first available entry |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6242 | */ |
| 6243 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6244 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6245 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6246 | appctx->st2 = STAT_ST_LIST; |
| 6247 | /* fall through */ |
| 6248 | |
| 6249 | case STAT_ST_LIST: |
| 6250 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6251 | chunk_reset(&trash); |
| 6252 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6253 | /* Build messages. If the reference is used by another category than |
| 6254 | * the listed categorie, display the information in the massage. |
| 6255 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6256 | 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] | 6257 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6258 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6259 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6260 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6261 | /* let's try again later from this stream. We add ourselves into |
| 6262 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6263 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6264 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6265 | return 0; |
| 6266 | } |
| 6267 | |
| 6268 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6269 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6270 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | appctx->st2 = STAT_ST_FIN; |
| 6274 | /* fall through */ |
| 6275 | |
| 6276 | default: |
| 6277 | appctx->st2 = STAT_ST_FIN; |
| 6278 | return 1; |
| 6279 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6280 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6281 | } |
| 6282 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6283 | static int stats_map_lookup(struct stream_interface *si) |
| 6284 | { |
| 6285 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6286 | struct sample sample; |
| 6287 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6288 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6289 | |
| 6290 | switch (appctx->st2) { |
| 6291 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6292 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6293 | 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] | 6294 | 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] | 6295 | appctx->st2 = STAT_ST_LIST; |
| 6296 | /* fall through */ |
| 6297 | |
| 6298 | case STAT_ST_LIST: |
| 6299 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6300 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6301 | /* initialise chunk to build new message */ |
| 6302 | chunk_reset(&trash); |
| 6303 | |
| 6304 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6305 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6306 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6307 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6308 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6309 | if (appctx->ctx.map.expr->pat_head->match && |
| 6310 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6311 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6312 | else |
| 6313 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6314 | |
| 6315 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6316 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6317 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6318 | break; |
| 6319 | if (match_method >= PAT_MATCH_NUM) |
| 6320 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6321 | else |
| 6322 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6323 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6324 | /* case sensitive */ |
| 6325 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6326 | chunk_appendf(&trash, ", case=insensitive"); |
| 6327 | else |
| 6328 | chunk_appendf(&trash, ", case=sensitive"); |
| 6329 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6330 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6331 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6332 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6333 | chunk_appendf(&trash, ", found=no"); |
| 6334 | else |
| 6335 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | /* Display match and match info */ |
| 6339 | else { |
| 6340 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6341 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6342 | chunk_appendf(&trash, ", found=yes"); |
| 6343 | else |
| 6344 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6345 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6346 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6347 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6348 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6349 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6350 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6351 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6352 | /* display pattern */ |
| 6353 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6354 | if (pat->ref && pat->ref->pattern) |
| 6355 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6356 | else |
| 6357 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6358 | } |
| 6359 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6360 | if (pat->ref && pat->ref->pattern) |
| 6361 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6362 | else |
| 6363 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6364 | } |
| 6365 | |
| 6366 | /* display return value */ |
| 6367 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6368 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6369 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6370 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6371 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6372 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6373 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6374 | } |
| 6375 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6376 | chunk_appendf(&trash, "\n"); |
| 6377 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6378 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6379 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6380 | /* let's try again later from this stream. We add ourselves into |
| 6381 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6382 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6383 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6384 | return 0; |
| 6385 | } |
| 6386 | |
| 6387 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6388 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6389 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6390 | } |
| 6391 | |
| 6392 | appctx->st2 = STAT_ST_FIN; |
| 6393 | /* fall through */ |
| 6394 | |
| 6395 | default: |
| 6396 | appctx->st2 = STAT_ST_FIN; |
| 6397 | free(appctx->ctx.map.chunk.str); |
| 6398 | return 1; |
| 6399 | } |
| 6400 | } |
| 6401 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6402 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6403 | { |
| 6404 | struct appctx *appctx = __objt_appctx(si->end); |
| 6405 | |
| 6406 | switch (appctx->st2) { |
| 6407 | |
| 6408 | case STAT_ST_INIT: |
| 6409 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6410 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6411 | struct pat_ref_elt *, list); |
| 6412 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6413 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6414 | appctx->st2 = STAT_ST_LIST; |
| 6415 | /* fall through */ |
| 6416 | |
| 6417 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6418 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6419 | chunk_reset(&trash); |
| 6420 | |
| 6421 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6422 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6423 | chunk_appendf(&trash, "%p %s %s\n", |
| 6424 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6425 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6426 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6427 | chunk_appendf(&trash, "%p %s\n", |
| 6428 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6429 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6430 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6431 | /* let's try again later from this stream. We add ourselves into |
| 6432 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6433 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6434 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6435 | return 0; |
| 6436 | } |
| 6437 | |
| 6438 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6439 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6440 | struct pat_ref_elt *, list); |
| 6441 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6442 | break; |
| 6443 | } |
| 6444 | |
| 6445 | appctx->st2 = STAT_ST_FIN; |
| 6446 | /* fall through */ |
| 6447 | |
| 6448 | default: |
| 6449 | appctx->st2 = STAT_ST_FIN; |
| 6450 | return 1; |
| 6451 | } |
| 6452 | } |
| 6453 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6454 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6455 | * 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] | 6456 | * to be called again, otherwise non-zero. It is designed to be called |
| 6457 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6458 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6459 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6460 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6461 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6462 | struct connection *conn; |
| 6463 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6464 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6465 | /* 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] | 6466 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6467 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6468 | if (appctx->st2 == STAT_ST_LIST) { |
| 6469 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6470 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6471 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6472 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6473 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6474 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6475 | } |
| 6476 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6477 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6478 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6479 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6480 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6481 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6482 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6483 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6484 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6485 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6486 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6487 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6488 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6489 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6490 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6491 | /* fall through */ |
| 6492 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6493 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6494 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6495 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6496 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6497 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6501 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6502 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6503 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6504 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6505 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6506 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6507 | if (appctx->ctx.sess.target) { |
| 6508 | 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] | 6509 | goto next_sess; |
| 6510 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6511 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6512 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6513 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6514 | return 0; |
| 6515 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6516 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6517 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6518 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6519 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6520 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6521 | break; |
| 6522 | } |
| 6523 | else |
| 6524 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6525 | } |
| 6526 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6527 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6528 | "%p: proto=%s", |
| 6529 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6530 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6531 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6532 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6533 | 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] | 6534 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6535 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6536 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6537 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6538 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6539 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6540 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6541 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6542 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6543 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6544 | break; |
| 6545 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6546 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6547 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6548 | strm_li(curr_sess)->luid, |
| 6549 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6550 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6551 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6552 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6553 | break; |
| 6554 | } |
| 6555 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6556 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6557 | " ts=%02x age=%s calls=%d", |
| 6558 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6559 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6560 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6561 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6562 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6563 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6564 | curr_sess->req.flags, |
| 6565 | curr_sess->req.buf->i, |
| 6566 | curr_sess->req.analysers, |
| 6567 | curr_sess->req.rex ? |
| 6568 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6569 | TICKS_TO_MS(1000)) : ""); |
| 6570 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6571 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6572 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6573 | curr_sess->req.wex ? |
| 6574 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6575 | TICKS_TO_MS(1000)) : ""); |
| 6576 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6577 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6578 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6579 | curr_sess->req.analyse_exp ? |
| 6580 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6581 | TICKS_TO_MS(1000)) : ""); |
| 6582 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6583 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6584 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6585 | curr_sess->res.flags, |
| 6586 | curr_sess->res.buf->i, |
| 6587 | curr_sess->res.analysers, |
| 6588 | curr_sess->res.rex ? |
| 6589 | human_time(TICKS_TO_MS(curr_sess->res.rex - 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 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6594 | curr_sess->res.wex ? |
| 6595 | human_time(TICKS_TO_MS(curr_sess->res.wex - 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 | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6599 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6600 | curr_sess->res.analyse_exp ? |
| 6601 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6602 | TICKS_TO_MS(1000)) : ""); |
| 6603 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6604 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6605 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6606 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6607 | curr_sess->si[0].state, |
| 6608 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6609 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6610 | curr_sess->si[0].exp ? |
| 6611 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6612 | TICKS_TO_MS(1000)) : ""); |
| 6613 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6614 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6615 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6616 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6617 | curr_sess->si[1].state, |
| 6618 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6619 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6620 | curr_sess->si[1].exp ? |
| 6621 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6622 | TICKS_TO_MS(1000)) : ""); |
| 6623 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6624 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6625 | " exp=%s", |
| 6626 | curr_sess->task->expire ? |
| 6627 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6628 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6629 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6630 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6631 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6632 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6633 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6634 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6635 | /* let's try again later from this stream. We add ourselves into |
| 6636 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6637 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6638 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6639 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6640 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6641 | } |
| 6642 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6643 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6644 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6645 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6646 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6647 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6648 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6649 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6650 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6651 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6652 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6653 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6654 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6655 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6656 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6657 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6658 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6659 | appctx->ctx.sess.target = NULL; |
| 6660 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6661 | return 1; |
| 6662 | } |
| 6663 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6664 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6665 | /* fall through */ |
| 6666 | |
| 6667 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6668 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6669 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6670 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6671 | } |
| 6672 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6673 | /* This is called when the stream interface is closed. For instance, upon an |
| 6674 | * 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] | 6675 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6676 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6677 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6678 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6679 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6680 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6681 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6682 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6683 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6684 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6685 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6686 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6687 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6688 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6689 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6690 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6691 | } |
| 6692 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6693 | /* This function is used to either dump tables states (when action is set |
| 6694 | * 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] | 6695 | * It returns 0 if the output buffer is full and it needs to be called |
| 6696 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6697 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6698 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6699 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6700 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6701 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6702 | struct ebmb_node *eb; |
| 6703 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6704 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6705 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6706 | |
| 6707 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6708 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6709 | * - STAT_ST_INIT : the first call |
| 6710 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6711 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6712 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6713 | * and the entry pointer points to the next entry to be dumped, |
| 6714 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6715 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6716 | * data though. |
| 6717 | */ |
| 6718 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6719 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6720 | /* 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] | 6721 | if (appctx->st2 == STAT_ST_LIST) { |
| 6722 | appctx->ctx.table.entry->ref_cnt--; |
| 6723 | 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] | 6724 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6725 | return 1; |
| 6726 | } |
| 6727 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6728 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6729 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6730 | while (appctx->st2 != STAT_ST_FIN) { |
| 6731 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6732 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6733 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6734 | if (!appctx->ctx.table.proxy) |
| 6735 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6736 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6737 | appctx->ctx.table.entry = NULL; |
| 6738 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6739 | break; |
| 6740 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6741 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6742 | if (!appctx->ctx.table.proxy || |
| 6743 | (appctx->ctx.table.target && |
| 6744 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6745 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6746 | break; |
| 6747 | } |
| 6748 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6749 | if (appctx->ctx.table.proxy->table.size) { |
| 6750 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6751 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6752 | return 0; |
| 6753 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6754 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6755 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6756 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6757 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6758 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6759 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6760 | appctx->ctx.table.entry->ref_cnt++; |
| 6761 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6762 | break; |
| 6763 | } |
| 6764 | } |
| 6765 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6766 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6767 | break; |
| 6768 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6769 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6770 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6771 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6772 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6773 | /* we're filtering on some data contents */ |
| 6774 | void *ptr; |
| 6775 | long long data; |
| 6776 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6777 | dt = appctx->ctx.table.data_type; |
| 6778 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6779 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6780 | dt); |
| 6781 | |
| 6782 | data = 0; |
| 6783 | switch (stktable_data_types[dt].std_type) { |
| 6784 | case STD_T_SINT: |
| 6785 | data = stktable_data_cast(ptr, std_t_sint); |
| 6786 | break; |
| 6787 | case STD_T_UINT: |
| 6788 | data = stktable_data_cast(ptr, std_t_uint); |
| 6789 | break; |
| 6790 | case STD_T_ULL: |
| 6791 | data = stktable_data_cast(ptr, std_t_ull); |
| 6792 | break; |
| 6793 | case STD_T_FRQP: |
| 6794 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6795 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6796 | break; |
| 6797 | } |
| 6798 | |
| 6799 | /* 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] | 6800 | if ((data < appctx->ctx.table.value && |
| 6801 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6802 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6803 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6804 | (data == appctx->ctx.table.value && |
| 6805 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6806 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6807 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6808 | (data > appctx->ctx.table.value && |
| 6809 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6810 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6811 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6812 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6813 | } |
| 6814 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6815 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6816 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6817 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6818 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6819 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6820 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6821 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6822 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6823 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6824 | struct stksess *old = appctx->ctx.table.entry; |
| 6825 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6826 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6827 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6828 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6829 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6830 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6831 | break; |
| 6832 | } |
| 6833 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6834 | |
| 6835 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6836 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6837 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6838 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6839 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6840 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6841 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6842 | break; |
| 6843 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6844 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6845 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6846 | break; |
| 6847 | } |
| 6848 | } |
| 6849 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6850 | } |
| 6851 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6852 | /* 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] | 6853 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6854 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6855 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6856 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6857 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6858 | * after the offset. The new pointer is returned. |
| 6859 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6860 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6861 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6862 | { |
| 6863 | int end; |
| 6864 | unsigned char c; |
| 6865 | |
| 6866 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6867 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6868 | return ptr; |
| 6869 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6870 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6871 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6872 | while (ptr < len && ptr < bsize) { |
| 6873 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6874 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6875 | if (out->len > end - 2) |
| 6876 | break; |
| 6877 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6878 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6879 | if (out->len > end - 3) |
| 6880 | break; |
| 6881 | out->str[out->len++] = '\\'; |
| 6882 | switch (c) { |
| 6883 | case '\t': c = 't'; break; |
| 6884 | case '\n': c = 'n'; break; |
| 6885 | case '\r': c = 'r'; break; |
| 6886 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6887 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6888 | } |
| 6889 | out->str[out->len++] = c; |
| 6890 | } else { |
| 6891 | if (out->len > end - 5) |
| 6892 | break; |
| 6893 | out->str[out->len++] = '\\'; |
| 6894 | out->str[out->len++] = 'x'; |
| 6895 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6896 | out->str[out->len++] = hextab[c & 0xF]; |
| 6897 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6898 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6899 | /* we had a line break, let's return now */ |
| 6900 | out->str[out->len++] = '\n'; |
| 6901 | *line = ptr; |
| 6902 | return ptr; |
| 6903 | } |
| 6904 | } |
| 6905 | /* we have an incomplete line, we return it as-is */ |
| 6906 | out->str[out->len++] = '\n'; |
| 6907 | return ptr; |
| 6908 | } |
| 6909 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6910 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6911 | * It returns 0 if the output buffer is full and it needs |
| 6912 | * to be called again, otherwise non-zero. |
| 6913 | */ |
| 6914 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6915 | { |
| 6916 | struct appctx *appctx = __objt_appctx(si->end); |
| 6917 | struct dns_resolvers *presolvers; |
| 6918 | struct dns_nameserver *pnameserver; |
| 6919 | |
| 6920 | chunk_reset(&trash); |
| 6921 | |
| 6922 | switch (appctx->st2) { |
| 6923 | case STAT_ST_INIT: |
| 6924 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6925 | /* fall through */ |
| 6926 | |
| 6927 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6928 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6929 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6930 | } |
| 6931 | else { |
| 6932 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6933 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6934 | continue; |
| 6935 | |
| 6936 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6937 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6938 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6939 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6940 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6941 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6942 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6943 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6944 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6945 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6946 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6947 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6948 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6949 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6950 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6951 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6952 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6953 | } |
| 6954 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | /* display response */ |
| 6958 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6959 | /* let's try again later from this session. We add ourselves into |
| 6960 | * this session's users so that it can remove us upon termination. |
| 6961 | */ |
| 6962 | si->flags |= SI_FL_WAIT_ROOM; |
| 6963 | return 0; |
| 6964 | } |
| 6965 | |
| 6966 | appctx->st2 = STAT_ST_FIN; |
| 6967 | /* fall through */ |
| 6968 | |
| 6969 | default: |
| 6970 | appctx->st2 = STAT_ST_FIN; |
| 6971 | return 1; |
| 6972 | } |
| 6973 | } |
| 6974 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6975 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6976 | * 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] | 6977 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6978 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6979 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6980 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6981 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6982 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6983 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6984 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6985 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6986 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6987 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6988 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6989 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6990 | /* the function had not been called yet, let's prepare the |
| 6991 | * buffer for a response. |
| 6992 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6993 | struct tm tm; |
| 6994 | |
| 6995 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6996 | 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] | 6997 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6998 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6999 | error_snapshot_id); |
| 7000 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7001 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7002 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7003 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 7004 | return 0; |
| 7005 | } |
| 7006 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7007 | appctx->ctx.errors.px = proxy; |
| 7008 | appctx->ctx.errors.buf = 0; |
| 7009 | appctx->ctx.errors.bol = 0; |
| 7010 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7011 | } |
| 7012 | |
| 7013 | /* we have two inner loops here, one for the proxy, the other one for |
| 7014 | * the buffer. |
| 7015 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7016 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7017 | struct error_snapshot *es; |
| 7018 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7019 | if (appctx->ctx.errors.buf == 0) |
| 7020 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7021 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7022 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7023 | |
| 7024 | if (!es->when.tv_sec) |
| 7025 | goto next; |
| 7026 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7027 | if (appctx->ctx.errors.iid >= 0 && |
| 7028 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 7029 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7030 | goto next; |
| 7031 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7032 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7033 | /* just print headers now */ |
| 7034 | |
| 7035 | char pn[INET6_ADDRSTRLEN]; |
| 7036 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7037 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7038 | |
| 7039 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7040 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7041 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 7042 | 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] | 7043 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7044 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 7045 | case AF_INET: |
| 7046 | case AF_INET6: |
| 7047 | port = get_host_port(&es->src); |
| 7048 | break; |
| 7049 | default: |
| 7050 | port = 0; |
| 7051 | } |
| 7052 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7053 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7054 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7055 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7056 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7057 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7058 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7059 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 7060 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7061 | break; |
| 7062 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7063 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 7064 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7065 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7066 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7067 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7068 | break; |
| 7069 | } |
| 7070 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7071 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 7072 | ", server %s (#%d), event #%u\n" |
| 7073 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 7074 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 7075 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 7076 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 7077 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 7078 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 7079 | es->ev_id, |
| 7080 | pn, port, es->sid, es->s_flags, |
| 7081 | es->state, es->m_flags, es->t_flags, |
| 7082 | es->m_clen, es->m_blen, |
| 7083 | es->b_flags, es->b_out, es->b_tot, |
| 7084 | es->len, es->b_wrap, es->pos); |
| 7085 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7086 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7087 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7088 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7089 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7090 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7091 | appctx->ctx.errors.ptr = 0; |
| 7092 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7093 | } |
| 7094 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7095 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7096 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7097 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7098 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7099 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7100 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7101 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7102 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7103 | goto next; |
| 7104 | } |
| 7105 | |
| 7106 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7107 | 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] | 7108 | int newptr; |
| 7109 | int newline; |
| 7110 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7111 | newline = appctx->ctx.errors.bol; |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7112 | 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] | 7113 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7114 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7115 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7116 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7117 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7118 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7119 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7120 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7121 | appctx->ctx.errors.ptr = newptr; |
| 7122 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7123 | }; |
| 7124 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7125 | appctx->ctx.errors.bol = 0; |
| 7126 | appctx->ctx.errors.ptr = -1; |
| 7127 | appctx->ctx.errors.buf++; |
| 7128 | if (appctx->ctx.errors.buf > 1) { |
| 7129 | appctx->ctx.errors.buf = 0; |
| 7130 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7131 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 7132 | } |
| 7133 | |
| 7134 | /* dump complete */ |
| 7135 | return 1; |
| 7136 | } |
| 7137 | |
| 7138 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 7139 | * if the output buffer is full and it needs to be called again, otherwise |
| 7140 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 7141 | */ |
| 7142 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 7143 | { |
| 7144 | struct appctx *appctx = __objt_appctx(si->end); |
| 7145 | |
| 7146 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 7147 | return 1; |
| 7148 | |
| 7149 | chunk_reset(&trash); |
| 7150 | |
| 7151 | /* we have two inner loops here, one for the proxy, the other one for |
| 7152 | * the buffer. |
| 7153 | */ |
| 7154 | while (*appctx->ctx.env.var) { |
| 7155 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 7156 | |
| 7157 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 7158 | si_applet_cant_put(si); |
| 7159 | return 0; |
| 7160 | } |
| 7161 | if (appctx->st2 == STAT_ST_END) |
| 7162 | break; |
| 7163 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7164 | } |
| 7165 | |
| 7166 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7167 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7168 | } |
| 7169 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7170 | /* parse the "level" argument on the bind lines */ |
| 7171 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 7172 | { |
| 7173 | if (!*args[cur_arg + 1]) { |
| 7174 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 7175 | return ERR_ALERT | ERR_FATAL; |
| 7176 | } |
| 7177 | |
| 7178 | if (!strcmp(args[cur_arg+1], "user")) |
| 7179 | conf->level = ACCESS_LVL_USER; |
| 7180 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 7181 | conf->level = ACCESS_LVL_OPER; |
| 7182 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 7183 | conf->level = ACCESS_LVL_ADMIN; |
| 7184 | else { |
| 7185 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 7186 | args[cur_arg], args[cur_arg+1]); |
| 7187 | return ERR_ALERT | ERR_FATAL; |
| 7188 | } |
| 7189 | |
| 7190 | return 0; |
| 7191 | } |
| 7192 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7193 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7194 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7195 | .name = "<STATS>", /* used for logging */ |
| 7196 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 7197 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7198 | }; |
| 7199 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7200 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7201 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7202 | .name = "<CLI>", /* used for logging */ |
| 7203 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 7204 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7205 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 7206 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 7207 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7208 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 7209 | { 0, NULL, NULL }, |
| 7210 | }}; |
| 7211 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7212 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 7213 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 7214 | { NULL, NULL, 0 }, |
| 7215 | }}; |
| 7216 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7217 | __attribute__((constructor)) |
| 7218 | static void __dumpstats_module_init(void) |
| 7219 | { |
| 7220 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7221 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7222 | } |
| 7223 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 7224 | /* |
| 7225 | * Local variables: |
| 7226 | * c-indent-level: 8 |
| 7227 | * c-basic-offset: 8 |
| 7228 | * End: |
| 7229 | */ |