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 */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 89 | STAT_CLI_O_PATS, /* list all pattern reference avalaible */ |
| 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 */ |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 94 | STAT_CLI_O_RESOLVERS,/* dump a resolver's section nameservers counters */ |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 95 | STAT_CLI_O_SERVERS_STATE, /* dump server state and changing information */ |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 96 | STAT_CLI_O_BACKEND, /* dump backend list */ |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 97 | STAT_CLI_O_ENV, /* dump environment */ |
Willy Tarreau | 91b843d | 2014-01-28 16:27:17 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 100 | /* Actions available for the stats admin forms */ |
| 101 | enum { |
| 102 | ST_ADM_ACTION_NONE = 0, |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 103 | |
| 104 | /* enable/disable health checks */ |
| 105 | ST_ADM_ACTION_DHLTH, |
| 106 | ST_ADM_ACTION_EHLTH, |
| 107 | |
| 108 | /* force health check status */ |
| 109 | ST_ADM_ACTION_HRUNN, |
| 110 | ST_ADM_ACTION_HNOLB, |
| 111 | ST_ADM_ACTION_HDOWN, |
| 112 | |
| 113 | /* enable/disable agent checks */ |
| 114 | ST_ADM_ACTION_DAGENT, |
| 115 | ST_ADM_ACTION_EAGENT, |
| 116 | |
| 117 | /* force agent check status */ |
| 118 | ST_ADM_ACTION_ARUNN, |
| 119 | ST_ADM_ACTION_ADOWN, |
| 120 | |
| 121 | /* set admin state */ |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 122 | ST_ADM_ACTION_READY, |
| 123 | ST_ADM_ACTION_DRAIN, |
| 124 | ST_ADM_ACTION_MAINT, |
| 125 | ST_ADM_ACTION_SHUTDOWN, |
| 126 | /* these are the ancient actions, still available for compatibility */ |
| 127 | ST_ADM_ACTION_DISABLE, |
| 128 | ST_ADM_ACTION_ENABLE, |
| 129 | ST_ADM_ACTION_STOP, |
| 130 | ST_ADM_ACTION_START, |
| 131 | }; |
| 132 | |
Willy Tarreau | c4832de | 2016-01-11 18:12:26 +0100 | [diff] [blame] | 133 | |
Willy Tarreau | c4832de | 2016-01-11 18:12:26 +0100 | [diff] [blame] | 134 | /* These are the field names for each INF_* field position. Please pay attention |
| 135 | * to always use the exact same name except that the strings for new names must |
| 136 | * be lower case or CamelCase while the enum entries must be upper case. |
| 137 | */ |
| 138 | const char *info_field_names[INF_TOTAL_FIELDS] = { |
| 139 | [INF_NAME] = "Name", |
| 140 | [INF_VERSION] = "Version", |
| 141 | [INF_RELEASE_DATE] = "Release_date", |
| 142 | [INF_NBPROC] = "Nbproc", |
| 143 | [INF_PROCESS_NUM] = "Process_num", |
| 144 | [INF_PID] = "Pid", |
| 145 | [INF_UPTIME] = "Uptime", |
| 146 | [INF_UPTIME_SEC] = "Uptime_sec", |
| 147 | [INF_MEMMAX_MB] = "Memmax_MB", |
| 148 | [INF_POOL_ALLOC_MB] = "PoolAlloc_MB", |
| 149 | [INF_POOL_USED_MB] = "PoolUsed_MB", |
| 150 | [INF_POOL_FAILED] = "PoolFailed", |
| 151 | [INF_ULIMIT_N] = "Ulimit-n", |
| 152 | [INF_MAXSOCK] = "Maxsock", |
| 153 | [INF_MAXCONN] = "Maxconn", |
| 154 | [INF_HARD_MAXCONN] = "Hard_maxconn", |
| 155 | [INF_CURR_CONN] = "CurrConns", |
| 156 | [INF_CUM_CONN] = "CumConns", |
| 157 | [INF_CUM_REQ] = "CumReq", |
| 158 | [INF_MAX_SSL_CONNS] = "MaxSslConns", |
| 159 | [INF_CURR_SSL_CONNS] = "CurrSslConns", |
| 160 | [INF_CUM_SSL_CONNS] = "CumSslConns", |
| 161 | [INF_MAXPIPES] = "Maxpipes", |
| 162 | [INF_PIPES_USED] = "PipesUsed", |
| 163 | [INF_PIPES_FREE] = "PipesFree", |
| 164 | [INF_CONN_RATE] = "ConnRate", |
| 165 | [INF_CONN_RATE_LIMIT] = "ConnRateLimit", |
| 166 | [INF_MAX_CONN_RATE] = "MaxConnRate", |
| 167 | [INF_SESS_RATE] = "SessRate", |
| 168 | [INF_SESS_RATE_LIMIT] = "SessRateLimit", |
| 169 | [INF_MAX_SESS_RATE] = "MaxSessRate", |
| 170 | [INF_SSL_RATE] = "SslRate", |
| 171 | [INF_SSL_RATE_LIMIT] = "SslRateLimit", |
| 172 | [INF_MAX_SSL_RATE] = "MaxSslRate", |
| 173 | [INF_SSL_FRONTEND_KEY_RATE] = "SslFrontendKeyRate", |
| 174 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = "SslFrontendMaxKeyRate", |
| 175 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = "SslFrontendSessionReuse_pct", |
| 176 | [INF_SSL_BACKEND_KEY_RATE] = "SslBackendKeyRate", |
| 177 | [INF_SSL_BACKEND_MAX_KEY_RATE] = "SslBackendMaxKeyRate", |
| 178 | [INF_SSL_CACHE_LOOKUPS] = "SslCacheLookups", |
| 179 | [INF_SSL_CACHE_MISSES] = "SslCacheMisses", |
| 180 | [INF_COMPRESS_BPS_IN] = "CompressBpsIn", |
| 181 | [INF_COMPRESS_BPS_OUT] = "CompressBpsOut", |
| 182 | [INF_COMPRESS_BPS_RATE_LIM] = "CompressBpsRateLim", |
| 183 | [INF_ZLIB_MEM_USAGE] = "ZlibMemUsage", |
| 184 | [INF_MAX_ZLIB_MEM_USAGE] = "MaxZlibMemUsage", |
| 185 | [INF_TASKS] = "Tasks", |
| 186 | [INF_RUN_QUEUE] = "Run_queue", |
| 187 | [INF_IDLE_PCT] = "Idle_pct", |
| 188 | [INF_NODE] = "node", |
| 189 | [INF_DESCRIPTION] = "description", |
| 190 | }; |
| 191 | |
| 192 | /* one line of stats */ |
| 193 | static struct field info[INF_TOTAL_FIELDS]; |
| 194 | |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 195 | /* These are the field names for each ST_F_* field position. Please pay attention |
| 196 | * to always use the exact same name except that the strings must be lower case |
| 197 | * while the enum entries must be upper case. |
| 198 | */ |
| 199 | const char *stat_field_names[ST_F_TOTAL_FIELDS] = { |
| 200 | [ST_F_PXNAME] = "pxname", |
| 201 | [ST_F_SVNAME] = "svname", |
| 202 | [ST_F_QCUR] = "qcur", |
| 203 | [ST_F_QMAX] = "qmax", |
| 204 | [ST_F_SCUR] = "scur", |
| 205 | [ST_F_SMAX] = "smax", |
| 206 | [ST_F_SLIM] = "slim", |
| 207 | [ST_F_STOT] = "stot", |
| 208 | [ST_F_BIN] = "bin", |
| 209 | [ST_F_BOUT] = "bout", |
| 210 | [ST_F_DREQ] = "dreq", |
| 211 | [ST_F_DRESP] = "dresp", |
| 212 | [ST_F_EREQ] = "ereq", |
| 213 | [ST_F_ECON] = "econ", |
| 214 | [ST_F_ERESP] = "eresp", |
| 215 | [ST_F_WRETR] = "wretr", |
| 216 | [ST_F_WREDIS] = "wredis", |
| 217 | [ST_F_STATUS] = "status", |
| 218 | [ST_F_WEIGHT] = "weight", |
| 219 | [ST_F_ACT] = "act", |
| 220 | [ST_F_BCK] = "bck", |
| 221 | [ST_F_CHKFAIL] = "chkfail", |
| 222 | [ST_F_CHKDOWN] = "chkdown", |
| 223 | [ST_F_LASTCHG] = "lastchg", |
| 224 | [ST_F_DOWNTIME] = "downtime", |
| 225 | [ST_F_QLIMIT] = "qlimit", |
| 226 | [ST_F_PID] = "pid", |
| 227 | [ST_F_IID] = "iid", |
| 228 | [ST_F_SID] = "sid", |
| 229 | [ST_F_THROTTLE] = "throttle", |
| 230 | [ST_F_LBTOT] = "lbtot", |
| 231 | [ST_F_TRACKED] = "tracked", |
| 232 | [ST_F_TYPE] = "type", |
| 233 | [ST_F_RATE] = "rate", |
| 234 | [ST_F_RATE_LIM] = "rate_lim", |
| 235 | [ST_F_RATE_MAX] = "rate_max", |
| 236 | [ST_F_CHECK_STATUS] = "check_status", |
| 237 | [ST_F_CHECK_CODE] = "check_code", |
| 238 | [ST_F_CHECK_DURATION] = "check_duration", |
| 239 | [ST_F_HRSP_1XX] = "hrsp_1xx", |
| 240 | [ST_F_HRSP_2XX] = "hrsp_2xx", |
| 241 | [ST_F_HRSP_3XX] = "hrsp_3xx", |
| 242 | [ST_F_HRSP_4XX] = "hrsp_4xx", |
| 243 | [ST_F_HRSP_5XX] = "hrsp_5xx", |
| 244 | [ST_F_HRSP_OTHER] = "hrsp_other", |
| 245 | [ST_F_HANAFAIL] = "hanafail", |
| 246 | [ST_F_REQ_RATE] = "req_rate", |
| 247 | [ST_F_REQ_RATE_MAX] = "req_rate_max", |
| 248 | [ST_F_REQ_TOT] = "req_tot", |
| 249 | [ST_F_CLI_ABRT] = "cli_abrt", |
| 250 | [ST_F_SRV_ABRT] = "srv_abrt", |
| 251 | [ST_F_COMP_IN] = "comp_in", |
| 252 | [ST_F_COMP_OUT] = "comp_out", |
| 253 | [ST_F_COMP_BYP] = "comp_byp", |
| 254 | [ST_F_COMP_RSP] = "comp_rsp", |
| 255 | [ST_F_LASTSESS] = "lastsess", |
| 256 | [ST_F_LAST_CHK] = "last_chk", |
| 257 | [ST_F_LAST_AGT] = "last_agt", |
| 258 | [ST_F_QTIME] = "qtime", |
| 259 | [ST_F_CTIME] = "ctime", |
| 260 | [ST_F_RTIME] = "rtime", |
| 261 | [ST_F_TTIME] = "ttime", |
Willy Tarreau | 7f61884 | 2016-01-08 11:40:03 +0100 | [diff] [blame] | 262 | [ST_F_AGENT_STATUS] = "agent_status", |
| 263 | [ST_F_AGENT_CODE] = "agent_code", |
| 264 | [ST_F_AGENT_DURATION] = "agent_duration", |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 265 | [ST_F_CHECK_DESC] = "check_desc", |
| 266 | [ST_F_AGENT_DESC] = "agent_desc", |
Willy Tarreau | 3141f59 | 2016-01-08 14:25:28 +0100 | [diff] [blame] | 267 | [ST_F_CHECK_RISE] = "check_rise", |
| 268 | [ST_F_CHECK_FALL] = "check_fall", |
| 269 | [ST_F_CHECK_HEALTH] = "check_health", |
| 270 | [ST_F_AGENT_RISE] = "agent_rise", |
| 271 | [ST_F_AGENT_FALL] = "agent_fall", |
| 272 | [ST_F_AGENT_HEALTH] = "agent_health", |
Willy Tarreau | 3a4ec3a | 2016-01-08 15:35:43 +0100 | [diff] [blame] | 273 | [ST_F_ADDR] = "addr", |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 274 | [ST_F_COOKIE] = "cookie", |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 275 | [ST_F_MODE] = "mode", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 276 | [ST_F_ALGO] = "algo", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 277 | [ST_F_CONN_RATE] = "conn_rate", |
| 278 | [ST_F_CONN_RATE_MAX] = "conn_rate_max", |
| 279 | [ST_F_CONN_TOT] = "conn_tot", |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 280 | [ST_F_INTERCEPTED] = "intercepted", |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 281 | }; |
| 282 | |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 283 | /* one line of stats */ |
| 284 | static struct field stats[ST_F_TOTAL_FIELDS]; |
| 285 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 286 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 287 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 288 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 289 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 290 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 291 | 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] | 292 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 293 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 294 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 295 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 296 | 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] | 297 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 298 | static int stats_pats_list(struct stream_interface *si); |
| 299 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 300 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 301 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 302 | static int stats_tlskeys_list(struct stream_interface *si); |
| 303 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 304 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 305 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 306 | static void dump_servers_state(struct proxy *backend, struct chunk *buf); |
| 307 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 308 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 309 | * cli_io_handler() |
| 310 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 311 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 312 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 313 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 314 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 315 | * -> stats_dump_stat_to_buffer() // "show stat" |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 316 | * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 317 | * -> stats_dump_csv_header() |
| 318 | * -> stats_dump_proxy_to_buffer() |
| 319 | * -> stats_dump_fe_stats() |
| 320 | * -> stats_dump_li_stats() |
| 321 | * -> stats_dump_sv_stats() |
| 322 | * -> stats_dump_be_stats() |
| 323 | * |
| 324 | * http_stats_io_handler() |
| 325 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 326 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 327 | * -> stats_dump_html_head() // emits the HTML headers |
| 328 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 329 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 330 | * -> stats_dump_html_px_hdr() |
| 331 | * -> stats_dump_fe_stats() |
| 332 | * -> stats_dump_li_stats() |
| 333 | * -> stats_dump_sv_stats() |
| 334 | * -> stats_dump_be_stats() |
| 335 | * -> stats_dump_html_px_end() |
| 336 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 337 | */ |
| 338 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 339 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 340 | |
| 341 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 342 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 343 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 344 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 345 | " help : this message\n" |
| 346 | " prompt : toggle interactive mode with prompt\n" |
| 347 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 348 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 349 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 350 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 351 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 352 | " show stat : report counters for each proxy and server\n" |
| 353 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 354 | " 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] | 355 | " 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] | 356 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 357 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 358 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 359 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 360 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 361 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 362 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 363 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 364 | " disable : put a server or frontend in maintenance mode\n" |
| 365 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 366 | " shutdown : kill a session or a frontend (eg:to release listening ports)\n" |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 367 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 368 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 369 | " add acl : add acl entry\n" |
| 370 | " del acl : delete acl entry\n" |
| 371 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 372 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 373 | " get map : reports the keys and values matching a sample for a map\n" |
| 374 | " set map : modify map entry\n" |
| 375 | " add map : add map entry\n" |
| 376 | " del map : delete map entry\n" |
| 377 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 378 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 379 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 380 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 381 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 382 | "Permission denied\n" |
| 383 | ""; |
| 384 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 385 | /* data transmission states for the stats responses */ |
| 386 | enum { |
| 387 | STAT_ST_INIT = 0, |
| 388 | STAT_ST_HEAD, |
| 389 | STAT_ST_INFO, |
| 390 | STAT_ST_LIST, |
| 391 | STAT_ST_END, |
| 392 | STAT_ST_FIN, |
| 393 | }; |
| 394 | |
| 395 | /* data transmission states for the stats responses inside a proxy */ |
| 396 | enum { |
| 397 | STAT_PX_ST_INIT = 0, |
| 398 | STAT_PX_ST_TH, |
| 399 | STAT_PX_ST_FE, |
| 400 | STAT_PX_ST_LI, |
| 401 | STAT_PX_ST_SV, |
| 402 | STAT_PX_ST_BE, |
| 403 | STAT_PX_ST_END, |
| 404 | STAT_PX_ST_FIN, |
| 405 | }; |
| 406 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 407 | extern const char *stat_status_codes[]; |
| 408 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 409 | /* allocate a new stats frontend named <name>, and return it |
| 410 | * (or NULL in case of lack of memory). |
| 411 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 412 | static struct proxy *alloc_stats_fe(const char *name, const char *file, int line) |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 413 | { |
| 414 | struct proxy *fe; |
| 415 | |
Vincent Bernat | 02779b6 | 2016-04-03 13:48:43 +0200 | [diff] [blame] | 416 | fe = calloc(1, sizeof(*fe)); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 417 | if (!fe) |
| 418 | return NULL; |
| 419 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 420 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 421 | fe->next = proxy; |
| 422 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 423 | fe->last_change = now.tv_sec; |
| 424 | fe->id = strdup("GLOBAL"); |
| 425 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 426 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 427 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 428 | fe->conf.file = strdup(file); |
| 429 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 430 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 431 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 432 | |
| 433 | /* the stats frontend is the only one able to assign ID #0 */ |
| 434 | fe->conf.id.key = fe->uuid = 0; |
| 435 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 436 | return fe; |
| 437 | } |
| 438 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 439 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 440 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 441 | * error message into the <err> buffer which will be preallocated. The trailing |
| 442 | * '\n' must not be written. The function must be called with <args> pointing to |
| 443 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 444 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 445 | static int stats_parse_global(char **args, int section_type, struct proxy *curpx, |
Willy Tarreau | 28a47d6 | 2012-09-18 20:02:48 +0200 | [diff] [blame] | 446 | struct proxy *defpx, const char *file, int line, |
| 447 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 448 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 449 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 450 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 451 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 452 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 453 | int cur_arg; |
| 454 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 455 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 456 | memprintf(err, "'%s %s' in global section expects an address or a path to a UNIX socket", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 457 | return -1; |
| 458 | } |
| 459 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 460 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 461 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 462 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 463 | return -1; |
| 464 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 467 | bind_conf = bind_conf_alloc(&global.stats_fe->conf.bind, file, line, args[2]); |
Willy Tarreau | 290e63a | 2012-09-20 18:07:14 +0200 | [diff] [blame] | 468 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 469 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 470 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 471 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 472 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 473 | return -1; |
| 474 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 475 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 476 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 477 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 478 | static int bind_dumped; |
| 479 | struct bind_kw *kw; |
| 480 | |
| 481 | kw = bind_find_kw(args[cur_arg]); |
| 482 | if (kw) { |
| 483 | if (!kw->parse) { |
| 484 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 485 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 486 | return -1; |
| 487 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 488 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 489 | if (kw->parse(args, cur_arg, global.stats_fe, bind_conf, err) != 0) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 490 | if (err && *err) |
| 491 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 492 | else |
| 493 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 494 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 495 | return -1; |
| 496 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 497 | |
| 498 | cur_arg += 1 + kw->skip; |
| 499 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 500 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 501 | |
| 502 | if (!bind_dumped) { |
| 503 | bind_dump_kws(err); |
| 504 | indent_msg(err, 4); |
| 505 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 506 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 507 | |
| 508 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 509 | args[0], args[1], args[cur_arg], |
| 510 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 511 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 512 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 513 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 514 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 515 | l->maxconn = global.stats_fe->maxconn; |
| 516 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 517 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 518 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 519 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 520 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 521 | l->nice = -64; /* we want to boost priority for local stats */ |
| 522 | global.maxsock += l->maxconn; |
| 523 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 524 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 525 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 526 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 527 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 528 | |
| 529 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 530 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 531 | return -1; |
| 532 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 533 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 534 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 535 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 536 | return -1; |
| 537 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 538 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 539 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 540 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 541 | return -1; |
| 542 | } |
| 543 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 544 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 545 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 546 | else if (!strcmp(args[1], "maxconn")) { |
| 547 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 548 | |
| 549 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 550 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 551 | return -1; |
| 552 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 553 | |
| 554 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 555 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 556 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 557 | return -1; |
| 558 | } |
| 559 | } |
| 560 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 561 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 562 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 563 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 564 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 565 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 566 | if (!global.stats_fe) { |
| 567 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 568 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 569 | return -1; |
| 570 | } |
| 571 | } |
| 572 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 573 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 574 | unsigned int low, high; |
| 575 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 576 | if (strcmp(args[cur_arg], "all") == 0) { |
| 577 | set = 0; |
| 578 | break; |
| 579 | } |
| 580 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 581 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 582 | } |
| 583 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 584 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 585 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 586 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 587 | char *dash = strchr(args[cur_arg], '-'); |
| 588 | |
| 589 | low = high = str2uic(args[cur_arg]); |
| 590 | if (dash) |
| 591 | high = str2uic(dash + 1); |
| 592 | |
| 593 | if (high < low) { |
| 594 | unsigned int swap = low; |
| 595 | low = high; |
| 596 | high = swap; |
| 597 | } |
| 598 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 599 | if (low < 1 || high > LONGBITS) { |
| 600 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 601 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 602 | return -1; |
| 603 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 604 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 605 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 606 | } |
| 607 | else { |
| 608 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 609 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 610 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 611 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 612 | } |
| 613 | cur_arg++; |
| 614 | } |
| 615 | global.stats_fe->bind_proc = set; |
| 616 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 617 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 618 | memprintf(err, "'%s' only supports 'socket', 'maxconn', 'bind-process' and 'timeout' (got '%s')", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 619 | return -1; |
| 620 | } |
| 621 | return 0; |
| 622 | } |
| 623 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 624 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 625 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 626 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 627 | * so please only append new fields at the end, never in the middle. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 628 | */ |
| 629 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 630 | { |
Willy Tarreau | f614229 | 2016-01-04 17:24:29 +0100 | [diff] [blame] | 631 | int field; |
| 632 | |
| 633 | chunk_appendf(&trash, "# "); |
| 634 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) |
| 635 | chunk_appendf(&trash, "%s,", stat_field_names[field]); |
| 636 | |
| 637 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 638 | } |
| 639 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 640 | /* print a string of text buffer to <out>. The format is : |
| 641 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 642 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 643 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 644 | */ |
| 645 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 646 | { |
| 647 | unsigned char c; |
| 648 | int ptr = 0; |
| 649 | |
| 650 | while (buf[ptr] && ptr < bsize) { |
| 651 | c = buf[ptr]; |
| 652 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 653 | if (out->len > out->size - 1) |
| 654 | break; |
| 655 | out->str[out->len++] = c; |
| 656 | } |
| 657 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 658 | if (out->len > out->size - 2) |
| 659 | break; |
| 660 | out->str[out->len++] = '\\'; |
| 661 | switch (c) { |
| 662 | case ' ': c = ' '; break; |
| 663 | case '\t': c = 't'; break; |
| 664 | case '\n': c = 'n'; break; |
| 665 | case '\r': c = 'r'; break; |
| 666 | case '\e': c = 'e'; break; |
| 667 | case '\\': c = '\\'; break; |
| 668 | } |
| 669 | out->str[out->len++] = c; |
| 670 | } |
| 671 | else { |
| 672 | if (out->len > out->size - 4) |
| 673 | break; |
| 674 | out->str[out->len++] = '\\'; |
| 675 | out->str[out->len++] = 'x'; |
| 676 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 677 | out->str[out->len++] = hextab[c & 0xF]; |
| 678 | } |
| 679 | ptr++; |
| 680 | } |
| 681 | |
| 682 | return ptr; |
| 683 | } |
| 684 | |
| 685 | /* print a buffer in hexa. |
| 686 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 687 | */ |
| 688 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 689 | { |
| 690 | unsigned char c; |
| 691 | int ptr = 0; |
| 692 | |
| 693 | while (ptr < bsize) { |
| 694 | c = buf[ptr]; |
| 695 | |
| 696 | if (out->len > out->size - 2) |
| 697 | break; |
| 698 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 699 | out->str[out->len++] = hextab[c & 0xF]; |
| 700 | |
| 701 | ptr++; |
| 702 | } |
| 703 | return ptr; |
| 704 | } |
| 705 | |
| 706 | /* Dump the status of a table to a stream interface's |
| 707 | * read buffer. It returns 0 if the output buffer is full |
| 708 | * and needs to be called again, otherwise non-zero. |
| 709 | */ |
| 710 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 711 | struct proxy *proxy, struct proxy *target) |
| 712 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 713 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 714 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 715 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 716 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 717 | |
| 718 | /* any other information should be dumped here */ |
| 719 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 720 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 721 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 722 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 723 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 724 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 725 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 726 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 727 | |
| 728 | return 1; |
| 729 | } |
| 730 | |
| 731 | /* Dump the a table entry to a stream interface's |
| 732 | * read buffer. It returns 0 if the output buffer is full |
| 733 | * and needs to be called again, otherwise non-zero. |
| 734 | */ |
| 735 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 736 | struct proxy *proxy, struct stksess *entry) |
| 737 | { |
| 738 | int dt; |
| 739 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 740 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 741 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 742 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 743 | char addr[INET_ADDRSTRLEN]; |
| 744 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 745 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 746 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 747 | else if (proxy->table.type == SMP_T_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 748 | char addr[INET6_ADDRSTRLEN]; |
| 749 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 750 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 751 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 752 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 753 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 754 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 755 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 756 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 757 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 758 | } |
| 759 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 760 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 761 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 762 | } |
| 763 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 764 | 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] | 765 | |
| 766 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 767 | void *ptr; |
| 768 | |
| 769 | if (proxy->table.data_ofs[dt] == 0) |
| 770 | continue; |
| 771 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 772 | 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] | 773 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 774 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 775 | |
| 776 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 777 | switch (stktable_data_types[dt].std_type) { |
| 778 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 779 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 780 | break; |
| 781 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 782 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 783 | break; |
| 784 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 785 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 786 | break; |
| 787 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 788 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 789 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 790 | proxy->table.data_arg[dt].u)); |
| 791 | break; |
| 792 | } |
| 793 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 794 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 795 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 796 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 797 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 798 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 799 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 800 | |
| 801 | return 1; |
| 802 | } |
| 803 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 804 | 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] | 805 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 806 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 807 | struct appctx *appctx = __objt_appctx(si->end); |
| 808 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 809 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 810 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 811 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 812 | long long value; |
| 813 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 814 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 815 | void *ptr; |
| 816 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 817 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 818 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 819 | |
| 820 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 821 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 822 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 823 | return; |
| 824 | } |
| 825 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 826 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 827 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 828 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 829 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 830 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 831 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 832 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 833 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 834 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 835 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 836 | { |
| 837 | char *endptr; |
| 838 | unsigned long val; |
| 839 | errno = 0; |
| 840 | val = strtoul(args[4], &endptr, 10); |
| 841 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 842 | (errno != 0 && val == 0) || endptr == args[4] || |
| 843 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 844 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 845 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 846 | return; |
| 847 | } |
| 848 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 849 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 850 | break; |
| 851 | } |
| 852 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 853 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 854 | static_table_key->key = args[4]; |
| 855 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 856 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 857 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 858 | switch (action) { |
| 859 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 860 | 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] | 861 | break; |
| 862 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 863 | 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] | 864 | break; |
| 865 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 866 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 867 | break; |
| 868 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 869 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 870 | return; |
| 871 | } |
| 872 | |
| 873 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 874 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 875 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 876 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 877 | return; |
| 878 | } |
| 879 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 880 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 881 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 882 | switch (action) { |
| 883 | case STAT_CLI_O_TAB: |
| 884 | if (!ts) |
| 885 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 886 | chunk_reset(&trash); |
| 887 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 888 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 889 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 890 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 891 | |
| 892 | case STAT_CLI_O_CLR: |
| 893 | if (!ts) |
| 894 | return; |
| 895 | if (ts->ref_cnt) { |
| 896 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 897 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 898 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 899 | return; |
| 900 | } |
| 901 | stksess_kill(&px->table, ts); |
| 902 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 903 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 904 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 905 | if (ts) |
| 906 | stktable_touch(&px->table, ts, 1); |
| 907 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 908 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 909 | if (!ts) { |
| 910 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 911 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 912 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 913 | return; |
| 914 | } |
| 915 | stktable_store(&px->table, ts, 1); |
| 916 | } |
| 917 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 918 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 919 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 920 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 921 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 922 | return; |
| 923 | } |
| 924 | |
| 925 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 926 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 927 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 928 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 929 | return; |
| 930 | } |
| 931 | |
| 932 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 933 | appctx->ctx.cli.msg = "Data type not stored in this table\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 (!*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] | 939 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 940 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 941 | return; |
| 942 | } |
| 943 | |
| 944 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 945 | |
| 946 | switch (stktable_data_types[data_type].std_type) { |
| 947 | case STD_T_SINT: |
| 948 | stktable_data_cast(ptr, std_t_sint) = value; |
| 949 | break; |
| 950 | case STD_T_UINT: |
| 951 | stktable_data_cast(ptr, std_t_uint) = value; |
| 952 | break; |
| 953 | case STD_T_ULL: |
| 954 | stktable_data_cast(ptr, std_t_ull) = value; |
| 955 | break; |
| 956 | case STD_T_FRQP: |
| 957 | /* We set both the current and previous values. That way |
| 958 | * the reported frequency is stable during all the period |
| 959 | * then slowly fades out. This allows external tools to |
| 960 | * push measures without having to update them too often. |
| 961 | */ |
| 962 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 963 | frqp->curr_tick = now_ms; |
| 964 | frqp->prev_ctr = 0; |
| 965 | frqp->curr_ctr = value; |
| 966 | break; |
| 967 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 968 | } |
| 969 | break; |
| 970 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 971 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 972 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 973 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 974 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 975 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 976 | } |
| 977 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 978 | 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] | 979 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 980 | struct appctx *appctx = __objt_appctx(si->end); |
| 981 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 982 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 983 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 984 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 985 | return; |
| 986 | } |
| 987 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 988 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 989 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 990 | if (appctx->ctx.table.data_type < 0) { |
| 991 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 992 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 993 | return; |
| 994 | } |
| 995 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 996 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 997 | appctx->ctx.cli.msg = "Data type not stored in this table\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 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 1003 | if (appctx->ctx.table.data_op < 0) { |
| 1004 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 1005 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1006 | return; |
| 1007 | } |
| 1008 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1009 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 1010 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 1011 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1012 | return; |
| 1013 | } |
| 1014 | } |
| 1015 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1016 | 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] | 1017 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1018 | struct appctx *appctx = __objt_appctx(si->end); |
| 1019 | |
| 1020 | appctx->ctx.table.data_type = -1; |
| 1021 | appctx->st2 = STAT_ST_INIT; |
| 1022 | appctx->ctx.table.target = NULL; |
| 1023 | appctx->ctx.table.proxy = NULL; |
| 1024 | appctx->ctx.table.entry = NULL; |
| 1025 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1026 | |
| 1027 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 1028 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1029 | if (!appctx->ctx.table.target) { |
| 1030 | appctx->ctx.cli.msg = "No such table\n"; |
| 1031 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1032 | return; |
| 1033 | } |
| 1034 | } |
| 1035 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1036 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1037 | goto err_args; |
| 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1042 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1043 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1044 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1045 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1046 | goto err_args; |
| 1047 | |
| 1048 | return; |
| 1049 | |
| 1050 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1051 | switch (action) { |
| 1052 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1053 | 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] | 1054 | break; |
| 1055 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1056 | 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] | 1057 | break; |
| 1058 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1059 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1060 | break; |
| 1061 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1062 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1063 | } |
| 1064 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1065 | /* 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] | 1066 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1067 | * level to be admin. |
| 1068 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1069 | 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] | 1070 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1071 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1072 | struct proxy *px; |
| 1073 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1074 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1075 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1076 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1077 | return NULL; |
| 1078 | } |
| 1079 | |
| 1080 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1081 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 1082 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1083 | return NULL; |
| 1084 | } |
| 1085 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 1086 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1087 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1088 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 1089 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1090 | return NULL; |
| 1091 | } |
| 1092 | return px; |
| 1093 | } |
| 1094 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1095 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 1096 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1097 | * 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] | 1098 | * the <arg> is modified to remove the '/'. |
| 1099 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1100 | 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] | 1101 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1102 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1103 | struct proxy *px; |
| 1104 | struct server *sv; |
| 1105 | char *line; |
| 1106 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1107 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1108 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1109 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1110 | return NULL; |
| 1111 | } |
| 1112 | |
| 1113 | /* split "backend/server" and make <line> point to server */ |
| 1114 | for (line = arg; *line; line++) |
| 1115 | if (*line == '/') { |
| 1116 | *line++ = '\0'; |
| 1117 | break; |
| 1118 | } |
| 1119 | |
| 1120 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1121 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1122 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1123 | return NULL; |
| 1124 | } |
| 1125 | |
| 1126 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1127 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\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 (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1133 | appctx->ctx.cli.msg = "Proxy is disabled.\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 | return sv; |
| 1139 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1140 | |
| 1141 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1142 | * each reference. The variable <getnext> must contain the current node, |
| 1143 | * <end> point to the root node. |
| 1144 | */ |
| 1145 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1146 | static inline |
| 1147 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1148 | { |
| 1149 | struct tls_keys_ref *ref = getnext; |
| 1150 | |
| 1151 | while (1) { |
| 1152 | |
| 1153 | /* Get next list entry. */ |
| 1154 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1155 | |
| 1156 | /* If the entry is the last of the list, return NULL. */ |
| 1157 | if (&ref->list == end) |
| 1158 | return NULL; |
| 1159 | |
| 1160 | return ref; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | static inline |
| 1165 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1166 | { |
| 1167 | int id; |
| 1168 | char *error; |
| 1169 | |
| 1170 | /* If the reference starts by a '#', this is numeric id. */ |
| 1171 | if (reference[0] == '#') { |
| 1172 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1173 | id = strtol(reference + 1, &error, 10); |
| 1174 | if (*error != '\0') |
| 1175 | return NULL; |
| 1176 | |
| 1177 | /* Perform the unique id lookup. */ |
| 1178 | return tlskeys_ref_lookupid(id); |
| 1179 | } |
| 1180 | |
| 1181 | /* Perform the string lookup. */ |
| 1182 | return tlskeys_ref_lookup(reference); |
| 1183 | } |
| 1184 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1185 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1186 | /* This function is used with map and acl management. It permits to browse |
| 1187 | * each reference. The variable <getnext> must contain the current node, |
| 1188 | * <end> point to the root node and the <flags> permit to filter required |
| 1189 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1190 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1191 | static inline |
| 1192 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1193 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1194 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1195 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1196 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1197 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1198 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1199 | /* Get next list entry. */ |
| 1200 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1201 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1202 | /* If the entry is the last of the list, return NULL. */ |
| 1203 | if (&ref->list == end) |
| 1204 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1205 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1206 | /* If the entry match the flag, return it. */ |
| 1207 | if (ref->flags & flags) |
| 1208 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1209 | } |
| 1210 | } |
| 1211 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1212 | static inline |
| 1213 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1214 | { |
| 1215 | int id; |
| 1216 | char *error; |
| 1217 | |
| 1218 | /* If the reference starts by a '#', this is numeric id. */ |
| 1219 | if (reference[0] == '#') { |
| 1220 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1221 | id = strtol(reference + 1, &error, 10); |
| 1222 | if (*error != '\0') |
| 1223 | return NULL; |
| 1224 | |
| 1225 | /* Perform the unique id lookup. */ |
| 1226 | return pat_ref_lookupid(id); |
| 1227 | } |
| 1228 | |
| 1229 | /* Perform the string lookup. */ |
| 1230 | return pat_ref_lookup(reference); |
| 1231 | } |
| 1232 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1233 | /* This function is used with map and acl management. It permits to browse |
| 1234 | * each reference. |
| 1235 | */ |
| 1236 | static inline |
| 1237 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1238 | { |
| 1239 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1240 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1241 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1242 | return NULL; |
| 1243 | return expr; |
| 1244 | } |
| 1245 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1246 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1247 | * 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] | 1248 | * 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] | 1249 | * designating the function which will have to process the request, which can |
| 1250 | * 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] | 1251 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1252 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1253 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1254 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1255 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1256 | char *args[MAX_STATS_ARGS + 1]; |
| 1257 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1258 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1259 | |
| 1260 | while (isspace((unsigned char)*line)) |
| 1261 | line++; |
| 1262 | |
| 1263 | arg = 0; |
| 1264 | args[arg] = line; |
| 1265 | |
| 1266 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1267 | if (*line == '\\') { |
| 1268 | line++; |
| 1269 | if (*line == '\0') |
| 1270 | break; |
| 1271 | } |
| 1272 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1273 | *line++ = '\0'; |
| 1274 | |
| 1275 | while (isspace((unsigned char)*line)) |
| 1276 | line++; |
| 1277 | |
| 1278 | args[++arg] = line; |
| 1279 | continue; |
| 1280 | } |
| 1281 | |
| 1282 | line++; |
| 1283 | } |
| 1284 | |
| 1285 | while (++arg <= MAX_STATS_ARGS) |
| 1286 | args[arg] = line; |
| 1287 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1288 | /* remove \ */ |
| 1289 | arg = 0; |
| 1290 | while (*args[arg] != '\0') { |
| 1291 | j = 0; |
| 1292 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1293 | if (args[arg][i] == '\\') |
| 1294 | continue; |
| 1295 | args[arg][j] = args[arg][i]; |
| 1296 | j++; |
| 1297 | } |
| 1298 | args[arg][j] = '\0'; |
| 1299 | arg++; |
| 1300 | } |
| 1301 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1302 | appctx->ctx.stats.scope_str = 0; |
| 1303 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1304 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1305 | if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1306 | if (strcmp(args[1], "backend") == 0) { |
| 1307 | appctx->st2 = STAT_ST_INIT; |
| 1308 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1309 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1310 | else if (strcmp(args[1], "env") == 0) { |
| 1311 | extern char **environ; |
| 1312 | |
| 1313 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1314 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1315 | appctx->st0 = STAT_CLI_PRINT; |
| 1316 | return 1; |
| 1317 | } |
| 1318 | appctx->ctx.env.var = environ; |
| 1319 | appctx->st2 = STAT_ST_INIT; |
| 1320 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1321 | |
| 1322 | if (*args[2]) { |
| 1323 | int len = strlen(args[2]); |
| 1324 | |
| 1325 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1326 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1327 | (*appctx->ctx.env.var)[len] == '=') |
| 1328 | break; |
| 1329 | } |
| 1330 | if (!*appctx->ctx.env.var) { |
| 1331 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1332 | appctx->st0 = STAT_CLI_PRINT; |
| 1333 | return 1; |
| 1334 | } |
| 1335 | appctx->st2 = STAT_ST_END; |
| 1336 | } |
| 1337 | } |
| 1338 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1339 | if (strcmp(args[2], "resolvers") == 0) { |
| 1340 | struct dns_resolvers *presolvers; |
| 1341 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1342 | if (*args[3]) { |
| 1343 | appctx->ctx.resolvers.ptr = NULL; |
| 1344 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1345 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1346 | appctx->ctx.resolvers.ptr = presolvers; |
| 1347 | break; |
| 1348 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1349 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1350 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1351 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1352 | appctx->st0 = STAT_CLI_PRINT; |
| 1353 | return 1; |
| 1354 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | appctx->st2 = STAT_ST_INIT; |
| 1358 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1359 | return 1; |
| 1360 | } |
| 1361 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1362 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1363 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1364 | appctx->ctx.stats.type = atoi(args[3]); |
| 1365 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1366 | if (strcmp(args[5], "typed") == 0) |
| 1367 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1368 | } |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 1369 | else if (strcmp(args[2], "typed") == 0) |
| 1370 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1371 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1372 | appctx->st2 = STAT_ST_INIT; |
| 1373 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1374 | } |
| 1375 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 1376 | if (strcmp(args[2], "typed") == 0) |
| 1377 | appctx->ctx.stats.flags |= STAT_FMT_TYPED; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1378 | appctx->st2 = STAT_ST_INIT; |
| 1379 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1380 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1381 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
| 1382 | appctx->ctx.server_state.backend = NULL; |
| 1383 | |
| 1384 | /* check if a backend name has been provided */ |
| 1385 | if (*args[3]) { |
| 1386 | /* read server state from local file */ |
| 1387 | appctx->ctx.server_state.backend = proxy_be_by_name(args[3]); |
| 1388 | |
| 1389 | if (appctx->ctx.server_state.backend == NULL) { |
| 1390 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1391 | appctx->st0 = STAT_CLI_PRINT; |
| 1392 | return 1; |
| 1393 | } |
| 1394 | } |
| 1395 | appctx->st2 = STAT_ST_INIT; |
| 1396 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1397 | return 1; |
| 1398 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1399 | else if (strcmp(args[1], "pools") == 0) { |
| 1400 | appctx->st2 = STAT_ST_INIT; |
| 1401 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1402 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1403 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1404 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1405 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1406 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1407 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1408 | return 1; |
| 1409 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1410 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1411 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1412 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1413 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1414 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1415 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1416 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1417 | appctx->ctx.sess.pos = 0; |
| 1418 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1419 | } |
| 1420 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1421 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1422 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1423 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1424 | return 1; |
| 1425 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1426 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1427 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1428 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1429 | appctx->ctx.errors.iid = -1; |
| 1430 | appctx->ctx.errors.px = NULL; |
| 1431 | appctx->st2 = STAT_ST_INIT; |
| 1432 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1433 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1434 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1435 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1436 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1437 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1438 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1439 | appctx->st2 = STAT_ST_INIT; |
| 1440 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1441 | #else |
| 1442 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1443 | "that doesn't support specifying TLS ticket keys\n"; |
| 1444 | appctx->st0 = STAT_CLI_PRINT; |
| 1445 | #endif |
| 1446 | return 1; |
| 1447 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1448 | else if (strcmp(args[1], "map") == 0 || |
| 1449 | strcmp(args[1], "acl") == 0) { |
| 1450 | |
| 1451 | /* Set ACL or MAP flags. */ |
| 1452 | if (args[1][0] == 'm') |
| 1453 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1454 | else |
| 1455 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1456 | |
| 1457 | /* no parameter: display all map avalaible */ |
| 1458 | if (!*args[2]) { |
| 1459 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1460 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1461 | return 1; |
| 1462 | } |
| 1463 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1464 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1465 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1466 | if (!appctx->ctx.map.ref || |
| 1467 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1468 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1469 | 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] | 1470 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1471 | 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] | 1472 | appctx->st0 = STAT_CLI_PRINT; |
| 1473 | return 1; |
| 1474 | } |
| 1475 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1476 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1477 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1478 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1479 | return 0; |
| 1480 | } |
| 1481 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1482 | else if (strcmp(args[0], "clear") == 0) { |
| 1483 | if (strcmp(args[1], "counters") == 0) { |
| 1484 | struct proxy *px; |
| 1485 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1486 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1487 | int clrall = 0; |
| 1488 | |
| 1489 | if (strcmp(args[2], "all") == 0) |
| 1490 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1491 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1492 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1493 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1494 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1495 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1496 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1497 | return 1; |
| 1498 | } |
| 1499 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1500 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1501 | if (clrall) { |
| 1502 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1503 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1504 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1505 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1506 | px->be_counters.conn_max = 0; |
| 1507 | px->be_counters.p.http.rps_max = 0; |
| 1508 | px->be_counters.sps_max = 0; |
| 1509 | px->be_counters.cps_max = 0; |
| 1510 | px->be_counters.nbpend_max = 0; |
| 1511 | |
| 1512 | px->fe_counters.conn_max = 0; |
| 1513 | px->fe_counters.p.http.rps_max = 0; |
| 1514 | px->fe_counters.sps_max = 0; |
| 1515 | px->fe_counters.cps_max = 0; |
| 1516 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1517 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1518 | |
| 1519 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1520 | if (clrall) |
| 1521 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1522 | else { |
| 1523 | sv->counters.cur_sess_max = 0; |
| 1524 | sv->counters.nbpend_max = 0; |
| 1525 | sv->counters.sps_max = 0; |
| 1526 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1527 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1528 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1529 | if (li->counters) { |
| 1530 | if (clrall) |
| 1531 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1532 | else |
| 1533 | li->counters->conn_max = 0; |
| 1534 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1535 | } |
| 1536 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1537 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1538 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1539 | return 1; |
| 1540 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1541 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1542 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1543 | /* end of processing */ |
| 1544 | return 1; |
| 1545 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1546 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1547 | /* Set ACL or MAP flags. */ |
| 1548 | if (args[1][0] == 'm') |
| 1549 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1550 | else |
| 1551 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1552 | |
| 1553 | /* no parameter */ |
| 1554 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1555 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1556 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1557 | else |
| 1558 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1559 | appctx->st0 = STAT_CLI_PRINT; |
| 1560 | return 1; |
| 1561 | } |
| 1562 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1563 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1564 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1565 | if (!appctx->ctx.map.ref || |
| 1566 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1567 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1568 | 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] | 1569 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1570 | 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] | 1571 | appctx->st0 = STAT_CLI_PRINT; |
| 1572 | return 1; |
| 1573 | } |
| 1574 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1575 | /* Clear all. */ |
| 1576 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1577 | |
| 1578 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1579 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1580 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1581 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1582 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1583 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1584 | return 0; |
| 1585 | } |
| 1586 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1587 | else if (strcmp(args[0], "get") == 0) { |
| 1588 | if (strcmp(args[1], "weight") == 0) { |
| 1589 | struct proxy *px; |
| 1590 | struct server *sv; |
| 1591 | |
| 1592 | /* split "backend/server" and make <line> point to server */ |
| 1593 | for (line = args[2]; *line; line++) |
| 1594 | if (*line == '/') { |
| 1595 | *line++ = '\0'; |
| 1596 | break; |
| 1597 | } |
| 1598 | |
| 1599 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1600 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1601 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1602 | return 1; |
| 1603 | } |
| 1604 | |
| 1605 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1606 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1607 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1608 | return 1; |
| 1609 | } |
| 1610 | |
| 1611 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1612 | 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] | 1613 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1614 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1615 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1616 | return 1; |
| 1617 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1618 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1619 | /* Set flags. */ |
| 1620 | if (args[1][0] == 'm') |
| 1621 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1622 | else |
| 1623 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1624 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1625 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1626 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1627 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1628 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1629 | else |
| 1630 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1631 | appctx->st0 = STAT_CLI_PRINT; |
| 1632 | return 1; |
| 1633 | } |
| 1634 | |
| 1635 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1636 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1637 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1638 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1639 | 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] | 1640 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1641 | 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] | 1642 | appctx->st0 = STAT_CLI_PRINT; |
| 1643 | return 1; |
| 1644 | } |
| 1645 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1646 | /* copy input string. The string must be allocated because |
| 1647 | * it may be used over multiple iterations. It's released |
| 1648 | * at the end and upon abort anyway. |
| 1649 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1650 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1651 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1652 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1653 | if (!appctx->ctx.map.chunk.str) { |
| 1654 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1655 | appctx->st0 = STAT_CLI_PRINT; |
| 1656 | return 1; |
| 1657 | } |
| 1658 | |
| 1659 | /* prepare response */ |
| 1660 | appctx->st2 = STAT_ST_INIT; |
| 1661 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1662 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1663 | else { /* not "get weight" */ |
| 1664 | return 0; |
| 1665 | } |
| 1666 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1667 | else if (strcmp(args[0], "set") == 0) { |
| 1668 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1669 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1670 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1671 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1672 | sv = expect_server_admin(s, si, args[2]); |
| 1673 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1674 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1675 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1676 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1677 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1678 | appctx->ctx.cli.msg = warning; |
| 1679 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1680 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1681 | return 1; |
| 1682 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1683 | else if (strcmp(args[1], "server") == 0) { |
| 1684 | struct server *sv; |
| 1685 | const char *warning; |
| 1686 | |
| 1687 | sv = expect_server_admin(s, si, args[2]); |
| 1688 | if (!sv) |
| 1689 | return 1; |
| 1690 | |
| 1691 | if (strcmp(args[3], "weight") == 0) { |
| 1692 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1693 | if (warning) { |
| 1694 | appctx->ctx.cli.msg = warning; |
| 1695 | appctx->st0 = STAT_CLI_PRINT; |
| 1696 | } |
| 1697 | } |
| 1698 | else if (strcmp(args[3], "state") == 0) { |
| 1699 | if (strcmp(args[4], "ready") == 0) |
| 1700 | srv_adm_set_ready(sv); |
| 1701 | else if (strcmp(args[4], "drain") == 0) |
| 1702 | srv_adm_set_drain(sv); |
| 1703 | else if (strcmp(args[4], "maint") == 0) |
| 1704 | srv_adm_set_maint(sv); |
| 1705 | else { |
| 1706 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1707 | appctx->st0 = STAT_CLI_PRINT; |
| 1708 | } |
| 1709 | } |
| 1710 | else if (strcmp(args[3], "health") == 0) { |
| 1711 | if (sv->track) { |
| 1712 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1713 | appctx->st0 = STAT_CLI_PRINT; |
| 1714 | } |
| 1715 | else if (strcmp(args[4], "up") == 0) { |
| 1716 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1717 | srv_set_running(sv, "changed from CLI"); |
| 1718 | } |
| 1719 | else if (strcmp(args[4], "stopping") == 0) { |
| 1720 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1721 | srv_set_stopping(sv, "changed from CLI"); |
| 1722 | } |
| 1723 | else if (strcmp(args[4], "down") == 0) { |
| 1724 | sv->check.health = 0; |
| 1725 | srv_set_stopped(sv, "changed from CLI"); |
| 1726 | } |
| 1727 | else { |
| 1728 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1729 | appctx->st0 = STAT_CLI_PRINT; |
| 1730 | } |
| 1731 | } |
| 1732 | else if (strcmp(args[3], "agent") == 0) { |
| 1733 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1734 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1735 | appctx->st0 = STAT_CLI_PRINT; |
| 1736 | } |
| 1737 | else if (strcmp(args[4], "up") == 0) { |
| 1738 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1739 | srv_set_running(sv, "changed from CLI"); |
| 1740 | } |
| 1741 | else if (strcmp(args[4], "down") == 0) { |
| 1742 | sv->agent.health = 0; |
| 1743 | srv_set_stopped(sv, "changed from CLI"); |
| 1744 | } |
| 1745 | else { |
| 1746 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1747 | appctx->st0 = STAT_CLI_PRINT; |
| 1748 | } |
| 1749 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1750 | else if (strcmp(args[3], "addr") == 0) { |
Thierry Fournier | 09a9178 | 2016-02-24 08:25:39 +0100 | [diff] [blame] | 1751 | warning = server_parse_addr_change_request(sv, args[4], "stats command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1752 | if (warning) { |
| 1753 | appctx->ctx.cli.msg = warning; |
| 1754 | appctx->st0 = STAT_CLI_PRINT; |
| 1755 | } |
| 1756 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1757 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1758 | 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] | 1759 | appctx->st0 = STAT_CLI_PRINT; |
| 1760 | } |
| 1761 | return 1; |
| 1762 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1763 | else if (strcmp(args[1], "timeout") == 0) { |
| 1764 | if (strcmp(args[2], "cli") == 0) { |
| 1765 | unsigned timeout; |
| 1766 | const char *res; |
| 1767 | |
| 1768 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1769 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1770 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1771 | return 1; |
| 1772 | } |
| 1773 | |
| 1774 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1775 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1776 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1777 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1778 | return 1; |
| 1779 | } |
| 1780 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1781 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1782 | return 1; |
| 1783 | } |
| 1784 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1785 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1786 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1787 | return 1; |
| 1788 | } |
| 1789 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1790 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1791 | if (strcmp(args[2], "frontend") == 0) { |
| 1792 | struct proxy *px; |
| 1793 | struct listener *l; |
| 1794 | int v; |
| 1795 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1796 | px = expect_frontend_admin(s, si, args[3]); |
| 1797 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1798 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1799 | |
| 1800 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1801 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1802 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1803 | return 1; |
| 1804 | } |
| 1805 | |
| 1806 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1807 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1808 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1809 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1810 | return 1; |
| 1811 | } |
| 1812 | |
| 1813 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1814 | * its listeners. The blocked ones will be dequeued. |
| 1815 | */ |
| 1816 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1817 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1818 | l->maxconn = v; |
| 1819 | if (l->state == LI_FULL) |
| 1820 | resume_listener(l); |
| 1821 | } |
| 1822 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1823 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1824 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1825 | |
| 1826 | return 1; |
| 1827 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1828 | else if (strcmp(args[2], "server") == 0) { |
| 1829 | struct server *sv; |
Nenad Merdanovic | 5c3ed34 | 2016-04-24 23:10:07 +0200 | [diff] [blame] | 1830 | const char *warning; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1831 | |
| 1832 | sv = expect_server_admin(s, si, args[3]); |
| 1833 | if (!sv) |
| 1834 | return 1; |
| 1835 | |
Nenad Merdanovic | 5c3ed34 | 2016-04-24 23:10:07 +0200 | [diff] [blame] | 1836 | warning = server_parse_maxconn_change_request(sv, args[4]); |
| 1837 | if (warning) { |
| 1838 | appctx->ctx.cli.msg = warning; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1839 | appctx->st0 = STAT_CLI_PRINT; |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1842 | return 1; |
| 1843 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1844 | else if (strcmp(args[2], "global") == 0) { |
| 1845 | int v; |
| 1846 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1847 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1848 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1849 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1850 | return 1; |
| 1851 | } |
| 1852 | |
| 1853 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1854 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1855 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1856 | return 1; |
| 1857 | } |
| 1858 | |
| 1859 | v = atoi(args[3]); |
| 1860 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1861 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1862 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1863 | return 1; |
| 1864 | } |
| 1865 | |
| 1866 | /* check for unlimited values */ |
| 1867 | if (v <= 0) |
| 1868 | v = global.hardmaxconn; |
| 1869 | |
| 1870 | global.maxconn = v; |
| 1871 | |
| 1872 | /* Dequeues all of the listeners waiting for a resource */ |
| 1873 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1874 | dequeue_all_listeners(&global_listener_queue); |
| 1875 | |
| 1876 | return 1; |
| 1877 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1878 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1879 | 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] | 1880 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1881 | return 1; |
| 1882 | } |
| 1883 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1884 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1885 | if (strcmp(args[2], "connections") == 0) { |
| 1886 | if (strcmp(args[3], "global") == 0) { |
| 1887 | int v; |
| 1888 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1889 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1890 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1891 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1892 | return 1; |
| 1893 | } |
| 1894 | |
| 1895 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1896 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1897 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1898 | return 1; |
| 1899 | } |
| 1900 | |
| 1901 | v = atoi(args[4]); |
| 1902 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1903 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1904 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1905 | return 1; |
| 1906 | } |
| 1907 | |
| 1908 | global.cps_lim = v; |
| 1909 | |
| 1910 | /* Dequeues all of the listeners waiting for a resource */ |
| 1911 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1912 | dequeue_all_listeners(&global_listener_queue); |
| 1913 | |
| 1914 | return 1; |
| 1915 | } |
| 1916 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1917 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1918 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1919 | return 1; |
| 1920 | } |
| 1921 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1922 | else if (strcmp(args[2], "sessions") == 0) { |
| 1923 | if (strcmp(args[3], "global") == 0) { |
| 1924 | int v; |
| 1925 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1926 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1927 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1928 | appctx->st0 = STAT_CLI_PRINT; |
| 1929 | return 1; |
| 1930 | } |
| 1931 | |
| 1932 | if (!*args[4]) { |
| 1933 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1934 | appctx->st0 = STAT_CLI_PRINT; |
| 1935 | return 1; |
| 1936 | } |
| 1937 | |
| 1938 | v = atoi(args[4]); |
| 1939 | if (v < 0) { |
| 1940 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1941 | appctx->st0 = STAT_CLI_PRINT; |
| 1942 | return 1; |
| 1943 | } |
| 1944 | |
| 1945 | global.sps_lim = v; |
| 1946 | |
| 1947 | /* Dequeues all of the listeners waiting for a resource */ |
| 1948 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1949 | dequeue_all_listeners(&global_listener_queue); |
| 1950 | |
| 1951 | return 1; |
| 1952 | } |
| 1953 | else { |
| 1954 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1955 | appctx->st0 = STAT_CLI_PRINT; |
| 1956 | return 1; |
| 1957 | } |
| 1958 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1959 | #ifdef USE_OPENSSL |
| 1960 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1961 | if (strcmp(args[3], "global") == 0) { |
| 1962 | int v; |
| 1963 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1964 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1965 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1966 | appctx->st0 = STAT_CLI_PRINT; |
| 1967 | return 1; |
| 1968 | } |
| 1969 | |
| 1970 | if (!*args[4]) { |
| 1971 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1972 | appctx->st0 = STAT_CLI_PRINT; |
| 1973 | return 1; |
| 1974 | } |
| 1975 | |
| 1976 | v = atoi(args[4]); |
| 1977 | if (v < 0) { |
| 1978 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1979 | appctx->st0 = STAT_CLI_PRINT; |
| 1980 | return 1; |
| 1981 | } |
| 1982 | |
| 1983 | global.ssl_lim = v; |
| 1984 | |
| 1985 | /* Dequeues all of the listeners waiting for a resource */ |
| 1986 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1987 | dequeue_all_listeners(&global_listener_queue); |
| 1988 | |
| 1989 | return 1; |
| 1990 | } |
| 1991 | else { |
| 1992 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1993 | appctx->st0 = STAT_CLI_PRINT; |
| 1994 | return 1; |
| 1995 | } |
| 1996 | } |
| 1997 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1998 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1999 | if (strcmp(args[3], "global") == 0) { |
| 2000 | int v; |
| 2001 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 2002 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 2003 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2004 | appctx->st0 = STAT_CLI_PRINT; |
| 2005 | return 1; |
| 2006 | } |
| 2007 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2008 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2009 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 2010 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2011 | return 1; |
| 2012 | } |
| 2013 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2014 | v = atoi(args[4]); |
| 2015 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 2016 | } |
| 2017 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2018 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 2019 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2020 | return 1; |
| 2021 | } |
| 2022 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2023 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2024 | 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] | 2025 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2026 | return 1; |
| 2027 | } |
| 2028 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 2029 | else if (strcmp(args[1], "table") == 0) { |
| 2030 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 2031 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2032 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2033 | char *err; |
| 2034 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2035 | /* Set flags. */ |
| 2036 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2037 | |
| 2038 | /* Expect three parameters: map name, key and new value. */ |
| 2039 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 2040 | 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] | 2041 | appctx->st0 = STAT_CLI_PRINT; |
| 2042 | return 1; |
| 2043 | } |
| 2044 | |
| 2045 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2046 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2047 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2048 | 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] | 2049 | appctx->st0 = STAT_CLI_PRINT; |
| 2050 | return 1; |
| 2051 | } |
| 2052 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2053 | /* If the entry identifier start with a '#', it is considered as |
| 2054 | * pointer id |
| 2055 | */ |
| 2056 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2057 | struct pat_ref_elt *ref; |
| 2058 | long long int conv; |
| 2059 | char *error; |
| 2060 | |
| 2061 | /* Convert argument to integer value. */ |
| 2062 | conv = strtoll(&args[3][1], &error, 16); |
| 2063 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2064 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2065 | appctx->st0 = STAT_CLI_PRINT; |
| 2066 | return 1; |
| 2067 | } |
| 2068 | |
| 2069 | /* Convert and check integer to pointer. */ |
| 2070 | ref = (struct pat_ref_elt *)(long)conv; |
| 2071 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2072 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2073 | appctx->st0 = STAT_CLI_PRINT; |
| 2074 | return 1; |
| 2075 | } |
| 2076 | |
| 2077 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2078 | err = NULL; |
| 2079 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 2080 | if (err) |
| 2081 | memprintf(&err, "%s.\n", err); |
| 2082 | appctx->ctx.cli.err = err; |
| 2083 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2084 | return 1; |
| 2085 | } |
| 2086 | } |
| 2087 | else { |
| 2088 | /* Else, use the entry identifier as pattern |
| 2089 | * string, and update the value. |
| 2090 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2091 | err = NULL; |
| 2092 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 2093 | if (err) |
| 2094 | memprintf(&err, "%s.\n", err); |
| 2095 | appctx->ctx.cli.err = err; |
| 2096 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2097 | return 1; |
| 2098 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2099 | } |
| 2100 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2101 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2102 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2103 | return 1; |
| 2104 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2105 | #ifdef USE_OPENSSL |
| 2106 | else if (strcmp(args[1], "ssl") == 0) { |
| 2107 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 2108 | #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] | 2109 | char *err = NULL; |
| 2110 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 2111 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2112 | if (!*args[3]) { |
| 2113 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 2114 | appctx->st0 = STAT_CLI_PRINT; |
| 2115 | return 1; |
| 2116 | } |
| 2117 | |
| 2118 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 2119 | if (trash.len < 0) { |
| 2120 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 2121 | appctx->st0 = STAT_CLI_PRINT; |
| 2122 | return 1; |
| 2123 | } |
| 2124 | |
| 2125 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 2126 | if (err) { |
| 2127 | memprintf(&err, "%s.\n", err); |
| 2128 | appctx->ctx.cli.err = err; |
| 2129 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 2130 | } |
| 2131 | return 1; |
| 2132 | } |
| 2133 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2134 | appctx->st0 = STAT_CLI_PRINT; |
| 2135 | return 1; |
| 2136 | #else |
| 2137 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2138 | appctx->st0 = STAT_CLI_PRINT; |
| 2139 | return 1; |
| 2140 | #endif |
| 2141 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2142 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2143 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2144 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2145 | if (!*args[3] || !*args[4]) { |
| 2146 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2147 | appctx->st0 = STAT_CLI_PRINT; |
| 2148 | return 1; |
| 2149 | } |
| 2150 | |
| 2151 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2152 | if(!appctx->ctx.tlskeys.ref) { |
| 2153 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2154 | appctx->st0 = STAT_CLI_PRINT; |
| 2155 | return 1; |
| 2156 | } |
| 2157 | |
| 2158 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2159 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2160 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2161 | appctx->st0 = STAT_CLI_PRINT; |
| 2162 | return 1; |
| 2163 | } |
| 2164 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2165 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2166 | 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] | 2167 | |
| 2168 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2169 | appctx->st0 = STAT_CLI_PRINT; |
| 2170 | return 1; |
| 2171 | #else |
| 2172 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2173 | "that doesn't support specifying TLS ticket keys\n"; |
| 2174 | appctx->st0 = STAT_CLI_PRINT; |
| 2175 | return 1; |
| 2176 | #endif |
| 2177 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2178 | else { |
| 2179 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2180 | appctx->st0 = STAT_CLI_PRINT; |
| 2181 | return 1; |
| 2182 | } |
| 2183 | } |
| 2184 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2185 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2186 | return 0; |
| 2187 | } |
| 2188 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2189 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2190 | if (strcmp(args[1], "agent") == 0) { |
| 2191 | struct server *sv; |
| 2192 | |
| 2193 | sv = expect_server_admin(s, si, args[2]); |
| 2194 | if (!sv) |
| 2195 | return 1; |
| 2196 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2197 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2198 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2199 | appctx->st0 = STAT_CLI_PRINT; |
| 2200 | return 1; |
| 2201 | } |
| 2202 | |
| 2203 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2204 | return 1; |
| 2205 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2206 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2207 | struct server *sv; |
| 2208 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2209 | sv = expect_server_admin(s, si, args[2]); |
| 2210 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2211 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2212 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2213 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2214 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2215 | appctx->st0 = STAT_CLI_PRINT; |
| 2216 | return 1; |
| 2217 | } |
| 2218 | |
| 2219 | sv->check.state |= CHK_ST_ENABLED; |
| 2220 | return 1; |
| 2221 | } |
| 2222 | else if (strcmp(args[1], "server") == 0) { |
| 2223 | struct server *sv; |
| 2224 | |
| 2225 | sv = expect_server_admin(s, si, args[2]); |
| 2226 | if (!sv) |
| 2227 | return 1; |
| 2228 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2229 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2230 | return 1; |
| 2231 | } |
| 2232 | else if (strcmp(args[1], "frontend") == 0) { |
| 2233 | struct proxy *px; |
| 2234 | |
| 2235 | px = expect_frontend_admin(s, si, args[2]); |
| 2236 | if (!px) |
| 2237 | return 1; |
| 2238 | |
| 2239 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2240 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2241 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2242 | return 1; |
| 2243 | } |
| 2244 | |
| 2245 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2246 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2247 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2248 | return 1; |
| 2249 | } |
| 2250 | |
| 2251 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2252 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2253 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2254 | return 1; |
| 2255 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2256 | return 1; |
| 2257 | } |
| 2258 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2259 | 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] | 2260 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2261 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2262 | } |
| 2263 | } |
| 2264 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2265 | if (strcmp(args[1], "agent") == 0) { |
| 2266 | struct server *sv; |
| 2267 | |
| 2268 | sv = expect_server_admin(s, si, args[2]); |
| 2269 | if (!sv) |
| 2270 | return 1; |
| 2271 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2272 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2273 | return 1; |
| 2274 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2275 | else if (strcmp(args[1], "health") == 0) { |
| 2276 | struct server *sv; |
| 2277 | |
| 2278 | sv = expect_server_admin(s, si, args[2]); |
| 2279 | if (!sv) |
| 2280 | return 1; |
| 2281 | |
| 2282 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2283 | return 1; |
| 2284 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2285 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2286 | struct server *sv; |
| 2287 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2288 | sv = expect_server_admin(s, si, args[2]); |
| 2289 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2290 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2291 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2292 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2293 | return 1; |
| 2294 | } |
| 2295 | else if (strcmp(args[1], "frontend") == 0) { |
| 2296 | struct proxy *px; |
| 2297 | |
| 2298 | px = expect_frontend_admin(s, si, args[2]); |
| 2299 | if (!px) |
| 2300 | return 1; |
| 2301 | |
| 2302 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2303 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2304 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2305 | return 1; |
| 2306 | } |
| 2307 | |
| 2308 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2309 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2310 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2311 | return 1; |
| 2312 | } |
| 2313 | |
| 2314 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2315 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2316 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2317 | return 1; |
| 2318 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2319 | return 1; |
| 2320 | } |
| 2321 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2322 | 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] | 2323 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2324 | return 1; |
| 2325 | } |
| 2326 | } |
| 2327 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2328 | if (strcmp(args[1], "frontend") == 0) { |
| 2329 | struct proxy *px; |
| 2330 | |
| 2331 | px = expect_frontend_admin(s, si, args[2]); |
| 2332 | if (!px) |
| 2333 | return 1; |
| 2334 | |
| 2335 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2336 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2337 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2338 | return 1; |
| 2339 | } |
| 2340 | |
| 2341 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2342 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2343 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2344 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2345 | stop_proxy(px); |
| 2346 | return 1; |
| 2347 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2348 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2349 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2350 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2351 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2352 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2353 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2354 | return 1; |
| 2355 | } |
| 2356 | |
| 2357 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2358 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2359 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2360 | return 1; |
| 2361 | } |
| 2362 | |
| 2363 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2364 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2365 | /* first, look for the requested stream in the stream table */ |
| 2366 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2367 | if (sess == ptr) |
| 2368 | break; |
| 2369 | } |
| 2370 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2371 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2372 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2373 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2374 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2375 | return 1; |
| 2376 | } |
| 2377 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2378 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2379 | return 1; |
| 2380 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2381 | else if (strcmp(args[1], "sessions") == 0) { |
| 2382 | if (strcmp(args[2], "server") == 0) { |
| 2383 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2384 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2385 | |
| 2386 | sv = expect_server_admin(s, si, args[3]); |
| 2387 | if (!sv) |
| 2388 | return 1; |
| 2389 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2390 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2391 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2392 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2393 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2394 | |
| 2395 | return 1; |
| 2396 | } |
| 2397 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2398 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2399 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2400 | return 1; |
| 2401 | } |
| 2402 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2403 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2404 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2405 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2406 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2407 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2408 | } |
| 2409 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2410 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2411 | if (args[1][0] == 'm') |
| 2412 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2413 | else |
| 2414 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2415 | |
| 2416 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2417 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2418 | if (!*args[2] || !*args[3]) { |
| 2419 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2420 | appctx->st0 = STAT_CLI_PRINT; |
| 2421 | return 1; |
| 2422 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2423 | } |
| 2424 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2425 | else { |
| 2426 | if (!*args[2] || !*args[3]) { |
| 2427 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2428 | appctx->st0 = STAT_CLI_PRINT; |
| 2429 | return 1; |
| 2430 | } |
| 2431 | } |
| 2432 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2433 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2434 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2435 | if (!appctx->ctx.map.ref || |
| 2436 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2437 | 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] | 2438 | appctx->st0 = STAT_CLI_PRINT; |
| 2439 | return 1; |
| 2440 | } |
| 2441 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2442 | /* If the entry identifier start with a '#', it is considered as |
| 2443 | * pointer id |
| 2444 | */ |
| 2445 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2446 | struct pat_ref_elt *ref; |
| 2447 | long long int conv; |
| 2448 | char *error; |
| 2449 | |
| 2450 | /* Convert argument to integer value. */ |
| 2451 | conv = strtoll(&args[3][1], &error, 16); |
| 2452 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2453 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2454 | appctx->st0 = STAT_CLI_PRINT; |
| 2455 | return 1; |
| 2456 | } |
| 2457 | |
| 2458 | /* Convert and check integer to pointer. */ |
| 2459 | ref = (struct pat_ref_elt *)(long)conv; |
| 2460 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2461 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2462 | appctx->st0 = STAT_CLI_PRINT; |
| 2463 | return 1; |
| 2464 | } |
| 2465 | |
| 2466 | /* Try to delete the entry. */ |
| 2467 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2468 | /* The entry is not found, send message. */ |
| 2469 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2470 | appctx->st0 = STAT_CLI_PRINT; |
| 2471 | return 1; |
| 2472 | } |
| 2473 | } |
| 2474 | else { |
| 2475 | /* Else, use the entry identifier as pattern |
| 2476 | * string and try to delete the entry. |
| 2477 | */ |
| 2478 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2479 | /* The entry is not found, send message. */ |
| 2480 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2481 | appctx->st0 = STAT_CLI_PRINT; |
| 2482 | return 1; |
| 2483 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2484 | } |
| 2485 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2486 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2487 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2488 | return 1; |
| 2489 | } |
| 2490 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2491 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2492 | appctx->st0 = STAT_CLI_PRINT; |
| 2493 | return 1; |
| 2494 | } |
| 2495 | } |
| 2496 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2497 | if (strcmp(args[1], "map") == 0 || |
| 2498 | strcmp(args[1], "acl") == 0) { |
| 2499 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2500 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2501 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2502 | /* Set flags. */ |
| 2503 | if (args[1][0] == 'm') |
| 2504 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2505 | else |
| 2506 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2507 | |
| 2508 | /* If the keywork is "map", we expect three parameters, if it |
| 2509 | * is "acl", we expect only two parameters |
| 2510 | */ |
| 2511 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2512 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2513 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2514 | appctx->st0 = STAT_CLI_PRINT; |
| 2515 | return 1; |
| 2516 | } |
| 2517 | } |
| 2518 | else { |
| 2519 | if (!*args[2] || !*args[3]) { |
| 2520 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2521 | appctx->st0 = STAT_CLI_PRINT; |
| 2522 | return 1; |
| 2523 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2524 | } |
| 2525 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2526 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2527 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2528 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2529 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2530 | 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] | 2531 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2532 | 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] | 2533 | appctx->st0 = STAT_CLI_PRINT; |
| 2534 | return 1; |
| 2535 | } |
| 2536 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2537 | /* The command "add acl" is prohibited if the reference |
| 2538 | * use samples. |
| 2539 | */ |
| 2540 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2541 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2542 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2543 | "You must use the command 'add map' to add values.\n"; |
| 2544 | appctx->st0 = STAT_CLI_PRINT; |
| 2545 | return 1; |
| 2546 | } |
| 2547 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2548 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2549 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2550 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2551 | 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] | 2552 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2553 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2554 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2555 | if (err) |
| 2556 | memprintf(&err, "%s.\n", err); |
| 2557 | appctx->ctx.cli.err = err; |
| 2558 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2559 | return 1; |
| 2560 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2561 | |
| 2562 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2563 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2564 | return 1; |
| 2565 | } |
| 2566 | else { /* unknown "del" parameter */ |
| 2567 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2568 | appctx->st0 = STAT_CLI_PRINT; |
| 2569 | return 1; |
| 2570 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2571 | } |
| 2572 | 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] | 2573 | return 0; |
| 2574 | } |
| 2575 | return 1; |
| 2576 | } |
| 2577 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2578 | /* 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] | 2579 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2580 | * state machine handling requests and various responses. We read a request, |
| 2581 | * 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] | 2582 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2583 | * 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] | 2584 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2585 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2586 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2587 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2588 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2589 | struct channel *req = si_oc(si); |
| 2590 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2591 | int reql; |
| 2592 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2593 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2594 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2595 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2596 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2597 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2598 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2599 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2600 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2601 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2602 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2603 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2604 | /* Let's close for real now. We just close the request |
| 2605 | * side, the conditions below will complete if needed. |
| 2606 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2607 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2608 | break; |
| 2609 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2610 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2611 | /* ensure we have some output room left in the event we |
| 2612 | * would want to return some info right after parsing. |
| 2613 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2614 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2615 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2616 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2617 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2618 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2619 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2620 | if (reql <= 0) { /* closed or EOL not found */ |
| 2621 | if (reql == 0) |
| 2622 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2623 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2624 | continue; |
| 2625 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2626 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2627 | /* seek for a possible semi-colon. If we find one, we |
| 2628 | * replace it with an LF and skip only this part. |
| 2629 | */ |
| 2630 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2631 | if (trash.str[len] == ';') { |
| 2632 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2633 | reql = len + 1; |
| 2634 | break; |
| 2635 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2636 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2637 | /* now it is time to check that we have a full line, |
| 2638 | * remove the trailing \n and possibly \r, then cut the |
| 2639 | * line. |
| 2640 | */ |
| 2641 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2642 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2643 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2644 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2645 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2646 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2647 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2648 | len--; |
| 2649 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2650 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2651 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2652 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2653 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2654 | if (strcmp(trash.str, "quit") == 0) { |
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 | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2658 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2659 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2660 | else if (strcmp(trash.str, "help") == 0 || |
| 2661 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2662 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2663 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2664 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2665 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2666 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2667 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2668 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2669 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2670 | /* if prompt is disabled, print help on empty lines, |
| 2671 | * so that the user at least knows how to enable |
| 2672 | * prompt and find help. |
| 2673 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2674 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2675 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2679 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2680 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2681 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2682 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2683 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2684 | case STAT_CLI_PROMPT: |
| 2685 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2686 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2687 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2688 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2689 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2690 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2691 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2692 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2693 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2694 | free(appctx->ctx.cli.err); |
| 2695 | appctx->st0 = STAT_CLI_PROMPT; |
| 2696 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2697 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2698 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2699 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2700 | case STAT_CLI_O_BACKEND: |
| 2701 | if (stats_dump_backend_to_buffer(si)) |
| 2702 | appctx->st0 = STAT_CLI_PROMPT; |
| 2703 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2704 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2705 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2706 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2707 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2708 | case STAT_CLI_O_SERVERS_STATE: |
| 2709 | if (stats_dump_servers_state_to_buffer(si)) |
| 2710 | appctx->st0 = STAT_CLI_PROMPT; |
| 2711 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2712 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2713 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2714 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2715 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2716 | case STAT_CLI_O_RESOLVERS: |
| 2717 | if (stats_dump_resolvers_to_buffer(si)) |
| 2718 | appctx->st0 = STAT_CLI_PROMPT; |
| 2719 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2720 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2721 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2722 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2723 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2724 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2725 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2726 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2727 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2728 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2729 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2730 | if (stats_table_request(si, appctx->st0)) |
| 2731 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2732 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2733 | case STAT_CLI_O_PATS: |
| 2734 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2735 | appctx->st0 = STAT_CLI_PROMPT; |
| 2736 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2737 | case STAT_CLI_O_PAT: |
| 2738 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2739 | appctx->st0 = STAT_CLI_PROMPT; |
| 2740 | break; |
| 2741 | case STAT_CLI_O_MLOOK: |
| 2742 | if (stats_map_lookup(si)) |
| 2743 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2744 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2745 | case STAT_CLI_O_POOLS: |
| 2746 | if (stats_dump_pools_to_buffer(si)) |
| 2747 | appctx->st0 = STAT_CLI_PROMPT; |
| 2748 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2749 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2750 | case STAT_CLI_O_TLSK: |
| 2751 | if (stats_tlskeys_list(si)) |
| 2752 | appctx->st0 = STAT_CLI_PROMPT; |
| 2753 | break; |
| 2754 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2755 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2756 | if (stats_dump_env_to_buffer(si)) |
| 2757 | appctx->st0 = STAT_CLI_PROMPT; |
| 2758 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2759 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2760 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2761 | break; |
| 2762 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2763 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2764 | /* 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] | 2765 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2766 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2767 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2768 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2769 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2770 | } |
| 2771 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2772 | /* 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] | 2773 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2774 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2775 | |
| 2776 | /* Now we close the output if one of the writers did so, |
| 2777 | * or if we're not in interactive mode and the request |
| 2778 | * buffer is empty. This still allows pipelined requests |
| 2779 | * to be sent in non-interactive mode. |
| 2780 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2781 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2782 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2783 | continue; |
| 2784 | } |
| 2785 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2786 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2787 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2788 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2789 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2790 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2791 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2792 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2793 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2794 | /* 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] | 2795 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2796 | * we forward the close to the request side so that it flows upstream to |
| 2797 | * the client. |
| 2798 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2799 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2800 | } |
| 2801 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2802 | 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] | 2803 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2804 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2805 | /* We have no more processing to do, and nothing more to send, and |
| 2806 | * the client side has closed. So we'll forward this state downstream |
| 2807 | * on the response buffer. |
| 2808 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2809 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2810 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2811 | } |
| 2812 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2813 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2814 | 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] | 2815 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2816 | 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] | 2817 | } |
| 2818 | |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2819 | /* Emits a stats field without any surrounding element and properly encoded to |
| 2820 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 2821 | */ |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 2822 | 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] | 2823 | { |
| 2824 | switch (field_format(f, 0)) { |
| 2825 | case FF_EMPTY: return 1; |
| 2826 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 2827 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 2828 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 2829 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 2830 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 2831 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 2832 | } |
| 2833 | } |
| 2834 | |
Willy Tarreau | b47785f | 2016-02-24 23:28:31 +0100 | [diff] [blame] | 2835 | /* Emits a stats field prefixed with its type. No CSV encoding is prepared, the |
| 2836 | * output is supposed to be used on its own line. Returns non-zero on success, 0 |
| 2837 | * if the buffer is full. |
| 2838 | */ |
| 2839 | int stats_emit_typed_data_field(struct chunk *out, const struct field *f) |
| 2840 | { |
| 2841 | switch (field_format(f, 0)) { |
| 2842 | case FF_EMPTY: return 1; |
| 2843 | case FF_S32: return chunk_appendf(out, "s32:%d", f->u.s32); |
| 2844 | case FF_U32: return chunk_appendf(out, "u32:%u", f->u.u32); |
| 2845 | case FF_S64: return chunk_appendf(out, "s64:%lld", (long long)f->u.s64); |
| 2846 | case FF_U64: return chunk_appendf(out, "u64:%llu", (unsigned long long)f->u.u64); |
| 2847 | case FF_STR: return chunk_appendf(out, "str:%s", field_str(f, 0)); |
| 2848 | default: return chunk_appendf(out, "%08x:?", f->type); |
| 2849 | } |
| 2850 | } |
| 2851 | |
| 2852 | /* Emits an encoding of the field type on 3 characters followed by a delimiter. |
| 2853 | * Returns non-zero on success, 0 if the buffer is full. |
| 2854 | */ |
| 2855 | int stats_emit_field_tags(struct chunk *out, const struct field *f, char delim) |
| 2856 | { |
| 2857 | char origin, nature, scope; |
| 2858 | |
| 2859 | switch (field_origin(f, 0)) { |
| 2860 | case FO_METRIC: origin = 'M'; break; |
| 2861 | case FO_STATUS: origin = 'S'; break; |
| 2862 | case FO_KEY: origin = 'K'; break; |
| 2863 | case FO_CONFIG: origin = 'C'; break; |
| 2864 | case FO_PRODUCT: origin = 'P'; break; |
| 2865 | default: origin = '?'; break; |
| 2866 | } |
| 2867 | |
| 2868 | switch (field_nature(f, 0)) { |
| 2869 | case FN_GAUGE: nature = 'G'; break; |
| 2870 | case FN_LIMIT: nature = 'L'; break; |
| 2871 | case FN_MIN: nature = 'm'; break; |
| 2872 | case FN_MAX: nature = 'M'; break; |
| 2873 | case FN_RATE: nature = 'R'; break; |
| 2874 | case FN_COUNTER: nature = 'C'; break; |
| 2875 | case FN_DURATION: nature = 'D'; break; |
| 2876 | case FN_AGE: nature = 'A'; break; |
| 2877 | case FN_TIME: nature = 'T'; break; |
| 2878 | case FN_NAME: nature = 'N'; break; |
| 2879 | case FN_OUTPUT: nature = 'O'; break; |
| 2880 | case FN_AVG: nature = 'a'; break; |
| 2881 | default: nature = '?'; break; |
| 2882 | } |
| 2883 | |
| 2884 | switch (field_scope(f, 0)) { |
| 2885 | case FS_PROCESS: scope = 'P'; break; |
| 2886 | case FS_SERVICE: scope = 'S'; break; |
| 2887 | case FS_SYSTEM: scope = 's'; break; |
| 2888 | case FS_CLUSTER: scope = 'C'; break; |
| 2889 | default: scope = '?'; break; |
| 2890 | } |
| 2891 | |
| 2892 | return chunk_appendf(out, "%c%c%c%c", origin, nature, scope, delim); |
| 2893 | } |
| 2894 | |
Willy Tarreau | bf95cba | 2016-01-11 18:27:29 +0100 | [diff] [blame] | 2895 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
| 2896 | static int stats_dump_info_fields(struct chunk *out, const struct field *info) |
| 2897 | { |
| 2898 | int field; |
| 2899 | |
| 2900 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 2901 | if (!field_format(info, field)) |
| 2902 | continue; |
| 2903 | |
| 2904 | if (!chunk_appendf(out, "%s: ", info_field_names[field])) |
| 2905 | return 0; |
| 2906 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 2907 | return 0; |
| 2908 | if (!chunk_strcat(out, "\n")) |
| 2909 | return 0; |
| 2910 | } |
| 2911 | return 1; |
| 2912 | } |
| 2913 | |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 2914 | /* Dump all fields from <info> into <out> using the "show info typed" format */ |
| 2915 | static int stats_dump_typed_info_fields(struct chunk *out, const struct field *info) |
| 2916 | { |
| 2917 | int field; |
| 2918 | |
| 2919 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 2920 | if (!field_format(info, field)) |
| 2921 | continue; |
| 2922 | |
| 2923 | if (!chunk_appendf(out, "%d.%s.%u:", field, info_field_names[field], info[INF_PROCESS_NUM].u.u32)) |
| 2924 | return 0; |
| 2925 | if (!stats_emit_field_tags(out, &info[field], ':')) |
| 2926 | return 0; |
| 2927 | if (!stats_emit_typed_data_field(out, &info[field])) |
| 2928 | return 0; |
| 2929 | if (!chunk_strcat(out, "\n")) |
| 2930 | return 0; |
| 2931 | } |
| 2932 | return 1; |
| 2933 | } |
| 2934 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2935 | /* Fill <info> with HAProxy global info. <info> is preallocated |
| 2936 | * array of length <len>. The length of the aray must be |
| 2937 | * INF_TOTAL_FIELDS. If this length is less then this value, the |
| 2938 | * function returns 0, otherwise, it returns 1. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2939 | */ |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2940 | int stats_fill_info(struct field *info, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2941 | { |
| 2942 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2943 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2944 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2945 | #ifdef USE_OPENSSL |
| 2946 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2947 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2948 | int ssl_reuse = 0; |
| 2949 | |
| 2950 | if (ssl_key_rate < ssl_sess_rate) { |
| 2951 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2952 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2953 | } |
| 2954 | #endif |
| 2955 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2956 | if (len < INF_TOTAL_FIELDS) |
| 2957 | return 0; |
| 2958 | |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2959 | chunk_reset(out); |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 2960 | memset(info, 0, sizeof(*info) * len); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2961 | |
| 2962 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
| 2963 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION); |
| 2964 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE); |
| 2965 | |
| 2966 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 2967 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 2968 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 2969 | |
| 2970 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 2971 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 2972 | |
| 2973 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 2974 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 2975 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 2976 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 2977 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 2978 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 2979 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 2980 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 2981 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 2982 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 2983 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 2984 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 2985 | #ifdef USE_OPENSSL |
| 2986 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 2987 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 2988 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 2989 | #endif |
| 2990 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 2991 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 2992 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 2993 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 2994 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 2995 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 2996 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 2997 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 2998 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 2999 | |
| 3000 | #ifdef USE_OPENSSL |
| 3001 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3002 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3003 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3004 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3005 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3006 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3007 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3008 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3009 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3010 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3011 | #endif |
| 3012 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3013 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3014 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3015 | #ifdef USE_ZLIB |
| 3016 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3017 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3018 | #endif |
| 3019 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
| 3020 | info[INF_RUN_QUEUE] = mkf_u32(0, run_queue_cur); |
| 3021 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct); |
| 3022 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3023 | if (global.desc) |
| 3024 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
| 3025 | |
Thierry Fournier | cb2c767 | 2016-03-25 08:19:23 +0100 | [diff] [blame] | 3026 | return 1; |
| 3027 | } |
| 3028 | |
| 3029 | /* This function dumps information onto the stream interface's read buffer. |
| 3030 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 3031 | * No state is used. |
| 3032 | */ |
| 3033 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
| 3034 | { |
| 3035 | struct appctx *appctx = __objt_appctx(si->end); |
| 3036 | |
| 3037 | if (!stats_fill_info(info, INF_TOTAL_FIELDS)) |
| 3038 | return 0; |
| 3039 | |
Willy Tarreau | 1b4ba1e | 2016-01-11 18:29:04 +0100 | [diff] [blame] | 3040 | chunk_reset(&trash); |
Willy Tarreau | cb80912 | 2016-01-11 20:08:42 +0100 | [diff] [blame] | 3041 | |
| 3042 | if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3043 | stats_dump_typed_info_fields(&trash, info); |
| 3044 | else |
| 3045 | stats_dump_info_fields(&trash, info); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3046 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3047 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3048 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3049 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3050 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3051 | |
| 3052 | return 1; |
| 3053 | } |
| 3054 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3055 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 3056 | * These information are all the parameters which may change during HAProxy runtime. |
| 3057 | * By default, we only export to the last known server state file format. |
| 3058 | * These information can be used at next startup to recover same level of server state. |
| 3059 | */ |
| 3060 | static void dump_servers_state(struct proxy *backend, struct chunk *buf) |
| 3061 | { |
| 3062 | struct server *srv; |
| 3063 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 3064 | time_t srv_time_since_last_change; |
| 3065 | int bk_f_forced_id, srv_f_forced_id; |
| 3066 | |
| 3067 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 3068 | if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1)))) |
| 3069 | return; |
| 3070 | |
| 3071 | srv = backend->srv; |
| 3072 | |
| 3073 | while (srv) { |
| 3074 | srv_addr[0] = '\0'; |
| 3075 | srv_time_since_last_change = 0; |
| 3076 | bk_f_forced_id = 0; |
| 3077 | srv_f_forced_id = 0; |
| 3078 | |
| 3079 | switch (srv->addr.ss_family) { |
| 3080 | case AF_INET: |
| 3081 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 3082 | srv_addr, INET_ADDRSTRLEN + 1); |
| 3083 | break; |
| 3084 | case AF_INET6: |
| 3085 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 3086 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 3087 | break; |
| 3088 | } |
| 3089 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
| 3090 | bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0; |
| 3091 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 3092 | |
| 3093 | chunk_appendf(buf, |
| 3094 | "%d %s " |
| 3095 | "%d %s %s " |
| 3096 | "%d %d %d %d %ld " |
| 3097 | "%d %d %d %d %d " |
| 3098 | "%d %d" |
| 3099 | "\n", |
| 3100 | backend->uuid, backend->id, |
| 3101 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 3102 | 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] | 3103 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 3104 | bk_f_forced_id, srv_f_forced_id); |
| 3105 | |
| 3106 | srv = srv->next; |
| 3107 | } |
| 3108 | } |
| 3109 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3110 | /* Parses backend list and simply report backend names */ |
| 3111 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 3112 | { |
| 3113 | extern struct proxy *proxy; |
| 3114 | struct proxy *curproxy; |
| 3115 | |
| 3116 | chunk_reset(&trash); |
| 3117 | chunk_printf(&trash, "# name\n"); |
| 3118 | |
| 3119 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3120 | /* looking for backends only */ |
| 3121 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3122 | continue; |
| 3123 | |
| 3124 | /* we don't want to list a backend which is bound to this process */ |
| 3125 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 3126 | continue; |
| 3127 | |
| 3128 | chunk_appendf(&trash, "%s\n", curproxy->id); |
| 3129 | } |
| 3130 | |
| 3131 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3132 | si_applet_cant_put(si); |
| 3133 | return 0; |
| 3134 | } |
| 3135 | |
| 3136 | return 1; |
| 3137 | } |
| 3138 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3139 | /* Parses backend list or simply use backend name provided by the user to return |
| 3140 | * states of servers to stdout. |
| 3141 | */ |
| 3142 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 3143 | { |
| 3144 | struct appctx *appctx = __objt_appctx(si->end); |
| 3145 | extern struct proxy *proxy; |
| 3146 | struct proxy *curproxy; |
| 3147 | |
| 3148 | chunk_reset(&trash); |
| 3149 | |
| 3150 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3151 | |
| 3152 | if (appctx->ctx.server_state.backend) { |
| 3153 | dump_servers_state(appctx->ctx.server_state.backend, &trash); |
| 3154 | } |
| 3155 | else { |
| 3156 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3157 | /* servers are only in backends */ |
| 3158 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3159 | continue; |
| 3160 | |
| 3161 | dump_servers_state(curproxy, &trash); |
| 3162 | } |
| 3163 | } |
| 3164 | |
| 3165 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3166 | si_applet_cant_put(si); |
| 3167 | return 0; |
| 3168 | } |
| 3169 | |
| 3170 | return 1; |
| 3171 | } |
| 3172 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3173 | /* This function dumps memory usage information onto the stream interface's |
| 3174 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3175 | * completion. No state is used. |
| 3176 | */ |
| 3177 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3178 | { |
| 3179 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3180 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3181 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3182 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3183 | } |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 3184 | return 1; |
| 3185 | } |
| 3186 | |
| 3187 | /* Dump all fields from <stats> into <out> using CSV format */ |
| 3188 | static int stats_dump_fields_csv(struct chunk *out, const struct field *stats) |
| 3189 | { |
| 3190 | int field; |
| 3191 | |
| 3192 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3193 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 3194 | return 0; |
| 3195 | if (!chunk_strcat(out, ",")) |
| 3196 | return 0; |
| 3197 | } |
Conrad Hoffmann | 692c938 | 2016-04-01 20:40:58 +0200 | [diff] [blame] | 3198 | chunk_strcat(out, "\n"); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3199 | return 1; |
| 3200 | } |
| 3201 | |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3202 | /* Dump all fields from <stats> into <out> using a typed "field:desc:type:value" format */ |
| 3203 | static int stats_dump_fields_typed(struct chunk *out, const struct field *stats) |
| 3204 | { |
| 3205 | int field; |
| 3206 | |
| 3207 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3208 | if (!stats[field].type) |
| 3209 | continue; |
| 3210 | |
| 3211 | chunk_appendf(out, "%c.%u.%u.%d.%s.%u:", |
| 3212 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE ? 'F' : |
| 3213 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE ? 'B' : |
| 3214 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO ? 'L' : |
| 3215 | stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV ? 'S' : |
| 3216 | '?', |
| 3217 | stats[ST_F_IID].u.u32, stats[ST_F_SID].u.u32, |
| 3218 | field, stat_field_names[field], stats[ST_F_PID].u.u32); |
| 3219 | |
| 3220 | if (!stats_emit_field_tags(out, &stats[field], ':')) |
| 3221 | return 0; |
| 3222 | if (!stats_emit_typed_data_field(out, &stats[field])) |
| 3223 | return 0; |
| 3224 | if (!chunk_strcat(out, "\n")) |
| 3225 | return 0; |
| 3226 | } |
| 3227 | return 1; |
| 3228 | } |
| 3229 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3230 | /* 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] | 3231 | * reserved for the checkbox is ST_SHOWADMIN is set in <flags>. Some extra info |
| 3232 | * are provided if ST_SHLGNDS is present in <flags>. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3233 | */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3234 | 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] | 3235 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3236 | struct chunk src; |
| 3237 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3238 | if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_FE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3239 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3240 | /* name, queue */ |
| 3241 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3242 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3243 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3244 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3245 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3246 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3247 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3248 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3249 | "<td class=ac>" |
| 3250 | "<a name=\"%s/Frontend\"></a>" |
| 3251 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3252 | "<td colspan=3></td>" |
| 3253 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3254 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3255 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3256 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3257 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3258 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3259 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3260 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3261 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3262 | U2H(stats[ST_F_RATE].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3263 | U2H(stats[ST_F_CONN_RATE].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3264 | U2H(stats[ST_F_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3265 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3266 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3267 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3268 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3269 | U2H(stats[ST_F_REQ_RATE].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3270 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3271 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3272 | "</table></div></u></td>" |
| 3273 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3274 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3275 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3276 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3277 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3278 | U2H(stats[ST_F_RATE_MAX].u.u32), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3279 | U2H(stats[ST_F_CONN_RATE_MAX].u.u32), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3280 | U2H(stats[ST_F_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3281 | |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3282 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3283 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3284 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3285 | U2H(stats[ST_F_REQ_RATE_MAX].u.u32)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3286 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3287 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3288 | "</table></div></u></td>" |
| 3289 | /* sessions rate : limit */ |
| 3290 | "<td>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3291 | LIM2A(stats[ST_F_RATE_LIM].u.u32, "-")); |
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 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3294 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3295 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3296 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3297 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3298 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3299 | "", |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3300 | 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] | 3301 | U2H(stats[ST_F_STOT].u.u64), |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3302 | U2H(stats[ST_F_CONN_TOT].u.u64), |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3303 | U2H(stats[ST_F_STOT].u.u64)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3304 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3305 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3306 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3307 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3308 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3309 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3310 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3311 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3312 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3313 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3314 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3315 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3316 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3317 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3318 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3319 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3320 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3321 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3322 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3323 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3324 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3325 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3326 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3327 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3328 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3329 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3330 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3331 | chunk_appendf(out, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3332 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3333 | /* sessions: lbtot, lastsess */ |
| 3334 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3335 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3336 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3337 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3338 | U2H(stats[ST_F_BIN].u.u64)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3339 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3340 | chunk_appendf(out, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3341 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3342 | "<td>%s%s<div class=tips><table class=det>" |
| 3343 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3344 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3345 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3346 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3347 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3348 | "</table></div>%s</td>", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3349 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3350 | U2H(stats[ST_F_BOUT].u.u64), |
| 3351 | U2H(stats[ST_F_BOUT].u.u64), |
| 3352 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3353 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3354 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3355 | U2H(stats[ST_F_COMP_BYP].u.u64), |
| 3356 | U2H(stats[ST_F_COMP_IN].u.u64 - stats[ST_F_COMP_OUT].u.u64), |
| 3357 | 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, |
| 3358 | (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] | 3359 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3360 | chunk_appendf(out, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3361 | /* denied: req, resp */ |
| 3362 | "<td>%s</td><td>%s</td>" |
| 3363 | /* errors : request, connect, response */ |
| 3364 | "<td>%s</td><td></td><td></td>" |
| 3365 | /* warnings: retries, redispatches */ |
| 3366 | "<td></td><td></td>" |
| 3367 | /* server status : reflect frontend status */ |
| 3368 | "<td class=ac>%s</td>" |
| 3369 | /* rest of server: nothing */ |
| 3370 | "<td class=ac colspan=8></td></tr>" |
| 3371 | "", |
Willy Tarreau | d72c917 | 2016-01-06 15:26:40 +0100 | [diff] [blame] | 3372 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3373 | U2H(stats[ST_F_EREQ].u.u64), |
| 3374 | field_str(stats, ST_F_STATUS)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3375 | } |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3376 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SO) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3377 | chunk_appendf(out, "<tr class=socket>"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3378 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3379 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3380 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3381 | } |
| 3382 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3383 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3384 | /* frontend name, listener name */ |
| 3385 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3386 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3387 | "", |
| 3388 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3389 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3390 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), field_str(stats, ST_F_SVNAME)); |
| 3391 | |
| 3392 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3393 | chunk_appendf(out, "<div class=tips>"); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3394 | |
| 3395 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3396 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3397 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3398 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3399 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3400 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3401 | |
| 3402 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3403 | chunk_appendf(out, "id: %d</div>", stats[ST_F_SID].u.u32); |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3404 | } |
| 3405 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3406 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3407 | /* queue */ |
| 3408 | "%s</td><td colspan=3></td>" |
| 3409 | /* sessions rate: current, max, limit */ |
| 3410 | "<td colspan=3> </td>" |
| 3411 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
| 3412 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3413 | "<td>%s</td><td> </td><td> </td>" |
| 3414 | /* bytes: in, out */ |
| 3415 | "<td>%s</td><td>%s</td>" |
| 3416 | "", |
| 3417 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3418 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3419 | U2H(stats[ST_F_STOT].u.u64), U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64)); |
| 3420 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3421 | chunk_appendf(out, |
Willy Tarreau | fa9512f | 2016-01-08 17:20:51 +0100 | [diff] [blame] | 3422 | /* denied: req, resp */ |
| 3423 | "<td>%s</td><td>%s</td>" |
| 3424 | /* errors: request, connect, response */ |
| 3425 | "<td>%s</td><td></td><td></td>" |
| 3426 | /* warnings: retries, redispatches */ |
| 3427 | "<td></td><td></td>" |
| 3428 | /* server status: reflect listener status */ |
| 3429 | "<td class=ac>%s</td>" |
| 3430 | /* rest of server: nothing */ |
| 3431 | "<td class=ac colspan=8></td></tr>" |
| 3432 | "", |
| 3433 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3434 | U2H(stats[ST_F_EREQ].u.u64), |
| 3435 | field_str(stats, ST_F_STATUS)); |
| 3436 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3437 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_SV) { |
| 3438 | const char *style; |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3439 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3440 | /* determine the style to use depending on the server's state, |
| 3441 | * its health and weight. There isn't a 1-to-1 mapping between |
| 3442 | * state and styles for the cases where the server is (still) |
| 3443 | * up. The reason is that we don't want to report nolb and |
| 3444 | * drain with the same color. |
| 3445 | */ |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3446 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3447 | if (strcmp(field_str(stats, ST_F_STATUS), "DOWN") == 0 || |
| 3448 | strcmp(field_str(stats, ST_F_STATUS), "DOWN (agent)") == 0) { |
| 3449 | style = "down"; |
| 3450 | } |
| 3451 | else if (strcmp(field_str(stats, ST_F_STATUS), "DOWN ") == 0) { |
| 3452 | style = "going_up"; |
| 3453 | } |
| 3454 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB ") == 0) { |
| 3455 | style = "going_down"; |
| 3456 | } |
| 3457 | else if (strcmp(field_str(stats, ST_F_STATUS), "NOLB") == 0) { |
| 3458 | style = "nolb"; |
| 3459 | } |
| 3460 | else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { |
| 3461 | style = "no_check"; |
| 3462 | } |
| 3463 | else if (!stats[ST_F_CHKFAIL].type || |
| 3464 | stats[ST_F_CHECK_HEALTH].u.u32 == stats[ST_F_CHECK_RISE].u.u32 + stats[ST_F_CHECK_FALL].u.u32 - 1) { |
| 3465 | /* no check or max health = UP */ |
| 3466 | if (stats[ST_F_WEIGHT].u.u32) |
| 3467 | style = "up"; |
| 3468 | else |
| 3469 | style = "draining"; |
| 3470 | } |
| 3471 | else { |
| 3472 | style = "going_down"; |
| 3473 | } |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3474 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3475 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3476 | chunk_appendf(out, "<tr class=\"maintain\">"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3477 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3478 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3479 | "<tr class=\"%s_%s\">", |
| 3480 | (stats[ST_F_BCK].u.u32) ? "backup" : "active", style); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3481 | |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3482 | |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3483 | if (flags & ST_SHOWADMIN) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3484 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3485 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3486 | field_str(stats, ST_F_SVNAME)); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3487 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3488 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3489 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3490 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3491 | "", |
| 3492 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_SVNAME), |
| 3493 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3494 | 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] | 3495 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3496 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3497 | chunk_appendf(out, "<div class=tips>"); |
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 | if (isdigit(*field_str(stats, ST_F_ADDR))) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3500 | chunk_appendf(out, "IPv4: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3501 | else if (*field_str(stats, ST_F_ADDR) == '[') |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3502 | chunk_appendf(out, "IPv6: %s, ", field_str(stats, ST_F_ADDR)); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3503 | else if (*field_str(stats, ST_F_ADDR)) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3504 | chunk_appendf(out, "%s, ", field_str(stats, ST_F_ADDR)); |
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 | /* id */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3507 | chunk_appendf(out, "id: %d", stats[ST_F_SID].u.u32); |
Willy Tarreau | b5f66b8 | 2016-01-08 17:15:39 +0100 | [diff] [blame] | 3508 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3509 | /* cookie */ |
| 3510 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3511 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3512 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3513 | chunk_htmlencode(out, &src); |
| 3514 | chunk_appendf(out, "'"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3515 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3516 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3517 | chunk_appendf(out, "</div>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3518 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3519 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3520 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3521 | /* queue : current, max, limit */ |
| 3522 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
| 3523 | /* sessions rate : current, max, limit */ |
| 3524 | "<td>%s</td><td>%s</td><td></td>" |
| 3525 | "", |
| 3526 | (flags & ST_SHLGNDS) ? "</u>" : "", |
| 3527 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), LIM2A(stats[ST_F_QLIMIT].u.u32, "-"), |
| 3528 | 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] | 3529 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3530 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3531 | /* sessions: current, max, limit, total */ |
| 3532 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3533 | "<td><u>%s<div class=tips><table class=det>" |
| 3534 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3535 | "", |
| 3536 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SMAX].u.u32), LIM2A(stats[ST_F_SLIM].u.u32, "-"), |
| 3537 | U2H(stats[ST_F_STOT].u.u64), |
| 3538 | U2H(stats[ST_F_STOT].u.u64)); |
Willy Tarreau | 4607fad | 2016-01-06 15:41:29 +0100 | [diff] [blame] | 3539 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3540 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3541 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3542 | unsigned long long tot; |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3543 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3544 | tot = stats[ST_F_HRSP_OTHER].u.u64; |
| 3545 | tot += stats[ST_F_HRSP_1XX].u.u64; |
| 3546 | tot += stats[ST_F_HRSP_2XX].u.u64; |
| 3547 | tot += stats[ST_F_HRSP_3XX].u.u64; |
| 3548 | tot += stats[ST_F_HRSP_4XX].u.u64; |
| 3549 | tot += stats[ST_F_HRSP_5XX].u.u64; |
| 3550 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3551 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3552 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3553 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3554 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3555 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3556 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3557 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3558 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3559 | "", |
| 3560 | U2H(tot), |
| 3561 | U2H(stats[ST_F_HRSP_1XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_1XX].u.u64 / tot) : 0, |
| 3562 | U2H(stats[ST_F_HRSP_2XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_2XX].u.u64 / tot) : 0, |
| 3563 | U2H(stats[ST_F_HRSP_3XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_3XX].u.u64 / tot) : 0, |
| 3564 | U2H(stats[ST_F_HRSP_4XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_4XX].u.u64 / tot) : 0, |
| 3565 | U2H(stats[ST_F_HRSP_5XX].u.u64), tot ? (int)(100 * stats[ST_F_HRSP_5XX].u.u64 / tot) : 0, |
| 3566 | 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] | 3567 | } |
Willy Tarreau | a6f5a73 | 2016-01-08 16:59:56 +0100 | [diff] [blame] | 3568 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3569 | chunk_appendf(out, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3570 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3571 | 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] | 3572 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3573 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3574 | 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] | 3575 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3576 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3577 | "</table></div></u></td>" |
| 3578 | /* sessions: lbtot, last */ |
| 3579 | "<td>%s</td><td>%s</td>", |
| 3580 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3581 | human_time(stats[ST_F_LASTSESS].u.s32, 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3582 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3583 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3584 | /* bytes : in, out */ |
| 3585 | "<td>%s</td><td>%s</td>" |
| 3586 | /* denied: req, resp */ |
| 3587 | "<td></td><td>%s</td>" |
| 3588 | /* errors : request, connect */ |
| 3589 | "<td></td><td>%s</td>" |
| 3590 | /* errors : response */ |
| 3591 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3592 | /* warnings: retries, redispatches */ |
| 3593 | "<td>%lld</td><td>%lld</td>" |
| 3594 | "", |
| 3595 | U2H(stats[ST_F_BIN].u.u64), U2H(stats[ST_F_BOUT].u.u64), |
| 3596 | U2H(stats[ST_F_DRESP].u.u64), |
| 3597 | U2H(stats[ST_F_ECON].u.u64), |
| 3598 | U2H(stats[ST_F_ERESP].u.u64), |
| 3599 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3600 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3601 | (long long)stats[ST_F_WRETR].u.u64, |
| 3602 | (long long)stats[ST_F_WREDIS].u.u64); |
| 3603 | |
| 3604 | /* status, last change */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3605 | chunk_appendf(out, "<td class=ac>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3606 | |
| 3607 | /* FIXME!!!! |
| 3608 | * LASTCHG should contain the last change for *this* server and must be computed |
| 3609 | * properly above, as was done below, ie: this server if maint, otherwise ref server |
| 3610 | * if tracking. Note that ref is either local or remote depending on tracking. |
| 3611 | */ |
| 3612 | |
| 3613 | |
| 3614 | if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3615 | 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] | 3616 | } |
| 3617 | 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] | 3618 | chunk_strcat(out, "<i>no check</i>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3619 | } |
| 3620 | else { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3621 | 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] | 3622 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { |
| 3623 | if (stats[ST_F_CHECK_HEALTH].u.u32) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3624 | chunk_strcat(out, " ↑"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3625 | } |
| 3626 | 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] | 3627 | chunk_strcat(out, " ↓"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && |
| 3631 | 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] | 3632 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3633 | "</td><td class=ac><u> %s", |
| 3634 | field_str(stats, ST_F_AGENT_STATUS)); |
| 3635 | |
| 3636 | if (stats[ST_F_AGENT_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3637 | chunk_appendf(out, "/%d", stats[ST_F_AGENT_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3638 | |
| 3639 | 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] | 3640 | 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] | 3641 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3642 | 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] | 3643 | |
| 3644 | if (*field_str(stats, ST_F_LAST_AGT)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3645 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3646 | chunk_initstr(&src, field_str(stats, ST_F_LAST_AGT)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3647 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3648 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3649 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3650 | } |
| 3651 | else if (stats[ST_F_CHECK_STATUS].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3652 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3653 | "</td><td class=ac><u> %s", |
| 3654 | field_str(stats, ST_F_CHECK_STATUS)); |
| 3655 | |
| 3656 | if (stats[ST_F_CHECK_CODE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3657 | chunk_appendf(out, "/%d", stats[ST_F_CHECK_CODE].u.u32); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3658 | |
| 3659 | 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] | 3660 | 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] | 3661 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3662 | 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] | 3663 | |
| 3664 | if (*field_str(stats, ST_F_LAST_CHK)) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3665 | chunk_appendf(out, ": "); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3666 | chunk_initstr(&src, field_str(stats, ST_F_LAST_CHK)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3667 | chunk_htmlencode(out, &src); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3668 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3669 | chunk_appendf(out, "</div></u>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3670 | } |
| 3671 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3672 | chunk_appendf(out, "</td><td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3673 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3674 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3675 | /* weight */ |
| 3676 | "</td><td class=ac>%d</td>" |
| 3677 | /* act, bck */ |
| 3678 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3679 | "", |
| 3680 | stats[ST_F_WEIGHT].u.u32, |
| 3681 | stats[ST_F_BCK].u.u32 ? "-" : "Y", |
| 3682 | stats[ST_F_BCK].u.u32 ? "Y" : "-"); |
| 3683 | |
| 3684 | /* check failures: unique, fatal, down time */ |
| 3685 | if (stats[ST_F_CHKFAIL].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3686 | 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] | 3687 | |
| 3688 | if (stats[ST_F_HANAFAIL].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3689 | chunk_appendf(out, "/%lld", (long long)stats[ST_F_HANAFAIL].u.u64); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3690 | |
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 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
| 3693 | "<td>%lld</td><td>%s</td>" |
| 3694 | "", |
| 3695 | stats[ST_F_HANAFAIL].type ? "/Health Analyses" : "", |
| 3696 | (long long)stats[ST_F_CHKDOWN].u.u64, human_time(stats[ST_F_DOWNTIME].u.u32, 1)); |
| 3697 | } |
| 3698 | else if (strcmp(field_str(stats, ST_F_STATUS), "MAINT") != 0 && field_format(stats, ST_F_TRACKED) == FF_STR) { |
| 3699 | /* tracking a server (hence inherited maint would appear as "MAINT (via...)" */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3700 | chunk_appendf(out, |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3701 | "<td class=ac colspan=3><a class=lfsb href=\"#%s\">via %s</a></td>", |
| 3702 | field_str(stats, ST_F_TRACKED), field_str(stats, ST_F_TRACKED)); |
| 3703 | } |
| 3704 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3705 | chunk_appendf(out, "<td colspan=3></td>"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3706 | |
| 3707 | /* throttle */ |
| 3708 | if (stats[ST_F_THROTTLE].type) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3709 | 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] | 3710 | else |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3711 | chunk_appendf(out, "<td class=ac>-</td></tr>\n"); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3712 | } |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3713 | else if (stats[ST_F_TYPE].u.u32 == STATS_TYPE_BE) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3714 | chunk_appendf(out, "<tr class=\"backend\">"); |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3715 | if (flags & ST_SHOWADMIN) { |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3716 | /* Column sub-heading for Enable or Disable server */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3717 | chunk_appendf(out, "<td></td>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3718 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3719 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3720 | "<td class=ac>" |
| 3721 | /* name */ |
| 3722 | "%s<a name=\"%s/Backend\"></a>" |
| 3723 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 3724 | "", |
| 3725 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3726 | field_str(stats, ST_F_PXNAME), field_str(stats, ST_F_PXNAME)); |
| 3727 | |
| 3728 | if (flags & ST_SHLGNDS) { |
| 3729 | /* balancing */ |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3730 | chunk_appendf(out, "<div class=tips>balancing: %s", |
Willy Tarreau | f1516d9 | 2016-01-11 14:48:36 +0100 | [diff] [blame] | 3731 | field_str(stats, ST_F_ALGO)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3732 | |
| 3733 | /* cookie */ |
| 3734 | if (stats[ST_F_COOKIE].type) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3735 | chunk_appendf(out, ", cookie: '"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3736 | chunk_initstr(&src, field_str(stats, ST_F_COOKIE)); |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3737 | chunk_htmlencode(out, &src); |
| 3738 | chunk_appendf(out, "'"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3739 | } |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3740 | chunk_appendf(out, "</div>"); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3741 | } |
| 3742 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3743 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3744 | "%s</td>" |
| 3745 | /* queue : current, max */ |
| 3746 | "<td>%s</td><td>%s</td><td></td>" |
| 3747 | /* sessions rate : current, max, limit */ |
| 3748 | "<td>%s</td><td>%s</td><td></td>" |
| 3749 | "", |
| 3750 | (flags & ST_SHLGNDS)?"</u>":"", |
| 3751 | U2H(stats[ST_F_QCUR].u.u32), U2H(stats[ST_F_QMAX].u.u32), |
| 3752 | U2H(stats[ST_F_RATE].u.u32), U2H(stats[ST_F_RATE_MAX].u.u32)); |
| 3753 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3754 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3755 | /* sessions: current, max, limit, total */ |
| 3756 | "<td>%s</td><td>%s</td><td>%s</td>" |
| 3757 | "<td><u>%s<div class=tips><table class=det>" |
| 3758 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3759 | "", |
| 3760 | U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SCUR].u.u32), U2H(stats[ST_F_SLIM].u.u32), |
| 3761 | U2H(stats[ST_F_STOT].u.u64), |
| 3762 | U2H(stats[ST_F_STOT].u.u64)); |
| 3763 | |
| 3764 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | f8211df | 2016-01-11 14:09:38 +0100 | [diff] [blame] | 3765 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) { |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3766 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3767 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3768 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3769 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3770 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3771 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3772 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3773 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3774 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3775 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3776 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
| 3777 | "", |
| 3778 | U2H(stats[ST_F_REQ_TOT].u.u64), |
| 3779 | U2H(stats[ST_F_HRSP_1XX].u.u64), |
| 3780 | U2H(stats[ST_F_HRSP_2XX].u.u64), |
| 3781 | U2H(stats[ST_F_COMP_RSP].u.u64), |
| 3782 | stats[ST_F_HRSP_2XX].u.u64 ? |
| 3783 | (int)(100 * stats[ST_F_COMP_RSP].u.u64 / stats[ST_F_HRSP_2XX].u.u64) : 0, |
| 3784 | U2H(stats[ST_F_HRSP_3XX].u.u64), |
| 3785 | U2H(stats[ST_F_HRSP_4XX].u.u64), |
| 3786 | U2H(stats[ST_F_HRSP_5XX].u.u64), |
| 3787 | U2H(stats[ST_F_HRSP_OTHER].u.u64), |
Willy Tarreau | 5b9bdff | 2016-01-11 14:40:47 +0100 | [diff] [blame] | 3788 | U2H(stats[ST_F_INTERCEPTED].u.u64)); |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3789 | } |
| 3790 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3791 | chunk_appendf(out, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_QTIME].u.u32)); |
| 3792 | 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] | 3793 | if (strcmp(field_str(stats, ST_F_MODE), "http") == 0) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3794 | chunk_appendf(out, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(stats[ST_F_RTIME].u.u32)); |
| 3795 | 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] | 3796 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3797 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3798 | "</table></div></u></td>" |
| 3799 | /* sessions: lbtot, last */ |
| 3800 | "<td>%s</td><td>%s</td>" |
| 3801 | /* bytes: in */ |
| 3802 | "<td>%s</td>" |
| 3803 | "", |
| 3804 | U2H(stats[ST_F_LBTOT].u.u64), |
| 3805 | human_time(stats[ST_F_LASTSESS].u.s32, 1), |
| 3806 | U2H(stats[ST_F_BIN].u.u64)); |
| 3807 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3808 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3809 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
| 3810 | "<td>%s%s<div class=tips><table class=det>" |
| 3811 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3812 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3813 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3814 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3815 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3816 | "</table></div>%s</td>", |
| 3817 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "<u>":"", |
| 3818 | U2H(stats[ST_F_BOUT].u.u64), |
| 3819 | U2H(stats[ST_F_BOUT].u.u64), |
| 3820 | U2H(stats[ST_F_COMP_IN].u.u64), |
| 3821 | U2H(stats[ST_F_COMP_OUT].u.u64), |
| 3822 | stats[ST_F_COMP_IN].u.u64 ? (int)(stats[ST_F_COMP_OUT].u.u64 * 100 / stats[ST_F_COMP_IN].u.u64) : 0, |
| 3823 | U2H(stats[ST_F_COMP_BYP].u.u64), |
Christopher Faulet | 0b64f62 | 2016-04-28 15:09:31 +0200 | [diff] [blame] | 3824 | 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] | 3825 | 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, |
| 3826 | (stats[ST_F_COMP_IN].u.u64 || stats[ST_F_COMP_BYP].u.u64) ? "</u>":""); |
| 3827 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3828 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3829 | /* denied: req, resp */ |
| 3830 | "<td>%s</td><td>%s</td>" |
| 3831 | /* errors : request, connect */ |
| 3832 | "<td></td><td>%s</td>" |
| 3833 | /* errors : response */ |
| 3834 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
| 3835 | /* warnings: retries, redispatches */ |
| 3836 | "<td>%lld</td><td>%lld</td>" |
| 3837 | /* backend status: reflect backend status (up/down): we display UP |
| 3838 | * if the backend has known working servers or if it has no server at |
| 3839 | * all (eg: for stats). Then we display the total weight, number of |
| 3840 | * active and backups. */ |
| 3841 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 3842 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 3843 | "", |
| 3844 | U2H(stats[ST_F_DREQ].u.u64), U2H(stats[ST_F_DRESP].u.u64), |
| 3845 | U2H(stats[ST_F_ECON].u.u64), |
| 3846 | U2H(stats[ST_F_ERESP].u.u64), |
| 3847 | (long long)stats[ST_F_CLI_ABRT].u.u64, |
| 3848 | (long long)stats[ST_F_SRV_ABRT].u.u64, |
| 3849 | (long long)stats[ST_F_WRETR].u.u64, (long long)stats[ST_F_WREDIS].u.u64, |
| 3850 | human_time(stats[ST_F_LASTCHG].u.u32, 1), |
| 3851 | strcmp(field_str(stats, ST_F_STATUS), "DOWN") ? field_str(stats, ST_F_STATUS) : "<font color=\"red\"><b>DOWN</b></font>", |
| 3852 | stats[ST_F_WEIGHT].u.u32, |
| 3853 | stats[ST_F_ACT].u.u32, stats[ST_F_BCK].u.u32); |
| 3854 | |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3855 | chunk_appendf(out, |
Willy Tarreau | bbf8450 | 2016-01-08 17:25:50 +0100 | [diff] [blame] | 3856 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 3857 | "<td class=ac> </td><td>%d</td>" |
| 3858 | "<td>%s</td>" |
| 3859 | "<td></td>" |
| 3860 | "</tr>", |
| 3861 | stats[ST_F_CHKDOWN].u.u32, |
| 3862 | stats[ST_F_DOWNTIME].type ? human_time(stats[ST_F_DOWNTIME].u.u32, 1) : " "); |
| 3863 | } |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3864 | return 1; |
| 3865 | } |
| 3866 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3867 | static int stats_dump_one_line(const struct field *stats, unsigned int flags, struct proxy *px, struct appctx *appctx) |
| 3868 | { |
Willy Tarreau | 508a63f | 2016-01-11 15:28:40 +0100 | [diff] [blame] | 3869 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
| 3870 | flags |= ST_SHOWADMIN; |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3871 | |
| 3872 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | 6060074 | 2016-01-11 15:32:30 +0100 | [diff] [blame] | 3873 | return stats_dump_fields_html(&trash, stats, flags); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 3874 | else if (appctx->ctx.stats.flags & STAT_FMT_TYPED) |
| 3875 | return stats_dump_fields_typed(&trash, stats); |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3876 | else |
| 3877 | return stats_dump_fields_csv(&trash, stats); |
| 3878 | } |
| 3879 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3880 | /* Fill <stats> with the frontend statistics. <stats> is |
| 3881 | * preallocated array of length <len>. The length of the array |
| 3882 | * must be at least ST_F_TOTAL_FIELDS. If this length is less then |
| 3883 | * this value, the function returns 0, otherwise, it returns 1. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3884 | */ |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3885 | 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] | 3886 | { |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3887 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3888 | return 0; |
| 3889 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3890 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3891 | |
| 3892 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 3893 | 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] | 3894 | 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] | 3895 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 3896 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 3897 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 3898 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 3899 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 3900 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 3901 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 3902 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 3903 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 3904 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); |
| 3905 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 3906 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 3907 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 3908 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 3909 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 3910 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 3911 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 3912 | |
| 3913 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3914 | if (px->mode == PR_MODE_HTTP) { |
| 3915 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 3916 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 3917 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 3918 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 3919 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 3920 | 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] | 3921 | 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] | 3922 | } |
| 3923 | |
| 3924 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3925 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 3926 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 3927 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 3928 | |
| 3929 | /* compression: in, out, bypassed, responses */ |
| 3930 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 3931 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 3932 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 3933 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 3934 | |
Willy Tarreau | c73810f | 2016-01-11 13:52:04 +0100 | [diff] [blame] | 3935 | /* connections : conn_rate, conn_rate_max, conn_tot, conn_max */ |
| 3936 | stats[ST_F_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_conn_per_sec)); |
| 3937 | stats[ST_F_CONN_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.cps_max); |
| 3938 | stats[ST_F_CONN_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_conn); |
| 3939 | |
Thierry Fournier | 23d2d64 | 2016-03-25 08:20:11 +0100 | [diff] [blame] | 3940 | return 1; |
| 3941 | } |
| 3942 | |
| 3943 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 3944 | * the state from stream interface <si>. The caller is responsible for clearing |
| 3945 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3946 | */ |
| 3947 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
| 3948 | { |
| 3949 | struct appctx *appctx = __objt_appctx(si->end); |
| 3950 | |
| 3951 | if (!(px->cap & PR_CAP_FE)) |
| 3952 | return 0; |
| 3953 | |
| 3954 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
| 3955 | return 0; |
| 3956 | |
| 3957 | if (!stats_fill_fe_stats(px, stats, ST_F_TOTAL_FIELDS)) |
| 3958 | return 0; |
| 3959 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 3960 | return stats_dump_one_line(stats, 0, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3961 | } |
| 3962 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 3963 | /* Fill <stats> with the listener statistics. <stats> is |
| 3964 | * preallocated array of length <len>. The length of the array |
| 3965 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 3966 | * then this value, the function returns 0, otherwise, it |
| 3967 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3968 | */ |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 3969 | int stats_fill_li_stats(struct proxy *px, struct listener *l, int flags, |
| 3970 | struct field *stats, int len) |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3971 | { |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3972 | struct chunk *out = get_trash_chunk(); |
| 3973 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 3974 | if (len < ST_F_TOTAL_FIELDS) |
| 3975 | return 0; |
| 3976 | |
Thierry Fournier | ac9d467 | 2016-03-25 08:43:46 +0100 | [diff] [blame] | 3977 | if (!l->counters) |
| 3978 | return 0; |
| 3979 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3980 | chunk_reset(out); |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 3981 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 3982 | |
| 3983 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 3984 | 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] | 3985 | 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] | 3986 | stats[ST_F_SCUR] = mkf_u32(0, l->nbconn); |
| 3987 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, l->counters->conn_max); |
| 3988 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, l->maxconn); |
| 3989 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, l->counters->cum_conn); |
| 3990 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, l->counters->bytes_in); |
| 3991 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, l->counters->bytes_out); |
| 3992 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, l->counters->denied_req); |
| 3993 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, l->counters->denied_resp); |
| 3994 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, l->counters->failed_req); |
| 3995 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 3996 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 3997 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 3998 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, l->luid); |
| 3999 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SO); |
| 4000 | |
| 4001 | if (flags & ST_SHLGNDS) { |
| 4002 | char str[INET6_ADDRSTRLEN]; |
| 4003 | int port; |
| 4004 | |
| 4005 | port = get_host_port(&l->addr); |
| 4006 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 4007 | case AF_INET: |
| 4008 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4009 | chunk_appendf(out, "%s:%d", str, port); |
| 4010 | break; |
| 4011 | case AF_INET6: |
| 4012 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4013 | chunk_appendf(out, "[%s]:%d", str, port); |
| 4014 | break; |
| 4015 | case AF_UNIX: |
| 4016 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4017 | break; |
| 4018 | case -1: |
| 4019 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4020 | chunk_strcat(out, strerror(errno)); |
| 4021 | break; |
| 4022 | default: /* address family not supported */ |
| 4023 | break; |
| 4024 | } |
| 4025 | } |
| 4026 | |
Thierry Fournier | c445685 | 2016-03-25 08:20:49 +0100 | [diff] [blame] | 4027 | return 1; |
| 4028 | } |
| 4029 | |
| 4030 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 4031 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 4032 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 4033 | * otherwise. |
| 4034 | */ |
| 4035 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
| 4036 | { |
| 4037 | struct appctx *appctx = __objt_appctx(si->end); |
| 4038 | |
| 4039 | if (!stats_fill_li_stats(px, l, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4040 | return 0; |
| 4041 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4042 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4043 | } |
| 4044 | |
| 4045 | enum srv_stats_state { |
| 4046 | SRV_STATS_STATE_DOWN = 0, |
| 4047 | SRV_STATS_STATE_DOWN_AGENT, |
| 4048 | SRV_STATS_STATE_GOING_UP, |
| 4049 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 4050 | SRV_STATS_STATE_UP, |
| 4051 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4052 | SRV_STATS_STATE_NOLB, |
| 4053 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 4054 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4055 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4056 | SRV_STATS_STATE_NO_CHECK, |
| 4057 | |
| 4058 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 4059 | }; |
| 4060 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4061 | static const char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 4062 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 4063 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 4064 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d", |
| 4065 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d", |
| 4066 | [SRV_STATS_STATE_UP] = "UP", |
| 4067 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d", |
| 4068 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 4069 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d", |
| 4070 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
| 4071 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
| 4072 | [SRV_STATS_STATE_NO_CHECK] = "no check" |
| 4073 | }; |
| 4074 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4075 | /* Fill <stats> with the server statistics. <stats> is |
| 4076 | * preallocated array of length <len>. The length of the array |
| 4077 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4078 | * then this value, the function returns 0, otherwise, it |
| 4079 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4080 | */ |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4081 | int stats_fill_sv_stats(struct proxy *px, struct server *sv, int flags, |
| 4082 | struct field *stats, int len) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4083 | { |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4084 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4085 | char str[INET6_ADDRSTRLEN]; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4086 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4087 | enum srv_stats_state state; |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4088 | char *fld_status; |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4089 | |
| 4090 | if (len < ST_F_TOTAL_FIELDS) |
| 4091 | return 0; |
| 4092 | |
| 4093 | memset(stats, 0, sizeof(*stats) * len); |
| 4094 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4095 | /* we have "via" which is the tracked server as described in the configuration, |
| 4096 | * and "ref" which is the checked server and the end of the chain. |
| 4097 | */ |
| 4098 | via = sv->track ? sv->track : sv; |
| 4099 | ref = via; |
| 4100 | while (ref->track) |
| 4101 | ref = ref->track; |
| 4102 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4103 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
| 4104 | if ((ref->check.state & CHK_ST_ENABLED) && |
| 4105 | (ref->check.health < ref->check.rise + ref->check.fall - 1)) { |
| 4106 | state = SRV_STATS_STATE_UP_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4107 | } else { |
| 4108 | state = SRV_STATS_STATE_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4109 | } |
| 4110 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4111 | if (sv->admin & SRV_ADMF_DRAIN) { |
| 4112 | if (ref->agent.state & CHK_ST_ENABLED) |
| 4113 | state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4114 | else if (state == SRV_STATS_STATE_UP_GOING_DOWN) |
| 4115 | state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
| 4116 | else |
| 4117 | state = SRV_STATS_STATE_DRAIN; |
| 4118 | } |
| 4119 | |
| 4120 | if (state == SRV_STATS_STATE_UP && !(ref->check.state & CHK_ST_ENABLED)) { |
| 4121 | state = SRV_STATS_STATE_NO_CHECK; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4122 | } |
| 4123 | } |
| 4124 | else if (sv->state == SRV_ST_STOPPING) { |
| 4125 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
| 4126 | (ref->check.health == ref->check.rise + ref->check.fall - 1)) { |
| 4127 | state = SRV_STATS_STATE_NOLB; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4128 | } else { |
| 4129 | state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4130 | } |
| 4131 | } |
| 4132 | else { /* stopped */ |
| 4133 | if ((ref->agent.state & CHK_ST_ENABLED) && !ref->agent.health) { |
| 4134 | state = SRV_STATS_STATE_DOWN_AGENT; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4135 | } else if ((ref->check.state & CHK_ST_ENABLED) && !ref->check.health) { |
| 4136 | state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4137 | } else if ((ref->agent.state & CHK_ST_ENABLED) || (ref->check.state & CHK_ST_ENABLED)) { |
| 4138 | state = SRV_STATS_STATE_GOING_UP; |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4139 | } else { |
| 4140 | state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4141 | } |
| 4142 | } |
| 4143 | |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4144 | chunk_reset(out); |
Willy Tarreau | 2b96cf1 | 2016-01-06 19:25:38 +0100 | [diff] [blame] | 4145 | |
| 4146 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4147 | 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] | 4148 | 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] | 4149 | stats[ST_F_QCUR] = mkf_u32(0, sv->nbpend); |
| 4150 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, sv->counters.nbpend_max); |
| 4151 | stats[ST_F_SCUR] = mkf_u32(0, sv->cur_sess); |
| 4152 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, sv->counters.cur_sess_max); |
| 4153 | |
| 4154 | if (sv->maxconn) |
| 4155 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, sv->maxconn); |
| 4156 | |
| 4157 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, sv->counters.cum_sess); |
| 4158 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, sv->counters.bytes_in); |
| 4159 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, sv->counters.bytes_out); |
| 4160 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, sv->counters.failed_secu); |
| 4161 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, sv->counters.failed_conns); |
| 4162 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, sv->counters.failed_resp); |
| 4163 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, sv->counters.retries); |
| 4164 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, sv->counters.redispatches); |
| 4165 | |
| 4166 | /* status */ |
| 4167 | fld_status = chunk_newstr(out); |
| 4168 | if (sv->admin & SRV_ADMF_IMAINT) |
| 4169 | chunk_appendf(out, "MAINT (via %s/%s)", via->proxy->id, via->id); |
| 4170 | else if (sv->admin & SRV_ADMF_MAINT) |
| 4171 | chunk_appendf(out, "MAINT"); |
| 4172 | else |
| 4173 | chunk_appendf(out, |
| 4174 | srv_hlt_st[state], |
| 4175 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 4176 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
| 4177 | |
| 4178 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, fld_status); |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4179 | stats[ST_F_LASTCHG] = mkf_u32(FN_AGE, now.tv_sec - sv->last_change); |
| 4180 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4181 | stats[ST_F_ACT] = mkf_u32(FO_STATUS, (sv->flags & SRV_F_BACKUP) ? 0 : 1); |
| 4182 | 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] | 4183 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4184 | /* check failures: unique, fatal; last change, total downtime */ |
| 4185 | if (sv->check.state & CHK_ST_ENABLED) { |
| 4186 | stats[ST_F_CHKFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_checks); |
| 4187 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, sv->counters.down_trans); |
| 4188 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, srv_downtime(sv)); |
| 4189 | } |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4190 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4191 | if (sv->maxqueue) |
| 4192 | stats[ST_F_QLIMIT] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->maxqueue); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4193 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4194 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4195 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4196 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4197 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4198 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
| 4199 | stats[ST_F_THROTTLE] = mkf_u32(FN_AVG, server_throttle_rate(sv)); |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4200 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4201 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, sv->counters.cum_lbconn); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4202 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4203 | if (sv->track) { |
| 4204 | char *fld_track = chunk_newstr(out); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4205 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4206 | chunk_appendf(out, "%s/%s", sv->track->proxy->id, sv->track->id); |
| 4207 | stats[ST_F_TRACKED] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, fld_track); |
| 4208 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4209 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4210 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_SV); |
| 4211 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&sv->sess_per_sec)); |
| 4212 | 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] | 4213 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4214 | if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4215 | const char *fld_chksts; |
Willy Tarreau | 164d4a9 | 2016-01-06 19:48:21 +0100 | [diff] [blame] | 4216 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4217 | fld_chksts = chunk_newstr(out); |
| 4218 | chunk_strcat(out, "* "); // for check in progress |
| 4219 | chunk_strcat(out, get_check_status_info(sv->check.status)); |
| 4220 | if (!(sv->check.state & CHK_ST_INPROGRESS)) |
| 4221 | fld_chksts += 2; // skip "* " |
| 4222 | stats[ST_F_CHECK_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4223 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4224 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 4225 | stats[ST_F_CHECK_CODE] = mkf_u32(FN_OUTPUT, sv->check.code); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4226 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4227 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 4228 | stats[ST_F_CHECK_DURATION] = mkf_u64(FN_DURATION, sv->check.duration); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4229 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4230 | stats[ST_F_CHECK_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->check.status)); |
| 4231 | stats[ST_F_LAST_CHK] = mkf_str(FN_OUTPUT, sv->check.desc); |
| 4232 | stats[ST_F_CHECK_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.rise); |
| 4233 | stats[ST_F_CHECK_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.fall); |
| 4234 | stats[ST_F_CHECK_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, ref->check.health); |
| 4235 | } |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 4236 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4237 | if ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
| 4238 | const char *fld_chksts; |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4239 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4240 | fld_chksts = chunk_newstr(out); |
| 4241 | chunk_strcat(out, "* "); // for check in progress |
| 4242 | chunk_strcat(out, get_check_status_info(sv->agent.status)); |
| 4243 | if (!(sv->agent.state & CHK_ST_INPROGRESS)) |
| 4244 | fld_chksts += 2; // skip "* " |
| 4245 | stats[ST_F_AGENT_STATUS] = mkf_str(FN_OUTPUT, fld_chksts); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4246 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4247 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 4248 | stats[ST_F_AGENT_CODE] = mkf_u32(FN_OUTPUT, sv->agent.code); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4249 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4250 | if (sv->agent.status >= HCHK_STATUS_CHECKED) |
| 4251 | stats[ST_F_AGENT_DURATION] = mkf_u64(FN_DURATION, sv->agent.duration); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4252 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4253 | stats[ST_F_AGENT_DESC] = mkf_str(FN_OUTPUT, get_check_status_description(sv->agent.status)); |
| 4254 | stats[ST_F_LAST_AGT] = mkf_str(FN_OUTPUT, sv->agent.desc); |
| 4255 | stats[ST_F_AGENT_RISE] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.rise); |
| 4256 | stats[ST_F_AGENT_FALL] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.fall); |
| 4257 | stats[ST_F_AGENT_HEALTH] = mkf_u32(FO_CONFIG|FS_SERVICE, sv->agent.health); |
| 4258 | } |
Willy Tarreau | dd7354b | 2016-01-08 13:47:26 +0100 | [diff] [blame] | 4259 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4260 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4261 | if (px->mode == PR_MODE_HTTP) { |
| 4262 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[1]); |
| 4263 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[2]); |
| 4264 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[3]); |
| 4265 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[4]); |
| 4266 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[5]); |
| 4267 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, sv->counters.p.http.rsp[0]); |
| 4268 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4269 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4270 | if (ref->observe) |
| 4271 | stats[ST_F_HANAFAIL] = mkf_u64(FN_COUNTER, sv->counters.failed_hana); |
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 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, sv->counters.cli_aborts); |
| 4274 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, sv->counters.srv_aborts); |
| 4275 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, srv_lastsession(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4276 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4277 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES)); |
| 4278 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES)); |
| 4279 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES)); |
| 4280 | 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] | 4281 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4282 | if (flags & ST_SHLGNDS) { |
| 4283 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 4284 | case AF_INET: |
| 4285 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4286 | chunk_appendf(out, "%s:%d", str, get_host_port(&sv->addr)); |
| 4287 | break; |
| 4288 | case AF_INET6: |
| 4289 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4290 | chunk_appendf(out, "[%s]:%d", str, get_host_port(&sv->addr)); |
| 4291 | break; |
| 4292 | case AF_UNIX: |
| 4293 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, "unix"); |
| 4294 | break; |
| 4295 | case -1: |
| 4296 | stats[ST_F_ADDR] = mkf_str(FO_CONFIG|FS_SERVICE, chunk_newstr(out)); |
| 4297 | chunk_strcat(out, strerror(errno)); |
| 4298 | break; |
| 4299 | default: /* address family not supported */ |
| 4300 | break; |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 4301 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4302 | |
Willy Tarreau | 362eaeb | 2016-01-08 17:23:28 +0100 | [diff] [blame] | 4303 | if (sv->cookie) |
| 4304 | stats[ST_F_COOKIE] = mkf_str(FO_CONFIG|FN_NAME|FS_SERVICE, sv->cookie); |
| 4305 | } |
| 4306 | |
Thierry Fournier | 61fe6c0 | 2016-03-25 08:21:21 +0100 | [diff] [blame] | 4307 | return 1; |
| 4308 | } |
| 4309 | |
| 4310 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 4311 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 4312 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
| 4313 | * if it emits anything, zero otherwise. |
| 4314 | */ |
| 4315 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv) |
| 4316 | { |
| 4317 | struct appctx *appctx = __objt_appctx(si->end); |
| 4318 | |
| 4319 | if (!stats_fill_sv_stats(px, sv, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4320 | return 0; |
| 4321 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4322 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4323 | } |
| 4324 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4325 | /* Fill <stats> with the backend statistics. <stats> is |
| 4326 | * preallocated array of length <len>. The length of the array |
| 4327 | * must be at least ST_F_TOTAL_FIELDS. If this length is less |
| 4328 | * then this value, the function returns 0, otherwise, it |
| 4329 | * returns 1. <flags> can take the value ST_SHLGNDS. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4330 | */ |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4331 | 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] | 4332 | { |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4333 | if (len < ST_F_TOTAL_FIELDS) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4334 | return 0; |
| 4335 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4336 | memset(stats, 0, sizeof(*stats) * len); |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4337 | |
| 4338 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 4339 | 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] | 4340 | 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] | 4341 | stats[ST_F_QCUR] = mkf_u32(0, px->nbpend); |
| 4342 | stats[ST_F_QMAX] = mkf_u32(FN_MAX, px->be_counters.nbpend_max); |
| 4343 | stats[ST_F_SCUR] = mkf_u32(FO_CONFIG|FN_LIMIT, px->beconn); |
| 4344 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->be_counters.conn_max); |
| 4345 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fullconn); |
| 4346 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_conn); |
| 4347 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->be_counters.bytes_in); |
| 4348 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->be_counters.bytes_out); |
| 4349 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->be_counters.denied_req); |
| 4350 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->be_counters.denied_resp); |
| 4351 | stats[ST_F_ECON] = mkf_u64(FN_COUNTER, px->be_counters.failed_conns); |
| 4352 | stats[ST_F_ERESP] = mkf_u64(FN_COUNTER, px->be_counters.failed_resp); |
| 4353 | stats[ST_F_WRETR] = mkf_u64(FN_COUNTER, px->be_counters.retries); |
| 4354 | stats[ST_F_WREDIS] = mkf_u64(FN_COUNTER, px->be_counters.redispatches); |
| 4355 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN"); |
| 4356 | stats[ST_F_WEIGHT] = mkf_u32(FN_AVG, (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv); |
| 4357 | stats[ST_F_ACT] = mkf_u32(0, px->srv_act); |
| 4358 | stats[ST_F_BCK] = mkf_u32(0, px->srv_bck); |
| 4359 | stats[ST_F_CHKDOWN] = mkf_u64(FN_COUNTER, px->down_trans); |
| 4360 | 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] | 4361 | if (px->srv) |
| 4362 | stats[ST_F_DOWNTIME] = mkf_u32(FN_COUNTER, be_downtime(px)); |
| 4363 | |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4364 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 4365 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 4366 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 4367 | stats[ST_F_LBTOT] = mkf_u64(FN_COUNTER, px->be_counters.cum_lbconn); |
| 4368 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_BE); |
| 4369 | stats[ST_F_RATE] = mkf_u32(0, read_freq_ctr(&px->be_sess_per_sec)); |
| 4370 | 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] | 4371 | |
Willy Tarreau | e4847c6 | 2016-01-08 15:43:54 +0100 | [diff] [blame] | 4372 | if (flags & ST_SHLGNDS) { |
| 4373 | if (px->cookie_name) |
| 4374 | 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] | 4375 | 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] | 4376 | } |
Willy Tarreau | f6eecbe | 2016-01-06 16:14:50 +0100 | [diff] [blame] | 4377 | |
| 4378 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4379 | if (px->mode == PR_MODE_HTTP) { |
| 4380 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->be_counters.p.http.cum_req); |
| 4381 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[1]); |
| 4382 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[2]); |
| 4383 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[3]); |
| 4384 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[4]); |
| 4385 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->be_counters.p.http.rsp[5]); |
| 4386 | 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] | 4387 | 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] | 4388 | } |
| 4389 | |
| 4390 | stats[ST_F_CLI_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.cli_aborts); |
| 4391 | stats[ST_F_SRV_ABRT] = mkf_u64(FN_COUNTER, px->be_counters.srv_aborts); |
| 4392 | |
| 4393 | /* compression: in, out, bypassed, responses */ |
| 4394 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->be_counters.comp_in); |
| 4395 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->be_counters.comp_out); |
| 4396 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->be_counters.comp_byp); |
| 4397 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->be_counters.p.http.comp_rsp); |
| 4398 | stats[ST_F_LASTSESS] = mkf_s32(FN_AGE, be_lastsession(px)); |
| 4399 | |
| 4400 | stats[ST_F_QTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES)); |
| 4401 | stats[ST_F_CTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES)); |
| 4402 | stats[ST_F_RTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES)); |
| 4403 | stats[ST_F_TTIME] = mkf_u32(FN_AVG, swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4404 | |
Thierry Fournier | d0a56c2 | 2016-03-25 08:21:51 +0100 | [diff] [blame] | 4405 | return 1; |
| 4406 | } |
| 4407 | |
| 4408 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 4409 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 4410 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4411 | */ |
| 4412 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 4413 | { |
| 4414 | struct appctx *appctx = __objt_appctx(si->end); |
| 4415 | |
| 4416 | if (!(px->cap & PR_CAP_BE)) |
| 4417 | return 0; |
| 4418 | |
| 4419 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
| 4420 | return 0; |
| 4421 | |
| 4422 | if (!stats_fill_be_stats(px, flags, stats, ST_F_TOTAL_FIELDS)) |
| 4423 | return 0; |
| 4424 | |
Willy Tarreau | 501f602 | 2016-01-08 17:37:22 +0100 | [diff] [blame] | 4425 | return stats_dump_one_line(stats, flags, px, appctx); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4426 | } |
| 4427 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4428 | /* 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] | 4429 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4430 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4431 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4432 | 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] | 4433 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4434 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4435 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4436 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4437 | 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] | 4438 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4439 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4440 | /* 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] | 4441 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4442 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4443 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4444 | 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] | 4445 | 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] | 4446 | } |
| 4447 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4448 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4449 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | /* print a new table */ |
| 4453 | chunk_appendf(&trash, |
| 4454 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4455 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4456 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4457 | |
| 4458 | chunk_appendf(&trash, |
| 4459 | "<a name=\"%s\"></a>%s" |
| 4460 | "<a class=px href=\"#%s\">%s</a>", |
| 4461 | px->id, |
| 4462 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4463 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4464 | |
| 4465 | if (uri->flags & ST_SHLGNDS) { |
| 4466 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4467 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4468 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4469 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4470 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4471 | } |
| 4472 | |
| 4473 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4474 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4475 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4476 | "</tr>\n" |
| 4477 | "</table>\n" |
| 4478 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4479 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4480 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4481 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4482 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4483 | 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] | 4484 | /* Column heading for Enable or Disable server */ |
| 4485 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4486 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4487 | |
| 4488 | chunk_appendf(&trash, |
| 4489 | "<th rowspan=2></th>" |
| 4490 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4491 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4492 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4493 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4494 | "<th colspan=9>Server</th>" |
| 4495 | "</tr>\n" |
| 4496 | "<tr class=\"titre\">" |
| 4497 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4498 | "<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] | 4499 | "<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] | 4500 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4501 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4502 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4503 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4504 | "<th>Thrtle</th>\n" |
| 4505 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4506 | } |
| 4507 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4508 | /* 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] | 4509 | * 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] | 4510 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4511 | 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] | 4512 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4513 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4514 | chunk_appendf(&trash, "</table>"); |
| 4515 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4516 | 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] | 4517 | /* close the form used to enable/disable this proxy servers */ |
| 4518 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4519 | "Choose the action to perform on the checked servers : " |
| 4520 | "<select name=action>" |
| 4521 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4522 | "<option value=\"ready\">Set state to READY</option>" |
| 4523 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4524 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4525 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4526 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4527 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4528 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4529 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4530 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4531 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4532 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4533 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4534 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4535 | "</select>" |
| 4536 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4537 | " <input type=\"submit\" value=\"Apply\">" |
| 4538 | "</form>", |
| 4539 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4540 | } |
| 4541 | |
| 4542 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4543 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4544 | |
| 4545 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4546 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4547 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4548 | * buffer space, or non-zero if everything completed. This function is used |
| 4549 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4550 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4551 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4552 | 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] | 4553 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4554 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4555 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4556 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4557 | 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] | 4558 | struct listener *l; |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4559 | unsigned int flags; |
| 4560 | |
| 4561 | if (uri) |
| 4562 | flags = uri->flags; |
| 4563 | else if (strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) |
| 4564 | flags = ST_SHLGNDS | ST_SHNODE | ST_SHDESC; |
| 4565 | else |
| 4566 | flags = ST_SHNODE | ST_SHDESC; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4567 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4568 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4569 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4570 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4571 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4572 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4573 | if (uri && uri->scope) { |
| 4574 | /* we have a limited scope, we have to check the proxy name */ |
| 4575 | struct stat_scope *scope; |
| 4576 | int len; |
| 4577 | |
| 4578 | len = strlen(px->id); |
| 4579 | scope = uri->scope; |
| 4580 | |
| 4581 | while (scope) { |
| 4582 | /* match exact proxy name */ |
| 4583 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4584 | break; |
| 4585 | |
| 4586 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4587 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4588 | break; |
| 4589 | scope = scope->next; |
| 4590 | } |
| 4591 | |
| 4592 | /* proxy name not found : don't dump anything */ |
| 4593 | if (scope == NULL) |
| 4594 | return 1; |
| 4595 | } |
| 4596 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4597 | /* if the user has requested a limited output and the proxy |
| 4598 | * name does not match, skip it. |
| 4599 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4600 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4601 | 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] | 4602 | return 1; |
| 4603 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4604 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4605 | (appctx->ctx.stats.iid != -1) && |
| 4606 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4607 | return 1; |
| 4608 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4609 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4610 | /* fall through */ |
| 4611 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4612 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4613 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4614 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4615 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4616 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4617 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4618 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4619 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4620 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4621 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4622 | /* fall through */ |
| 4623 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4624 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4625 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4626 | if (stats_dump_fe_stats(si, px)) { |
| 4627 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4628 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4629 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4630 | } |
| 4631 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4632 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4633 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4634 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4635 | /* fall through */ |
| 4636 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4637 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4638 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4639 | 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] | 4640 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4641 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4642 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4643 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4644 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4645 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4646 | if (!l->counters) |
| 4647 | continue; |
| 4648 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4649 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4650 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4651 | break; |
| 4652 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4653 | 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] | 4654 | continue; |
| 4655 | } |
| 4656 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4657 | /* print the frontend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4658 | if (stats_dump_li_stats(si, px, l, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4659 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4660 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4661 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4662 | } |
| 4663 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4664 | } |
| 4665 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4666 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4667 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4668 | /* fall through */ |
| 4669 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4670 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4671 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4672 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4673 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4674 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4675 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4676 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4677 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4678 | sv = appctx->ctx.stats.sv; |
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 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4681 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4682 | break; |
| 4683 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4684 | 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] | 4685 | continue; |
| 4686 | } |
| 4687 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4688 | svs = sv; |
| 4689 | while (svs->track) |
| 4690 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4691 | |
Willy Tarreau | ba2f264 | 2016-01-07 09:54:40 +0100 | [diff] [blame] | 4692 | /* do not report servers which are DOWN and not changing state */ |
| 4693 | if ((appctx->ctx.stats.flags & STAT_HIDE_DOWN) && |
| 4694 | ((sv->admin & SRV_ADMF_MAINT) || /* server is in maintenance */ |
| 4695 | (sv->state == SRV_ST_STOPPED && /* server is down */ |
| 4696 | (!((svs->agent.state | svs->check.state) & CHK_ST_ENABLED) || |
| 4697 | ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) || |
| 4698 | ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health))))) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4699 | continue; |
| 4700 | } |
| 4701 | |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4702 | if (stats_dump_sv_stats(si, px, flags, sv)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4703 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4704 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4705 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4706 | } |
| 4707 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4708 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4709 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4710 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4711 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4712 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4713 | case STAT_PX_ST_BE: |
| 4714 | /* print the backend */ |
Willy Tarreau | 0deb85a | 2016-01-08 15:33:18 +0100 | [diff] [blame] | 4715 | if (stats_dump_be_stats(si, px, flags)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4716 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4717 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4718 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4719 | } |
| 4720 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4721 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4722 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4723 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4724 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4725 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4726 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4727 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4728 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4729 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4730 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4731 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4732 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4733 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4734 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4735 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4736 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4737 | case STAT_PX_ST_FIN: |
| 4738 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4739 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4740 | default: |
| 4741 | /* unknown state, we should put an abort() here ! */ |
| 4742 | return 1; |
| 4743 | } |
| 4744 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4745 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4746 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4747 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4748 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4749 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4750 | { |
| 4751 | /* WARNING! This must fit in the first buffer !!! */ |
| 4752 | chunk_appendf(&trash, |
| 4753 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4754 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4755 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4756 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4757 | "<style type=\"text/css\"><!--\n" |
| 4758 | "body {" |
| 4759 | " font-family: arial, helvetica, sans-serif;" |
| 4760 | " font-size: 12px;" |
| 4761 | " font-weight: normal;" |
| 4762 | " color: black;" |
| 4763 | " background: white;" |
| 4764 | "}\n" |
| 4765 | "th,td {" |
| 4766 | " font-size: 10px;" |
| 4767 | "}\n" |
| 4768 | "h1 {" |
| 4769 | " font-size: x-large;" |
| 4770 | " margin-bottom: 0.5em;" |
| 4771 | "}\n" |
| 4772 | "h2 {" |
| 4773 | " font-family: helvetica, arial;" |
| 4774 | " font-size: x-large;" |
| 4775 | " font-weight: bold;" |
| 4776 | " font-style: italic;" |
| 4777 | " color: #6020a0;" |
| 4778 | " margin-top: 0em;" |
| 4779 | " margin-bottom: 0em;" |
| 4780 | "}\n" |
| 4781 | "h3 {" |
| 4782 | " font-family: helvetica, arial;" |
| 4783 | " font-size: 16px;" |
| 4784 | " font-weight: bold;" |
| 4785 | " color: #b00040;" |
| 4786 | " background: #e8e8d0;" |
| 4787 | " margin-top: 0em;" |
| 4788 | " margin-bottom: 0em;" |
| 4789 | "}\n" |
| 4790 | "li {" |
| 4791 | " margin-top: 0.25em;" |
| 4792 | " margin-right: 2em;" |
| 4793 | "}\n" |
| 4794 | ".hr {margin-top: 0.25em;" |
| 4795 | " border-color: black;" |
| 4796 | " border-bottom-style: solid;" |
| 4797 | "}\n" |
| 4798 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4799 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4800 | ".frontend {background: #e8e8d0;}\n" |
| 4801 | ".socket {background: #d0d0d0;}\n" |
| 4802 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4803 | ".active_down {background: #ff9090;}\n" |
| 4804 | ".active_going_up {background: #ffd020;}\n" |
| 4805 | ".active_going_down {background: #ffffa0;}\n" |
| 4806 | ".active_up {background: #c0ffc0;}\n" |
| 4807 | ".active_nolb {background: #20a0ff;}\n" |
| 4808 | ".active_draining {background: #20a0FF;}\n" |
| 4809 | ".active_no_check {background: #e0e0e0;}\n" |
| 4810 | ".backup_down {background: #ff9090;}\n" |
| 4811 | ".backup_going_up {background: #ff80ff;}\n" |
| 4812 | ".backup_going_down {background: #c060ff;}\n" |
| 4813 | ".backup_up {background: #b0d0ff;}\n" |
| 4814 | ".backup_nolb {background: #90b0e0;}\n" |
| 4815 | ".backup_draining {background: #cc9900;}\n" |
| 4816 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4817 | ".maintain {background: #c07820;}\n" |
| 4818 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4819 | "\n" |
| 4820 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4821 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4822 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4823 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4824 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4825 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4826 | "\n" |
| 4827 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4828 | "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" |
| 4829 | "table.tbl td.ac { text-align: center;}\n" |
| 4830 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4831 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4832 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4833 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4834 | "\n" |
| 4835 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4836 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4837 | "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] | 4838 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4839 | "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] | 4840 | "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] | 4841 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4842 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4843 | " display:block;\n" |
| 4844 | " visibility:hidden;\n" |
| 4845 | " z-index:2147483647;\n" |
| 4846 | " position:absolute;\n" |
| 4847 | " padding:2px 4px 3px;\n" |
| 4848 | " background:#f0f060; color:#000000;\n" |
| 4849 | " border:1px solid #7040c0;\n" |
| 4850 | " white-space:nowrap;\n" |
| 4851 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4852 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4853 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4854 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4855 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4856 | "-->\n" |
| 4857 | "</style></head>\n", |
| 4858 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4859 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4860 | ); |
| 4861 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4862 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4863 | /* 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] | 4864 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4865 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4866 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4867 | 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] | 4868 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4869 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4870 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4871 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4872 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4873 | /* WARNING! this has to fit the first packet too. |
| 4874 | * We are around 3.5 kB, add adding entries will |
| 4875 | * become tricky if we want to support 4kB buffers ! |
| 4876 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4877 | chunk_appendf(&trash, |
| 4878 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4879 | PRODUCT_NAME "%s</a></h1>\n" |
| 4880 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4881 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4882 | "<h3>> General process information</h3>\n" |
| 4883 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4884 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4885 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4886 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4887 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4888 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4889 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4890 | "</td><td align=\"center\" nowrap>\n" |
| 4891 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4892 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4893 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4894 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4895 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4896 | "<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] | 4897 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4898 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4899 | "<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] | 4900 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4901 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4902 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4903 | "</tr><tr>\n" |
| 4904 | "<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] | 4905 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4906 | "<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] | 4907 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4908 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4909 | "</td>" |
| 4910 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4911 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4912 | "", |
| 4913 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4914 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4915 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4916 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4917 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4918 | pid, relative_pid, global.nbproc, |
| 4919 | up / 86400, (up % 86400) / 3600, |
| 4920 | (up % 3600) / 60, (up % 60), |
| 4921 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4922 | global.rlimit_memmax ? " MB" : "", |
| 4923 | global.rlimit_nofile, |
| 4924 | global.maxsock, global.maxconn, global.maxpipes, |
| 4925 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4926 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4927 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4928 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4929 | /* 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] | 4930 | 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] | 4931 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4932 | |
| 4933 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4934 | "<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] | 4935 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4936 | STAT_SCOPE_TXT_MAXLEN); |
| 4937 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4938 | /* 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] | 4939 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4940 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4941 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4942 | 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] | 4943 | 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] | 4944 | } |
| 4945 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4946 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4947 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4948 | "<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] | 4949 | uri->uri_prefix, |
| 4950 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4951 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4952 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4953 | else |
| 4954 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4955 | "<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] | 4956 | uri->uri_prefix, |
| 4957 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4958 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4959 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4960 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4961 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4962 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4963 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4964 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4965 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4966 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4967 | "", |
| 4968 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4969 | else |
| 4970 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4971 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4972 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4973 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4974 | ";norefresh", |
| 4975 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4976 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4977 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4978 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4979 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4980 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4981 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4982 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4983 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4984 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4985 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4986 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4987 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4988 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4989 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4990 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4991 | chunk_appendf(&trash, |
| 4992 | "</ul></td>" |
| 4993 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4994 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4995 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4996 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4997 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4998 | "</ul>" |
| 4999 | "</td>" |
| 5000 | "</tr></table>\n" |
| 5001 | "" |
| 5002 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 5003 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5004 | if (appctx->ctx.stats.st_code) { |
| 5005 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5006 | case STAT_STATUS_DONE: |
| 5007 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5008 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5009 | "<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] | 5010 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5011 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5012 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5013 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5014 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5015 | break; |
| 5016 | case STAT_STATUS_NONE: |
| 5017 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5018 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5019 | "<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] | 5020 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5021 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5022 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5023 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5024 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5025 | break; |
| 5026 | case STAT_STATUS_PART: |
| 5027 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5028 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5029 | "<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] | 5030 | "Action partially processed.<br>" |
| 5031 | "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] | 5032 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5033 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5034 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5035 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5036 | break; |
| 5037 | case STAT_STATUS_ERRP: |
| 5038 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5039 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5040 | "<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] | 5041 | "Action not processed because of invalid parameters." |
| 5042 | "<ul>" |
| 5043 | "<li>The action is maybe unknown.</li>" |
| 5044 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 5045 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 5046 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5047 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5048 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5049 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5050 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5051 | break; |
| 5052 | case STAT_STATUS_EXCD: |
| 5053 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5054 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5055 | "<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] | 5056 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 5057 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5058 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5059 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5060 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5061 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5062 | break; |
| 5063 | case STAT_STATUS_DENY: |
| 5064 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5065 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5066 | "<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] | 5067 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5068 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5069 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5070 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5071 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5072 | break; |
| 5073 | default: |
| 5074 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 5075 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5076 | "<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] | 5077 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5078 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5079 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5080 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5081 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5082 | } |
| 5083 | chunk_appendf(&trash, "<p>\n"); |
| 5084 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5085 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5086 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5087 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 5088 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5089 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5090 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5091 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5092 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5093 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5094 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5095 | /* This function dumps statistics onto the stream interface's read buffer in |
| 5096 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5097 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 5098 | * 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] | 5099 | * 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] | 5100 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5101 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5102 | 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] | 5103 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5104 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5105 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5106 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5107 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5108 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5109 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5110 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5111 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5112 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5113 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 5114 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5115 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5116 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5117 | stats_dump_html_head(uri); |
Willy Tarreau | 1e62df9 | 2016-01-11 18:57:53 +0100 | [diff] [blame] | 5118 | else if (!(appctx->ctx.stats.flags & STAT_FMT_TYPED)) |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 5119 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 5120 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5121 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5122 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5123 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5124 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5125 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5126 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5127 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5128 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5129 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5130 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5131 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5132 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5133 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5134 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5135 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5136 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5137 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5138 | appctx->ctx.stats.px = proxy; |
| 5139 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 5140 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5141 | /* fall through */ |
| 5142 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5143 | case STAT_ST_LIST: |
| 5144 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5145 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5146 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5147 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5148 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5149 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5150 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5151 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5152 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5153 | 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] | 5154 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5155 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5156 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5157 | appctx->ctx.stats.px = px->next; |
| 5158 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5159 | } |
| 5160 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5161 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5162 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5163 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5164 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5165 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5166 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5167 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5168 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5169 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5170 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5171 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5172 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5173 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5174 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5175 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5176 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5177 | case STAT_ST_FIN: |
| 5178 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5179 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5180 | default: |
| 5181 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5182 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5183 | return -1; |
| 5184 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5185 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5186 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5187 | /* We reached the stats page through a POST request. The appctx is |
| 5188 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5189 | * Parse the posted data and enable/disable servers if necessary. |
| 5190 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5191 | */ |
| 5192 | static int stats_process_http_post(struct stream_interface *si) |
| 5193 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5194 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5195 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5196 | |
| 5197 | struct proxy *px = NULL; |
| 5198 | struct server *sv = NULL; |
| 5199 | |
| 5200 | char key[LINESIZE]; |
| 5201 | int action = ST_ADM_ACTION_NONE; |
| 5202 | int reprocess = 0; |
| 5203 | |
| 5204 | int total_servers = 0; |
| 5205 | int altered_servers = 0; |
| 5206 | |
| 5207 | char *first_param, *cur_param, *next_param, *end_params; |
| 5208 | char *st_cur_param = NULL; |
| 5209 | char *st_next_param = NULL; |
| 5210 | |
| 5211 | struct chunk *temp; |
| 5212 | int reql; |
| 5213 | |
| 5214 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5215 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5216 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5217 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5218 | goto out; |
| 5219 | } |
| 5220 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5221 | 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] | 5222 | if (reql <= 0) { |
| 5223 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5224 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5225 | return 0; |
| 5226 | } |
| 5227 | |
| 5228 | first_param = temp->str; |
| 5229 | end_params = temp->str + reql; |
| 5230 | cur_param = next_param = end_params; |
| 5231 | *end_params = '\0'; |
| 5232 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5233 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5234 | |
| 5235 | /* |
| 5236 | * Parse the parameters in reverse order to only store the last value. |
| 5237 | * From the html form, the backend and the action are at the end. |
| 5238 | */ |
| 5239 | while (cur_param > first_param) { |
| 5240 | char *value; |
| 5241 | int poffset, plen; |
| 5242 | |
| 5243 | cur_param--; |
| 5244 | |
| 5245 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5246 | reprocess_servers: |
| 5247 | /* Parse the key */ |
| 5248 | poffset = (cur_param != first_param ? 1 : 0); |
| 5249 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5250 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5251 | strncpy(key, cur_param + poffset, plen); |
| 5252 | key[plen - 1] = '\0'; |
| 5253 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5254 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5255 | goto out; |
| 5256 | } |
| 5257 | |
| 5258 | /* Parse the value */ |
| 5259 | value = key; |
| 5260 | while (*value != '\0' && *value != '=') { |
| 5261 | value++; |
| 5262 | } |
| 5263 | if (*value == '=') { |
| 5264 | /* Ok, a value is found, we can mark the end of the key */ |
| 5265 | *value++ = '\0'; |
| 5266 | } |
| 5267 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5268 | break; |
| 5269 | |
| 5270 | /* Now we can check the key to see what to do */ |
| 5271 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5272 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5273 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5274 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5275 | goto out; |
| 5276 | } |
| 5277 | } |
| 5278 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5279 | if (strcmp(value, "ready") == 0) { |
| 5280 | action = ST_ADM_ACTION_READY; |
| 5281 | } |
| 5282 | else if (strcmp(value, "drain") == 0) { |
| 5283 | action = ST_ADM_ACTION_DRAIN; |
| 5284 | } |
| 5285 | else if (strcmp(value, "maint") == 0) { |
| 5286 | action = ST_ADM_ACTION_MAINT; |
| 5287 | } |
| 5288 | else if (strcmp(value, "shutdown") == 0) { |
| 5289 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5290 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5291 | else if (strcmp(value, "dhlth") == 0) { |
| 5292 | action = ST_ADM_ACTION_DHLTH; |
| 5293 | } |
| 5294 | else if (strcmp(value, "ehlth") == 0) { |
| 5295 | action = ST_ADM_ACTION_EHLTH; |
| 5296 | } |
| 5297 | else if (strcmp(value, "hrunn") == 0) { |
| 5298 | action = ST_ADM_ACTION_HRUNN; |
| 5299 | } |
| 5300 | else if (strcmp(value, "hnolb") == 0) { |
| 5301 | action = ST_ADM_ACTION_HNOLB; |
| 5302 | } |
| 5303 | else if (strcmp(value, "hdown") == 0) { |
| 5304 | action = ST_ADM_ACTION_HDOWN; |
| 5305 | } |
| 5306 | else if (strcmp(value, "dagent") == 0) { |
| 5307 | action = ST_ADM_ACTION_DAGENT; |
| 5308 | } |
| 5309 | else if (strcmp(value, "eagent") == 0) { |
| 5310 | action = ST_ADM_ACTION_EAGENT; |
| 5311 | } |
| 5312 | else if (strcmp(value, "arunn") == 0) { |
| 5313 | action = ST_ADM_ACTION_ARUNN; |
| 5314 | } |
| 5315 | else if (strcmp(value, "adown") == 0) { |
| 5316 | action = ST_ADM_ACTION_ADOWN; |
| 5317 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5318 | /* else these are the old supported methods */ |
| 5319 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5320 | action = ST_ADM_ACTION_DISABLE; |
| 5321 | } |
| 5322 | else if (strcmp(value, "enable") == 0) { |
| 5323 | action = ST_ADM_ACTION_ENABLE; |
| 5324 | } |
| 5325 | else if (strcmp(value, "stop") == 0) { |
| 5326 | action = ST_ADM_ACTION_STOP; |
| 5327 | } |
| 5328 | else if (strcmp(value, "start") == 0) { |
| 5329 | action = ST_ADM_ACTION_START; |
| 5330 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5331 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5332 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5333 | goto out; |
| 5334 | } |
| 5335 | } |
| 5336 | else if (strcmp(key, "s") == 0) { |
| 5337 | if (!(px && action)) { |
| 5338 | /* |
| 5339 | * Indicates that we'll need to reprocess the parameters |
| 5340 | * as soon as backend and action are known |
| 5341 | */ |
| 5342 | if (!reprocess) { |
| 5343 | st_cur_param = cur_param; |
| 5344 | st_next_param = next_param; |
| 5345 | } |
| 5346 | reprocess = 1; |
| 5347 | } |
| 5348 | else if ((sv = findserver(px, value)) != NULL) { |
| 5349 | switch (action) { |
| 5350 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5351 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5352 | altered_servers++; |
| 5353 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5354 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5355 | } |
| 5356 | break; |
| 5357 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5358 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5359 | altered_servers++; |
| 5360 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5361 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5362 | } |
| 5363 | break; |
| 5364 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5365 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5366 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5367 | altered_servers++; |
| 5368 | total_servers++; |
| 5369 | } |
| 5370 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5371 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5372 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5373 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5374 | altered_servers++; |
| 5375 | total_servers++; |
| 5376 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5377 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5378 | case ST_ADM_ACTION_DHLTH: |
| 5379 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5380 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5381 | altered_servers++; |
| 5382 | total_servers++; |
| 5383 | } |
| 5384 | break; |
| 5385 | case ST_ADM_ACTION_EHLTH: |
| 5386 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5387 | sv->check.state |= CHK_ST_ENABLED; |
| 5388 | altered_servers++; |
| 5389 | total_servers++; |
| 5390 | } |
| 5391 | break; |
| 5392 | case ST_ADM_ACTION_HRUNN: |
| 5393 | if (!(sv->track)) { |
| 5394 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5395 | srv_set_running(sv, "changed from Web interface"); |
| 5396 | altered_servers++; |
| 5397 | total_servers++; |
| 5398 | } |
| 5399 | break; |
| 5400 | case ST_ADM_ACTION_HNOLB: |
| 5401 | if (!(sv->track)) { |
| 5402 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5403 | srv_set_stopping(sv, "changed from Web interface"); |
| 5404 | altered_servers++; |
| 5405 | total_servers++; |
| 5406 | } |
| 5407 | break; |
| 5408 | case ST_ADM_ACTION_HDOWN: |
| 5409 | if (!(sv->track)) { |
| 5410 | sv->check.health = 0; |
| 5411 | srv_set_stopped(sv, "changed from Web interface"); |
| 5412 | altered_servers++; |
| 5413 | total_servers++; |
| 5414 | } |
| 5415 | break; |
| 5416 | case ST_ADM_ACTION_DAGENT: |
| 5417 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5418 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5419 | altered_servers++; |
| 5420 | total_servers++; |
| 5421 | } |
| 5422 | break; |
| 5423 | case ST_ADM_ACTION_EAGENT: |
| 5424 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5425 | sv->agent.state |= CHK_ST_ENABLED; |
| 5426 | altered_servers++; |
| 5427 | total_servers++; |
| 5428 | } |
| 5429 | break; |
| 5430 | case ST_ADM_ACTION_ARUNN: |
| 5431 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5432 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5433 | srv_set_running(sv, "changed from Web interface"); |
| 5434 | altered_servers++; |
| 5435 | total_servers++; |
| 5436 | } |
| 5437 | break; |
| 5438 | case ST_ADM_ACTION_ADOWN: |
| 5439 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5440 | sv->agent.health = 0; |
| 5441 | srv_set_stopped(sv, "changed from Web interface"); |
| 5442 | altered_servers++; |
| 5443 | total_servers++; |
| 5444 | } |
| 5445 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5446 | case ST_ADM_ACTION_READY: |
| 5447 | srv_adm_set_ready(sv); |
| 5448 | altered_servers++; |
| 5449 | total_servers++; |
| 5450 | break; |
| 5451 | case ST_ADM_ACTION_DRAIN: |
| 5452 | srv_adm_set_drain(sv); |
| 5453 | altered_servers++; |
| 5454 | total_servers++; |
| 5455 | break; |
| 5456 | case ST_ADM_ACTION_MAINT: |
| 5457 | srv_adm_set_maint(sv); |
| 5458 | altered_servers++; |
| 5459 | total_servers++; |
| 5460 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5461 | case ST_ADM_ACTION_SHUTDOWN: |
| 5462 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5463 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5464 | |
| 5465 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5466 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5467 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5468 | |
| 5469 | altered_servers++; |
| 5470 | total_servers++; |
| 5471 | } |
| 5472 | break; |
| 5473 | } |
| 5474 | } else { |
| 5475 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5476 | total_servers++; |
| 5477 | } |
| 5478 | } |
| 5479 | if (reprocess && px && action) { |
| 5480 | /* Now, we know the backend and the action chosen by the user. |
| 5481 | * We can safely restart from the first server parameter |
| 5482 | * to reprocess them |
| 5483 | */ |
| 5484 | cur_param = st_cur_param; |
| 5485 | next_param = st_next_param; |
| 5486 | reprocess = 0; |
| 5487 | goto reprocess_servers; |
| 5488 | } |
| 5489 | |
| 5490 | next_param = cur_param; |
| 5491 | } |
| 5492 | } |
| 5493 | |
| 5494 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5495 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5496 | } |
| 5497 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5498 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5499 | } |
| 5500 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5501 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5502 | } |
| 5503 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5504 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5505 | } |
| 5506 | out: |
| 5507 | return 1; |
| 5508 | } |
| 5509 | |
| 5510 | |
| 5511 | static int stats_send_http_headers(struct stream_interface *si) |
| 5512 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5513 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5514 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5515 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5516 | |
| 5517 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5518 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5519 | "Cache-Control: no-cache\r\n" |
| 5520 | "Connection: close\r\n" |
| 5521 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5522 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5523 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5524 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5525 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5526 | uri->refresh); |
| 5527 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5528 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5529 | |
| 5530 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5531 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5532 | else |
| 5533 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5534 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5535 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5536 | s->logs.tv_request = now; |
| 5537 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5538 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5539 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5540 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5541 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5542 | |
| 5543 | return 1; |
| 5544 | } |
| 5545 | |
| 5546 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5547 | { |
| 5548 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5549 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5550 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5551 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5552 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5553 | /* 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] | 5554 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5555 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5556 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5557 | 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] | 5558 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5559 | } |
| 5560 | |
| 5561 | /* We don't want to land on the posted stats page because a refresh will |
| 5562 | * repost the data. We don't want this to happen on accident so we redirect |
| 5563 | * the browse to the stats page with a GET. |
| 5564 | */ |
| 5565 | chunk_printf(&trash, |
| 5566 | "HTTP/1.1 303 See Other\r\n" |
| 5567 | "Cache-Control: no-cache\r\n" |
| 5568 | "Content-Type: text/plain\r\n" |
| 5569 | "Connection: close\r\n" |
| 5570 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5571 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5572 | "\r\n", |
| 5573 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5574 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5575 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5576 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5577 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5578 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5579 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5580 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5581 | scope_txt); |
| 5582 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5583 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5584 | s->logs.tv_request = now; |
| 5585 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5586 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5587 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5588 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5589 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5590 | |
| 5591 | return 1; |
| 5592 | } |
| 5593 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5594 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5595 | * 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] | 5596 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5597 | * automatically unregisters itself once transfer is complete. |
| 5598 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5599 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5600 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5601 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5602 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5603 | struct channel *req = si_oc(si); |
| 5604 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5605 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5606 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5607 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5608 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5609 | /* check that the output is not closed */ |
| 5610 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5611 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5612 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5613 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5614 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5615 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5616 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5617 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5618 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5619 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5620 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5621 | } |
| 5622 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5623 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5624 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5625 | unsigned int data_len; |
| 5626 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5627 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5628 | |
| 5629 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5630 | /* One difficulty we're facing is that we must prevent |
| 5631 | * the input data from being automatically forwarded to |
| 5632 | * the output area. For this, we temporarily disable |
| 5633 | * forwarding on the channel. |
| 5634 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5635 | last_fwd = si_ic(si)->to_forward; |
| 5636 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5637 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5638 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5639 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5640 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5641 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5642 | } |
| 5643 | } |
| 5644 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5645 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5646 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5647 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5648 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5649 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5650 | |
| 5651 | /* Now we must either adjust or remove the chunk size. This is |
| 5652 | * not easy because the chunk size might wrap at the end of the |
| 5653 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5654 | * the size, then restore the buffer's contents. Note that we can |
| 5655 | * only do that because no forwarding is scheduled on the stats |
| 5656 | * applet. |
| 5657 | */ |
| 5658 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5659 | si_ic(si)->total -= (last_len - prev_len); |
| 5660 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5661 | |
| 5662 | if (last_len != data_len) { |
| 5663 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5664 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5665 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5666 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5667 | si_ic(si)->total += (last_len - data_len); |
| 5668 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5669 | } |
| 5670 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5671 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5672 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5673 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5674 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5675 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5676 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5677 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5678 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5679 | appctx->st0 = STAT_HTTP_DONE; |
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_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5683 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5684 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5685 | } |
| 5686 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5687 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5688 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5689 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5690 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5691 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5692 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5693 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5694 | } |
| 5695 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5696 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5697 | res->flags |= CF_READ_NULL; |
| 5698 | si_shutr(si); |
| 5699 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5700 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5701 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5702 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5703 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5704 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5705 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5706 | si_shutr(si); |
| 5707 | res->flags |= CF_READ_NULL; |
| 5708 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5709 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5710 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5711 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5712 | } |
| 5713 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5714 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5715 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5716 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5717 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5718 | return "NONE"; |
| 5719 | return conn->ctrl->name; |
| 5720 | } |
| 5721 | |
| 5722 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5723 | { |
| 5724 | static char ptr[17]; |
| 5725 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5726 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5727 | return "NONE"; |
| 5728 | |
| 5729 | if (conn->xprt == &raw_sock) |
| 5730 | return "RAW"; |
| 5731 | |
| 5732 | #ifdef USE_OPENSSL |
| 5733 | if (conn->xprt == &ssl_sock) |
| 5734 | return "SSL"; |
| 5735 | #endif |
| 5736 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5737 | return ptr; |
| 5738 | } |
| 5739 | |
| 5740 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5741 | { |
| 5742 | static char ptr[17]; |
| 5743 | |
| 5744 | if (!conn->data) |
| 5745 | return "NONE"; |
| 5746 | |
| 5747 | if (conn->data == &sess_conn_cb) |
| 5748 | return "SESS"; |
| 5749 | |
| 5750 | if (conn->data == &si_conn_cb) |
| 5751 | return "STRM"; |
| 5752 | |
| 5753 | if (conn->data == &check_conn_cb) |
| 5754 | return "CHCK"; |
| 5755 | |
| 5756 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5757 | return ptr; |
| 5758 | } |
| 5759 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5760 | /* This function dumps a complete stream state onto the stream interface's |
| 5761 | * 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] | 5762 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5763 | * 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] | 5764 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5765 | 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] | 5766 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5767 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5768 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5769 | extern const char *monthname[12]; |
| 5770 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5771 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5772 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5773 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5774 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5775 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5776 | 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] | 5777 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5778 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5779 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5780 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5781 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5782 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5783 | appctx->ctx.sess.uid = 0; |
| 5784 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5785 | return 1; |
| 5786 | } |
| 5787 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5788 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5789 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5790 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5791 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5792 | /* fall through */ |
| 5793 | |
| 5794 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5795 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5796 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5797 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5798 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5799 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5800 | 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] | 5801 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5802 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5803 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5804 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5805 | 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] | 5806 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5807 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5808 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5809 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5810 | break; |
| 5811 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5812 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5813 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5814 | default: |
| 5815 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5816 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5817 | break; |
| 5818 | } |
| 5819 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5820 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5821 | " 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] | 5822 | 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] | 5823 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5824 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5825 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5826 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5827 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5828 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5829 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5830 | if (conn) |
| 5831 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5832 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5833 | 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] | 5834 | case AF_INET: |
| 5835 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5836 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5837 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5838 | break; |
| 5839 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5840 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5841 | break; |
| 5842 | default: |
| 5843 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5844 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5845 | break; |
| 5846 | } |
| 5847 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5848 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5849 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5850 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5851 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5852 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5853 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5854 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5855 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5856 | conn = objt_conn(sess->si[1].end); |
| 5857 | if (conn) |
| 5858 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5859 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5860 | 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] | 5861 | case AF_INET: |
| 5862 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5863 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5864 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5865 | break; |
| 5866 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5867 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5868 | break; |
| 5869 | default: |
| 5870 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5871 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5872 | break; |
| 5873 | } |
| 5874 | |
| 5875 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5876 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5877 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5878 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5879 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5880 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5881 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5882 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5883 | if (conn) |
| 5884 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5885 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5886 | 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] | 5887 | case AF_INET: |
| 5888 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5889 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5890 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5891 | break; |
| 5892 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5893 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5894 | break; |
| 5895 | default: |
| 5896 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5897 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5898 | break; |
| 5899 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5900 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5901 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5902 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5903 | sess->task, |
| 5904 | sess->task->state, |
| 5905 | sess->task->nice, sess->task->calls, |
| 5906 | sess->task->expire ? |
| 5907 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5908 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5909 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5910 | task_in_rq(sess->task) ? ", running" : ""); |
| 5911 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5912 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5913 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5914 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5915 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5916 | if (sess->txn) |
| 5917 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5918 | " 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] | 5919 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5920 | 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] | 5921 | |
| 5922 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5923 | " 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] | 5924 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5925 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5926 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5927 | obj_type_name(sess->si[0].end), |
| 5928 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5929 | sess->si[0].exp ? |
| 5930 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5931 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5932 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5933 | sess->si[0].err_type); |
| 5934 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5935 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5936 | " 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] | 5937 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5938 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5939 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5940 | obj_type_name(sess->si[1].end), |
| 5941 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5942 | sess->si[1].exp ? |
| 5943 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5944 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5945 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5946 | sess->si[1].err_type); |
| 5947 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5948 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5949 | chunk_appendf(&trash, |
| 5950 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5951 | conn, |
| 5952 | get_conn_ctrl_name(conn), |
| 5953 | get_conn_xprt_name(conn), |
| 5954 | get_conn_data_name(conn), |
| 5955 | obj_type_name(conn->target), |
| 5956 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5957 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5958 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5959 | " 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] | 5960 | conn->flags, |
| 5961 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5962 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5963 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5964 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5965 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5966 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5967 | chunk_appendf(&trash, |
| 5968 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5969 | tmpctx, |
| 5970 | tmpctx->st0, |
| 5971 | tmpctx->st1, |
| 5972 | tmpctx->st2, |
| 5973 | tmpctx->applet->name); |
| 5974 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5975 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5976 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5977 | chunk_appendf(&trash, |
| 5978 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5979 | conn, |
| 5980 | get_conn_ctrl_name(conn), |
| 5981 | get_conn_xprt_name(conn), |
| 5982 | get_conn_data_name(conn), |
| 5983 | obj_type_name(conn->target), |
| 5984 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5985 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5986 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 5987 | " 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] | 5988 | conn->flags, |
| 5989 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5990 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5991 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5992 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5993 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5994 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5995 | chunk_appendf(&trash, |
| 5996 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5997 | tmpctx, |
| 5998 | tmpctx->st0, |
| 5999 | tmpctx->st1, |
| 6000 | tmpctx->st2, |
| 6001 | tmpctx->applet->name); |
| 6002 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6003 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6004 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6005 | " 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] | 6006 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6007 | &sess->req, |
| 6008 | sess->req.flags, sess->req.analysers, |
| 6009 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 6010 | sess->req.to_forward, sess->req.total, |
| 6011 | sess->req.analyse_exp ? |
| 6012 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6013 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6014 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6015 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6016 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6017 | sess->req.rex ? |
| 6018 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6019 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6020 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6021 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6022 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6023 | " 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] | 6024 | sess->req.wex ? |
| 6025 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6026 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6027 | sess->req.buf, |
| 6028 | sess->req.buf->data, sess->req.buf->o, |
| 6029 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6030 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6031 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6032 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6033 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6034 | " 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] | 6035 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6036 | &sess->res, |
| 6037 | sess->res.flags, sess->res.analysers, |
| 6038 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 6039 | sess->res.to_forward, sess->res.total, |
| 6040 | sess->res.analyse_exp ? |
| 6041 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6042 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6043 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6044 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6045 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6046 | sess->res.rex ? |
| 6047 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6048 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 6049 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6050 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6051 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 6052 | " 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] | 6053 | sess->res.wex ? |
| 6054 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6055 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6056 | sess->res.buf, |
| 6057 | sess->res.buf->data, sess->res.buf->o, |
| 6058 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 6059 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6060 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6061 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6062 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6063 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6064 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6065 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6066 | |
| 6067 | /* use other states to dump the contents */ |
| 6068 | } |
| 6069 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6070 | appctx->ctx.sess.uid = 0; |
| 6071 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6072 | return 1; |
| 6073 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6074 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 6075 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 6076 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 6077 | struct appctx *appctx = __objt_appctx(si->end); |
| 6078 | |
| 6079 | switch (appctx->st2) { |
| 6080 | case STAT_ST_INIT: |
| 6081 | /* Display the column headers. If the message cannot be sent, |
| 6082 | * quit the fucntion with returning 0. The function is called |
| 6083 | * later and restart at the state "STAT_ST_INIT". |
| 6084 | */ |
| 6085 | chunk_reset(&trash); |
| 6086 | chunk_appendf(&trash, "# id (file)\n"); |
| 6087 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6088 | si_applet_cant_put(si); |
| 6089 | return 0; |
| 6090 | } |
| 6091 | |
| 6092 | /* Now, we start the browsing of the references lists. |
| 6093 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6094 | * avalaible field of this pointer is <list>. It is used with the function |
| 6095 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 6096 | */ |
| 6097 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 6098 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6099 | |
| 6100 | appctx->st2 = STAT_ST_LIST; |
| 6101 | /* fall through */ |
| 6102 | |
| 6103 | case STAT_ST_LIST: |
| 6104 | while (appctx->ctx.tlskeys.ref) { |
| 6105 | chunk_reset(&trash); |
| 6106 | |
| 6107 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 6108 | appctx->ctx.tlskeys.ref->filename); |
| 6109 | |
| 6110 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6111 | /* let's try again later from this stream. We add ourselves into |
| 6112 | * this stream's users so that it can remove us upon termination. |
| 6113 | */ |
| 6114 | si_applet_cant_put(si); |
| 6115 | return 0; |
| 6116 | } |
| 6117 | |
| 6118 | /* get next list entry and check the end of the list */ |
| 6119 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6120 | } |
| 6121 | |
| 6122 | appctx->st2 = STAT_ST_FIN; |
| 6123 | /* fall through */ |
| 6124 | |
| 6125 | default: |
| 6126 | appctx->st2 = STAT_ST_FIN; |
| 6127 | return 1; |
| 6128 | } |
| 6129 | return 0; |
| 6130 | } |
| 6131 | #endif |
| 6132 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6133 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6134 | { |
| 6135 | struct appctx *appctx = __objt_appctx(si->end); |
| 6136 | |
| 6137 | switch (appctx->st2) { |
| 6138 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6139 | /* Display the column headers. If the message cannot be sent, |
| 6140 | * quit the fucntion with returning 0. The function is called |
| 6141 | * later and restart at the state "STAT_ST_INIT". |
| 6142 | */ |
| 6143 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 6144 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6145 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6146 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6147 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6148 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6149 | |
| 6150 | /* Now, we start the browsing of the references lists. |
| 6151 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6152 | * avalaible field of this pointer is <list>. It is used with the function |
| 6153 | * pat_list_get_next() for retruning the first avalaible entry |
| 6154 | */ |
| 6155 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6156 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6157 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6158 | appctx->st2 = STAT_ST_LIST; |
| 6159 | /* fall through */ |
| 6160 | |
| 6161 | case STAT_ST_LIST: |
| 6162 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6163 | chunk_reset(&trash); |
| 6164 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6165 | /* Build messages. If the reference is used by another category than |
| 6166 | * the listed categorie, display the information in the massage. |
| 6167 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6168 | 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] | 6169 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6170 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6171 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6172 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6173 | /* let's try again later from this stream. We add ourselves into |
| 6174 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6175 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6176 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6177 | return 0; |
| 6178 | } |
| 6179 | |
| 6180 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6181 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6182 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6183 | } |
| 6184 | |
| 6185 | appctx->st2 = STAT_ST_FIN; |
| 6186 | /* fall through */ |
| 6187 | |
| 6188 | default: |
| 6189 | appctx->st2 = STAT_ST_FIN; |
| 6190 | return 1; |
| 6191 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6192 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6193 | } |
| 6194 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6195 | static int stats_map_lookup(struct stream_interface *si) |
| 6196 | { |
| 6197 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6198 | struct sample sample; |
| 6199 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6200 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6201 | |
| 6202 | switch (appctx->st2) { |
| 6203 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6204 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6205 | 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] | 6206 | 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] | 6207 | appctx->st2 = STAT_ST_LIST; |
| 6208 | /* fall through */ |
| 6209 | |
| 6210 | case STAT_ST_LIST: |
| 6211 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6212 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6213 | /* initialise chunk to build new message */ |
| 6214 | chunk_reset(&trash); |
| 6215 | |
| 6216 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6217 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6218 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6219 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6220 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6221 | if (appctx->ctx.map.expr->pat_head->match && |
| 6222 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6223 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6224 | else |
| 6225 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6226 | |
| 6227 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6228 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6229 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6230 | break; |
| 6231 | if (match_method >= PAT_MATCH_NUM) |
| 6232 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6233 | else |
| 6234 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6235 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6236 | /* case sensitive */ |
| 6237 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6238 | chunk_appendf(&trash, ", case=insensitive"); |
| 6239 | else |
| 6240 | chunk_appendf(&trash, ", case=sensitive"); |
| 6241 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6242 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6243 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6244 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6245 | chunk_appendf(&trash, ", found=no"); |
| 6246 | else |
| 6247 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6248 | } |
| 6249 | |
| 6250 | /* Display match and match info */ |
| 6251 | else { |
| 6252 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6253 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6254 | chunk_appendf(&trash, ", found=yes"); |
| 6255 | else |
| 6256 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6257 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6258 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6259 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6260 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6261 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6262 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6263 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6264 | /* display pattern */ |
| 6265 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6266 | if (pat->ref && pat->ref->pattern) |
| 6267 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6268 | else |
| 6269 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6270 | } |
| 6271 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6272 | if (pat->ref && pat->ref->pattern) |
| 6273 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6274 | else |
| 6275 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6276 | } |
| 6277 | |
| 6278 | /* display return value */ |
| 6279 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6280 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6281 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6282 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6283 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6284 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6285 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6286 | } |
| 6287 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6288 | chunk_appendf(&trash, "\n"); |
| 6289 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6290 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6291 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6292 | /* let's try again later from this stream. We add ourselves into |
| 6293 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6294 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6295 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6296 | return 0; |
| 6297 | } |
| 6298 | |
| 6299 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6300 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6301 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6302 | } |
| 6303 | |
| 6304 | appctx->st2 = STAT_ST_FIN; |
| 6305 | /* fall through */ |
| 6306 | |
| 6307 | default: |
| 6308 | appctx->st2 = STAT_ST_FIN; |
| 6309 | free(appctx->ctx.map.chunk.str); |
| 6310 | return 1; |
| 6311 | } |
| 6312 | } |
| 6313 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6314 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6315 | { |
| 6316 | struct appctx *appctx = __objt_appctx(si->end); |
| 6317 | |
| 6318 | switch (appctx->st2) { |
| 6319 | |
| 6320 | case STAT_ST_INIT: |
| 6321 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6322 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6323 | struct pat_ref_elt *, list); |
| 6324 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6325 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6326 | appctx->st2 = STAT_ST_LIST; |
| 6327 | /* fall through */ |
| 6328 | |
| 6329 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6330 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6331 | chunk_reset(&trash); |
| 6332 | |
| 6333 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6334 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6335 | chunk_appendf(&trash, "%p %s %s\n", |
| 6336 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6337 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6338 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6339 | chunk_appendf(&trash, "%p %s\n", |
| 6340 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6341 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6342 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6343 | /* let's try again later from this stream. We add ourselves into |
| 6344 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6345 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6346 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6347 | return 0; |
| 6348 | } |
| 6349 | |
| 6350 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6351 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6352 | struct pat_ref_elt *, list); |
| 6353 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6354 | break; |
| 6355 | } |
| 6356 | |
| 6357 | appctx->st2 = STAT_ST_FIN; |
| 6358 | /* fall through */ |
| 6359 | |
| 6360 | default: |
| 6361 | appctx->st2 = STAT_ST_FIN; |
| 6362 | return 1; |
| 6363 | } |
| 6364 | } |
| 6365 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6366 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6367 | * 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] | 6368 | * to be called again, otherwise non-zero. It is designed to be called |
| 6369 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6370 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6371 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6372 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6373 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6374 | struct connection *conn; |
| 6375 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6376 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6377 | /* 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] | 6378 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6379 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6380 | if (appctx->st2 == STAT_ST_LIST) { |
| 6381 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6382 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6383 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6384 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6385 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6386 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6387 | } |
| 6388 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6389 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6390 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6391 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6392 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6393 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6394 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6395 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6396 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6397 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6398 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6399 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6400 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6401 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6402 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6403 | /* fall through */ |
| 6404 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6405 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6406 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6407 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6408 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6409 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6410 | } |
| 6411 | |
| 6412 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6413 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6414 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6415 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6416 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6417 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6418 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6419 | if (appctx->ctx.sess.target) { |
| 6420 | 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] | 6421 | goto next_sess; |
| 6422 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6423 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6424 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6425 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6426 | return 0; |
| 6427 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6428 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6429 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6430 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6431 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6432 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6433 | break; |
| 6434 | } |
| 6435 | else |
| 6436 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6437 | } |
| 6438 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6439 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6440 | "%p: proto=%s", |
| 6441 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6442 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6443 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6444 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6445 | 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] | 6446 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6447 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6448 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6449 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6450 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6451 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6452 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6453 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6454 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6455 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6456 | break; |
| 6457 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6458 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6459 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6460 | strm_li(curr_sess)->luid, |
| 6461 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6462 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6463 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6464 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6465 | break; |
| 6466 | } |
| 6467 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6468 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6469 | " ts=%02x age=%s calls=%d", |
| 6470 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6471 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6472 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6473 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6474 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6475 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6476 | curr_sess->req.flags, |
| 6477 | curr_sess->req.buf->i, |
| 6478 | curr_sess->req.analysers, |
| 6479 | curr_sess->req.rex ? |
| 6480 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6481 | TICKS_TO_MS(1000)) : ""); |
| 6482 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6483 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6484 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6485 | curr_sess->req.wex ? |
| 6486 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6487 | TICKS_TO_MS(1000)) : ""); |
| 6488 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6489 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6490 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6491 | curr_sess->req.analyse_exp ? |
| 6492 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6493 | TICKS_TO_MS(1000)) : ""); |
| 6494 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6495 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6496 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6497 | curr_sess->res.flags, |
| 6498 | curr_sess->res.buf->i, |
| 6499 | curr_sess->res.analysers, |
| 6500 | curr_sess->res.rex ? |
| 6501 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6502 | TICKS_TO_MS(1000)) : ""); |
| 6503 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6504 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6505 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6506 | curr_sess->res.wex ? |
| 6507 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6508 | TICKS_TO_MS(1000)) : ""); |
| 6509 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6510 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6511 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6512 | curr_sess->res.analyse_exp ? |
| 6513 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6514 | TICKS_TO_MS(1000)) : ""); |
| 6515 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6516 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6517 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6518 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6519 | curr_sess->si[0].state, |
| 6520 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6521 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6522 | curr_sess->si[0].exp ? |
| 6523 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6524 | TICKS_TO_MS(1000)) : ""); |
| 6525 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6526 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6527 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6528 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6529 | curr_sess->si[1].state, |
| 6530 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6531 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6532 | curr_sess->si[1].exp ? |
| 6533 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6534 | TICKS_TO_MS(1000)) : ""); |
| 6535 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6536 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6537 | " exp=%s", |
| 6538 | curr_sess->task->expire ? |
| 6539 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6540 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6541 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6542 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6543 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6544 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6545 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6546 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6547 | /* let's try again later from this stream. We add ourselves into |
| 6548 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6549 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6550 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6551 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6552 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6553 | } |
| 6554 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6555 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6556 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6557 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6558 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6559 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6560 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6561 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6562 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6563 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6564 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6565 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6566 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6567 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6568 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6569 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6570 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6571 | appctx->ctx.sess.target = NULL; |
| 6572 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6573 | return 1; |
| 6574 | } |
| 6575 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6576 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6577 | /* fall through */ |
| 6578 | |
| 6579 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6580 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6581 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6582 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6583 | } |
| 6584 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6585 | /* This is called when the stream interface is closed. For instance, upon an |
| 6586 | * 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] | 6587 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6588 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6589 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6590 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6591 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6592 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6593 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6594 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6595 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6596 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6597 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6598 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6599 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6600 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6601 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6602 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6603 | } |
| 6604 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6605 | /* This function is used to either dump tables states (when action is set |
| 6606 | * 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] | 6607 | * It returns 0 if the output buffer is full and it needs to be called |
| 6608 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6609 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6610 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6611 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6612 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6613 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6614 | struct ebmb_node *eb; |
| 6615 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6616 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6617 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6618 | |
| 6619 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6620 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6621 | * - STAT_ST_INIT : the first call |
| 6622 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6623 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6624 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6625 | * and the entry pointer points to the next entry to be dumped, |
| 6626 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6627 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6628 | * data though. |
| 6629 | */ |
| 6630 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6631 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6632 | /* 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] | 6633 | if (appctx->st2 == STAT_ST_LIST) { |
| 6634 | appctx->ctx.table.entry->ref_cnt--; |
| 6635 | 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] | 6636 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6637 | return 1; |
| 6638 | } |
| 6639 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6640 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6641 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6642 | while (appctx->st2 != STAT_ST_FIN) { |
| 6643 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6644 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6645 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6646 | if (!appctx->ctx.table.proxy) |
| 6647 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6648 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6649 | appctx->ctx.table.entry = NULL; |
| 6650 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6651 | break; |
| 6652 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6653 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6654 | if (!appctx->ctx.table.proxy || |
| 6655 | (appctx->ctx.table.target && |
| 6656 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6657 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6658 | break; |
| 6659 | } |
| 6660 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6661 | if (appctx->ctx.table.proxy->table.size) { |
| 6662 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6663 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6664 | return 0; |
| 6665 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6666 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6667 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6668 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6669 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6670 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6671 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6672 | appctx->ctx.table.entry->ref_cnt++; |
| 6673 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6674 | break; |
| 6675 | } |
| 6676 | } |
| 6677 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6678 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6679 | break; |
| 6680 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6681 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6682 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6683 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6684 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6685 | /* we're filtering on some data contents */ |
| 6686 | void *ptr; |
| 6687 | long long data; |
| 6688 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6689 | dt = appctx->ctx.table.data_type; |
| 6690 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6691 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6692 | dt); |
| 6693 | |
| 6694 | data = 0; |
| 6695 | switch (stktable_data_types[dt].std_type) { |
| 6696 | case STD_T_SINT: |
| 6697 | data = stktable_data_cast(ptr, std_t_sint); |
| 6698 | break; |
| 6699 | case STD_T_UINT: |
| 6700 | data = stktable_data_cast(ptr, std_t_uint); |
| 6701 | break; |
| 6702 | case STD_T_ULL: |
| 6703 | data = stktable_data_cast(ptr, std_t_ull); |
| 6704 | break; |
| 6705 | case STD_T_FRQP: |
| 6706 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6707 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6708 | break; |
| 6709 | } |
| 6710 | |
| 6711 | /* 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] | 6712 | if ((data < appctx->ctx.table.value && |
| 6713 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6714 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6715 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6716 | (data == appctx->ctx.table.value && |
| 6717 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6718 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6719 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6720 | (data > appctx->ctx.table.value && |
| 6721 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6722 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6723 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6724 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6725 | } |
| 6726 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6727 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6728 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6729 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6730 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6731 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6732 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6733 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6734 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6735 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6736 | struct stksess *old = appctx->ctx.table.entry; |
| 6737 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6738 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6739 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6740 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6741 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6742 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6743 | break; |
| 6744 | } |
| 6745 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6746 | |
| 6747 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6748 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6749 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6750 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6751 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6752 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6753 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6754 | break; |
| 6755 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6756 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6757 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6758 | break; |
| 6759 | } |
| 6760 | } |
| 6761 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6762 | } |
| 6763 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6764 | /* 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] | 6765 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6766 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6767 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6768 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6769 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6770 | * after the offset. The new pointer is returned. |
| 6771 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6772 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6773 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6774 | { |
| 6775 | int end; |
| 6776 | unsigned char c; |
| 6777 | |
| 6778 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6779 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6780 | return ptr; |
| 6781 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6782 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6783 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6784 | while (ptr < len && ptr < bsize) { |
| 6785 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6786 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6787 | if (out->len > end - 2) |
| 6788 | break; |
| 6789 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6790 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6791 | if (out->len > end - 3) |
| 6792 | break; |
| 6793 | out->str[out->len++] = '\\'; |
| 6794 | switch (c) { |
| 6795 | case '\t': c = 't'; break; |
| 6796 | case '\n': c = 'n'; break; |
| 6797 | case '\r': c = 'r'; break; |
| 6798 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6799 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6800 | } |
| 6801 | out->str[out->len++] = c; |
| 6802 | } else { |
| 6803 | if (out->len > end - 5) |
| 6804 | break; |
| 6805 | out->str[out->len++] = '\\'; |
| 6806 | out->str[out->len++] = 'x'; |
| 6807 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6808 | out->str[out->len++] = hextab[c & 0xF]; |
| 6809 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6810 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6811 | /* we had a line break, let's return now */ |
| 6812 | out->str[out->len++] = '\n'; |
| 6813 | *line = ptr; |
| 6814 | return ptr; |
| 6815 | } |
| 6816 | } |
| 6817 | /* we have an incomplete line, we return it as-is */ |
| 6818 | out->str[out->len++] = '\n'; |
| 6819 | return ptr; |
| 6820 | } |
| 6821 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6822 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6823 | * It returns 0 if the output buffer is full and it needs |
| 6824 | * to be called again, otherwise non-zero. |
| 6825 | */ |
| 6826 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6827 | { |
| 6828 | struct appctx *appctx = __objt_appctx(si->end); |
| 6829 | struct dns_resolvers *presolvers; |
| 6830 | struct dns_nameserver *pnameserver; |
| 6831 | |
| 6832 | chunk_reset(&trash); |
| 6833 | |
| 6834 | switch (appctx->st2) { |
| 6835 | case STAT_ST_INIT: |
| 6836 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6837 | /* fall through */ |
| 6838 | |
| 6839 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6840 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6841 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6842 | } |
| 6843 | else { |
| 6844 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6845 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6846 | continue; |
| 6847 | |
| 6848 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6849 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6850 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6851 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6852 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6853 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6854 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6855 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6856 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6857 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6858 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6859 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6860 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6861 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6862 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6863 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6864 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6865 | } |
| 6866 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6867 | } |
| 6868 | |
| 6869 | /* display response */ |
| 6870 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6871 | /* let's try again later from this session. We add ourselves into |
| 6872 | * this session's users so that it can remove us upon termination. |
| 6873 | */ |
| 6874 | si->flags |= SI_FL_WAIT_ROOM; |
| 6875 | return 0; |
| 6876 | } |
| 6877 | |
| 6878 | appctx->st2 = STAT_ST_FIN; |
| 6879 | /* fall through */ |
| 6880 | |
| 6881 | default: |
| 6882 | appctx->st2 = STAT_ST_FIN; |
| 6883 | return 1; |
| 6884 | } |
| 6885 | } |
| 6886 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6887 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6888 | * 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] | 6889 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6890 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6891 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6892 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6893 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6894 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6895 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6896 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6897 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6898 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6899 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6900 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6901 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6902 | /* the function had not been called yet, let's prepare the |
| 6903 | * buffer for a response. |
| 6904 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6905 | struct tm tm; |
| 6906 | |
| 6907 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6908 | 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] | 6909 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6910 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6911 | error_snapshot_id); |
| 6912 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6913 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6914 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6915 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6916 | return 0; |
| 6917 | } |
| 6918 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6919 | appctx->ctx.errors.px = proxy; |
| 6920 | appctx->ctx.errors.buf = 0; |
| 6921 | appctx->ctx.errors.bol = 0; |
| 6922 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6923 | } |
| 6924 | |
| 6925 | /* we have two inner loops here, one for the proxy, the other one for |
| 6926 | * the buffer. |
| 6927 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6928 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6929 | struct error_snapshot *es; |
| 6930 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6931 | if (appctx->ctx.errors.buf == 0) |
| 6932 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6933 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6934 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6935 | |
| 6936 | if (!es->when.tv_sec) |
| 6937 | goto next; |
| 6938 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6939 | if (appctx->ctx.errors.iid >= 0 && |
| 6940 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6941 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6942 | goto next; |
| 6943 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6944 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6945 | /* just print headers now */ |
| 6946 | |
| 6947 | char pn[INET6_ADDRSTRLEN]; |
| 6948 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6949 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6950 | |
| 6951 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6952 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6953 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6954 | 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] | 6955 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6956 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6957 | case AF_INET: |
| 6958 | case AF_INET6: |
| 6959 | port = get_host_port(&es->src); |
| 6960 | break; |
| 6961 | default: |
| 6962 | port = 0; |
| 6963 | } |
| 6964 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6965 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6966 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6967 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6968 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6969 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6970 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6971 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6972 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6973 | break; |
| 6974 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6975 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6976 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6977 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6978 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6979 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6980 | break; |
| 6981 | } |
| 6982 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6983 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6984 | ", server %s (#%d), event #%u\n" |
| 6985 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6986 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6987 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6988 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6989 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6990 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6991 | es->ev_id, |
| 6992 | pn, port, es->sid, es->s_flags, |
| 6993 | es->state, es->m_flags, es->t_flags, |
| 6994 | es->m_clen, es->m_blen, |
| 6995 | es->b_flags, es->b_out, es->b_tot, |
| 6996 | es->len, es->b_wrap, es->pos); |
| 6997 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6998 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6999 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7000 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7001 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7002 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7003 | appctx->ctx.errors.ptr = 0; |
| 7004 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7005 | } |
| 7006 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7007 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7008 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 7009 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7010 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7011 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7012 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7013 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 7014 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7015 | goto next; |
| 7016 | } |
| 7017 | |
| 7018 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7019 | 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] | 7020 | int newptr; |
| 7021 | int newline; |
| 7022 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7023 | newline = appctx->ctx.errors.bol; |
Willy Tarreau | f3764b7 | 2016-03-31 13:45:10 +0200 | [diff] [blame] | 7024 | 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] | 7025 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7026 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7027 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 7028 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7029 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 7030 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7031 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7032 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7033 | appctx->ctx.errors.ptr = newptr; |
| 7034 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7035 | }; |
| 7036 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 7037 | appctx->ctx.errors.bol = 0; |
| 7038 | appctx->ctx.errors.ptr = -1; |
| 7039 | appctx->ctx.errors.buf++; |
| 7040 | if (appctx->ctx.errors.buf > 1) { |
| 7041 | appctx->ctx.errors.buf = 0; |
| 7042 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7043 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 7044 | } |
| 7045 | |
| 7046 | /* dump complete */ |
| 7047 | return 1; |
| 7048 | } |
| 7049 | |
| 7050 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 7051 | * if the output buffer is full and it needs to be called again, otherwise |
| 7052 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 7053 | */ |
| 7054 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 7055 | { |
| 7056 | struct appctx *appctx = __objt_appctx(si->end); |
| 7057 | |
| 7058 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 7059 | return 1; |
| 7060 | |
| 7061 | chunk_reset(&trash); |
| 7062 | |
| 7063 | /* we have two inner loops here, one for the proxy, the other one for |
| 7064 | * the buffer. |
| 7065 | */ |
| 7066 | while (*appctx->ctx.env.var) { |
| 7067 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 7068 | |
| 7069 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 7070 | si_applet_cant_put(si); |
| 7071 | return 0; |
| 7072 | } |
| 7073 | if (appctx->st2 == STAT_ST_END) |
| 7074 | break; |
| 7075 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7076 | } |
| 7077 | |
| 7078 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7079 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7080 | } |
| 7081 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7082 | /* parse the "level" argument on the bind lines */ |
| 7083 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 7084 | { |
| 7085 | if (!*args[cur_arg + 1]) { |
| 7086 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 7087 | return ERR_ALERT | ERR_FATAL; |
| 7088 | } |
| 7089 | |
| 7090 | if (!strcmp(args[cur_arg+1], "user")) |
| 7091 | conf->level = ACCESS_LVL_USER; |
| 7092 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 7093 | conf->level = ACCESS_LVL_OPER; |
| 7094 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 7095 | conf->level = ACCESS_LVL_ADMIN; |
| 7096 | else { |
| 7097 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 7098 | args[cur_arg], args[cur_arg+1]); |
| 7099 | return ERR_ALERT | ERR_FATAL; |
| 7100 | } |
| 7101 | |
| 7102 | return 0; |
| 7103 | } |
| 7104 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7105 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7106 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7107 | .name = "<STATS>", /* used for logging */ |
| 7108 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 7109 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7110 | }; |
| 7111 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7112 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7113 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7114 | .name = "<CLI>", /* used for logging */ |
| 7115 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 7116 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7117 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 7118 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 7119 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7120 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 7121 | { 0, NULL, NULL }, |
| 7122 | }}; |
| 7123 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7124 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 7125 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 7126 | { NULL, NULL, 0 }, |
| 7127 | }}; |
| 7128 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7129 | __attribute__((constructor)) |
| 7130 | static void __dumpstats_module_init(void) |
| 7131 | { |
| 7132 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7133 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7134 | } |
| 7135 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 7136 | /* |
| 7137 | * Local variables: |
| 7138 | * c-indent-level: 8 |
| 7139 | * c-basic-offset: 8 |
| 7140 | * End: |
| 7141 | */ |