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 | |
| 134 | /* Show Info fields for CLI output. For any field added here, please add the text |
| 135 | * representation in the info_field_names array below. Please only append at the end, |
| 136 | * before the INF_TOTAL_FIELDS entry, and never insert anything in the middle |
| 137 | * nor at the beginning. |
| 138 | */ |
| 139 | enum info_field { |
| 140 | INF_NAME, |
| 141 | INF_VERSION, |
| 142 | INF_RELEASE_DATE, |
| 143 | INF_NBPROC, |
| 144 | INF_PROCESS_NUM, |
| 145 | INF_PID, |
| 146 | INF_UPTIME, |
| 147 | INF_UPTIME_SEC, |
| 148 | INF_MEMMAX_MB, |
| 149 | INF_POOL_ALLOC_MB, |
| 150 | INF_POOL_USED_MB, |
| 151 | INF_POOL_FAILED, |
| 152 | INF_ULIMIT_N, |
| 153 | INF_MAXSOCK, |
| 154 | INF_MAXCONN, |
| 155 | INF_HARD_MAXCONN, |
| 156 | INF_CURR_CONN, |
| 157 | INF_CUM_CONN, |
| 158 | INF_CUM_REQ, |
| 159 | INF_MAX_SSL_CONNS, |
| 160 | INF_CURR_SSL_CONNS, |
| 161 | INF_CUM_SSL_CONNS, |
| 162 | INF_MAXPIPES, |
| 163 | INF_PIPES_USED, |
| 164 | INF_PIPES_FREE, |
| 165 | INF_CONN_RATE, |
| 166 | INF_CONN_RATE_LIMIT, |
| 167 | INF_MAX_CONN_RATE, |
| 168 | INF_SESS_RATE, |
| 169 | INF_SESS_RATE_LIMIT, |
| 170 | INF_MAX_SESS_RATE, |
| 171 | INF_SSL_RATE, |
| 172 | INF_SSL_RATE_LIMIT, |
| 173 | INF_MAX_SSL_RATE, |
| 174 | INF_SSL_FRONTEND_KEY_RATE, |
| 175 | INF_SSL_FRONTEND_MAX_KEY_RATE, |
| 176 | INF_SSL_FRONTEND_SESSION_REUSE_PCT, |
| 177 | INF_SSL_BACKEND_KEY_RATE, |
| 178 | INF_SSL_BACKEND_MAX_KEY_RATE, |
| 179 | INF_SSL_CACHE_LOOKUPS, |
| 180 | INF_SSL_CACHE_MISSES, |
| 181 | INF_COMPRESS_BPS_IN, |
| 182 | INF_COMPRESS_BPS_OUT, |
| 183 | INF_COMPRESS_BPS_RATE_LIM, |
| 184 | INF_ZLIB_MEM_USAGE, |
| 185 | INF_MAX_ZLIB_MEM_USAGE, |
| 186 | INF_TASKS, |
| 187 | INF_RUN_QUEUE, |
| 188 | INF_IDLE_PCT, |
| 189 | INF_NODE, |
| 190 | INF_DESCRIPTION, |
| 191 | |
| 192 | /* must always be the last one */ |
| 193 | INF_TOTAL_FIELDS |
| 194 | }; |
| 195 | |
| 196 | /* These are the field names for each INF_* field position. Please pay attention |
| 197 | * to always use the exact same name except that the strings for new names must |
| 198 | * be lower case or CamelCase while the enum entries must be upper case. |
| 199 | */ |
| 200 | const char *info_field_names[INF_TOTAL_FIELDS] = { |
| 201 | [INF_NAME] = "Name", |
| 202 | [INF_VERSION] = "Version", |
| 203 | [INF_RELEASE_DATE] = "Release_date", |
| 204 | [INF_NBPROC] = "Nbproc", |
| 205 | [INF_PROCESS_NUM] = "Process_num", |
| 206 | [INF_PID] = "Pid", |
| 207 | [INF_UPTIME] = "Uptime", |
| 208 | [INF_UPTIME_SEC] = "Uptime_sec", |
| 209 | [INF_MEMMAX_MB] = "Memmax_MB", |
| 210 | [INF_POOL_ALLOC_MB] = "PoolAlloc_MB", |
| 211 | [INF_POOL_USED_MB] = "PoolUsed_MB", |
| 212 | [INF_POOL_FAILED] = "PoolFailed", |
| 213 | [INF_ULIMIT_N] = "Ulimit-n", |
| 214 | [INF_MAXSOCK] = "Maxsock", |
| 215 | [INF_MAXCONN] = "Maxconn", |
| 216 | [INF_HARD_MAXCONN] = "Hard_maxconn", |
| 217 | [INF_CURR_CONN] = "CurrConns", |
| 218 | [INF_CUM_CONN] = "CumConns", |
| 219 | [INF_CUM_REQ] = "CumReq", |
| 220 | [INF_MAX_SSL_CONNS] = "MaxSslConns", |
| 221 | [INF_CURR_SSL_CONNS] = "CurrSslConns", |
| 222 | [INF_CUM_SSL_CONNS] = "CumSslConns", |
| 223 | [INF_MAXPIPES] = "Maxpipes", |
| 224 | [INF_PIPES_USED] = "PipesUsed", |
| 225 | [INF_PIPES_FREE] = "PipesFree", |
| 226 | [INF_CONN_RATE] = "ConnRate", |
| 227 | [INF_CONN_RATE_LIMIT] = "ConnRateLimit", |
| 228 | [INF_MAX_CONN_RATE] = "MaxConnRate", |
| 229 | [INF_SESS_RATE] = "SessRate", |
| 230 | [INF_SESS_RATE_LIMIT] = "SessRateLimit", |
| 231 | [INF_MAX_SESS_RATE] = "MaxSessRate", |
| 232 | [INF_SSL_RATE] = "SslRate", |
| 233 | [INF_SSL_RATE_LIMIT] = "SslRateLimit", |
| 234 | [INF_MAX_SSL_RATE] = "MaxSslRate", |
| 235 | [INF_SSL_FRONTEND_KEY_RATE] = "SslFrontendKeyRate", |
| 236 | [INF_SSL_FRONTEND_MAX_KEY_RATE] = "SslFrontendMaxKeyRate", |
| 237 | [INF_SSL_FRONTEND_SESSION_REUSE_PCT] = "SslFrontendSessionReuse_pct", |
| 238 | [INF_SSL_BACKEND_KEY_RATE] = "SslBackendKeyRate", |
| 239 | [INF_SSL_BACKEND_MAX_KEY_RATE] = "SslBackendMaxKeyRate", |
| 240 | [INF_SSL_CACHE_LOOKUPS] = "SslCacheLookups", |
| 241 | [INF_SSL_CACHE_MISSES] = "SslCacheMisses", |
| 242 | [INF_COMPRESS_BPS_IN] = "CompressBpsIn", |
| 243 | [INF_COMPRESS_BPS_OUT] = "CompressBpsOut", |
| 244 | [INF_COMPRESS_BPS_RATE_LIM] = "CompressBpsRateLim", |
| 245 | [INF_ZLIB_MEM_USAGE] = "ZlibMemUsage", |
| 246 | [INF_MAX_ZLIB_MEM_USAGE] = "MaxZlibMemUsage", |
| 247 | [INF_TASKS] = "Tasks", |
| 248 | [INF_RUN_QUEUE] = "Run_queue", |
| 249 | [INF_IDLE_PCT] = "Idle_pct", |
| 250 | [INF_NODE] = "node", |
| 251 | [INF_DESCRIPTION] = "description", |
| 252 | }; |
| 253 | |
| 254 | /* one line of stats */ |
| 255 | static struct field info[INF_TOTAL_FIELDS]; |
| 256 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 257 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 258 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 259 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 260 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 261 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 262 | 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] | 263 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 264 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 265 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 266 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 267 | 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] | 268 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 269 | static int stats_pats_list(struct stream_interface *si); |
| 270 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 271 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 272 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 273 | static int stats_tlskeys_list(struct stream_interface *si); |
| 274 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 275 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 276 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 277 | static void dump_servers_state(struct proxy *backend, struct chunk *buf); |
| 278 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 279 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 280 | * cli_io_handler() |
| 281 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 282 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 283 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 284 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 285 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 286 | * -> stats_dump_stat_to_buffer() // "show stat" |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 287 | * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 288 | * -> stats_dump_csv_header() |
| 289 | * -> stats_dump_proxy_to_buffer() |
| 290 | * -> stats_dump_fe_stats() |
| 291 | * -> stats_dump_li_stats() |
| 292 | * -> stats_dump_sv_stats() |
| 293 | * -> stats_dump_be_stats() |
| 294 | * |
| 295 | * http_stats_io_handler() |
| 296 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 297 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 298 | * -> stats_dump_html_head() // emits the HTML headers |
| 299 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 300 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 301 | * -> stats_dump_html_px_hdr() |
| 302 | * -> stats_dump_fe_stats() |
| 303 | * -> stats_dump_li_stats() |
| 304 | * -> stats_dump_sv_stats() |
| 305 | * -> stats_dump_be_stats() |
| 306 | * -> stats_dump_html_px_end() |
| 307 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 308 | */ |
| 309 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 310 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 311 | |
| 312 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 313 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 314 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 315 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 316 | " help : this message\n" |
| 317 | " prompt : toggle interactive mode with prompt\n" |
| 318 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 319 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 320 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 321 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 322 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 323 | " show stat : report counters for each proxy and server\n" |
| 324 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 325 | " 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] | 326 | " 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] | 327 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 328 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 329 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 330 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 331 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 332 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 333 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 334 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 335 | " disable : put a server or frontend in maintenance mode\n" |
| 336 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 337 | " 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] | 338 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 339 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 340 | " add acl : add acl entry\n" |
| 341 | " del acl : delete acl entry\n" |
| 342 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 343 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 344 | " get map : reports the keys and values matching a sample for a map\n" |
| 345 | " set map : modify map entry\n" |
| 346 | " add map : add map entry\n" |
| 347 | " del map : delete map entry\n" |
| 348 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 349 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 350 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 351 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 352 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 353 | "Permission denied\n" |
| 354 | ""; |
| 355 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 356 | /* data transmission states for the stats responses */ |
| 357 | enum { |
| 358 | STAT_ST_INIT = 0, |
| 359 | STAT_ST_HEAD, |
| 360 | STAT_ST_INFO, |
| 361 | STAT_ST_LIST, |
| 362 | STAT_ST_END, |
| 363 | STAT_ST_FIN, |
| 364 | }; |
| 365 | |
| 366 | /* data transmission states for the stats responses inside a proxy */ |
| 367 | enum { |
| 368 | STAT_PX_ST_INIT = 0, |
| 369 | STAT_PX_ST_TH, |
| 370 | STAT_PX_ST_FE, |
| 371 | STAT_PX_ST_LI, |
| 372 | STAT_PX_ST_SV, |
| 373 | STAT_PX_ST_BE, |
| 374 | STAT_PX_ST_END, |
| 375 | STAT_PX_ST_FIN, |
| 376 | }; |
| 377 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 378 | extern const char *stat_status_codes[]; |
| 379 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 380 | /* allocate a new stats frontend named <name>, and return it |
| 381 | * (or NULL in case of lack of memory). |
| 382 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 383 | 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] | 384 | { |
| 385 | struct proxy *fe; |
| 386 | |
| 387 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 388 | if (!fe) |
| 389 | return NULL; |
| 390 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 391 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 392 | fe->next = proxy; |
| 393 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 394 | fe->last_change = now.tv_sec; |
| 395 | fe->id = strdup("GLOBAL"); |
| 396 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 397 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 398 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 399 | fe->conf.file = strdup(file); |
| 400 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 401 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 402 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 403 | |
| 404 | /* the stats frontend is the only one able to assign ID #0 */ |
| 405 | fe->conf.id.key = fe->uuid = 0; |
| 406 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 407 | return fe; |
| 408 | } |
| 409 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 410 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 411 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 412 | * error message into the <err> buffer which will be preallocated. The trailing |
| 413 | * '\n' must not be written. The function must be called with <args> pointing to |
| 414 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 415 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 416 | 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] | 417 | struct proxy *defpx, const char *file, int line, |
| 418 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 419 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 420 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 421 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 422 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 423 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 424 | int cur_arg; |
| 425 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 426 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 427 | 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] | 428 | return -1; |
| 429 | } |
| 430 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 431 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 432 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 433 | 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] | 434 | return -1; |
| 435 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 436 | } |
| 437 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 438 | 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] | 439 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 440 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 441 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 442 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 443 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 444 | return -1; |
| 445 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 446 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 447 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 448 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 449 | static int bind_dumped; |
| 450 | struct bind_kw *kw; |
| 451 | |
| 452 | kw = bind_find_kw(args[cur_arg]); |
| 453 | if (kw) { |
| 454 | if (!kw->parse) { |
| 455 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 456 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 457 | return -1; |
| 458 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 459 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 460 | 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] | 461 | if (err && *err) |
| 462 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 463 | else |
| 464 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 465 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 466 | return -1; |
| 467 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 468 | |
| 469 | cur_arg += 1 + kw->skip; |
| 470 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 471 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 472 | |
| 473 | if (!bind_dumped) { |
| 474 | bind_dump_kws(err); |
| 475 | indent_msg(err, 4); |
| 476 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 477 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 478 | |
| 479 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 480 | args[0], args[1], args[cur_arg], |
| 481 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 482 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 483 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 484 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 485 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 486 | l->maxconn = global.stats_fe->maxconn; |
| 487 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 488 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 489 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 490 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 491 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 492 | l->nice = -64; /* we want to boost priority for local stats */ |
| 493 | global.maxsock += l->maxconn; |
| 494 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 495 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 496 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 497 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 498 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 499 | |
| 500 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 501 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 502 | return -1; |
| 503 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 504 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 505 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 506 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 507 | return -1; |
| 508 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 509 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 510 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 511 | 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] | 512 | return -1; |
| 513 | } |
| 514 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 515 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 516 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 517 | else if (!strcmp(args[1], "maxconn")) { |
| 518 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 519 | |
| 520 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 521 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 522 | return -1; |
| 523 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 524 | |
| 525 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 526 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 527 | 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] | 528 | return -1; |
| 529 | } |
| 530 | } |
| 531 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 532 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 533 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 534 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 535 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 536 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 537 | if (!global.stats_fe) { |
| 538 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 539 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 540 | return -1; |
| 541 | } |
| 542 | } |
| 543 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 544 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 545 | unsigned int low, high; |
| 546 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 547 | if (strcmp(args[cur_arg], "all") == 0) { |
| 548 | set = 0; |
| 549 | break; |
| 550 | } |
| 551 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 552 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 553 | } |
| 554 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 555 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 556 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 557 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 558 | char *dash = strchr(args[cur_arg], '-'); |
| 559 | |
| 560 | low = high = str2uic(args[cur_arg]); |
| 561 | if (dash) |
| 562 | high = str2uic(dash + 1); |
| 563 | |
| 564 | if (high < low) { |
| 565 | unsigned int swap = low; |
| 566 | low = high; |
| 567 | high = swap; |
| 568 | } |
| 569 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 570 | if (low < 1 || high > LONGBITS) { |
| 571 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 572 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 573 | return -1; |
| 574 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 575 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 576 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 577 | } |
| 578 | else { |
| 579 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 580 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 581 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 582 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 583 | } |
| 584 | cur_arg++; |
| 585 | } |
| 586 | global.stats_fe->bind_proc = set; |
| 587 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 588 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 589 | 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] | 590 | return -1; |
| 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 595 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 596 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 597 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 598 | * 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] | 599 | */ |
| 600 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 601 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 602 | chunk_appendf(&trash, |
| 603 | "# pxname,svname," |
| 604 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 605 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 606 | "bin,bout," |
| 607 | "dreq,dresp," |
| 608 | "ereq,econ,eresp," |
| 609 | "wretr,wredis," |
| 610 | "status,weight,act,bck," |
| 611 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 612 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 613 | "rate,rate_lim,rate_max," |
| 614 | "check_status,check_code,check_duration," |
| 615 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 616 | "req_rate,req_rate_max,req_tot," |
| 617 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 618 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 619 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 620 | } |
| 621 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 622 | /* print a string of text buffer to <out>. The format is : |
| 623 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 624 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 625 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 626 | */ |
| 627 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 628 | { |
| 629 | unsigned char c; |
| 630 | int ptr = 0; |
| 631 | |
| 632 | while (buf[ptr] && ptr < bsize) { |
| 633 | c = buf[ptr]; |
| 634 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 635 | if (out->len > out->size - 1) |
| 636 | break; |
| 637 | out->str[out->len++] = c; |
| 638 | } |
| 639 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 640 | if (out->len > out->size - 2) |
| 641 | break; |
| 642 | out->str[out->len++] = '\\'; |
| 643 | switch (c) { |
| 644 | case ' ': c = ' '; break; |
| 645 | case '\t': c = 't'; break; |
| 646 | case '\n': c = 'n'; break; |
| 647 | case '\r': c = 'r'; break; |
| 648 | case '\e': c = 'e'; break; |
| 649 | case '\\': c = '\\'; break; |
| 650 | } |
| 651 | out->str[out->len++] = c; |
| 652 | } |
| 653 | else { |
| 654 | if (out->len > out->size - 4) |
| 655 | break; |
| 656 | out->str[out->len++] = '\\'; |
| 657 | out->str[out->len++] = 'x'; |
| 658 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 659 | out->str[out->len++] = hextab[c & 0xF]; |
| 660 | } |
| 661 | ptr++; |
| 662 | } |
| 663 | |
| 664 | return ptr; |
| 665 | } |
| 666 | |
| 667 | /* print a buffer in hexa. |
| 668 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 669 | */ |
| 670 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 671 | { |
| 672 | unsigned char c; |
| 673 | int ptr = 0; |
| 674 | |
| 675 | while (ptr < bsize) { |
| 676 | c = buf[ptr]; |
| 677 | |
| 678 | if (out->len > out->size - 2) |
| 679 | break; |
| 680 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 681 | out->str[out->len++] = hextab[c & 0xF]; |
| 682 | |
| 683 | ptr++; |
| 684 | } |
| 685 | return ptr; |
| 686 | } |
| 687 | |
| 688 | /* Dump the status of a table to a stream interface's |
| 689 | * read buffer. It returns 0 if the output buffer is full |
| 690 | * and needs to be called again, otherwise non-zero. |
| 691 | */ |
| 692 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 693 | struct proxy *proxy, struct proxy *target) |
| 694 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 695 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 696 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 697 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 698 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 699 | |
| 700 | /* any other information should be dumped here */ |
| 701 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 702 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 703 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 704 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 705 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 706 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 707 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 708 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 709 | |
| 710 | return 1; |
| 711 | } |
| 712 | |
| 713 | /* Dump the a table entry to a stream interface's |
| 714 | * read buffer. It returns 0 if the output buffer is full |
| 715 | * and needs to be called again, otherwise non-zero. |
| 716 | */ |
| 717 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 718 | struct proxy *proxy, struct stksess *entry) |
| 719 | { |
| 720 | int dt; |
| 721 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 722 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 723 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 724 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 725 | char addr[INET_ADDRSTRLEN]; |
| 726 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 727 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 728 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 729 | else if (proxy->table.type == SMP_T_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 730 | char addr[INET6_ADDRSTRLEN]; |
| 731 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 732 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 733 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 734 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 735 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 736 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 737 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 738 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 739 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 740 | } |
| 741 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 742 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 743 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 744 | } |
| 745 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 746 | 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] | 747 | |
| 748 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 749 | void *ptr; |
| 750 | |
| 751 | if (proxy->table.data_ofs[dt] == 0) |
| 752 | continue; |
| 753 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 754 | 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] | 755 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 756 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 757 | |
| 758 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 759 | switch (stktable_data_types[dt].std_type) { |
| 760 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 761 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 762 | break; |
| 763 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 764 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 765 | break; |
| 766 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 767 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 768 | break; |
| 769 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 770 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 771 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 772 | proxy->table.data_arg[dt].u)); |
| 773 | break; |
| 774 | } |
| 775 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 776 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 777 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 778 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 779 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 780 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 781 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 782 | |
| 783 | return 1; |
| 784 | } |
| 785 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 786 | 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] | 787 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 788 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 789 | struct appctx *appctx = __objt_appctx(si->end); |
| 790 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 791 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 792 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 793 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 794 | long long value; |
| 795 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 796 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 797 | void *ptr; |
| 798 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 799 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 800 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 801 | |
| 802 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 803 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 804 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 805 | return; |
| 806 | } |
| 807 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 808 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 809 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 810 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 811 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 812 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 813 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 814 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 815 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 816 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 817 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 818 | { |
| 819 | char *endptr; |
| 820 | unsigned long val; |
| 821 | errno = 0; |
| 822 | val = strtoul(args[4], &endptr, 10); |
| 823 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 824 | (errno != 0 && val == 0) || endptr == args[4] || |
| 825 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 826 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 827 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 828 | return; |
| 829 | } |
| 830 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 831 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 832 | break; |
| 833 | } |
| 834 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 835 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 836 | static_table_key->key = args[4]; |
| 837 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 838 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 839 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 840 | switch (action) { |
| 841 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 842 | 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] | 843 | break; |
| 844 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 845 | 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] | 846 | break; |
| 847 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 848 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 849 | break; |
| 850 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 851 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 852 | return; |
| 853 | } |
| 854 | |
| 855 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 856 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 857 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 858 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 859 | return; |
| 860 | } |
| 861 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 862 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 863 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 864 | switch (action) { |
| 865 | case STAT_CLI_O_TAB: |
| 866 | if (!ts) |
| 867 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 868 | chunk_reset(&trash); |
| 869 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 870 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 871 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 872 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 873 | |
| 874 | case STAT_CLI_O_CLR: |
| 875 | if (!ts) |
| 876 | return; |
| 877 | if (ts->ref_cnt) { |
| 878 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 879 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 880 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 881 | return; |
| 882 | } |
| 883 | stksess_kill(&px->table, ts); |
| 884 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 885 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 886 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 887 | if (ts) |
| 888 | stktable_touch(&px->table, ts, 1); |
| 889 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 890 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 891 | if (!ts) { |
| 892 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 893 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 894 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 895 | return; |
| 896 | } |
| 897 | stktable_store(&px->table, ts, 1); |
| 898 | } |
| 899 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 900 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 901 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 902 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 903 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 904 | return; |
| 905 | } |
| 906 | |
| 907 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 908 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 909 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 910 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 911 | return; |
| 912 | } |
| 913 | |
| 914 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 915 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 916 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 917 | return; |
| 918 | } |
| 919 | |
| 920 | 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] | 921 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 922 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 923 | return; |
| 924 | } |
| 925 | |
| 926 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 927 | |
| 928 | switch (stktable_data_types[data_type].std_type) { |
| 929 | case STD_T_SINT: |
| 930 | stktable_data_cast(ptr, std_t_sint) = value; |
| 931 | break; |
| 932 | case STD_T_UINT: |
| 933 | stktable_data_cast(ptr, std_t_uint) = value; |
| 934 | break; |
| 935 | case STD_T_ULL: |
| 936 | stktable_data_cast(ptr, std_t_ull) = value; |
| 937 | break; |
| 938 | case STD_T_FRQP: |
| 939 | /* We set both the current and previous values. That way |
| 940 | * the reported frequency is stable during all the period |
| 941 | * then slowly fades out. This allows external tools to |
| 942 | * push measures without having to update them too often. |
| 943 | */ |
| 944 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 945 | frqp->curr_tick = now_ms; |
| 946 | frqp->prev_ctr = 0; |
| 947 | frqp->curr_ctr = value; |
| 948 | break; |
| 949 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 950 | } |
| 951 | break; |
| 952 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 953 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 954 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 955 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 956 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 957 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 958 | } |
| 959 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 960 | 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] | 961 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 962 | struct appctx *appctx = __objt_appctx(si->end); |
| 963 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 964 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 965 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 966 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 967 | return; |
| 968 | } |
| 969 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 970 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 971 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 972 | if (appctx->ctx.table.data_type < 0) { |
| 973 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 974 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 975 | return; |
| 976 | } |
| 977 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 978 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 979 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 980 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 981 | return; |
| 982 | } |
| 983 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 984 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 985 | if (appctx->ctx.table.data_op < 0) { |
| 986 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 987 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 988 | return; |
| 989 | } |
| 990 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 991 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 992 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 993 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | } |
| 997 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 998 | 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] | 999 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1000 | struct appctx *appctx = __objt_appctx(si->end); |
| 1001 | |
| 1002 | appctx->ctx.table.data_type = -1; |
| 1003 | appctx->st2 = STAT_ST_INIT; |
| 1004 | appctx->ctx.table.target = NULL; |
| 1005 | appctx->ctx.table.proxy = NULL; |
| 1006 | appctx->ctx.table.entry = NULL; |
| 1007 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1008 | |
| 1009 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 1010 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1011 | if (!appctx->ctx.table.target) { |
| 1012 | appctx->ctx.cli.msg = "No such table\n"; |
| 1013 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1014 | return; |
| 1015 | } |
| 1016 | } |
| 1017 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1018 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1019 | goto err_args; |
| 1020 | return; |
| 1021 | } |
| 1022 | |
| 1023 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1024 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1025 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1026 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1027 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1028 | goto err_args; |
| 1029 | |
| 1030 | return; |
| 1031 | |
| 1032 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1033 | switch (action) { |
| 1034 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1035 | 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] | 1036 | break; |
| 1037 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1038 | 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] | 1039 | break; |
| 1040 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1041 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1042 | break; |
| 1043 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1044 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1045 | } |
| 1046 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1047 | /* 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] | 1048 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1049 | * level to be admin. |
| 1050 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1051 | 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] | 1052 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1053 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1054 | struct proxy *px; |
| 1055 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1056 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1057 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1058 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1059 | return NULL; |
| 1060 | } |
| 1061 | |
| 1062 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1063 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 1064 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1065 | return NULL; |
| 1066 | } |
| 1067 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 1068 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1069 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1070 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 1071 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1072 | return NULL; |
| 1073 | } |
| 1074 | return px; |
| 1075 | } |
| 1076 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1077 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 1078 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1079 | * 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] | 1080 | * the <arg> is modified to remove the '/'. |
| 1081 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1082 | 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] | 1083 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1084 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1085 | struct proxy *px; |
| 1086 | struct server *sv; |
| 1087 | char *line; |
| 1088 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1089 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1090 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1091 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1092 | return NULL; |
| 1093 | } |
| 1094 | |
| 1095 | /* split "backend/server" and make <line> point to server */ |
| 1096 | for (line = arg; *line; line++) |
| 1097 | if (*line == '/') { |
| 1098 | *line++ = '\0'; |
| 1099 | break; |
| 1100 | } |
| 1101 | |
| 1102 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1103 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1104 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1105 | return NULL; |
| 1106 | } |
| 1107 | |
| 1108 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1109 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1110 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1111 | return NULL; |
| 1112 | } |
| 1113 | |
| 1114 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1115 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 1116 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1117 | return NULL; |
| 1118 | } |
| 1119 | |
| 1120 | return sv; |
| 1121 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1122 | |
| 1123 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1124 | * each reference. The variable <getnext> must contain the current node, |
| 1125 | * <end> point to the root node. |
| 1126 | */ |
| 1127 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1128 | static inline |
| 1129 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1130 | { |
| 1131 | struct tls_keys_ref *ref = getnext; |
| 1132 | |
| 1133 | while (1) { |
| 1134 | |
| 1135 | /* Get next list entry. */ |
| 1136 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1137 | |
| 1138 | /* If the entry is the last of the list, return NULL. */ |
| 1139 | if (&ref->list == end) |
| 1140 | return NULL; |
| 1141 | |
| 1142 | return ref; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | static inline |
| 1147 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1148 | { |
| 1149 | int id; |
| 1150 | char *error; |
| 1151 | |
| 1152 | /* If the reference starts by a '#', this is numeric id. */ |
| 1153 | if (reference[0] == '#') { |
| 1154 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1155 | id = strtol(reference + 1, &error, 10); |
| 1156 | if (*error != '\0') |
| 1157 | return NULL; |
| 1158 | |
| 1159 | /* Perform the unique id lookup. */ |
| 1160 | return tlskeys_ref_lookupid(id); |
| 1161 | } |
| 1162 | |
| 1163 | /* Perform the string lookup. */ |
| 1164 | return tlskeys_ref_lookup(reference); |
| 1165 | } |
| 1166 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1167 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1168 | /* This function is used with map and acl management. It permits to browse |
| 1169 | * each reference. The variable <getnext> must contain the current node, |
| 1170 | * <end> point to the root node and the <flags> permit to filter required |
| 1171 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1172 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1173 | static inline |
| 1174 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1175 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1176 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1177 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1178 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1179 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1180 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1181 | /* Get next list entry. */ |
| 1182 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1183 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1184 | /* If the entry is the last of the list, return NULL. */ |
| 1185 | if (&ref->list == end) |
| 1186 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1187 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1188 | /* If the entry match the flag, return it. */ |
| 1189 | if (ref->flags & flags) |
| 1190 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1194 | static inline |
| 1195 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1196 | { |
| 1197 | int id; |
| 1198 | char *error; |
| 1199 | |
| 1200 | /* If the reference starts by a '#', this is numeric id. */ |
| 1201 | if (reference[0] == '#') { |
| 1202 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1203 | id = strtol(reference + 1, &error, 10); |
| 1204 | if (*error != '\0') |
| 1205 | return NULL; |
| 1206 | |
| 1207 | /* Perform the unique id lookup. */ |
| 1208 | return pat_ref_lookupid(id); |
| 1209 | } |
| 1210 | |
| 1211 | /* Perform the string lookup. */ |
| 1212 | return pat_ref_lookup(reference); |
| 1213 | } |
| 1214 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1215 | /* This function is used with map and acl management. It permits to browse |
| 1216 | * each reference. |
| 1217 | */ |
| 1218 | static inline |
| 1219 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1220 | { |
| 1221 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1222 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1223 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1224 | return NULL; |
| 1225 | return expr; |
| 1226 | } |
| 1227 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1228 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1229 | * 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] | 1230 | * 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] | 1231 | * designating the function which will have to process the request, which can |
| 1232 | * 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] | 1233 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1234 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1235 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1236 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1237 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1238 | char *args[MAX_STATS_ARGS + 1]; |
| 1239 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1240 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1241 | |
| 1242 | while (isspace((unsigned char)*line)) |
| 1243 | line++; |
| 1244 | |
| 1245 | arg = 0; |
| 1246 | args[arg] = line; |
| 1247 | |
| 1248 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1249 | if (*line == '\\') { |
| 1250 | line++; |
| 1251 | if (*line == '\0') |
| 1252 | break; |
| 1253 | } |
| 1254 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1255 | *line++ = '\0'; |
| 1256 | |
| 1257 | while (isspace((unsigned char)*line)) |
| 1258 | line++; |
| 1259 | |
| 1260 | args[++arg] = line; |
| 1261 | continue; |
| 1262 | } |
| 1263 | |
| 1264 | line++; |
| 1265 | } |
| 1266 | |
| 1267 | while (++arg <= MAX_STATS_ARGS) |
| 1268 | args[arg] = line; |
| 1269 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1270 | /* remove \ */ |
| 1271 | arg = 0; |
| 1272 | while (*args[arg] != '\0') { |
| 1273 | j = 0; |
| 1274 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1275 | if (args[arg][i] == '\\') |
| 1276 | continue; |
| 1277 | args[arg][j] = args[arg][i]; |
| 1278 | j++; |
| 1279 | } |
| 1280 | args[arg][j] = '\0'; |
| 1281 | arg++; |
| 1282 | } |
| 1283 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1284 | appctx->ctx.stats.scope_str = 0; |
| 1285 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1286 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1287 | if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1288 | if (strcmp(args[1], "backend") == 0) { |
| 1289 | appctx->st2 = STAT_ST_INIT; |
| 1290 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1291 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1292 | else if (strcmp(args[1], "env") == 0) { |
| 1293 | extern char **environ; |
| 1294 | |
| 1295 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1296 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1297 | appctx->st0 = STAT_CLI_PRINT; |
| 1298 | return 1; |
| 1299 | } |
| 1300 | appctx->ctx.env.var = environ; |
| 1301 | appctx->st2 = STAT_ST_INIT; |
| 1302 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1303 | |
| 1304 | if (*args[2]) { |
| 1305 | int len = strlen(args[2]); |
| 1306 | |
| 1307 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1308 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1309 | (*appctx->ctx.env.var)[len] == '=') |
| 1310 | break; |
| 1311 | } |
| 1312 | if (!*appctx->ctx.env.var) { |
| 1313 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1314 | appctx->st0 = STAT_CLI_PRINT; |
| 1315 | return 1; |
| 1316 | } |
| 1317 | appctx->st2 = STAT_ST_END; |
| 1318 | } |
| 1319 | } |
| 1320 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1321 | if (strcmp(args[2], "resolvers") == 0) { |
| 1322 | struct dns_resolvers *presolvers; |
| 1323 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1324 | if (*args[3]) { |
| 1325 | appctx->ctx.resolvers.ptr = NULL; |
| 1326 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1327 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1328 | appctx->ctx.resolvers.ptr = presolvers; |
| 1329 | break; |
| 1330 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1331 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1332 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1333 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1334 | appctx->st0 = STAT_CLI_PRINT; |
| 1335 | return 1; |
| 1336 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | appctx->st2 = STAT_ST_INIT; |
| 1340 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1341 | return 1; |
| 1342 | } |
| 1343 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1344 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1345 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1346 | appctx->ctx.stats.type = atoi(args[3]); |
| 1347 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1348 | } |
| 1349 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1350 | appctx->st2 = STAT_ST_INIT; |
| 1351 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1352 | } |
| 1353 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1354 | appctx->st2 = STAT_ST_INIT; |
| 1355 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1356 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1357 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
| 1358 | appctx->ctx.server_state.backend = NULL; |
| 1359 | |
| 1360 | /* check if a backend name has been provided */ |
| 1361 | if (*args[3]) { |
| 1362 | /* read server state from local file */ |
| 1363 | appctx->ctx.server_state.backend = proxy_be_by_name(args[3]); |
| 1364 | |
| 1365 | if (appctx->ctx.server_state.backend == NULL) { |
| 1366 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1367 | appctx->st0 = STAT_CLI_PRINT; |
| 1368 | return 1; |
| 1369 | } |
| 1370 | } |
| 1371 | appctx->st2 = STAT_ST_INIT; |
| 1372 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1373 | return 1; |
| 1374 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1375 | else if (strcmp(args[1], "pools") == 0) { |
| 1376 | appctx->st2 = STAT_ST_INIT; |
| 1377 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1378 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1379 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1380 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1381 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1382 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1383 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1384 | return 1; |
| 1385 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1386 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1387 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1388 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1389 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1390 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1391 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1392 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1393 | appctx->ctx.sess.pos = 0; |
| 1394 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1395 | } |
| 1396 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1397 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1398 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1399 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1400 | return 1; |
| 1401 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1402 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1403 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1404 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1405 | appctx->ctx.errors.iid = -1; |
| 1406 | appctx->ctx.errors.px = NULL; |
| 1407 | appctx->st2 = STAT_ST_INIT; |
| 1408 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1409 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1410 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1411 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1412 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1413 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1414 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1415 | appctx->st2 = STAT_ST_INIT; |
| 1416 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1417 | #else |
| 1418 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1419 | "that doesn't support specifying TLS ticket keys\n"; |
| 1420 | appctx->st0 = STAT_CLI_PRINT; |
| 1421 | #endif |
| 1422 | return 1; |
| 1423 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1424 | else if (strcmp(args[1], "map") == 0 || |
| 1425 | strcmp(args[1], "acl") == 0) { |
| 1426 | |
| 1427 | /* Set ACL or MAP flags. */ |
| 1428 | if (args[1][0] == 'm') |
| 1429 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1430 | else |
| 1431 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1432 | |
| 1433 | /* no parameter: display all map avalaible */ |
| 1434 | if (!*args[2]) { |
| 1435 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1436 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1437 | return 1; |
| 1438 | } |
| 1439 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1440 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1441 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1442 | if (!appctx->ctx.map.ref || |
| 1443 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1444 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1445 | 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] | 1446 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1447 | 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] | 1448 | appctx->st0 = STAT_CLI_PRINT; |
| 1449 | return 1; |
| 1450 | } |
| 1451 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1452 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1453 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1454 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1455 | return 0; |
| 1456 | } |
| 1457 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1458 | else if (strcmp(args[0], "clear") == 0) { |
| 1459 | if (strcmp(args[1], "counters") == 0) { |
| 1460 | struct proxy *px; |
| 1461 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1462 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1463 | int clrall = 0; |
| 1464 | |
| 1465 | if (strcmp(args[2], "all") == 0) |
| 1466 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1467 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1468 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1469 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1470 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1471 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1472 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1473 | return 1; |
| 1474 | } |
| 1475 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1476 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1477 | if (clrall) { |
| 1478 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1479 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1480 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1481 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1482 | px->be_counters.conn_max = 0; |
| 1483 | px->be_counters.p.http.rps_max = 0; |
| 1484 | px->be_counters.sps_max = 0; |
| 1485 | px->be_counters.cps_max = 0; |
| 1486 | px->be_counters.nbpend_max = 0; |
| 1487 | |
| 1488 | px->fe_counters.conn_max = 0; |
| 1489 | px->fe_counters.p.http.rps_max = 0; |
| 1490 | px->fe_counters.sps_max = 0; |
| 1491 | px->fe_counters.cps_max = 0; |
| 1492 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1493 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1494 | |
| 1495 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1496 | if (clrall) |
| 1497 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1498 | else { |
| 1499 | sv->counters.cur_sess_max = 0; |
| 1500 | sv->counters.nbpend_max = 0; |
| 1501 | sv->counters.sps_max = 0; |
| 1502 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1503 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1504 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1505 | if (li->counters) { |
| 1506 | if (clrall) |
| 1507 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1508 | else |
| 1509 | li->counters->conn_max = 0; |
| 1510 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1511 | } |
| 1512 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1513 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1514 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1515 | return 1; |
| 1516 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1517 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1518 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1519 | /* end of processing */ |
| 1520 | return 1; |
| 1521 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1522 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1523 | /* Set ACL or MAP flags. */ |
| 1524 | if (args[1][0] == 'm') |
| 1525 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1526 | else |
| 1527 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1528 | |
| 1529 | /* no parameter */ |
| 1530 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1531 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1532 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1533 | else |
| 1534 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1535 | appctx->st0 = STAT_CLI_PRINT; |
| 1536 | return 1; |
| 1537 | } |
| 1538 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1539 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1540 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1541 | if (!appctx->ctx.map.ref || |
| 1542 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1543 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1544 | 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] | 1545 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1546 | 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] | 1547 | appctx->st0 = STAT_CLI_PRINT; |
| 1548 | return 1; |
| 1549 | } |
| 1550 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1551 | /* Clear all. */ |
| 1552 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1553 | |
| 1554 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1555 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1556 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1557 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1558 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1559 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1560 | return 0; |
| 1561 | } |
| 1562 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1563 | else if (strcmp(args[0], "get") == 0) { |
| 1564 | if (strcmp(args[1], "weight") == 0) { |
| 1565 | struct proxy *px; |
| 1566 | struct server *sv; |
| 1567 | |
| 1568 | /* split "backend/server" and make <line> point to server */ |
| 1569 | for (line = args[2]; *line; line++) |
| 1570 | if (*line == '/') { |
| 1571 | *line++ = '\0'; |
| 1572 | break; |
| 1573 | } |
| 1574 | |
| 1575 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1576 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1577 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1578 | return 1; |
| 1579 | } |
| 1580 | |
| 1581 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1582 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1583 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1584 | return 1; |
| 1585 | } |
| 1586 | |
| 1587 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1588 | 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] | 1589 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1590 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1591 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1592 | return 1; |
| 1593 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1594 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1595 | /* Set flags. */ |
| 1596 | if (args[1][0] == 'm') |
| 1597 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1598 | else |
| 1599 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1600 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1601 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1602 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1603 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1604 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1605 | else |
| 1606 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1607 | appctx->st0 = STAT_CLI_PRINT; |
| 1608 | return 1; |
| 1609 | } |
| 1610 | |
| 1611 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1612 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1613 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1614 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1615 | 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] | 1616 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1617 | 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] | 1618 | appctx->st0 = STAT_CLI_PRINT; |
| 1619 | return 1; |
| 1620 | } |
| 1621 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1622 | /* copy input string. The string must be allocated because |
| 1623 | * it may be used over multiple iterations. It's released |
| 1624 | * at the end and upon abort anyway. |
| 1625 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1626 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1627 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1628 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1629 | if (!appctx->ctx.map.chunk.str) { |
| 1630 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1631 | appctx->st0 = STAT_CLI_PRINT; |
| 1632 | return 1; |
| 1633 | } |
| 1634 | |
| 1635 | /* prepare response */ |
| 1636 | appctx->st2 = STAT_ST_INIT; |
| 1637 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1638 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1639 | else { /* not "get weight" */ |
| 1640 | return 0; |
| 1641 | } |
| 1642 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1643 | else if (strcmp(args[0], "set") == 0) { |
| 1644 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1645 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1646 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1647 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1648 | sv = expect_server_admin(s, si, args[2]); |
| 1649 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1650 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1651 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1652 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1653 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1654 | appctx->ctx.cli.msg = warning; |
| 1655 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1656 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1657 | return 1; |
| 1658 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1659 | else if (strcmp(args[1], "server") == 0) { |
| 1660 | struct server *sv; |
| 1661 | const char *warning; |
| 1662 | |
| 1663 | sv = expect_server_admin(s, si, args[2]); |
| 1664 | if (!sv) |
| 1665 | return 1; |
| 1666 | |
| 1667 | if (strcmp(args[3], "weight") == 0) { |
| 1668 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1669 | if (warning) { |
| 1670 | appctx->ctx.cli.msg = warning; |
| 1671 | appctx->st0 = STAT_CLI_PRINT; |
| 1672 | } |
| 1673 | } |
| 1674 | else if (strcmp(args[3], "state") == 0) { |
| 1675 | if (strcmp(args[4], "ready") == 0) |
| 1676 | srv_adm_set_ready(sv); |
| 1677 | else if (strcmp(args[4], "drain") == 0) |
| 1678 | srv_adm_set_drain(sv); |
| 1679 | else if (strcmp(args[4], "maint") == 0) |
| 1680 | srv_adm_set_maint(sv); |
| 1681 | else { |
| 1682 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1683 | appctx->st0 = STAT_CLI_PRINT; |
| 1684 | } |
| 1685 | } |
| 1686 | else if (strcmp(args[3], "health") == 0) { |
| 1687 | if (sv->track) { |
| 1688 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1689 | appctx->st0 = STAT_CLI_PRINT; |
| 1690 | } |
| 1691 | else if (strcmp(args[4], "up") == 0) { |
| 1692 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1693 | srv_set_running(sv, "changed from CLI"); |
| 1694 | } |
| 1695 | else if (strcmp(args[4], "stopping") == 0) { |
| 1696 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1697 | srv_set_stopping(sv, "changed from CLI"); |
| 1698 | } |
| 1699 | else if (strcmp(args[4], "down") == 0) { |
| 1700 | sv->check.health = 0; |
| 1701 | srv_set_stopped(sv, "changed from CLI"); |
| 1702 | } |
| 1703 | else { |
| 1704 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1705 | appctx->st0 = STAT_CLI_PRINT; |
| 1706 | } |
| 1707 | } |
| 1708 | else if (strcmp(args[3], "agent") == 0) { |
| 1709 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1710 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1711 | appctx->st0 = STAT_CLI_PRINT; |
| 1712 | } |
| 1713 | else if (strcmp(args[4], "up") == 0) { |
| 1714 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1715 | srv_set_running(sv, "changed from CLI"); |
| 1716 | } |
| 1717 | else if (strcmp(args[4], "down") == 0) { |
| 1718 | sv->agent.health = 0; |
| 1719 | srv_set_stopped(sv, "changed from CLI"); |
| 1720 | } |
| 1721 | else { |
| 1722 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1723 | appctx->st0 = STAT_CLI_PRINT; |
| 1724 | } |
| 1725 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1726 | else if (strcmp(args[3], "addr") == 0) { |
Thierry Fournier | 09a9178 | 2016-02-24 08:25:39 +0100 | [diff] [blame] | 1727 | warning = server_parse_addr_change_request(sv, args[4], "stats command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1728 | if (warning) { |
| 1729 | appctx->ctx.cli.msg = warning; |
| 1730 | appctx->st0 = STAT_CLI_PRINT; |
| 1731 | } |
| 1732 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1733 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1734 | 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] | 1735 | appctx->st0 = STAT_CLI_PRINT; |
| 1736 | } |
| 1737 | return 1; |
| 1738 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1739 | else if (strcmp(args[1], "timeout") == 0) { |
| 1740 | if (strcmp(args[2], "cli") == 0) { |
| 1741 | unsigned timeout; |
| 1742 | const char *res; |
| 1743 | |
| 1744 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1745 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1746 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1747 | return 1; |
| 1748 | } |
| 1749 | |
| 1750 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1751 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1752 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1753 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1754 | return 1; |
| 1755 | } |
| 1756 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1757 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1758 | return 1; |
| 1759 | } |
| 1760 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1761 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1762 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1763 | return 1; |
| 1764 | } |
| 1765 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1766 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1767 | if (strcmp(args[2], "frontend") == 0) { |
| 1768 | struct proxy *px; |
| 1769 | struct listener *l; |
| 1770 | int v; |
| 1771 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1772 | px = expect_frontend_admin(s, si, args[3]); |
| 1773 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1774 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1775 | |
| 1776 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1777 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1778 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1779 | return 1; |
| 1780 | } |
| 1781 | |
| 1782 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1783 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1784 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1785 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1786 | return 1; |
| 1787 | } |
| 1788 | |
| 1789 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1790 | * its listeners. The blocked ones will be dequeued. |
| 1791 | */ |
| 1792 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1793 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1794 | l->maxconn = v; |
| 1795 | if (l->state == LI_FULL) |
| 1796 | resume_listener(l); |
| 1797 | } |
| 1798 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1799 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1800 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1801 | |
| 1802 | return 1; |
| 1803 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1804 | else if (strcmp(args[2], "server") == 0) { |
| 1805 | struct server *sv; |
| 1806 | int v; |
| 1807 | |
| 1808 | sv = expect_server_admin(s, si, args[3]); |
| 1809 | if (!sv) |
| 1810 | return 1; |
| 1811 | |
| 1812 | if (!*args[4]) { |
| 1813 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1814 | appctx->st0 = STAT_CLI_PRINT; |
| 1815 | return 1; |
| 1816 | } |
| 1817 | |
| 1818 | v = atoi(args[4]); |
| 1819 | if (v < 0) { |
| 1820 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1821 | appctx->st0 = STAT_CLI_PRINT; |
| 1822 | return 1; |
| 1823 | } |
| 1824 | |
| 1825 | if (sv->maxconn == sv->minconn) { // static maxconn |
| 1826 | sv->maxconn = sv->minconn = v; |
| 1827 | } else { // dynamic maxconn |
| 1828 | sv->maxconn = v; |
| 1829 | } |
| 1830 | |
| 1831 | if (may_dequeue_tasks(sv, sv->proxy)) |
| 1832 | process_srv_queue(sv); |
| 1833 | |
| 1834 | return 1; |
| 1835 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1836 | else if (strcmp(args[2], "global") == 0) { |
| 1837 | int v; |
| 1838 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1839 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1840 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1841 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1842 | return 1; |
| 1843 | } |
| 1844 | |
| 1845 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1846 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1847 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1848 | return 1; |
| 1849 | } |
| 1850 | |
| 1851 | v = atoi(args[3]); |
| 1852 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1853 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1854 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1855 | return 1; |
| 1856 | } |
| 1857 | |
| 1858 | /* check for unlimited values */ |
| 1859 | if (v <= 0) |
| 1860 | v = global.hardmaxconn; |
| 1861 | |
| 1862 | global.maxconn = v; |
| 1863 | |
| 1864 | /* Dequeues all of the listeners waiting for a resource */ |
| 1865 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1866 | dequeue_all_listeners(&global_listener_queue); |
| 1867 | |
| 1868 | return 1; |
| 1869 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1870 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1871 | 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] | 1872 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1873 | return 1; |
| 1874 | } |
| 1875 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1876 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 1877 | if (strcmp(args[2], "connections") == 0) { |
| 1878 | if (strcmp(args[3], "global") == 0) { |
| 1879 | int v; |
| 1880 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1881 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1882 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1883 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1884 | return 1; |
| 1885 | } |
| 1886 | |
| 1887 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1888 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1889 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1890 | return 1; |
| 1891 | } |
| 1892 | |
| 1893 | v = atoi(args[4]); |
| 1894 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1895 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1896 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1897 | return 1; |
| 1898 | } |
| 1899 | |
| 1900 | global.cps_lim = v; |
| 1901 | |
| 1902 | /* Dequeues all of the listeners waiting for a resource */ |
| 1903 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1904 | dequeue_all_listeners(&global_listener_queue); |
| 1905 | |
| 1906 | return 1; |
| 1907 | } |
| 1908 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1909 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 1910 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 1911 | return 1; |
| 1912 | } |
| 1913 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1914 | else if (strcmp(args[2], "sessions") == 0) { |
| 1915 | if (strcmp(args[3], "global") == 0) { |
| 1916 | int v; |
| 1917 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1918 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1919 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1920 | appctx->st0 = STAT_CLI_PRINT; |
| 1921 | return 1; |
| 1922 | } |
| 1923 | |
| 1924 | if (!*args[4]) { |
| 1925 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1926 | appctx->st0 = STAT_CLI_PRINT; |
| 1927 | return 1; |
| 1928 | } |
| 1929 | |
| 1930 | v = atoi(args[4]); |
| 1931 | if (v < 0) { |
| 1932 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1933 | appctx->st0 = STAT_CLI_PRINT; |
| 1934 | return 1; |
| 1935 | } |
| 1936 | |
| 1937 | global.sps_lim = v; |
| 1938 | |
| 1939 | /* Dequeues all of the listeners waiting for a resource */ |
| 1940 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1941 | dequeue_all_listeners(&global_listener_queue); |
| 1942 | |
| 1943 | return 1; |
| 1944 | } |
| 1945 | else { |
| 1946 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 1947 | appctx->st0 = STAT_CLI_PRINT; |
| 1948 | return 1; |
| 1949 | } |
| 1950 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1951 | #ifdef USE_OPENSSL |
| 1952 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 1953 | if (strcmp(args[3], "global") == 0) { |
| 1954 | int v; |
| 1955 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1956 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 1957 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1958 | appctx->st0 = STAT_CLI_PRINT; |
| 1959 | return 1; |
| 1960 | } |
| 1961 | |
| 1962 | if (!*args[4]) { |
| 1963 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1964 | appctx->st0 = STAT_CLI_PRINT; |
| 1965 | return 1; |
| 1966 | } |
| 1967 | |
| 1968 | v = atoi(args[4]); |
| 1969 | if (v < 0) { |
| 1970 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1971 | appctx->st0 = STAT_CLI_PRINT; |
| 1972 | return 1; |
| 1973 | } |
| 1974 | |
| 1975 | global.ssl_lim = v; |
| 1976 | |
| 1977 | /* Dequeues all of the listeners waiting for a resource */ |
| 1978 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 1979 | dequeue_all_listeners(&global_listener_queue); |
| 1980 | |
| 1981 | return 1; |
| 1982 | } |
| 1983 | else { |
| 1984 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 1985 | appctx->st0 = STAT_CLI_PRINT; |
| 1986 | return 1; |
| 1987 | } |
| 1988 | } |
| 1989 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 1990 | else if (strcmp(args[2], "http-compression") == 0) { |
| 1991 | if (strcmp(args[3], "global") == 0) { |
| 1992 | int v; |
| 1993 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 1994 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 1995 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1996 | appctx->st0 = STAT_CLI_PRINT; |
| 1997 | return 1; |
| 1998 | } |
| 1999 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2000 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2001 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 2002 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2003 | return 1; |
| 2004 | } |
| 2005 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2006 | v = atoi(args[4]); |
| 2007 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 2008 | } |
| 2009 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2010 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 2011 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2012 | return 1; |
| 2013 | } |
| 2014 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2015 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2016 | 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] | 2017 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2018 | return 1; |
| 2019 | } |
| 2020 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 2021 | else if (strcmp(args[1], "table") == 0) { |
| 2022 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 2023 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2024 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2025 | char *err; |
| 2026 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2027 | /* Set flags. */ |
| 2028 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2029 | |
| 2030 | /* Expect three parameters: map name, key and new value. */ |
| 2031 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 2032 | 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] | 2033 | appctx->st0 = STAT_CLI_PRINT; |
| 2034 | return 1; |
| 2035 | } |
| 2036 | |
| 2037 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2038 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2039 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2040 | 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] | 2041 | appctx->st0 = STAT_CLI_PRINT; |
| 2042 | return 1; |
| 2043 | } |
| 2044 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2045 | /* If the entry identifier start with a '#', it is considered as |
| 2046 | * pointer id |
| 2047 | */ |
| 2048 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2049 | struct pat_ref_elt *ref; |
| 2050 | long long int conv; |
| 2051 | char *error; |
| 2052 | |
| 2053 | /* Convert argument to integer value. */ |
| 2054 | conv = strtoll(&args[3][1], &error, 16); |
| 2055 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2056 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2057 | appctx->st0 = STAT_CLI_PRINT; |
| 2058 | return 1; |
| 2059 | } |
| 2060 | |
| 2061 | /* Convert and check integer to pointer. */ |
| 2062 | ref = (struct pat_ref_elt *)(long)conv; |
| 2063 | if ((long long int)(long)ref != conv) { |
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 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2070 | err = NULL; |
| 2071 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 2072 | if (err) |
| 2073 | memprintf(&err, "%s.\n", err); |
| 2074 | appctx->ctx.cli.err = err; |
| 2075 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2076 | return 1; |
| 2077 | } |
| 2078 | } |
| 2079 | else { |
| 2080 | /* Else, use the entry identifier as pattern |
| 2081 | * string, and update the value. |
| 2082 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2083 | err = NULL; |
| 2084 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 2085 | if (err) |
| 2086 | memprintf(&err, "%s.\n", err); |
| 2087 | appctx->ctx.cli.err = err; |
| 2088 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2089 | return 1; |
| 2090 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2091 | } |
| 2092 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2093 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2094 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2095 | return 1; |
| 2096 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2097 | #ifdef USE_OPENSSL |
| 2098 | else if (strcmp(args[1], "ssl") == 0) { |
| 2099 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 2100 | #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] | 2101 | char *err = NULL; |
| 2102 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 2103 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2104 | if (!*args[3]) { |
| 2105 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 2106 | appctx->st0 = STAT_CLI_PRINT; |
| 2107 | return 1; |
| 2108 | } |
| 2109 | |
| 2110 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 2111 | if (trash.len < 0) { |
| 2112 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 2113 | appctx->st0 = STAT_CLI_PRINT; |
| 2114 | return 1; |
| 2115 | } |
| 2116 | |
| 2117 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 2118 | if (err) { |
| 2119 | memprintf(&err, "%s.\n", err); |
| 2120 | appctx->ctx.cli.err = err; |
| 2121 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 2122 | } |
| 2123 | return 1; |
| 2124 | } |
| 2125 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2126 | appctx->st0 = STAT_CLI_PRINT; |
| 2127 | return 1; |
| 2128 | #else |
| 2129 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2130 | appctx->st0 = STAT_CLI_PRINT; |
| 2131 | return 1; |
| 2132 | #endif |
| 2133 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2134 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2135 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2136 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2137 | if (!*args[3] || !*args[4]) { |
| 2138 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2139 | appctx->st0 = STAT_CLI_PRINT; |
| 2140 | return 1; |
| 2141 | } |
| 2142 | |
| 2143 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2144 | if(!appctx->ctx.tlskeys.ref) { |
| 2145 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2146 | appctx->st0 = STAT_CLI_PRINT; |
| 2147 | return 1; |
| 2148 | } |
| 2149 | |
| 2150 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2151 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2152 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2153 | appctx->st0 = STAT_CLI_PRINT; |
| 2154 | return 1; |
| 2155 | } |
| 2156 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2157 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2158 | 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] | 2159 | |
| 2160 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2161 | appctx->st0 = STAT_CLI_PRINT; |
| 2162 | return 1; |
| 2163 | #else |
| 2164 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2165 | "that doesn't support specifying TLS ticket keys\n"; |
| 2166 | appctx->st0 = STAT_CLI_PRINT; |
| 2167 | return 1; |
| 2168 | #endif |
| 2169 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2170 | else { |
| 2171 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2172 | appctx->st0 = STAT_CLI_PRINT; |
| 2173 | return 1; |
| 2174 | } |
| 2175 | } |
| 2176 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2177 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2178 | return 0; |
| 2179 | } |
| 2180 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2181 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2182 | if (strcmp(args[1], "agent") == 0) { |
| 2183 | struct server *sv; |
| 2184 | |
| 2185 | sv = expect_server_admin(s, si, args[2]); |
| 2186 | if (!sv) |
| 2187 | return 1; |
| 2188 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2189 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2190 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2191 | appctx->st0 = STAT_CLI_PRINT; |
| 2192 | return 1; |
| 2193 | } |
| 2194 | |
| 2195 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2196 | return 1; |
| 2197 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2198 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2199 | struct server *sv; |
| 2200 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2201 | sv = expect_server_admin(s, si, args[2]); |
| 2202 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2203 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2204 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2205 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2206 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2207 | appctx->st0 = STAT_CLI_PRINT; |
| 2208 | return 1; |
| 2209 | } |
| 2210 | |
| 2211 | sv->check.state |= CHK_ST_ENABLED; |
| 2212 | return 1; |
| 2213 | } |
| 2214 | else if (strcmp(args[1], "server") == 0) { |
| 2215 | struct server *sv; |
| 2216 | |
| 2217 | sv = expect_server_admin(s, si, args[2]); |
| 2218 | if (!sv) |
| 2219 | return 1; |
| 2220 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2221 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2222 | return 1; |
| 2223 | } |
| 2224 | else if (strcmp(args[1], "frontend") == 0) { |
| 2225 | struct proxy *px; |
| 2226 | |
| 2227 | px = expect_frontend_admin(s, si, args[2]); |
| 2228 | if (!px) |
| 2229 | return 1; |
| 2230 | |
| 2231 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2232 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2233 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2234 | return 1; |
| 2235 | } |
| 2236 | |
| 2237 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2238 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2239 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2240 | return 1; |
| 2241 | } |
| 2242 | |
| 2243 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2244 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2245 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2246 | return 1; |
| 2247 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2248 | return 1; |
| 2249 | } |
| 2250 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2251 | 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] | 2252 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2253 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2254 | } |
| 2255 | } |
| 2256 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2257 | if (strcmp(args[1], "agent") == 0) { |
| 2258 | struct server *sv; |
| 2259 | |
| 2260 | sv = expect_server_admin(s, si, args[2]); |
| 2261 | if (!sv) |
| 2262 | return 1; |
| 2263 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2264 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2265 | return 1; |
| 2266 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2267 | else if (strcmp(args[1], "health") == 0) { |
| 2268 | struct server *sv; |
| 2269 | |
| 2270 | sv = expect_server_admin(s, si, args[2]); |
| 2271 | if (!sv) |
| 2272 | return 1; |
| 2273 | |
| 2274 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2275 | return 1; |
| 2276 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2277 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2278 | struct server *sv; |
| 2279 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2280 | sv = expect_server_admin(s, si, args[2]); |
| 2281 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2282 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2283 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2284 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2285 | return 1; |
| 2286 | } |
| 2287 | else if (strcmp(args[1], "frontend") == 0) { |
| 2288 | struct proxy *px; |
| 2289 | |
| 2290 | px = expect_frontend_admin(s, si, args[2]); |
| 2291 | if (!px) |
| 2292 | return 1; |
| 2293 | |
| 2294 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2295 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2296 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2297 | return 1; |
| 2298 | } |
| 2299 | |
| 2300 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2301 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2302 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2303 | return 1; |
| 2304 | } |
| 2305 | |
| 2306 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2307 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2308 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2309 | return 1; |
| 2310 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2311 | return 1; |
| 2312 | } |
| 2313 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2314 | 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] | 2315 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2316 | return 1; |
| 2317 | } |
| 2318 | } |
| 2319 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2320 | if (strcmp(args[1], "frontend") == 0) { |
| 2321 | struct proxy *px; |
| 2322 | |
| 2323 | px = expect_frontend_admin(s, si, args[2]); |
| 2324 | if (!px) |
| 2325 | return 1; |
| 2326 | |
| 2327 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2328 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2329 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2330 | return 1; |
| 2331 | } |
| 2332 | |
| 2333 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2334 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2335 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2336 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2337 | stop_proxy(px); |
| 2338 | return 1; |
| 2339 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2340 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2341 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2342 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2343 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2344 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2345 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2346 | return 1; |
| 2347 | } |
| 2348 | |
| 2349 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2350 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2351 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2352 | return 1; |
| 2353 | } |
| 2354 | |
| 2355 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2356 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2357 | /* first, look for the requested stream in the stream table */ |
| 2358 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2359 | if (sess == ptr) |
| 2360 | break; |
| 2361 | } |
| 2362 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2363 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2364 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2365 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2366 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2367 | return 1; |
| 2368 | } |
| 2369 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2370 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2371 | return 1; |
| 2372 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2373 | else if (strcmp(args[1], "sessions") == 0) { |
| 2374 | if (strcmp(args[2], "server") == 0) { |
| 2375 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2376 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2377 | |
| 2378 | sv = expect_server_admin(s, si, args[3]); |
| 2379 | if (!sv) |
| 2380 | return 1; |
| 2381 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2382 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2383 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2384 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2385 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2386 | |
| 2387 | return 1; |
| 2388 | } |
| 2389 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2390 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2391 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2392 | return 1; |
| 2393 | } |
| 2394 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2395 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2396 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2397 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2398 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2399 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2400 | } |
| 2401 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2402 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2403 | if (args[1][0] == 'm') |
| 2404 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2405 | else |
| 2406 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2407 | |
| 2408 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2409 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2410 | if (!*args[2] || !*args[3]) { |
| 2411 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2412 | appctx->st0 = STAT_CLI_PRINT; |
| 2413 | return 1; |
| 2414 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2415 | } |
| 2416 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2417 | else { |
| 2418 | if (!*args[2] || !*args[3]) { |
| 2419 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2420 | appctx->st0 = STAT_CLI_PRINT; |
| 2421 | return 1; |
| 2422 | } |
| 2423 | } |
| 2424 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2425 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2426 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2427 | if (!appctx->ctx.map.ref || |
| 2428 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2429 | 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] | 2430 | appctx->st0 = STAT_CLI_PRINT; |
| 2431 | return 1; |
| 2432 | } |
| 2433 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2434 | /* If the entry identifier start with a '#', it is considered as |
| 2435 | * pointer id |
| 2436 | */ |
| 2437 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2438 | struct pat_ref_elt *ref; |
| 2439 | long long int conv; |
| 2440 | char *error; |
| 2441 | |
| 2442 | /* Convert argument to integer value. */ |
| 2443 | conv = strtoll(&args[3][1], &error, 16); |
| 2444 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2445 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2446 | appctx->st0 = STAT_CLI_PRINT; |
| 2447 | return 1; |
| 2448 | } |
| 2449 | |
| 2450 | /* Convert and check integer to pointer. */ |
| 2451 | ref = (struct pat_ref_elt *)(long)conv; |
| 2452 | if ((long long int)(long)ref != conv) { |
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 | /* Try to delete the entry. */ |
| 2459 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2460 | /* The entry is not found, send message. */ |
| 2461 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2462 | appctx->st0 = STAT_CLI_PRINT; |
| 2463 | return 1; |
| 2464 | } |
| 2465 | } |
| 2466 | else { |
| 2467 | /* Else, use the entry identifier as pattern |
| 2468 | * string and try to delete the entry. |
| 2469 | */ |
| 2470 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2471 | /* The entry is not found, send message. */ |
| 2472 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2473 | appctx->st0 = STAT_CLI_PRINT; |
| 2474 | return 1; |
| 2475 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2476 | } |
| 2477 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2478 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2479 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2480 | return 1; |
| 2481 | } |
| 2482 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2483 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2484 | appctx->st0 = STAT_CLI_PRINT; |
| 2485 | return 1; |
| 2486 | } |
| 2487 | } |
| 2488 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2489 | if (strcmp(args[1], "map") == 0 || |
| 2490 | strcmp(args[1], "acl") == 0) { |
| 2491 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2492 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2493 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2494 | /* Set flags. */ |
| 2495 | if (args[1][0] == 'm') |
| 2496 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2497 | else |
| 2498 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2499 | |
| 2500 | /* If the keywork is "map", we expect three parameters, if it |
| 2501 | * is "acl", we expect only two parameters |
| 2502 | */ |
| 2503 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2504 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2505 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2506 | appctx->st0 = STAT_CLI_PRINT; |
| 2507 | return 1; |
| 2508 | } |
| 2509 | } |
| 2510 | else { |
| 2511 | if (!*args[2] || !*args[3]) { |
| 2512 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2513 | appctx->st0 = STAT_CLI_PRINT; |
| 2514 | return 1; |
| 2515 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2516 | } |
| 2517 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2518 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2519 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2520 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2521 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2522 | 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] | 2523 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2524 | 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] | 2525 | appctx->st0 = STAT_CLI_PRINT; |
| 2526 | return 1; |
| 2527 | } |
| 2528 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2529 | /* The command "add acl" is prohibited if the reference |
| 2530 | * use samples. |
| 2531 | */ |
| 2532 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2533 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2534 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2535 | "You must use the command 'add map' to add values.\n"; |
| 2536 | appctx->st0 = STAT_CLI_PRINT; |
| 2537 | return 1; |
| 2538 | } |
| 2539 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2540 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2541 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2542 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2543 | 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] | 2544 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2545 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2546 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2547 | if (err) |
| 2548 | memprintf(&err, "%s.\n", err); |
| 2549 | appctx->ctx.cli.err = err; |
| 2550 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2551 | return 1; |
| 2552 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2553 | |
| 2554 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2555 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2556 | return 1; |
| 2557 | } |
| 2558 | else { /* unknown "del" parameter */ |
| 2559 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2560 | appctx->st0 = STAT_CLI_PRINT; |
| 2561 | return 1; |
| 2562 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2563 | } |
| 2564 | 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] | 2565 | return 0; |
| 2566 | } |
| 2567 | return 1; |
| 2568 | } |
| 2569 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2570 | /* 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] | 2571 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2572 | * state machine handling requests and various responses. We read a request, |
| 2573 | * 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] | 2574 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2575 | * 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] | 2576 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2577 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2578 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2579 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2580 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2581 | struct channel *req = si_oc(si); |
| 2582 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2583 | int reql; |
| 2584 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2585 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2586 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2587 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2588 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2589 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2590 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2591 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2592 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2593 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2594 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2595 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2596 | /* Let's close for real now. We just close the request |
| 2597 | * side, the conditions below will complete if needed. |
| 2598 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2599 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2600 | break; |
| 2601 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2602 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2603 | /* ensure we have some output room left in the event we |
| 2604 | * would want to return some info right after parsing. |
| 2605 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2606 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2607 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2608 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2609 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2610 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2611 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2612 | if (reql <= 0) { /* closed or EOL not found */ |
| 2613 | if (reql == 0) |
| 2614 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2615 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2616 | continue; |
| 2617 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2618 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2619 | /* seek for a possible semi-colon. If we find one, we |
| 2620 | * replace it with an LF and skip only this part. |
| 2621 | */ |
| 2622 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2623 | if (trash.str[len] == ';') { |
| 2624 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2625 | reql = len + 1; |
| 2626 | break; |
| 2627 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2628 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2629 | /* now it is time to check that we have a full line, |
| 2630 | * remove the trailing \n and possibly \r, then cut the |
| 2631 | * line. |
| 2632 | */ |
| 2633 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2634 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2635 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2636 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2637 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2638 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2639 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2640 | len--; |
| 2641 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2642 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2643 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2644 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2645 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2646 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2647 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2648 | continue; |
| 2649 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2650 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2651 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2652 | else if (strcmp(trash.str, "help") == 0 || |
| 2653 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2654 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2655 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2656 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2657 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2658 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2659 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2660 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2661 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2662 | /* if prompt is disabled, print help on empty lines, |
| 2663 | * so that the user at least knows how to enable |
| 2664 | * prompt and find help. |
| 2665 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2666 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2667 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2671 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2672 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2673 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2674 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2675 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2676 | case STAT_CLI_PROMPT: |
| 2677 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2678 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2679 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2680 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2681 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2682 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2683 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2684 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2685 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2686 | free(appctx->ctx.cli.err); |
| 2687 | appctx->st0 = STAT_CLI_PROMPT; |
| 2688 | } |
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); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2691 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2692 | case STAT_CLI_O_BACKEND: |
| 2693 | if (stats_dump_backend_to_buffer(si)) |
| 2694 | appctx->st0 = STAT_CLI_PROMPT; |
| 2695 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2696 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2697 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2698 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2699 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2700 | case STAT_CLI_O_SERVERS_STATE: |
| 2701 | if (stats_dump_servers_state_to_buffer(si)) |
| 2702 | appctx->st0 = STAT_CLI_PROMPT; |
| 2703 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2704 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2705 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2706 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2707 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2708 | case STAT_CLI_O_RESOLVERS: |
| 2709 | if (stats_dump_resolvers_to_buffer(si)) |
| 2710 | appctx->st0 = STAT_CLI_PROMPT; |
| 2711 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2712 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2713 | if (stats_dump_sess_to_buffer(si)) |
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; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2716 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2717 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2718 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2719 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2720 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2721 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2722 | if (stats_table_request(si, appctx->st0)) |
| 2723 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2724 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2725 | case STAT_CLI_O_PATS: |
| 2726 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2727 | appctx->st0 = STAT_CLI_PROMPT; |
| 2728 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2729 | case STAT_CLI_O_PAT: |
| 2730 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2731 | appctx->st0 = STAT_CLI_PROMPT; |
| 2732 | break; |
| 2733 | case STAT_CLI_O_MLOOK: |
| 2734 | if (stats_map_lookup(si)) |
| 2735 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2736 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2737 | case STAT_CLI_O_POOLS: |
| 2738 | if (stats_dump_pools_to_buffer(si)) |
| 2739 | appctx->st0 = STAT_CLI_PROMPT; |
| 2740 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2741 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2742 | case STAT_CLI_O_TLSK: |
| 2743 | if (stats_tlskeys_list(si)) |
| 2744 | appctx->st0 = STAT_CLI_PROMPT; |
| 2745 | break; |
| 2746 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2747 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2748 | if (stats_dump_env_to_buffer(si)) |
| 2749 | appctx->st0 = STAT_CLI_PROMPT; |
| 2750 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2751 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2752 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2753 | break; |
| 2754 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2755 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2756 | /* 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] | 2757 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2758 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2759 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2760 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2761 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2762 | } |
| 2763 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2764 | /* 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] | 2765 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2766 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2767 | |
| 2768 | /* Now we close the output if one of the writers did so, |
| 2769 | * or if we're not in interactive mode and the request |
| 2770 | * buffer is empty. This still allows pipelined requests |
| 2771 | * to be sent in non-interactive mode. |
| 2772 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2773 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2774 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2775 | continue; |
| 2776 | } |
| 2777 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2778 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2779 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2780 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2781 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2782 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2783 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2784 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2785 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2786 | /* 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] | 2787 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2788 | * we forward the close to the request side so that it flows upstream to |
| 2789 | * the client. |
| 2790 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2791 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2792 | } |
| 2793 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2794 | 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] | 2795 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2796 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2797 | /* We have no more processing to do, and nothing more to send, and |
| 2798 | * the client side has closed. So we'll forward this state downstream |
| 2799 | * on the response buffer. |
| 2800 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2801 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2802 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2803 | } |
| 2804 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2805 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2806 | 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] | 2807 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2808 | 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] | 2809 | } |
| 2810 | |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame^] | 2811 | /* Emits a stats field without any surrounding element and properly encoded to |
| 2812 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 2813 | */ |
| 2814 | static int stats_emit_raw_data_field(struct chunk *out, const struct field *f) |
| 2815 | { |
| 2816 | switch (field_format(f, 0)) { |
| 2817 | case FF_EMPTY: return 1; |
| 2818 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 2819 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 2820 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 2821 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 2822 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 2823 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 2824 | } |
| 2825 | } |
| 2826 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2827 | /* This function dumps information onto the stream interface's read buffer. |
| 2828 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2829 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2830 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2831 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2832 | { |
| 2833 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2834 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2835 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2836 | #ifdef USE_OPENSSL |
| 2837 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2838 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2839 | int ssl_reuse = 0; |
| 2840 | |
| 2841 | if (ssl_key_rate < ssl_sess_rate) { |
| 2842 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2843 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2844 | } |
| 2845 | #endif |
| 2846 | |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2847 | chunk_reset(out); |
| 2848 | memset(&info, 0, sizeof(info)); |
| 2849 | |
| 2850 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
| 2851 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION); |
| 2852 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE); |
| 2853 | |
| 2854 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 2855 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 2856 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 2857 | |
| 2858 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 2859 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 2860 | |
| 2861 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 2862 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 2863 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 2864 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 2865 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 2866 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 2867 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 2868 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 2869 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 2870 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 2871 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 2872 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 2873 | #ifdef USE_OPENSSL |
| 2874 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 2875 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 2876 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 2877 | #endif |
| 2878 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 2879 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 2880 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 2881 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 2882 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 2883 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 2884 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 2885 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 2886 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 2887 | |
| 2888 | #ifdef USE_OPENSSL |
| 2889 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 2890 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 2891 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 2892 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 2893 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 2894 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 2895 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 2896 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 2897 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 2898 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 2899 | #endif |
| 2900 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 2901 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 2902 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 2903 | #ifdef USE_ZLIB |
| 2904 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 2905 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 2906 | #endif |
| 2907 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
| 2908 | info[INF_RUN_QUEUE] = mkf_u32(0, run_queue_cur); |
| 2909 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct); |
| 2910 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 2911 | if (global.desc) |
| 2912 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
| 2913 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2914 | chunk_printf(&trash, |
| 2915 | "Name: " PRODUCT_NAME "\n" |
| 2916 | "Version: " HAPROXY_VERSION "\n" |
| 2917 | "Release_date: " HAPROXY_DATE "\n" |
| 2918 | "Nbproc: %d\n" |
| 2919 | "Process_num: %d\n" |
| 2920 | "Pid: %d\n" |
| 2921 | "Uptime: %dd %dh%02dm%02ds\n" |
| 2922 | "Uptime_sec: %d\n" |
| 2923 | "Memmax_MB: %d\n" |
Willy Tarreau | 58102cf | 2015-10-28 16:24:21 +0100 | [diff] [blame] | 2924 | "PoolAlloc_MB: %d\n" |
| 2925 | "PoolUsed_MB: %d\n" |
| 2926 | "PoolFailed: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2927 | "Ulimit-n: %d\n" |
| 2928 | "Maxsock: %d\n" |
| 2929 | "Maxconn: %d\n" |
| 2930 | "Hard_maxconn: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2931 | "CurrConns: %d\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2932 | "CumConns: %d\n" |
Warren Turkal | b197d7f | 2015-01-27 15:04:16 -0800 | [diff] [blame] | 2933 | "CumReq: %u\n" |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2934 | #ifdef USE_OPENSSL |
| 2935 | "MaxSslConns: %d\n" |
| 2936 | "CurrSslConns: %d\n" |
| 2937 | "CumSslConns: %d\n" |
| 2938 | #endif |
| 2939 | "Maxpipes: %d\n" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2940 | "PipesUsed: %d\n" |
| 2941 | "PipesFree: %d\n" |
| 2942 | "ConnRate: %d\n" |
| 2943 | "ConnRateLimit: %d\n" |
| 2944 | "MaxConnRate: %d\n" |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2945 | "SessRate: %d\n" |
| 2946 | "SessRateLimit: %d\n" |
| 2947 | "MaxSessRate: %d\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2948 | #ifdef USE_OPENSSL |
| 2949 | "SslRate: %d\n" |
| 2950 | "SslRateLimit: %d\n" |
| 2951 | "MaxSslRate: %d\n" |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2952 | "SslFrontendKeyRate: %d\n" |
| 2953 | "SslFrontendMaxKeyRate: %d\n" |
| 2954 | "SslFrontendSessionReuse_pct: %d\n" |
| 2955 | "SslBackendKeyRate: %d\n" |
| 2956 | "SslBackendMaxKeyRate: %d\n" |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2957 | "SslCacheLookups: %u\n" |
| 2958 | "SslCacheMisses: %u\n" |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2959 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2960 | "CompressBpsIn: %u\n" |
| 2961 | "CompressBpsOut: %u\n" |
| 2962 | "CompressBpsRateLim: %u\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2963 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2964 | "ZlibMemUsage: %ld\n" |
| 2965 | "MaxZlibMemUsage: %ld\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2966 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2967 | "Tasks: %d\n" |
| 2968 | "Run_queue: %d\n" |
| 2969 | "Idle_pct: %d\n" |
| 2970 | "node: %s\n" |
| 2971 | "description: %s\n" |
| 2972 | "", |
| 2973 | global.nbproc, |
| 2974 | relative_pid, |
| 2975 | pid, |
| 2976 | up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60), |
| 2977 | up, |
| 2978 | global.rlimit_memmax, |
Willy Tarreau | 58102cf | 2015-10-28 16:24:21 +0100 | [diff] [blame] | 2979 | (int)(pool_total_allocated() / 1048576L), |
| 2980 | (int)(pool_total_used() / 1048576L), |
| 2981 | pool_total_failures(), |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2982 | global.rlimit_nofile, |
Willy Tarreau | 71b734c | 2014-01-28 15:19:44 +0100 | [diff] [blame] | 2983 | global.maxsock, global.maxconn, global.hardmaxconn, |
| 2984 | actconn, totalconn, global.req_count, |
| 2985 | #ifdef USE_OPENSSL |
| 2986 | global.maxsslconn, sslconns, totalsslconns, |
| 2987 | #endif |
| 2988 | global.maxpipes, pipes_used, pipes_free, |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2989 | read_freq_ctr(&global.conn_per_sec), global.cps_lim, global.cps_max, |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2990 | read_freq_ctr(&global.sess_per_sec), global.sps_lim, global.sps_max, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2991 | #ifdef USE_OPENSSL |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2992 | ssl_sess_rate, global.ssl_lim, global.ssl_max, |
| 2993 | ssl_key_rate, global.ssl_fe_keys_max, |
| 2994 | ssl_reuse, |
| 2995 | read_freq_ctr(&global.ssl_be_keys_per_sec), global.ssl_be_keys_max, |
Willy Tarreau | ce3f913 | 2014-05-28 16:47:01 +0200 | [diff] [blame] | 2996 | global.shctx_lookups, global.shctx_misses, |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2997 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2998 | read_freq_ctr(&global.comp_bps_in), read_freq_ctr(&global.comp_bps_out), |
| 2999 | global.comp_rate_lim, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3000 | #ifdef USE_ZLIB |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3001 | zlib_used_memory, global.maxzlibmem, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3002 | #endif |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 3003 | nb_tasks_cur, run_queue_cur, idle_pct, |
| 3004 | global.node, global.desc ? global.desc : "" |
| 3005 | ); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3006 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3007 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3008 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3009 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3010 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3011 | |
| 3012 | return 1; |
| 3013 | } |
| 3014 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3015 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 3016 | * These information are all the parameters which may change during HAProxy runtime. |
| 3017 | * By default, we only export to the last known server state file format. |
| 3018 | * These information can be used at next startup to recover same level of server state. |
| 3019 | */ |
| 3020 | static void dump_servers_state(struct proxy *backend, struct chunk *buf) |
| 3021 | { |
| 3022 | struct server *srv; |
| 3023 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 3024 | time_t srv_time_since_last_change; |
| 3025 | int bk_f_forced_id, srv_f_forced_id; |
| 3026 | |
| 3027 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 3028 | if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1)))) |
| 3029 | return; |
| 3030 | |
| 3031 | srv = backend->srv; |
| 3032 | |
| 3033 | while (srv) { |
| 3034 | srv_addr[0] = '\0'; |
| 3035 | srv_time_since_last_change = 0; |
| 3036 | bk_f_forced_id = 0; |
| 3037 | srv_f_forced_id = 0; |
| 3038 | |
| 3039 | switch (srv->addr.ss_family) { |
| 3040 | case AF_INET: |
| 3041 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 3042 | srv_addr, INET_ADDRSTRLEN + 1); |
| 3043 | break; |
| 3044 | case AF_INET6: |
| 3045 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 3046 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 3047 | break; |
| 3048 | } |
| 3049 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
| 3050 | bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0; |
| 3051 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 3052 | |
| 3053 | chunk_appendf(buf, |
| 3054 | "%d %s " |
| 3055 | "%d %s %s " |
| 3056 | "%d %d %d %d %ld " |
| 3057 | "%d %d %d %d %d " |
| 3058 | "%d %d" |
| 3059 | "\n", |
| 3060 | backend->uuid, backend->id, |
| 3061 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 3062 | 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] | 3063 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 3064 | bk_f_forced_id, srv_f_forced_id); |
| 3065 | |
| 3066 | srv = srv->next; |
| 3067 | } |
| 3068 | } |
| 3069 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3070 | /* Parses backend list and simply report backend names */ |
| 3071 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 3072 | { |
| 3073 | extern struct proxy *proxy; |
| 3074 | struct proxy *curproxy; |
| 3075 | |
| 3076 | chunk_reset(&trash); |
| 3077 | chunk_printf(&trash, "# name\n"); |
| 3078 | |
| 3079 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3080 | /* looking for backends only */ |
| 3081 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3082 | continue; |
| 3083 | |
| 3084 | /* we don't want to list a backend which is bound to this process */ |
| 3085 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 3086 | continue; |
| 3087 | |
| 3088 | chunk_appendf(&trash, "%s\n", curproxy->id); |
| 3089 | } |
| 3090 | |
| 3091 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3092 | si_applet_cant_put(si); |
| 3093 | return 0; |
| 3094 | } |
| 3095 | |
| 3096 | return 1; |
| 3097 | } |
| 3098 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3099 | /* Parses backend list or simply use backend name provided by the user to return |
| 3100 | * states of servers to stdout. |
| 3101 | */ |
| 3102 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 3103 | { |
| 3104 | struct appctx *appctx = __objt_appctx(si->end); |
| 3105 | extern struct proxy *proxy; |
| 3106 | struct proxy *curproxy; |
| 3107 | |
| 3108 | chunk_reset(&trash); |
| 3109 | |
| 3110 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3111 | |
| 3112 | if (appctx->ctx.server_state.backend) { |
| 3113 | dump_servers_state(appctx->ctx.server_state.backend, &trash); |
| 3114 | } |
| 3115 | else { |
| 3116 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3117 | /* servers are only in backends */ |
| 3118 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3119 | continue; |
| 3120 | |
| 3121 | dump_servers_state(curproxy, &trash); |
| 3122 | } |
| 3123 | } |
| 3124 | |
| 3125 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3126 | si_applet_cant_put(si); |
| 3127 | return 0; |
| 3128 | } |
| 3129 | |
| 3130 | return 1; |
| 3131 | } |
| 3132 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3133 | /* This function dumps memory usage information onto the stream interface's |
| 3134 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3135 | * completion. No state is used. |
| 3136 | */ |
| 3137 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3138 | { |
| 3139 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3140 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3141 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3142 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3143 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3144 | return 1; |
| 3145 | } |
| 3146 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3147 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 3148 | * the state from stream interface <si>. The caller is responsible for clearing |
| 3149 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3150 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3151 | static int stats_dump_fe_stats(struct stream_interface *si, struct proxy *px) |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3152 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3153 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3154 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3155 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3156 | if (!(px->cap & PR_CAP_FE)) |
| 3157 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3158 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3159 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_FE))) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3160 | return 0; |
| 3161 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3162 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3163 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3164 | /* name, queue */ |
| 3165 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3166 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3167 | 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] | 3168 | /* Column sub-heading for Enable or Disable server */ |
| 3169 | chunk_appendf(&trash, "<td></td>"); |
| 3170 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3171 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3172 | chunk_appendf(&trash, |
| 3173 | "<td class=ac>" |
| 3174 | "<a name=\"%s/Frontend\"></a>" |
| 3175 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3176 | "<td colspan=3></td>" |
| 3177 | "", |
| 3178 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3179 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3180 | chunk_appendf(&trash, |
| 3181 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3182 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3183 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3184 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3185 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3186 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 3187 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 3188 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3189 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3190 | if (px->mode == PR_MODE_HTTP) |
| 3191 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3192 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3193 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3194 | |
| 3195 | chunk_appendf(&trash, |
| 3196 | "</table></div></u></td>" |
| 3197 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3198 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3199 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3200 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3201 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3202 | U2H(px->fe_counters.sps_max), |
| 3203 | U2H(px->fe_counters.cps_max), |
| 3204 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3205 | |
| 3206 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3207 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3208 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3209 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3210 | |
| 3211 | chunk_appendf(&trash, |
| 3212 | "</table></div></u></td>" |
| 3213 | /* sessions rate : limit */ |
| 3214 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3215 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3216 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3217 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3218 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3219 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3220 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3221 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3222 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3223 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3224 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 3225 | U2H(px->fe_counters.cum_sess), |
| 3226 | U2H(px->fe_counters.cum_conn), |
| 3227 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3228 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3229 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3230 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3231 | chunk_appendf(&trash, |
| 3232 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3233 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3234 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3235 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3236 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3237 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3238 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3239 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3240 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3241 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3242 | U2H(px->fe_counters.p.http.cum_req), |
| 3243 | U2H(px->fe_counters.p.http.rsp[1]), |
| 3244 | U2H(px->fe_counters.p.http.rsp[2]), |
| 3245 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3246 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3247 | (int)(100*px->fe_counters.p.http.comp_rsp/px->fe_counters.p.http.rsp[2]) : 0, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3248 | U2H(px->fe_counters.p.http.rsp[3]), |
| 3249 | U2H(px->fe_counters.p.http.rsp[4]), |
| 3250 | U2H(px->fe_counters.p.http.rsp[5]), |
| 3251 | U2H(px->fe_counters.p.http.rsp[0]), |
| 3252 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3253 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3254 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3255 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3256 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3257 | /* sessions: lbtot, lastsess */ |
| 3258 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3259 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3260 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3261 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3262 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3263 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3264 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3265 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3266 | "<td>%s%s<div class=tips><table class=det>" |
| 3267 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3268 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3269 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3270 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3271 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3272 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3273 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3274 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3275 | U2H(px->fe_counters.bytes_out), |
| 3276 | U2H(px->fe_counters.comp_in), |
| 3277 | U2H(px->fe_counters.comp_out), |
| 3278 | px->fe_counters.comp_in ? (int)(px->fe_counters.comp_out * 100 / px->fe_counters.comp_in) : 0, |
| 3279 | U2H(px->fe_counters.comp_byp), |
| 3280 | U2H(px->fe_counters.comp_in - px->fe_counters.comp_out), |
| 3281 | px->fe_counters.bytes_out ? (int)((px->fe_counters.comp_in - px->fe_counters.comp_out) * 100 / px->fe_counters.bytes_out) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3282 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3283 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3284 | chunk_appendf(&trash, |
| 3285 | /* denied: req, resp */ |
| 3286 | "<td>%s</td><td>%s</td>" |
| 3287 | /* errors : request, connect, response */ |
| 3288 | "<td>%s</td><td></td><td></td>" |
| 3289 | /* warnings: retries, redispatches */ |
| 3290 | "<td></td><td></td>" |
| 3291 | /* server status : reflect frontend status */ |
| 3292 | "<td class=ac>%s</td>" |
| 3293 | /* rest of server: nothing */ |
| 3294 | "<td class=ac colspan=8></td></tr>" |
| 3295 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3296 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 3297 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3298 | px->state == PR_STREADY ? "OPEN" : |
| 3299 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3300 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3301 | else { /* CSV mode */ |
| 3302 | chunk_appendf(&trash, |
| 3303 | /* pxid, name, queue cur, queue max, */ |
| 3304 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3305 | /* sessions : current, max, limit, total */ |
| 3306 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3307 | /* bytes : in, out */ |
| 3308 | "%lld,%lld," |
| 3309 | /* denied: req, resp */ |
| 3310 | "%lld,%lld," |
| 3311 | /* errors : request, connect, response */ |
| 3312 | "%lld,,," |
| 3313 | /* warnings: retries, redispatches */ |
| 3314 | ",," |
| 3315 | /* server status : reflect frontend status */ |
| 3316 | "%s," |
| 3317 | /* rest of server: nothing */ |
| 3318 | ",,,,,,,," |
| 3319 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3320 | "%d,%d,0,,,,%d," |
| 3321 | /* rate, rate_lim, rate_max */ |
| 3322 | "%u,%u,%u," |
| 3323 | /* check_status, check_code, check_duration */ |
| 3324 | ",,,", |
| 3325 | px->id, |
| 3326 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 3327 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 3328 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 3329 | px->fe_counters.failed_req, |
| 3330 | px->state == PR_STREADY ? "OPEN" : |
| 3331 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 3332 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 3333 | read_freq_ctr(&px->fe_sess_per_sec), |
| 3334 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3335 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3336 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3337 | if (px->mode == PR_MODE_HTTP) { |
| 3338 | for (i=1; i<6; i++) |
| 3339 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 3340 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 3341 | } |
| 3342 | else |
| 3343 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3344 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3345 | /* failed health analyses */ |
| 3346 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3347 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3348 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3349 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 3350 | read_freq_ctr(&px->fe_req_per_sec), |
| 3351 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 3352 | |
| 3353 | /* errors: cli_aborts, srv_aborts */ |
| 3354 | chunk_appendf(&trash, ",,"); |
| 3355 | |
| 3356 | /* compression: in, out, bypassed */ |
| 3357 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3358 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 3359 | |
| 3360 | /* compression: comp_rsp */ |
| 3361 | chunk_appendf(&trash, "%lld,", |
| 3362 | px->fe_counters.p.http.comp_rsp); |
| 3363 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3364 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3365 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3366 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3367 | /* finish with EOL */ |
| 3368 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3369 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3370 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3371 | } |
| 3372 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 3374 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 3375 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 3376 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3377 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3378 | static int stats_dump_li_stats(struct stream_interface *si, struct proxy *px, struct listener *l, int flags) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3379 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3380 | struct appctx *appctx = __objt_appctx(si->end); |
| 3381 | |
| 3382 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3383 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3384 | 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] | 3385 | /* Column sub-heading for Enable or Disable server */ |
| 3386 | chunk_appendf(&trash, "<td></td>"); |
| 3387 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3388 | chunk_appendf(&trash, |
| 3389 | /* frontend name, listener name */ |
| 3390 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3391 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3392 | "", |
| 3393 | px->id, l->name, |
| 3394 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3395 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3396 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3397 | if (flags & ST_SHLGNDS) { |
| 3398 | char str[INET6_ADDRSTRLEN]; |
| 3399 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3400 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3401 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3402 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3403 | port = get_host_port(&l->addr); |
| 3404 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 3405 | case AF_INET: |
| 3406 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 3407 | break; |
| 3408 | case AF_INET6: |
| 3409 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 3410 | break; |
| 3411 | case AF_UNIX: |
| 3412 | chunk_appendf(&trash, "unix, "); |
| 3413 | break; |
| 3414 | case -1: |
| 3415 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3416 | break; |
| 3417 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3418 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3419 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3420 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3421 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3422 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3423 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3424 | /* queue */ |
| 3425 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3426 | /* sessions rate: current, max, limit */ |
| 3427 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3428 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3429 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3430 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3431 | /* bytes: in, out */ |
| 3432 | "<td>%s</td><td>%s</td>" |
| 3433 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3434 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3435 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 3436 | U2H(l->counters->cum_conn), U2H(l->counters->bytes_in), U2H(l->counters->bytes_out)); |
Willy Tarreau | 56a560a | 2009-09-22 19:27:35 +0200 | [diff] [blame] | 3437 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3438 | chunk_appendf(&trash, |
| 3439 | /* denied: req, resp */ |
| 3440 | "<td>%s</td><td>%s</td>" |
| 3441 | /* errors: request, connect, response */ |
| 3442 | "<td>%s</td><td></td><td></td>" |
| 3443 | /* warnings: retries, redispatches */ |
| 3444 | "<td></td><td></td>" |
| 3445 | /* server status: reflect listener status */ |
| 3446 | "<td class=ac>%s</td>" |
| 3447 | /* rest of server: nothing */ |
| 3448 | "<td class=ac colspan=8></td></tr>" |
| 3449 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3450 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 3451 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3452 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 3453 | } |
| 3454 | else { /* CSV mode */ |
| 3455 | chunk_appendf(&trash, |
| 3456 | /* pxid, name, queue cur, queue max, */ |
| 3457 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3458 | /* sessions: current, max, limit, total */ |
| 3459 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3460 | /* bytes: in, out */ |
| 3461 | "%lld,%lld," |
| 3462 | /* denied: req, resp */ |
| 3463 | "%lld,%lld," |
| 3464 | /* errors: request, connect, response */ |
| 3465 | "%lld,,," |
| 3466 | /* warnings: retries, redispatches */ |
| 3467 | ",," |
| 3468 | /* server status: reflect listener status */ |
| 3469 | "%s," |
| 3470 | /* rest of server: nothing */ |
| 3471 | ",,,,,,,," |
| 3472 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3473 | "%d,%d,%d,,,,%d," |
| 3474 | /* rate, rate_lim, rate_max */ |
| 3475 | ",,," |
| 3476 | /* check_status, check_code, check_duration */ |
| 3477 | ",,," |
| 3478 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3479 | ",,,,,," |
| 3480 | /* failed health analyses */ |
| 3481 | "," |
| 3482 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3483 | ",,," |
| 3484 | /* errors: cli_aborts, srv_aborts */ |
| 3485 | ",," |
| 3486 | /* compression: in, out, bypassed, comp_rsp */ |
| 3487 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3488 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3489 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3490 | "\n", |
| 3491 | px->id, l->name, |
| 3492 | l->nbconn, l->counters->conn_max, |
| 3493 | l->maxconn, l->counters->cum_conn, |
| 3494 | l->counters->bytes_in, l->counters->bytes_out, |
| 3495 | l->counters->denied_req, l->counters->denied_resp, |
| 3496 | l->counters->failed_req, |
| 3497 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 3498 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 3499 | } |
| 3500 | return 1; |
| 3501 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3502 | |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3503 | enum srv_stats_state { |
| 3504 | SRV_STATS_STATE_DOWN = 0, |
| 3505 | SRV_STATS_STATE_DOWN_AGENT, |
| 3506 | SRV_STATS_STATE_GOING_UP, |
| 3507 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 3508 | SRV_STATS_STATE_UP, |
| 3509 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 3510 | SRV_STATS_STATE_NOLB, |
| 3511 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 3512 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3513 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3514 | SRV_STATS_STATE_NO_CHECK, |
| 3515 | |
| 3516 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 3517 | }; |
| 3518 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3519 | enum srv_stats_colour { |
| 3520 | SRV_STATS_COLOUR_DOWN = 0, |
| 3521 | SRV_STATS_COLOUR_GOING_UP, |
| 3522 | SRV_STATS_COLOUR_GOING_DOWN, |
| 3523 | SRV_STATS_COLOUR_UP, |
| 3524 | SRV_STATS_COLOUR_NOLB, |
| 3525 | SRV_STATS_COLOUR_DRAINING, |
| 3526 | SRV_STATS_COLOUR_NO_CHECK, |
| 3527 | |
| 3528 | SRV_STATS_COLOUR_COUNT, /* Must be last */ |
| 3529 | }; |
| 3530 | |
| 3531 | static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = { |
| 3532 | [SRV_STATS_COLOUR_DOWN] = "down", |
| 3533 | [SRV_STATS_COLOUR_GOING_UP] = "going_up", |
| 3534 | [SRV_STATS_COLOUR_GOING_DOWN] = "going_down", |
| 3535 | [SRV_STATS_COLOUR_UP] = "up", |
| 3536 | [SRV_STATS_COLOUR_NOLB] = "nolb", |
| 3537 | [SRV_STATS_COLOUR_DRAINING] = "draining", |
| 3538 | [SRV_STATS_COLOUR_NO_CHECK] = "no_check", |
| 3539 | }; |
| 3540 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3541 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 3542 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 3543 | * The caller is responsible for clearing the trash if needed. Returns non-zero |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3544 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3545 | */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3546 | static int stats_dump_sv_stats(struct stream_interface *si, struct proxy *px, int flags, struct server *sv, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3547 | enum srv_stats_state state, enum srv_stats_colour colour) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3548 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3549 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3550 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3551 | char str[INET6_ADDRSTRLEN]; |
| 3552 | struct chunk src; |
| 3553 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3554 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3555 | /* we have "via" which is the tracked server as described in the configuration, |
| 3556 | * and "ref" which is the checked server and the end of the chain. |
| 3557 | */ |
| 3558 | via = sv->track ? sv->track : sv; |
| 3559 | ref = via; |
| 3560 | while (ref->track) |
| 3561 | ref = ref->track; |
| 3562 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3563 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3564 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3565 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 3566 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 3567 | [SRV_STATS_STATE_GOING_UP] = "DN %d/%d ↑", |
| 3568 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d ↓", |
| 3569 | [SRV_STATS_STATE_UP] = "UP", |
| 3570 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d ↓", |
| 3571 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 3572 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d ↓", |
| 3573 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3574 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3575 | [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3576 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3577 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3578 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3579 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 3580 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3581 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3582 | "<tr class=\"%s_%s\">", |
| 3583 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3584 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3585 | if ((px->cap & PR_CAP_BE) && px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3586 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3587 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3588 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3589 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3590 | chunk_appendf(&trash, |
| 3591 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3592 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3593 | "", |
| 3594 | px->id, sv->id, |
| 3595 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3596 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3597 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3598 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3599 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3600 | |
| 3601 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3602 | case AF_INET: |
| 3603 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3604 | break; |
| 3605 | case AF_INET6: |
| 3606 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3607 | break; |
| 3608 | case AF_UNIX: |
| 3609 | chunk_appendf(&trash, "unix, "); |
| 3610 | break; |
| 3611 | case -1: |
| 3612 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3613 | break; |
| 3614 | default: /* address family not supported */ |
| 3615 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3616 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3617 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3618 | /* id */ |
| 3619 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3620 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3621 | /* cookie */ |
| 3622 | if (sv->cookie) { |
| 3623 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3624 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3625 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3626 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3627 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3628 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3629 | } |
| 3630 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3631 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3632 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3633 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3634 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3635 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3636 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3637 | /* sessions rate : current, max, limit */ |
| 3638 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3639 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3640 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3641 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3642 | U2H(read_freq_ctr(&sv->sess_per_sec)), U2H(sv->counters.sps_max)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3643 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3644 | |
| 3645 | chunk_appendf(&trash, |
| 3646 | /* sessions: current, max, limit, total */ |
| 3647 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3648 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3649 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3650 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3651 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3652 | U2H(sv->counters.cum_sess), |
| 3653 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3654 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3655 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3656 | if (px->mode == PR_MODE_HTTP) { |
| 3657 | unsigned long long tot; |
| 3658 | for (tot = i = 0; i < 6; i++) |
| 3659 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3660 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3661 | chunk_appendf(&trash, |
| 3662 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3663 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3664 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3665 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3666 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3667 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3668 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3669 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3670 | U2H(tot), |
| 3671 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3672 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3673 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3674 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3675 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3676 | U2H(sv->counters.p.http.rsp[0]), tot ? (int)(100*sv->counters.p.http.rsp[0] / tot) : 0); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3677 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3678 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3679 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3680 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES))); |
| 3681 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES))); |
| 3682 | if (px->mode == PR_MODE_HTTP) |
| 3683 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES))); |
| 3684 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES))); |
| 3685 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3686 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3687 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3688 | /* sessions: lbtot, last */ |
| 3689 | "<td>%s</td><td>%s</td>", |
| 3690 | U2H(sv->counters.cum_lbconn), |
| 3691 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3692 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3693 | chunk_appendf(&trash, |
| 3694 | /* bytes : in, out */ |
| 3695 | "<td>%s</td><td>%s</td>" |
| 3696 | /* denied: req, resp */ |
| 3697 | "<td></td><td>%s</td>" |
| 3698 | /* errors : request, connect */ |
| 3699 | "<td></td><td>%s</td>" |
| 3700 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3701 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3702 | /* warnings: retries, redispatches */ |
| 3703 | "<td>%lld</td><td>%lld</td>" |
| 3704 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3705 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3706 | U2H(sv->counters.failed_secu), |
| 3707 | U2H(sv->counters.failed_conns), |
| 3708 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3709 | sv->counters.cli_aborts, |
| 3710 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3711 | sv->counters.retries, sv->counters.redispatches); |
| 3712 | |
| 3713 | /* status, lest check */ |
| 3714 | chunk_appendf(&trash, "<td class=ac>"); |
| 3715 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3716 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3717 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3718 | chunk_appendf(&trash, "MAINT"); |
| 3719 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3720 | else if ((ref->agent.state & CHK_ST_ENABLED) && !(sv->agent.health) && (ref->state == SRV_ST_STOPPED)) { |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3721 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
Willy Tarreau | ac49707 | 2014-05-29 01:04:35 +0200 | [diff] [blame] | 3722 | /* DOWN (agent) */ |
| 3723 | chunk_appendf(&trash, srv_hlt_st[1], "GCC: your -Werror=format-security is bogus, annoying, and hides real bugs, I don't thank you, really!"); |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3724 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3725 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3726 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3727 | chunk_appendf(&trash, |
| 3728 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3729 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3730 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3731 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3732 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3733 | if ((sv->state == SRV_ST_STOPPED) && |
| 3734 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3735 | chunk_appendf(&trash, |
| 3736 | "</td><td class=ac><u> %s%s", |
| 3737 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3738 | get_check_status_info(sv->agent.status)); |
| 3739 | |
| 3740 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3741 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3742 | |
| 3743 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3744 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3745 | |
| 3746 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3747 | get_check_status_description(sv->agent.status)); |
| 3748 | if (*sv->agent.desc) { |
| 3749 | chunk_appendf(&trash, ": "); |
| 3750 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3751 | chunk_htmlencode(&trash, &src); |
| 3752 | } |
| 3753 | chunk_appendf(&trash, "</div></u>"); |
| 3754 | } |
| 3755 | else if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3756 | chunk_appendf(&trash, |
| 3757 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3758 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3759 | get_check_status_info(sv->check.status)); |
| 3760 | |
| 3761 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3762 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3763 | |
| 3764 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3765 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3766 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3767 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3768 | get_check_status_description(sv->check.status)); |
| 3769 | if (*sv->check.desc) { |
| 3770 | chunk_appendf(&trash, ": "); |
| 3771 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3772 | chunk_htmlencode(&trash, &src); |
| 3773 | } |
| 3774 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3775 | } |
| 3776 | else |
| 3777 | chunk_appendf(&trash, "</td><td>"); |
| 3778 | |
| 3779 | chunk_appendf(&trash, |
| 3780 | /* weight */ |
| 3781 | "</td><td class=ac>%d</td>" |
| 3782 | /* act, bck */ |
| 3783 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3784 | "", |
| 3785 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3786 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3787 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3788 | |
| 3789 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3790 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3791 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3792 | |
| 3793 | if (ref->observe) |
| 3794 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3795 | |
| 3796 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3797 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3798 | "<td>%lld</td><td>%s</td>" |
| 3799 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3800 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3801 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3802 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3803 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3804 | /* tracking a server */ |
| 3805 | chunk_appendf(&trash, |
| 3806 | "<td class=ac colspan=3><a class=lfsb href=\"#%s/%s\">via %s/%s</a></td>", |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3807 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3808 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3809 | else |
| 3810 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3811 | |
| 3812 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3813 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3814 | chunk_appendf(&trash, "<td class=ac>%d %%</td></tr>\n", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3815 | else |
| 3816 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3817 | } |
| 3818 | else { /* CSV mode */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3819 | struct chunk *out = get_trash_chunk(); |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3820 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3821 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3822 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3823 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3824 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3825 | [SRV_STATS_STATE_UP] = "UP,", |
| 3826 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3827 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3828 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3829 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Raghu Udiyar | 0d6b7a4 | 2016-02-05 22:30:11 +0530 | [diff] [blame] | 3830 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent),", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3831 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3832 | }; |
| 3833 | |
| 3834 | chunk_appendf(&trash, |
| 3835 | /* pxid, name */ |
| 3836 | "%s,%s," |
| 3837 | /* queue : current, max */ |
| 3838 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3839 | /* sessions : current, max, limit, total */ |
| 3840 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3841 | /* bytes : in, out */ |
| 3842 | "%lld,%lld," |
| 3843 | /* denied: req, resp */ |
| 3844 | ",%lld," |
| 3845 | /* errors : request, connect, response */ |
| 3846 | ",%lld,%lld," |
| 3847 | /* warnings: retries, redispatches */ |
| 3848 | "%lld,%lld," |
| 3849 | "", |
| 3850 | px->id, sv->id, |
| 3851 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3852 | sv->cur_sess, sv->counters.cur_sess_max, LIM2A(sv->maxconn, ""), sv->counters.cum_sess, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3853 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3854 | sv->counters.failed_secu, |
| 3855 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3856 | sv->counters.retries, sv->counters.redispatches); |
| 3857 | |
| 3858 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3859 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3860 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3861 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3862 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3863 | else |
| 3864 | chunk_appendf(&trash, |
| 3865 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3866 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3867 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3868 | |
| 3869 | chunk_appendf(&trash, |
| 3870 | /* weight, active, backup */ |
| 3871 | "%d,%d,%d," |
| 3872 | "", |
| 3873 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3874 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3875 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3876 | |
| 3877 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3878 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3879 | chunk_appendf(&trash, |
| 3880 | "%lld,%lld,%d,%d,", |
| 3881 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3882 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3883 | else |
| 3884 | chunk_appendf(&trash, ",,,,"); |
| 3885 | |
| 3886 | /* queue limit, pid, iid, sid, */ |
| 3887 | chunk_appendf(&trash, |
| 3888 | "%s," |
| 3889 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3890 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3891 | relative_pid, px->uuid, sv->puid); |
| 3892 | |
| 3893 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3894 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3895 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3896 | |
| 3897 | /* sessions: lbtot */ |
| 3898 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3899 | |
| 3900 | /* tracked */ |
| 3901 | if (sv->track) |
| 3902 | chunk_appendf(&trash, "%s/%s,", |
| 3903 | sv->track->proxy->id, sv->track->id); |
| 3904 | else |
| 3905 | chunk_appendf(&trash, ","); |
| 3906 | |
| 3907 | /* type */ |
| 3908 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3909 | |
| 3910 | /* rate */ |
| 3911 | chunk_appendf(&trash, "%u,,%u,", |
| 3912 | read_freq_ctr(&sv->sess_per_sec), |
| 3913 | sv->counters.sps_max); |
| 3914 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3915 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3916 | /* check_status */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3917 | chunk_appendf(&trash, "%s,", csv_enc(get_check_status_info(sv->check.status), 1, out)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3918 | |
| 3919 | /* check_code */ |
| 3920 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3921 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3922 | else |
| 3923 | chunk_appendf(&trash, ","); |
| 3924 | |
| 3925 | /* check_duration */ |
| 3926 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3927 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3928 | else |
| 3929 | chunk_appendf(&trash, ","); |
| 3930 | |
| 3931 | } |
| 3932 | else |
| 3933 | chunk_appendf(&trash, ",,,"); |
| 3934 | |
| 3935 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3936 | if (px->mode == PR_MODE_HTTP) { |
| 3937 | for (i=1; i<6; i++) |
| 3938 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3939 | |
| 3940 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3941 | } |
| 3942 | else |
| 3943 | chunk_appendf(&trash, ",,,,,,"); |
| 3944 | |
| 3945 | /* failed health analyses */ |
| 3946 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 3947 | |
| 3948 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3949 | chunk_appendf(&trash, ",,,"); |
| 3950 | |
| 3951 | /* errors: cli_aborts, srv_aborts */ |
| 3952 | chunk_appendf(&trash, "%lld,%lld,", |
| 3953 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 3954 | |
| 3955 | /* compression: in, out, bypassed, comp_rsp */ |
| 3956 | chunk_appendf(&trash, ",,,,"); |
| 3957 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3958 | /* lastsess */ |
| 3959 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 3960 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3961 | /* capture of last check and agent statuses */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3962 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : ""); |
| 3963 | chunk_appendf(&trash, "%s,", ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->agent.desc), 1, out) : ""); |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 3964 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3965 | /* qtime, ctime, rtime, ttime, */ |
| 3966 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 3967 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 3968 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 3969 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 3970 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 3971 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3972 | /* finish with EOL */ |
| 3973 | chunk_appendf(&trash, "\n"); |
| 3974 | } |
| 3975 | return 1; |
| 3976 | } |
| 3977 | |
| 3978 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 3979 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 3980 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 3981 | */ |
| 3982 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 3983 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3984 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3985 | struct chunk src; |
| 3986 | int i; |
| 3987 | |
| 3988 | if (!(px->cap & PR_CAP_BE)) |
| 3989 | return 0; |
| 3990 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3991 | if ((appctx->ctx.stats.flags & STAT_BOUND) && !(appctx->ctx.stats.type & (1 << STATS_TYPE_BE))) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3992 | return 0; |
| 3993 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3994 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3995 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3996 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3997 | /* Column sub-heading for Enable or Disable server */ |
| 3998 | chunk_appendf(&trash, "<td></td>"); |
| 3999 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4000 | chunk_appendf(&trash, |
| 4001 | "<td class=ac>" |
| 4002 | /* name */ |
| 4003 | "%s<a name=\"%s/Backend\"></a>" |
| 4004 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 4005 | "", |
| 4006 | (flags & ST_SHLGNDS)?"<u>":"", |
| 4007 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4008 | |
| 4009 | if (flags & ST_SHLGNDS) { |
| 4010 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4011 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4012 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 4013 | |
| 4014 | /* cookie */ |
| 4015 | if (px->cookie_name) { |
| 4016 | chunk_appendf(&trash, ", cookie: '"); |
| 4017 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 4018 | chunk_htmlencode(&trash, &src); |
| 4019 | chunk_appendf(&trash, "'"); |
| 4020 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4021 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4025 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4026 | /* queue : current, max */ |
| 4027 | "<td>%s</td><td>%s</td><td></td>" |
| 4028 | /* sessions rate : current, max, limit */ |
| 4029 | "<td>%s</td><td>%s</td><td></td>" |
| 4030 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4031 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4032 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 4033 | U2H(read_freq_ctr(&px->be_sess_per_sec)), U2H(px->be_counters.sps_max)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4034 | |
| 4035 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4036 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4037 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4038 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4039 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4040 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4041 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 4042 | U2H(px->be_counters.cum_conn), |
| 4043 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4044 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4045 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4046 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4047 | chunk_appendf(&trash, |
| 4048 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 4049 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 4050 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 4051 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4052 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 4053 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 4054 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 4055 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 4056 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4057 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4058 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4059 | U2H(px->be_counters.p.http.cum_req), |
| 4060 | U2H(px->be_counters.p.http.rsp[1]), |
| 4061 | U2H(px->be_counters.p.http.rsp[2]), |
| 4062 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4063 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4064 | (int)(100*px->be_counters.p.http.comp_rsp/px->be_counters.p.http.rsp[2]) : 0, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4065 | U2H(px->be_counters.p.http.rsp[3]), |
| 4066 | U2H(px->be_counters.p.http.rsp[4]), |
| 4067 | U2H(px->be_counters.p.http.rsp[5]), |
| 4068 | U2H(px->be_counters.p.http.rsp[0]), |
| 4069 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4070 | } |
| 4071 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4072 | chunk_appendf(&trash, "<tr><th>- Queue time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES))); |
| 4073 | chunk_appendf(&trash, "<tr><th>- Connect time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES))); |
| 4074 | if (px->mode == PR_MODE_HTTP) |
| 4075 | chunk_appendf(&trash, "<tr><th>- Response time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES))); |
| 4076 | chunk_appendf(&trash, "<tr><th>- Total time:</th><td>%s</td><td>ms</td></tr>", U2H(swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES))); |
| 4077 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4078 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4079 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4080 | /* sessions: lbtot, last */ |
| 4081 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4082 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4083 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4084 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4085 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4086 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4087 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4088 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4089 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4090 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 4091 | "<td>%s%s<div class=tips><table class=det>" |
| 4092 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 4093 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 4094 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4095 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 4096 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4097 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4098 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4099 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 4100 | U2H(px->be_counters.bytes_out), |
| 4101 | U2H(px->be_counters.comp_in), |
| 4102 | U2H(px->be_counters.comp_out), |
| 4103 | px->be_counters.comp_in ? (int)(px->be_counters.comp_out * 100 / px->be_counters.comp_in) : 0, |
| 4104 | U2H(px->be_counters.comp_byp), |
| 4105 | U2H(px->be_counters.comp_in - px->be_counters.comp_out), |
| 4106 | px->be_counters.bytes_out ? (int)((px->be_counters.comp_in - px->be_counters.comp_out) * 100 / px->be_counters.bytes_out) : 0, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4107 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 4108 | |
| 4109 | chunk_appendf(&trash, |
| 4110 | /* denied: req, resp */ |
| 4111 | "<td>%s</td><td>%s</td>" |
| 4112 | /* errors : request, connect */ |
| 4113 | "<td></td><td>%s</td>" |
| 4114 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4115 | "<td><u>%s<div class=tips>Connection resets during transfers: %lld client, %lld server</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4116 | /* warnings: retries, redispatches */ |
| 4117 | "<td>%lld</td><td>%lld</td>" |
| 4118 | /* backend status: reflect backend status (up/down): we display UP |
| 4119 | * if the backend has known working servers or if it has no server at |
| 4120 | * all (eg: for stats). Then we display the total weight, number of |
| 4121 | * active and backups. */ |
| 4122 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 4123 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 4124 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4125 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 4126 | U2H(px->be_counters.failed_conns), |
| 4127 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4128 | px->be_counters.cli_aborts, |
| 4129 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4130 | px->be_counters.retries, px->be_counters.redispatches, |
| 4131 | human_time(now.tv_sec - px->last_change, 1), |
| 4132 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 4133 | "<font color=\"red\"><b>DOWN</b></font>", |
| 4134 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 4135 | px->srv_act, px->srv_bck); |
| 4136 | |
| 4137 | chunk_appendf(&trash, |
| 4138 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 4139 | "<td class=ac> </td><td>%d</td>" |
| 4140 | "<td>%s</td>" |
| 4141 | "<td></td>" |
| 4142 | "</tr>", |
| 4143 | px->down_trans, |
| 4144 | px->srv?human_time(be_downtime(px), 1):" "); |
| 4145 | } |
| 4146 | else { /* CSV mode */ |
| 4147 | chunk_appendf(&trash, |
| 4148 | /* pxid, name */ |
| 4149 | "%s,BACKEND," |
| 4150 | /* queue : current, max */ |
| 4151 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4152 | /* sessions : current, max, limit, total */ |
| 4153 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4154 | /* bytes : in, out */ |
| 4155 | "%lld,%lld," |
| 4156 | /* denied: req, resp */ |
| 4157 | "%lld,%lld," |
| 4158 | /* errors : request, connect, response */ |
| 4159 | ",%lld,%lld," |
| 4160 | /* warnings: retries, redispatches */ |
| 4161 | "%lld,%lld," |
| 4162 | /* backend status: reflect backend status (up/down): we display UP |
| 4163 | * if the backend has known working servers or if it has no server at |
| 4164 | * all (eg: for stats). Then we display the total weight, number of |
| 4165 | * active and backups. */ |
| 4166 | "%s," |
| 4167 | "%d,%d,%d," |
| 4168 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 4169 | ",%d,%d,%d,," |
| 4170 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 4171 | "%d,%d,0,,%lld,,%d," |
| 4172 | /* rate, rate_lim, rate_max, */ |
| 4173 | "%u,,%u," |
| 4174 | /* check_status, check_code, check_duration */ |
| 4175 | ",,,", |
| 4176 | px->id, |
| 4177 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 4178 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 4179 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 4180 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 4181 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 4182 | px->be_counters.retries, px->be_counters.redispatches, |
| 4183 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 4184 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 4185 | px->srv_act, px->srv_bck, |
| 4186 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 4187 | px->srv?be_downtime(px):0, |
| 4188 | relative_pid, px->uuid, |
| 4189 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 4190 | read_freq_ctr(&px->be_sess_per_sec), |
| 4191 | px->be_counters.sps_max); |
| 4192 | |
| 4193 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4194 | if (px->mode == PR_MODE_HTTP) { |
| 4195 | for (i=1; i<6; i++) |
| 4196 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 4197 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 4198 | } |
| 4199 | else |
| 4200 | chunk_appendf(&trash, ",,,,,,"); |
| 4201 | |
| 4202 | /* failed health analyses */ |
| 4203 | chunk_appendf(&trash, ","); |
| 4204 | |
| 4205 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 4206 | chunk_appendf(&trash, ",,,"); |
| 4207 | |
| 4208 | /* errors: cli_aborts, srv_aborts */ |
| 4209 | chunk_appendf(&trash, "%lld,%lld,", |
| 4210 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 4211 | |
| 4212 | /* compression: in, out, bypassed */ |
| 4213 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 4214 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 4215 | |
| 4216 | /* compression: comp_rsp */ |
| 4217 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 4218 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 4219 | /* lastsess, last_chk, last_agt, */ |
| 4220 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4221 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4222 | /* qtime, ctime, rtime, ttime, */ |
| 4223 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 4224 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 4225 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 4226 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 4227 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4228 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4229 | /* finish with EOL */ |
| 4230 | chunk_appendf(&trash, "\n"); |
| 4231 | } |
| 4232 | return 1; |
| 4233 | } |
| 4234 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4235 | /* 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] | 4236 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4237 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4238 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4239 | 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] | 4240 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4241 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4242 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4243 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4244 | 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] | 4245 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4246 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4247 | /* 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] | 4248 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4249 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4250 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4251 | 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] | 4252 | 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] | 4253 | } |
| 4254 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4255 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4256 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | /* print a new table */ |
| 4260 | chunk_appendf(&trash, |
| 4261 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4262 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4263 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4264 | |
| 4265 | chunk_appendf(&trash, |
| 4266 | "<a name=\"%s\"></a>%s" |
| 4267 | "<a class=px href=\"#%s\">%s</a>", |
| 4268 | px->id, |
| 4269 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4270 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4271 | |
| 4272 | if (uri->flags & ST_SHLGNDS) { |
| 4273 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4274 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4275 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4276 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4277 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4281 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4282 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4283 | "</tr>\n" |
| 4284 | "</table>\n" |
| 4285 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4286 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4287 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4288 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4289 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4290 | 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] | 4291 | /* Column heading for Enable or Disable server */ |
| 4292 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4293 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4294 | |
| 4295 | chunk_appendf(&trash, |
| 4296 | "<th rowspan=2></th>" |
| 4297 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4298 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4299 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4300 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4301 | "<th colspan=9>Server</th>" |
| 4302 | "</tr>\n" |
| 4303 | "<tr class=\"titre\">" |
| 4304 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4305 | "<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] | 4306 | "<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] | 4307 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4308 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4309 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4310 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4311 | "<th>Thrtle</th>\n" |
| 4312 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4313 | } |
| 4314 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4315 | /* 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] | 4316 | * 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] | 4317 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4318 | 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] | 4319 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4320 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4321 | chunk_appendf(&trash, "</table>"); |
| 4322 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4323 | 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] | 4324 | /* close the form used to enable/disable this proxy servers */ |
| 4325 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4326 | "Choose the action to perform on the checked servers : " |
| 4327 | "<select name=action>" |
| 4328 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4329 | "<option value=\"ready\">Set state to READY</option>" |
| 4330 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4331 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4332 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4333 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4334 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4335 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4336 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4337 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4338 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4339 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4340 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4341 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4342 | "</select>" |
| 4343 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4344 | " <input type=\"submit\" value=\"Apply\">" |
| 4345 | "</form>", |
| 4346 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4347 | } |
| 4348 | |
| 4349 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4350 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4351 | |
| 4352 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4353 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4354 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4355 | * buffer space, or non-zero if everything completed. This function is used |
| 4356 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4357 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4358 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4359 | 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] | 4360 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4361 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4362 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4363 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4364 | 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] | 4365 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4366 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4367 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4368 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4369 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4370 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4371 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4372 | if (uri && uri->scope) { |
| 4373 | /* we have a limited scope, we have to check the proxy name */ |
| 4374 | struct stat_scope *scope; |
| 4375 | int len; |
| 4376 | |
| 4377 | len = strlen(px->id); |
| 4378 | scope = uri->scope; |
| 4379 | |
| 4380 | while (scope) { |
| 4381 | /* match exact proxy name */ |
| 4382 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4383 | break; |
| 4384 | |
| 4385 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4386 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4387 | break; |
| 4388 | scope = scope->next; |
| 4389 | } |
| 4390 | |
| 4391 | /* proxy name not found : don't dump anything */ |
| 4392 | if (scope == NULL) |
| 4393 | return 1; |
| 4394 | } |
| 4395 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4396 | /* if the user has requested a limited output and the proxy |
| 4397 | * name does not match, skip it. |
| 4398 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4399 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4400 | 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] | 4401 | return 1; |
| 4402 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4403 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4404 | (appctx->ctx.stats.iid != -1) && |
| 4405 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4406 | return 1; |
| 4407 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4408 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4409 | /* fall through */ |
| 4410 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4411 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4412 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4413 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4414 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4415 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4416 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4417 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4418 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4419 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4420 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4421 | /* fall through */ |
| 4422 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4423 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4424 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4425 | if (stats_dump_fe_stats(si, px)) { |
| 4426 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4427 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4428 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4429 | } |
| 4430 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4431 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4432 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4433 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4434 | /* fall through */ |
| 4435 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4436 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4437 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4438 | 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] | 4439 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4440 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4441 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4442 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4443 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4444 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4445 | if (!l->counters) |
| 4446 | continue; |
| 4447 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4448 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4449 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4450 | break; |
| 4451 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4452 | 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] | 4453 | continue; |
| 4454 | } |
| 4455 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4456 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4457 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 4458 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4459 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4460 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4461 | } |
| 4462 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4463 | } |
| 4464 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4465 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4466 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4467 | /* fall through */ |
| 4468 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4469 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4470 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4471 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4472 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4473 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4474 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4475 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4476 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4477 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4478 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4479 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4480 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4481 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4482 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4483 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4484 | break; |
| 4485 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4486 | 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] | 4487 | continue; |
| 4488 | } |
| 4489 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4490 | svs = sv; |
| 4491 | while (svs->track) |
| 4492 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4493 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4494 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4495 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4496 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4497 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4498 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4499 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4500 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4501 | sv_colour = SRV_STATS_COLOUR_UP; |
| 4502 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4503 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4504 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 4505 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 4506 | |
| 4507 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4508 | if (svs->agent.state & CHK_ST_ENABLED) |
| 4509 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4510 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4511 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4512 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4513 | sv_state = SRV_STATS_STATE_DRAIN; |
| 4514 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4515 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4516 | if (sv_state == SRV_STATS_STATE_UP && !(svs->check.state & CHK_ST_ENABLED)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4517 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4518 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 4519 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4520 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4521 | else if (sv->state == SRV_ST_STOPPING) { |
| 4522 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4523 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4524 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4525 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 4526 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4527 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4528 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4529 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4530 | } |
| 4531 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4532 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4533 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4534 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4535 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4536 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4537 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4538 | } else if ((svs->agent.state & CHK_ST_ENABLED) || (svs->check.state & CHK_ST_ENABLED)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4539 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4540 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 4541 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4542 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4543 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4544 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4545 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4546 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4547 | if (((sv_state <= 1) || (sv->admin & SRV_ADMF_MAINT)) && (appctx->ctx.stats.flags & STAT_HIDE_DOWN)) { |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4548 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4549 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4550 | continue; |
| 4551 | } |
| 4552 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4553 | if (stats_dump_sv_stats(si, px, uri ? uri->flags : 0, sv, sv_state, sv_colour)) { |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4554 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4555 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4556 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4557 | } |
| 4558 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4559 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4560 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4561 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4562 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4563 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4564 | case STAT_PX_ST_BE: |
| 4565 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4566 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 4567 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4568 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4569 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4570 | } |
| 4571 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4572 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4573 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4574 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4575 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4576 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4577 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4578 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4579 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4580 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4581 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4582 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4583 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4584 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4585 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4586 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4587 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4588 | case STAT_PX_ST_FIN: |
| 4589 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4590 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4591 | default: |
| 4592 | /* unknown state, we should put an abort() here ! */ |
| 4593 | return 1; |
| 4594 | } |
| 4595 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4596 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4597 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4598 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4599 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4600 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4601 | { |
| 4602 | /* WARNING! This must fit in the first buffer !!! */ |
| 4603 | chunk_appendf(&trash, |
| 4604 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4605 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4606 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4607 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4608 | "<style type=\"text/css\"><!--\n" |
| 4609 | "body {" |
| 4610 | " font-family: arial, helvetica, sans-serif;" |
| 4611 | " font-size: 12px;" |
| 4612 | " font-weight: normal;" |
| 4613 | " color: black;" |
| 4614 | " background: white;" |
| 4615 | "}\n" |
| 4616 | "th,td {" |
| 4617 | " font-size: 10px;" |
| 4618 | "}\n" |
| 4619 | "h1 {" |
| 4620 | " font-size: x-large;" |
| 4621 | " margin-bottom: 0.5em;" |
| 4622 | "}\n" |
| 4623 | "h2 {" |
| 4624 | " font-family: helvetica, arial;" |
| 4625 | " font-size: x-large;" |
| 4626 | " font-weight: bold;" |
| 4627 | " font-style: italic;" |
| 4628 | " color: #6020a0;" |
| 4629 | " margin-top: 0em;" |
| 4630 | " margin-bottom: 0em;" |
| 4631 | "}\n" |
| 4632 | "h3 {" |
| 4633 | " font-family: helvetica, arial;" |
| 4634 | " font-size: 16px;" |
| 4635 | " font-weight: bold;" |
| 4636 | " color: #b00040;" |
| 4637 | " background: #e8e8d0;" |
| 4638 | " margin-top: 0em;" |
| 4639 | " margin-bottom: 0em;" |
| 4640 | "}\n" |
| 4641 | "li {" |
| 4642 | " margin-top: 0.25em;" |
| 4643 | " margin-right: 2em;" |
| 4644 | "}\n" |
| 4645 | ".hr {margin-top: 0.25em;" |
| 4646 | " border-color: black;" |
| 4647 | " border-bottom-style: solid;" |
| 4648 | "}\n" |
| 4649 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4650 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4651 | ".frontend {background: #e8e8d0;}\n" |
| 4652 | ".socket {background: #d0d0d0;}\n" |
| 4653 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4654 | ".active_down {background: #ff9090;}\n" |
| 4655 | ".active_going_up {background: #ffd020;}\n" |
| 4656 | ".active_going_down {background: #ffffa0;}\n" |
| 4657 | ".active_up {background: #c0ffc0;}\n" |
| 4658 | ".active_nolb {background: #20a0ff;}\n" |
| 4659 | ".active_draining {background: #20a0FF;}\n" |
| 4660 | ".active_no_check {background: #e0e0e0;}\n" |
| 4661 | ".backup_down {background: #ff9090;}\n" |
| 4662 | ".backup_going_up {background: #ff80ff;}\n" |
| 4663 | ".backup_going_down {background: #c060ff;}\n" |
| 4664 | ".backup_up {background: #b0d0ff;}\n" |
| 4665 | ".backup_nolb {background: #90b0e0;}\n" |
| 4666 | ".backup_draining {background: #cc9900;}\n" |
| 4667 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4668 | ".maintain {background: #c07820;}\n" |
| 4669 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4670 | "\n" |
| 4671 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4672 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4673 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4674 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4675 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4676 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4677 | "\n" |
| 4678 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4679 | "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" |
| 4680 | "table.tbl td.ac { text-align: center;}\n" |
| 4681 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4682 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4683 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4684 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4685 | "\n" |
| 4686 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4687 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4688 | "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] | 4689 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4690 | "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] | 4691 | "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] | 4692 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4693 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4694 | " display:block;\n" |
| 4695 | " visibility:hidden;\n" |
| 4696 | " z-index:2147483647;\n" |
| 4697 | " position:absolute;\n" |
| 4698 | " padding:2px 4px 3px;\n" |
| 4699 | " background:#f0f060; color:#000000;\n" |
| 4700 | " border:1px solid #7040c0;\n" |
| 4701 | " white-space:nowrap;\n" |
| 4702 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4703 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4704 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4705 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4706 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4707 | "-->\n" |
| 4708 | "</style></head>\n", |
| 4709 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4710 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4711 | ); |
| 4712 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4713 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4714 | /* 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] | 4715 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4716 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4717 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4718 | 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] | 4719 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4720 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4721 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4722 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4723 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4724 | /* WARNING! this has to fit the first packet too. |
| 4725 | * We are around 3.5 kB, add adding entries will |
| 4726 | * become tricky if we want to support 4kB buffers ! |
| 4727 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4728 | chunk_appendf(&trash, |
| 4729 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4730 | PRODUCT_NAME "%s</a></h1>\n" |
| 4731 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4732 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4733 | "<h3>> General process information</h3>\n" |
| 4734 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4735 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4736 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4737 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4738 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4739 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4740 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4741 | "</td><td align=\"center\" nowrap>\n" |
| 4742 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4743 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4744 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4745 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4746 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4747 | "<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] | 4748 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4749 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4750 | "<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] | 4751 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4752 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4753 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4754 | "</tr><tr>\n" |
| 4755 | "<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] | 4756 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4757 | "<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] | 4758 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4759 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4760 | "</td>" |
| 4761 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4762 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4763 | "", |
| 4764 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4765 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4766 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4767 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4768 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4769 | pid, relative_pid, global.nbproc, |
| 4770 | up / 86400, (up % 86400) / 3600, |
| 4771 | (up % 3600) / 60, (up % 60), |
| 4772 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4773 | global.rlimit_memmax ? " MB" : "", |
| 4774 | global.rlimit_nofile, |
| 4775 | global.maxsock, global.maxconn, global.maxpipes, |
| 4776 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4777 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4778 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4779 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4780 | /* 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] | 4781 | 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] | 4782 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4783 | |
| 4784 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4785 | "<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] | 4786 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4787 | STAT_SCOPE_TXT_MAXLEN); |
| 4788 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4789 | /* 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] | 4790 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4791 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4792 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4793 | 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] | 4794 | 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] | 4795 | } |
| 4796 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4797 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4798 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4799 | "<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] | 4800 | uri->uri_prefix, |
| 4801 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4802 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4803 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4804 | else |
| 4805 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4806 | "<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] | 4807 | uri->uri_prefix, |
| 4808 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4809 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4810 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4811 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4812 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4813 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4814 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4815 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4816 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4817 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4818 | "", |
| 4819 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4820 | else |
| 4821 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4822 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4823 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4824 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4825 | ";norefresh", |
| 4826 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4827 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4828 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4829 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4830 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4831 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4832 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4833 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4834 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4835 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4836 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4837 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4838 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4839 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4840 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4841 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4842 | chunk_appendf(&trash, |
| 4843 | "</ul></td>" |
| 4844 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4845 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4846 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4847 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4848 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4849 | "</ul>" |
| 4850 | "</td>" |
| 4851 | "</tr></table>\n" |
| 4852 | "" |
| 4853 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4854 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4855 | if (appctx->ctx.stats.st_code) { |
| 4856 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4857 | case STAT_STATUS_DONE: |
| 4858 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4859 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4860 | "<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] | 4861 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4862 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4863 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4864 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4865 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4866 | break; |
| 4867 | case STAT_STATUS_NONE: |
| 4868 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4869 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4870 | "<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] | 4871 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4872 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4873 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4874 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4875 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4876 | break; |
| 4877 | case STAT_STATUS_PART: |
| 4878 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4879 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4880 | "<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] | 4881 | "Action partially processed.<br>" |
| 4882 | "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] | 4883 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4884 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4885 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4886 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4887 | break; |
| 4888 | case STAT_STATUS_ERRP: |
| 4889 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4890 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4891 | "<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] | 4892 | "Action not processed because of invalid parameters." |
| 4893 | "<ul>" |
| 4894 | "<li>The action is maybe unknown.</li>" |
| 4895 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4896 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4897 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4898 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4899 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4900 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4901 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4902 | break; |
| 4903 | case STAT_STATUS_EXCD: |
| 4904 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4905 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4906 | "<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] | 4907 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4908 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4909 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4910 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4911 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4912 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4913 | break; |
| 4914 | case STAT_STATUS_DENY: |
| 4915 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4916 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4917 | "<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] | 4918 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4919 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4920 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4921 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4922 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4923 | break; |
| 4924 | default: |
| 4925 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4926 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4927 | "<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] | 4928 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4929 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4930 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4931 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4932 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4933 | } |
| 4934 | chunk_appendf(&trash, "<p>\n"); |
| 4935 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4936 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4937 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4938 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4939 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4940 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4941 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4942 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4943 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4944 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4945 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4946 | /* This function dumps statistics onto the stream interface's read buffer in |
| 4947 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 4948 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 4949 | * 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] | 4950 | * 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] | 4951 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4952 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4953 | 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] | 4954 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4955 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4956 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4957 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 4958 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4959 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 4960 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4961 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4962 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4963 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4964 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 4965 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4966 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4967 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4968 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 4969 | else |
| 4970 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 4971 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4972 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4973 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4974 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4975 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 4976 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4977 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4978 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 4979 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4980 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4981 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4982 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4983 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4984 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4985 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4986 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4987 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4988 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4989 | appctx->ctx.stats.px = proxy; |
| 4990 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 4991 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4992 | /* fall through */ |
| 4993 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4994 | case STAT_ST_LIST: |
| 4995 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4996 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4997 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4998 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4999 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5000 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5001 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5002 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5003 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5004 | 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] | 5005 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5006 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5007 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5008 | appctx->ctx.stats.px = px->next; |
| 5009 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5010 | } |
| 5011 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5012 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5013 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5014 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5015 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5016 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5017 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5018 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5019 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5020 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5021 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5022 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5023 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5024 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5025 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5026 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5027 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5028 | case STAT_ST_FIN: |
| 5029 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5030 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5031 | default: |
| 5032 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5033 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5034 | return -1; |
| 5035 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5036 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5037 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5038 | /* We reached the stats page through a POST request. The appctx is |
| 5039 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5040 | * Parse the posted data and enable/disable servers if necessary. |
| 5041 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5042 | */ |
| 5043 | static int stats_process_http_post(struct stream_interface *si) |
| 5044 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5045 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5046 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5047 | |
| 5048 | struct proxy *px = NULL; |
| 5049 | struct server *sv = NULL; |
| 5050 | |
| 5051 | char key[LINESIZE]; |
| 5052 | int action = ST_ADM_ACTION_NONE; |
| 5053 | int reprocess = 0; |
| 5054 | |
| 5055 | int total_servers = 0; |
| 5056 | int altered_servers = 0; |
| 5057 | |
| 5058 | char *first_param, *cur_param, *next_param, *end_params; |
| 5059 | char *st_cur_param = NULL; |
| 5060 | char *st_next_param = NULL; |
| 5061 | |
| 5062 | struct chunk *temp; |
| 5063 | int reql; |
| 5064 | |
| 5065 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5066 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5067 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5068 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5069 | goto out; |
| 5070 | } |
| 5071 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5072 | 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] | 5073 | if (reql <= 0) { |
| 5074 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5075 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5076 | return 0; |
| 5077 | } |
| 5078 | |
| 5079 | first_param = temp->str; |
| 5080 | end_params = temp->str + reql; |
| 5081 | cur_param = next_param = end_params; |
| 5082 | *end_params = '\0'; |
| 5083 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5084 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5085 | |
| 5086 | /* |
| 5087 | * Parse the parameters in reverse order to only store the last value. |
| 5088 | * From the html form, the backend and the action are at the end. |
| 5089 | */ |
| 5090 | while (cur_param > first_param) { |
| 5091 | char *value; |
| 5092 | int poffset, plen; |
| 5093 | |
| 5094 | cur_param--; |
| 5095 | |
| 5096 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5097 | reprocess_servers: |
| 5098 | /* Parse the key */ |
| 5099 | poffset = (cur_param != first_param ? 1 : 0); |
| 5100 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5101 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5102 | strncpy(key, cur_param + poffset, plen); |
| 5103 | key[plen - 1] = '\0'; |
| 5104 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5105 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5106 | goto out; |
| 5107 | } |
| 5108 | |
| 5109 | /* Parse the value */ |
| 5110 | value = key; |
| 5111 | while (*value != '\0' && *value != '=') { |
| 5112 | value++; |
| 5113 | } |
| 5114 | if (*value == '=') { |
| 5115 | /* Ok, a value is found, we can mark the end of the key */ |
| 5116 | *value++ = '\0'; |
| 5117 | } |
| 5118 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5119 | break; |
| 5120 | |
| 5121 | /* Now we can check the key to see what to do */ |
| 5122 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5123 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5124 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5125 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5126 | goto out; |
| 5127 | } |
| 5128 | } |
| 5129 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5130 | if (strcmp(value, "ready") == 0) { |
| 5131 | action = ST_ADM_ACTION_READY; |
| 5132 | } |
| 5133 | else if (strcmp(value, "drain") == 0) { |
| 5134 | action = ST_ADM_ACTION_DRAIN; |
| 5135 | } |
| 5136 | else if (strcmp(value, "maint") == 0) { |
| 5137 | action = ST_ADM_ACTION_MAINT; |
| 5138 | } |
| 5139 | else if (strcmp(value, "shutdown") == 0) { |
| 5140 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5141 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5142 | else if (strcmp(value, "dhlth") == 0) { |
| 5143 | action = ST_ADM_ACTION_DHLTH; |
| 5144 | } |
| 5145 | else if (strcmp(value, "ehlth") == 0) { |
| 5146 | action = ST_ADM_ACTION_EHLTH; |
| 5147 | } |
| 5148 | else if (strcmp(value, "hrunn") == 0) { |
| 5149 | action = ST_ADM_ACTION_HRUNN; |
| 5150 | } |
| 5151 | else if (strcmp(value, "hnolb") == 0) { |
| 5152 | action = ST_ADM_ACTION_HNOLB; |
| 5153 | } |
| 5154 | else if (strcmp(value, "hdown") == 0) { |
| 5155 | action = ST_ADM_ACTION_HDOWN; |
| 5156 | } |
| 5157 | else if (strcmp(value, "dagent") == 0) { |
| 5158 | action = ST_ADM_ACTION_DAGENT; |
| 5159 | } |
| 5160 | else if (strcmp(value, "eagent") == 0) { |
| 5161 | action = ST_ADM_ACTION_EAGENT; |
| 5162 | } |
| 5163 | else if (strcmp(value, "arunn") == 0) { |
| 5164 | action = ST_ADM_ACTION_ARUNN; |
| 5165 | } |
| 5166 | else if (strcmp(value, "adown") == 0) { |
| 5167 | action = ST_ADM_ACTION_ADOWN; |
| 5168 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5169 | /* else these are the old supported methods */ |
| 5170 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5171 | action = ST_ADM_ACTION_DISABLE; |
| 5172 | } |
| 5173 | else if (strcmp(value, "enable") == 0) { |
| 5174 | action = ST_ADM_ACTION_ENABLE; |
| 5175 | } |
| 5176 | else if (strcmp(value, "stop") == 0) { |
| 5177 | action = ST_ADM_ACTION_STOP; |
| 5178 | } |
| 5179 | else if (strcmp(value, "start") == 0) { |
| 5180 | action = ST_ADM_ACTION_START; |
| 5181 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5182 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5183 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5184 | goto out; |
| 5185 | } |
| 5186 | } |
| 5187 | else if (strcmp(key, "s") == 0) { |
| 5188 | if (!(px && action)) { |
| 5189 | /* |
| 5190 | * Indicates that we'll need to reprocess the parameters |
| 5191 | * as soon as backend and action are known |
| 5192 | */ |
| 5193 | if (!reprocess) { |
| 5194 | st_cur_param = cur_param; |
| 5195 | st_next_param = next_param; |
| 5196 | } |
| 5197 | reprocess = 1; |
| 5198 | } |
| 5199 | else if ((sv = findserver(px, value)) != NULL) { |
| 5200 | switch (action) { |
| 5201 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5202 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5203 | altered_servers++; |
| 5204 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5205 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5206 | } |
| 5207 | break; |
| 5208 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5209 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5210 | altered_servers++; |
| 5211 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5212 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5213 | } |
| 5214 | break; |
| 5215 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5216 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5217 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5218 | altered_servers++; |
| 5219 | total_servers++; |
| 5220 | } |
| 5221 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5222 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5223 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5224 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5225 | altered_servers++; |
| 5226 | total_servers++; |
| 5227 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5228 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5229 | case ST_ADM_ACTION_DHLTH: |
| 5230 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5231 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5232 | altered_servers++; |
| 5233 | total_servers++; |
| 5234 | } |
| 5235 | break; |
| 5236 | case ST_ADM_ACTION_EHLTH: |
| 5237 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5238 | sv->check.state |= CHK_ST_ENABLED; |
| 5239 | altered_servers++; |
| 5240 | total_servers++; |
| 5241 | } |
| 5242 | break; |
| 5243 | case ST_ADM_ACTION_HRUNN: |
| 5244 | if (!(sv->track)) { |
| 5245 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5246 | srv_set_running(sv, "changed from Web interface"); |
| 5247 | altered_servers++; |
| 5248 | total_servers++; |
| 5249 | } |
| 5250 | break; |
| 5251 | case ST_ADM_ACTION_HNOLB: |
| 5252 | if (!(sv->track)) { |
| 5253 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5254 | srv_set_stopping(sv, "changed from Web interface"); |
| 5255 | altered_servers++; |
| 5256 | total_servers++; |
| 5257 | } |
| 5258 | break; |
| 5259 | case ST_ADM_ACTION_HDOWN: |
| 5260 | if (!(sv->track)) { |
| 5261 | sv->check.health = 0; |
| 5262 | srv_set_stopped(sv, "changed from Web interface"); |
| 5263 | altered_servers++; |
| 5264 | total_servers++; |
| 5265 | } |
| 5266 | break; |
| 5267 | case ST_ADM_ACTION_DAGENT: |
| 5268 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5269 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5270 | altered_servers++; |
| 5271 | total_servers++; |
| 5272 | } |
| 5273 | break; |
| 5274 | case ST_ADM_ACTION_EAGENT: |
| 5275 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5276 | sv->agent.state |= CHK_ST_ENABLED; |
| 5277 | altered_servers++; |
| 5278 | total_servers++; |
| 5279 | } |
| 5280 | break; |
| 5281 | case ST_ADM_ACTION_ARUNN: |
| 5282 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5283 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5284 | srv_set_running(sv, "changed from Web interface"); |
| 5285 | altered_servers++; |
| 5286 | total_servers++; |
| 5287 | } |
| 5288 | break; |
| 5289 | case ST_ADM_ACTION_ADOWN: |
| 5290 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5291 | sv->agent.health = 0; |
| 5292 | srv_set_stopped(sv, "changed from Web interface"); |
| 5293 | altered_servers++; |
| 5294 | total_servers++; |
| 5295 | } |
| 5296 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5297 | case ST_ADM_ACTION_READY: |
| 5298 | srv_adm_set_ready(sv); |
| 5299 | altered_servers++; |
| 5300 | total_servers++; |
| 5301 | break; |
| 5302 | case ST_ADM_ACTION_DRAIN: |
| 5303 | srv_adm_set_drain(sv); |
| 5304 | altered_servers++; |
| 5305 | total_servers++; |
| 5306 | break; |
| 5307 | case ST_ADM_ACTION_MAINT: |
| 5308 | srv_adm_set_maint(sv); |
| 5309 | altered_servers++; |
| 5310 | total_servers++; |
| 5311 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5312 | case ST_ADM_ACTION_SHUTDOWN: |
| 5313 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5314 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5315 | |
| 5316 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5317 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5318 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5319 | |
| 5320 | altered_servers++; |
| 5321 | total_servers++; |
| 5322 | } |
| 5323 | break; |
| 5324 | } |
| 5325 | } else { |
| 5326 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5327 | total_servers++; |
| 5328 | } |
| 5329 | } |
| 5330 | if (reprocess && px && action) { |
| 5331 | /* Now, we know the backend and the action chosen by the user. |
| 5332 | * We can safely restart from the first server parameter |
| 5333 | * to reprocess them |
| 5334 | */ |
| 5335 | cur_param = st_cur_param; |
| 5336 | next_param = st_next_param; |
| 5337 | reprocess = 0; |
| 5338 | goto reprocess_servers; |
| 5339 | } |
| 5340 | |
| 5341 | next_param = cur_param; |
| 5342 | } |
| 5343 | } |
| 5344 | |
| 5345 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5346 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5347 | } |
| 5348 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5349 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5350 | } |
| 5351 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5352 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5353 | } |
| 5354 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5355 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5356 | } |
| 5357 | out: |
| 5358 | return 1; |
| 5359 | } |
| 5360 | |
| 5361 | |
| 5362 | static int stats_send_http_headers(struct stream_interface *si) |
| 5363 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5364 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5365 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5366 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5367 | |
| 5368 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5369 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5370 | "Cache-Control: no-cache\r\n" |
| 5371 | "Connection: close\r\n" |
| 5372 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5373 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5374 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5375 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5376 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5377 | uri->refresh); |
| 5378 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5379 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5380 | |
| 5381 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5382 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5383 | else |
| 5384 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5385 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5386 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5387 | s->logs.tv_request = now; |
| 5388 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5389 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5390 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5391 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5392 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5393 | |
| 5394 | return 1; |
| 5395 | } |
| 5396 | |
| 5397 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5398 | { |
| 5399 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5400 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5401 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5402 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5403 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5404 | /* 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] | 5405 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5406 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5407 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5408 | 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] | 5409 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | /* We don't want to land on the posted stats page because a refresh will |
| 5413 | * repost the data. We don't want this to happen on accident so we redirect |
| 5414 | * the browse to the stats page with a GET. |
| 5415 | */ |
| 5416 | chunk_printf(&trash, |
| 5417 | "HTTP/1.1 303 See Other\r\n" |
| 5418 | "Cache-Control: no-cache\r\n" |
| 5419 | "Content-Type: text/plain\r\n" |
| 5420 | "Connection: close\r\n" |
| 5421 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5422 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5423 | "\r\n", |
| 5424 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5425 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5426 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5427 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5428 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5429 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5430 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5431 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5432 | scope_txt); |
| 5433 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5434 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5435 | s->logs.tv_request = now; |
| 5436 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5437 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5438 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5439 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5440 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5441 | |
| 5442 | return 1; |
| 5443 | } |
| 5444 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5445 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5446 | * 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] | 5447 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5448 | * automatically unregisters itself once transfer is complete. |
| 5449 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5450 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5451 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5452 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5453 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5454 | struct channel *req = si_oc(si); |
| 5455 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5456 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5457 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5458 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5459 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5460 | /* check that the output is not closed */ |
| 5461 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5462 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5463 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5464 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5465 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5466 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5467 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5468 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5469 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5470 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5471 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5472 | } |
| 5473 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5474 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5475 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5476 | unsigned int data_len; |
| 5477 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5478 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5479 | |
| 5480 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5481 | /* One difficulty we're facing is that we must prevent |
| 5482 | * the input data from being automatically forwarded to |
| 5483 | * the output area. For this, we temporarily disable |
| 5484 | * forwarding on the channel. |
| 5485 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5486 | last_fwd = si_ic(si)->to_forward; |
| 5487 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5488 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5489 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5490 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5491 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5492 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5493 | } |
| 5494 | } |
| 5495 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5496 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5497 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5498 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5499 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5500 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5501 | |
| 5502 | /* Now we must either adjust or remove the chunk size. This is |
| 5503 | * not easy because the chunk size might wrap at the end of the |
| 5504 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5505 | * the size, then restore the buffer's contents. Note that we can |
| 5506 | * only do that because no forwarding is scheduled on the stats |
| 5507 | * applet. |
| 5508 | */ |
| 5509 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5510 | si_ic(si)->total -= (last_len - prev_len); |
| 5511 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5512 | |
| 5513 | if (last_len != data_len) { |
| 5514 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5515 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5516 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5517 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5518 | si_ic(si)->total += (last_len - data_len); |
| 5519 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5520 | } |
| 5521 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5522 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5523 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5524 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5525 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5526 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5527 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5528 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5529 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5530 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5531 | } |
| 5532 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5533 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5534 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5535 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5536 | } |
| 5537 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5538 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5539 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5540 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5541 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5542 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5543 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5544 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5545 | } |
| 5546 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5547 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5548 | res->flags |= CF_READ_NULL; |
| 5549 | si_shutr(si); |
| 5550 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5551 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5552 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5553 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5554 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5555 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5556 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5557 | si_shutr(si); |
| 5558 | res->flags |= CF_READ_NULL; |
| 5559 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5560 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5561 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5562 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5563 | } |
| 5564 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5565 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5566 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5567 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5568 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5569 | return "NONE"; |
| 5570 | return conn->ctrl->name; |
| 5571 | } |
| 5572 | |
| 5573 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5574 | { |
| 5575 | static char ptr[17]; |
| 5576 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5577 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5578 | return "NONE"; |
| 5579 | |
| 5580 | if (conn->xprt == &raw_sock) |
| 5581 | return "RAW"; |
| 5582 | |
| 5583 | #ifdef USE_OPENSSL |
| 5584 | if (conn->xprt == &ssl_sock) |
| 5585 | return "SSL"; |
| 5586 | #endif |
| 5587 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5588 | return ptr; |
| 5589 | } |
| 5590 | |
| 5591 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5592 | { |
| 5593 | static char ptr[17]; |
| 5594 | |
| 5595 | if (!conn->data) |
| 5596 | return "NONE"; |
| 5597 | |
| 5598 | if (conn->data == &sess_conn_cb) |
| 5599 | return "SESS"; |
| 5600 | |
| 5601 | if (conn->data == &si_conn_cb) |
| 5602 | return "STRM"; |
| 5603 | |
| 5604 | if (conn->data == &check_conn_cb) |
| 5605 | return "CHCK"; |
| 5606 | |
| 5607 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5608 | return ptr; |
| 5609 | } |
| 5610 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5611 | /* This function dumps a complete stream state onto the stream interface's |
| 5612 | * 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] | 5613 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5614 | * 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] | 5615 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5616 | 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] | 5617 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5618 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5619 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5620 | extern const char *monthname[12]; |
| 5621 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5622 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5623 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5624 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5625 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5626 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5627 | 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] | 5628 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5629 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5630 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5631 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5632 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5633 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5634 | appctx->ctx.sess.uid = 0; |
| 5635 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5636 | return 1; |
| 5637 | } |
| 5638 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5639 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5640 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5641 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5642 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5643 | /* fall through */ |
| 5644 | |
| 5645 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5646 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5647 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5648 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5649 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5650 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5651 | 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] | 5652 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5653 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5654 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5655 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5656 | 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] | 5657 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5658 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5659 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5660 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5661 | break; |
| 5662 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5663 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5664 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5665 | default: |
| 5666 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5667 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5668 | break; |
| 5669 | } |
| 5670 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5671 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5672 | " 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] | 5673 | 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] | 5674 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5675 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5676 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5677 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5678 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5679 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5680 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5681 | if (conn) |
| 5682 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5683 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5684 | 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] | 5685 | case AF_INET: |
| 5686 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5687 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5688 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5689 | break; |
| 5690 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5691 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5692 | break; |
| 5693 | default: |
| 5694 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5695 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5696 | break; |
| 5697 | } |
| 5698 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5699 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5700 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5701 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5702 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5703 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5704 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5705 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5706 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5707 | conn = objt_conn(sess->si[1].end); |
| 5708 | if (conn) |
| 5709 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5710 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5711 | 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] | 5712 | case AF_INET: |
| 5713 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5714 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5715 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5716 | break; |
| 5717 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5718 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5719 | break; |
| 5720 | default: |
| 5721 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5722 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5723 | break; |
| 5724 | } |
| 5725 | |
| 5726 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5727 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5728 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5729 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5730 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5731 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5732 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5733 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5734 | if (conn) |
| 5735 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5736 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5737 | 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] | 5738 | case AF_INET: |
| 5739 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5740 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5741 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5742 | break; |
| 5743 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5744 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5745 | break; |
| 5746 | default: |
| 5747 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5748 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5749 | break; |
| 5750 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5751 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5752 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5753 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5754 | sess->task, |
| 5755 | sess->task->state, |
| 5756 | sess->task->nice, sess->task->calls, |
| 5757 | sess->task->expire ? |
| 5758 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5759 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5760 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5761 | task_in_rq(sess->task) ? ", running" : ""); |
| 5762 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5763 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5764 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5765 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5766 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5767 | if (sess->txn) |
| 5768 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5769 | " 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] | 5770 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5771 | 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] | 5772 | |
| 5773 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5774 | " 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] | 5775 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5776 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5777 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5778 | obj_type_name(sess->si[0].end), |
| 5779 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5780 | sess->si[0].exp ? |
| 5781 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5782 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5783 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5784 | sess->si[0].err_type); |
| 5785 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5786 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5787 | " 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] | 5788 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5789 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5790 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5791 | obj_type_name(sess->si[1].end), |
| 5792 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5793 | sess->si[1].exp ? |
| 5794 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5795 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5796 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5797 | sess->si[1].err_type); |
| 5798 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5799 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5800 | chunk_appendf(&trash, |
| 5801 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5802 | conn, |
| 5803 | get_conn_ctrl_name(conn), |
| 5804 | get_conn_xprt_name(conn), |
| 5805 | get_conn_data_name(conn), |
| 5806 | obj_type_name(conn->target), |
| 5807 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5808 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5809 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5810 | " 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] | 5811 | conn->flags, |
| 5812 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5813 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5814 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5815 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5816 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5817 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5818 | chunk_appendf(&trash, |
| 5819 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5820 | tmpctx, |
| 5821 | tmpctx->st0, |
| 5822 | tmpctx->st1, |
| 5823 | tmpctx->st2, |
| 5824 | tmpctx->applet->name); |
| 5825 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5826 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5827 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5828 | chunk_appendf(&trash, |
| 5829 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5830 | conn, |
| 5831 | get_conn_ctrl_name(conn), |
| 5832 | get_conn_xprt_name(conn), |
| 5833 | get_conn_data_name(conn), |
| 5834 | obj_type_name(conn->target), |
| 5835 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5836 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5837 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 5838 | " 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] | 5839 | conn->flags, |
| 5840 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5841 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5842 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5843 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5844 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5845 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5846 | chunk_appendf(&trash, |
| 5847 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5848 | tmpctx, |
| 5849 | tmpctx->st0, |
| 5850 | tmpctx->st1, |
| 5851 | tmpctx->st2, |
| 5852 | tmpctx->applet->name); |
| 5853 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5854 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5855 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5856 | " 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] | 5857 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5858 | &sess->req, |
| 5859 | sess->req.flags, sess->req.analysers, |
| 5860 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5861 | sess->req.to_forward, sess->req.total, |
| 5862 | sess->req.analyse_exp ? |
| 5863 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5864 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5865 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5866 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5867 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5868 | sess->req.rex ? |
| 5869 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5870 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5871 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5872 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5873 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5874 | " 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] | 5875 | sess->req.wex ? |
| 5876 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5877 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5878 | sess->req.buf, |
| 5879 | sess->req.buf->data, sess->req.buf->o, |
| 5880 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5881 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5882 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5883 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5884 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5885 | " 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] | 5886 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5887 | &sess->res, |
| 5888 | sess->res.flags, sess->res.analysers, |
| 5889 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5890 | sess->res.to_forward, sess->res.total, |
| 5891 | sess->res.analyse_exp ? |
| 5892 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5893 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5894 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5895 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5896 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5897 | sess->res.rex ? |
| 5898 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5899 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5900 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5901 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5902 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5903 | " 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] | 5904 | sess->res.wex ? |
| 5905 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5906 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5907 | sess->res.buf, |
| 5908 | sess->res.buf->data, sess->res.buf->o, |
| 5909 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5910 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5911 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5912 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5913 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5914 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5915 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5916 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5917 | |
| 5918 | /* use other states to dump the contents */ |
| 5919 | } |
| 5920 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5921 | appctx->ctx.sess.uid = 0; |
| 5922 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5923 | return 1; |
| 5924 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5925 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 5926 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 5927 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 5928 | struct appctx *appctx = __objt_appctx(si->end); |
| 5929 | |
| 5930 | switch (appctx->st2) { |
| 5931 | case STAT_ST_INIT: |
| 5932 | /* Display the column headers. If the message cannot be sent, |
| 5933 | * quit the fucntion with returning 0. The function is called |
| 5934 | * later and restart at the state "STAT_ST_INIT". |
| 5935 | */ |
| 5936 | chunk_reset(&trash); |
| 5937 | chunk_appendf(&trash, "# id (file)\n"); |
| 5938 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5939 | si_applet_cant_put(si); |
| 5940 | return 0; |
| 5941 | } |
| 5942 | |
| 5943 | /* Now, we start the browsing of the references lists. |
| 5944 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 5945 | * avalaible field of this pointer is <list>. It is used with the function |
| 5946 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 5947 | */ |
| 5948 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 5949 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5950 | |
| 5951 | appctx->st2 = STAT_ST_LIST; |
| 5952 | /* fall through */ |
| 5953 | |
| 5954 | case STAT_ST_LIST: |
| 5955 | while (appctx->ctx.tlskeys.ref) { |
| 5956 | chunk_reset(&trash); |
| 5957 | |
| 5958 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 5959 | appctx->ctx.tlskeys.ref->filename); |
| 5960 | |
| 5961 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5962 | /* let's try again later from this stream. We add ourselves into |
| 5963 | * this stream's users so that it can remove us upon termination. |
| 5964 | */ |
| 5965 | si_applet_cant_put(si); |
| 5966 | return 0; |
| 5967 | } |
| 5968 | |
| 5969 | /* get next list entry and check the end of the list */ |
| 5970 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 5971 | } |
| 5972 | |
| 5973 | appctx->st2 = STAT_ST_FIN; |
| 5974 | /* fall through */ |
| 5975 | |
| 5976 | default: |
| 5977 | appctx->st2 = STAT_ST_FIN; |
| 5978 | return 1; |
| 5979 | } |
| 5980 | return 0; |
| 5981 | } |
| 5982 | #endif |
| 5983 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 5984 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 5985 | { |
| 5986 | struct appctx *appctx = __objt_appctx(si->end); |
| 5987 | |
| 5988 | switch (appctx->st2) { |
| 5989 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5990 | /* Display the column headers. If the message cannot be sent, |
| 5991 | * quit the fucntion with returning 0. The function is called |
| 5992 | * later and restart at the state "STAT_ST_INIT". |
| 5993 | */ |
| 5994 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 5995 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5996 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5997 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 5998 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5999 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6000 | |
| 6001 | /* Now, we start the browsing of the references lists. |
| 6002 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6003 | * avalaible field of this pointer is <list>. It is used with the function |
| 6004 | * pat_list_get_next() for retruning the first avalaible entry |
| 6005 | */ |
| 6006 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6007 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6008 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6009 | appctx->st2 = STAT_ST_LIST; |
| 6010 | /* fall through */ |
| 6011 | |
| 6012 | case STAT_ST_LIST: |
| 6013 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6014 | chunk_reset(&trash); |
| 6015 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6016 | /* Build messages. If the reference is used by another category than |
| 6017 | * the listed categorie, display the information in the massage. |
| 6018 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6019 | 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] | 6020 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6021 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6022 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6023 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6024 | /* let's try again later from this stream. We add ourselves into |
| 6025 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6026 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6027 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6028 | return 0; |
| 6029 | } |
| 6030 | |
| 6031 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6032 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6033 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | appctx->st2 = STAT_ST_FIN; |
| 6037 | /* fall through */ |
| 6038 | |
| 6039 | default: |
| 6040 | appctx->st2 = STAT_ST_FIN; |
| 6041 | return 1; |
| 6042 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6043 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6044 | } |
| 6045 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6046 | static int stats_map_lookup(struct stream_interface *si) |
| 6047 | { |
| 6048 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6049 | struct sample sample; |
| 6050 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6051 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6052 | |
| 6053 | switch (appctx->st2) { |
| 6054 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6055 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6056 | 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] | 6057 | 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] | 6058 | appctx->st2 = STAT_ST_LIST; |
| 6059 | /* fall through */ |
| 6060 | |
| 6061 | case STAT_ST_LIST: |
| 6062 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6063 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6064 | /* initialise chunk to build new message */ |
| 6065 | chunk_reset(&trash); |
| 6066 | |
| 6067 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6068 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6069 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6070 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6071 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6072 | if (appctx->ctx.map.expr->pat_head->match && |
| 6073 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6074 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6075 | else |
| 6076 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6077 | |
| 6078 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6079 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6080 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6081 | break; |
| 6082 | if (match_method >= PAT_MATCH_NUM) |
| 6083 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6084 | else |
| 6085 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6086 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6087 | /* case sensitive */ |
| 6088 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6089 | chunk_appendf(&trash, ", case=insensitive"); |
| 6090 | else |
| 6091 | chunk_appendf(&trash, ", case=sensitive"); |
| 6092 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6093 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6094 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6095 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6096 | chunk_appendf(&trash, ", found=no"); |
| 6097 | else |
| 6098 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | /* Display match and match info */ |
| 6102 | else { |
| 6103 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6104 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6105 | chunk_appendf(&trash, ", found=yes"); |
| 6106 | else |
| 6107 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6108 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6109 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6110 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6111 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6112 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6113 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6114 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6115 | /* display pattern */ |
| 6116 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6117 | if (pat->ref && pat->ref->pattern) |
| 6118 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6119 | else |
| 6120 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6121 | } |
| 6122 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6123 | if (pat->ref && pat->ref->pattern) |
| 6124 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6125 | else |
| 6126 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6127 | } |
| 6128 | |
| 6129 | /* display return value */ |
| 6130 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6131 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6132 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6133 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6134 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6135 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6136 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6137 | } |
| 6138 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6139 | chunk_appendf(&trash, "\n"); |
| 6140 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6141 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6142 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6143 | /* let's try again later from this stream. We add ourselves into |
| 6144 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6145 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6146 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6147 | return 0; |
| 6148 | } |
| 6149 | |
| 6150 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6151 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6152 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6153 | } |
| 6154 | |
| 6155 | appctx->st2 = STAT_ST_FIN; |
| 6156 | /* fall through */ |
| 6157 | |
| 6158 | default: |
| 6159 | appctx->st2 = STAT_ST_FIN; |
| 6160 | free(appctx->ctx.map.chunk.str); |
| 6161 | return 1; |
| 6162 | } |
| 6163 | } |
| 6164 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6165 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6166 | { |
| 6167 | struct appctx *appctx = __objt_appctx(si->end); |
| 6168 | |
| 6169 | switch (appctx->st2) { |
| 6170 | |
| 6171 | case STAT_ST_INIT: |
| 6172 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6173 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6174 | struct pat_ref_elt *, list); |
| 6175 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6176 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6177 | appctx->st2 = STAT_ST_LIST; |
| 6178 | /* fall through */ |
| 6179 | |
| 6180 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6181 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6182 | chunk_reset(&trash); |
| 6183 | |
| 6184 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6185 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6186 | chunk_appendf(&trash, "%p %s %s\n", |
| 6187 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6188 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6189 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6190 | chunk_appendf(&trash, "%p %s\n", |
| 6191 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6192 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6193 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6194 | /* let's try again later from this stream. We add ourselves into |
| 6195 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6196 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6197 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6198 | return 0; |
| 6199 | } |
| 6200 | |
| 6201 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6202 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6203 | struct pat_ref_elt *, list); |
| 6204 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6205 | break; |
| 6206 | } |
| 6207 | |
| 6208 | appctx->st2 = STAT_ST_FIN; |
| 6209 | /* fall through */ |
| 6210 | |
| 6211 | default: |
| 6212 | appctx->st2 = STAT_ST_FIN; |
| 6213 | return 1; |
| 6214 | } |
| 6215 | } |
| 6216 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6217 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6218 | * 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] | 6219 | * to be called again, otherwise non-zero. It is designed to be called |
| 6220 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6221 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6222 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6223 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6224 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6225 | struct connection *conn; |
| 6226 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6227 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6228 | /* 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] | 6229 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6230 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6231 | if (appctx->st2 == STAT_ST_LIST) { |
| 6232 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6233 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6234 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6235 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6236 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6237 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6238 | } |
| 6239 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6240 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6241 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6242 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6243 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6244 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6245 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6246 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6247 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6248 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6249 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6250 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6251 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6252 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6253 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6254 | /* fall through */ |
| 6255 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6256 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6257 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6258 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6259 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6260 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6261 | } |
| 6262 | |
| 6263 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6264 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6265 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6266 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6267 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6268 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6269 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6270 | if (appctx->ctx.sess.target) { |
| 6271 | 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] | 6272 | goto next_sess; |
| 6273 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6274 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6275 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6276 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6277 | return 0; |
| 6278 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6279 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6280 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6281 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6282 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6283 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6284 | break; |
| 6285 | } |
| 6286 | else |
| 6287 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6288 | } |
| 6289 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6290 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6291 | "%p: proto=%s", |
| 6292 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6293 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6294 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6295 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6296 | 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] | 6297 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6298 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6299 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6300 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6301 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6302 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6303 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6304 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6305 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6306 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6307 | break; |
| 6308 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6309 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6310 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6311 | strm_li(curr_sess)->luid, |
| 6312 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6313 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6314 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6315 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6316 | break; |
| 6317 | } |
| 6318 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6319 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6320 | " ts=%02x age=%s calls=%d", |
| 6321 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6322 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6323 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6324 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6325 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6326 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6327 | curr_sess->req.flags, |
| 6328 | curr_sess->req.buf->i, |
| 6329 | curr_sess->req.analysers, |
| 6330 | curr_sess->req.rex ? |
| 6331 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6332 | TICKS_TO_MS(1000)) : ""); |
| 6333 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6334 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6335 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6336 | curr_sess->req.wex ? |
| 6337 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6338 | TICKS_TO_MS(1000)) : ""); |
| 6339 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6340 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6341 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6342 | curr_sess->req.analyse_exp ? |
| 6343 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6344 | TICKS_TO_MS(1000)) : ""); |
| 6345 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6346 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6347 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6348 | curr_sess->res.flags, |
| 6349 | curr_sess->res.buf->i, |
| 6350 | curr_sess->res.analysers, |
| 6351 | curr_sess->res.rex ? |
| 6352 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6353 | TICKS_TO_MS(1000)) : ""); |
| 6354 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6355 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6356 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6357 | curr_sess->res.wex ? |
| 6358 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6359 | TICKS_TO_MS(1000)) : ""); |
| 6360 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6361 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6362 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6363 | curr_sess->res.analyse_exp ? |
| 6364 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6365 | TICKS_TO_MS(1000)) : ""); |
| 6366 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6367 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6368 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6369 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6370 | curr_sess->si[0].state, |
| 6371 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6372 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6373 | curr_sess->si[0].exp ? |
| 6374 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6375 | TICKS_TO_MS(1000)) : ""); |
| 6376 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6377 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6378 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6379 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6380 | curr_sess->si[1].state, |
| 6381 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6382 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6383 | curr_sess->si[1].exp ? |
| 6384 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6385 | TICKS_TO_MS(1000)) : ""); |
| 6386 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6387 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6388 | " exp=%s", |
| 6389 | curr_sess->task->expire ? |
| 6390 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6391 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6392 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6393 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6394 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6395 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6396 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6397 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6398 | /* let's try again later from this stream. We add ourselves into |
| 6399 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6400 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6401 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6402 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6403 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6404 | } |
| 6405 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6406 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6407 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6408 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6409 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6410 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6411 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6412 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6413 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6414 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6415 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6416 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6417 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6418 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6419 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6420 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6421 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6422 | appctx->ctx.sess.target = NULL; |
| 6423 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6424 | return 1; |
| 6425 | } |
| 6426 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6427 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6428 | /* fall through */ |
| 6429 | |
| 6430 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6431 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6432 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6433 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6434 | } |
| 6435 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6436 | /* This is called when the stream interface is closed. For instance, upon an |
| 6437 | * 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] | 6438 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6439 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6440 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6441 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6442 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6443 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6444 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6445 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6446 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6447 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6448 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6449 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6450 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6451 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6452 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6453 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6454 | } |
| 6455 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6456 | /* This function is used to either dump tables states (when action is set |
| 6457 | * 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] | 6458 | * It returns 0 if the output buffer is full and it needs to be called |
| 6459 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6460 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6461 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6462 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6463 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6464 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6465 | struct ebmb_node *eb; |
| 6466 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6467 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6468 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6469 | |
| 6470 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6471 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6472 | * - STAT_ST_INIT : the first call |
| 6473 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6474 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6475 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6476 | * and the entry pointer points to the next entry to be dumped, |
| 6477 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6478 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6479 | * data though. |
| 6480 | */ |
| 6481 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6482 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6483 | /* 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] | 6484 | if (appctx->st2 == STAT_ST_LIST) { |
| 6485 | appctx->ctx.table.entry->ref_cnt--; |
| 6486 | 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] | 6487 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6488 | return 1; |
| 6489 | } |
| 6490 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6491 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6492 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6493 | while (appctx->st2 != STAT_ST_FIN) { |
| 6494 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6495 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6496 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6497 | if (!appctx->ctx.table.proxy) |
| 6498 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6499 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6500 | appctx->ctx.table.entry = NULL; |
| 6501 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6502 | break; |
| 6503 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6504 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6505 | if (!appctx->ctx.table.proxy || |
| 6506 | (appctx->ctx.table.target && |
| 6507 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6508 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6509 | break; |
| 6510 | } |
| 6511 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6512 | if (appctx->ctx.table.proxy->table.size) { |
| 6513 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6514 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6515 | return 0; |
| 6516 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6517 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6518 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6519 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6520 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6521 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6522 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6523 | appctx->ctx.table.entry->ref_cnt++; |
| 6524 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6525 | break; |
| 6526 | } |
| 6527 | } |
| 6528 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6529 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6530 | break; |
| 6531 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6532 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6533 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6534 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6535 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6536 | /* we're filtering on some data contents */ |
| 6537 | void *ptr; |
| 6538 | long long data; |
| 6539 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6540 | dt = appctx->ctx.table.data_type; |
| 6541 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6542 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6543 | dt); |
| 6544 | |
| 6545 | data = 0; |
| 6546 | switch (stktable_data_types[dt].std_type) { |
| 6547 | case STD_T_SINT: |
| 6548 | data = stktable_data_cast(ptr, std_t_sint); |
| 6549 | break; |
| 6550 | case STD_T_UINT: |
| 6551 | data = stktable_data_cast(ptr, std_t_uint); |
| 6552 | break; |
| 6553 | case STD_T_ULL: |
| 6554 | data = stktable_data_cast(ptr, std_t_ull); |
| 6555 | break; |
| 6556 | case STD_T_FRQP: |
| 6557 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6558 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6559 | break; |
| 6560 | } |
| 6561 | |
| 6562 | /* 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] | 6563 | if ((data < appctx->ctx.table.value && |
| 6564 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6565 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6566 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6567 | (data == appctx->ctx.table.value && |
| 6568 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6569 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6570 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6571 | (data > appctx->ctx.table.value && |
| 6572 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6573 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6574 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6575 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6576 | } |
| 6577 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6578 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6579 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6580 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6581 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6582 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6583 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6584 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6585 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6586 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6587 | struct stksess *old = appctx->ctx.table.entry; |
| 6588 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6589 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6590 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6591 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6592 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6593 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6594 | break; |
| 6595 | } |
| 6596 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6597 | |
| 6598 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6599 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6600 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6601 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6602 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6603 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6604 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6605 | break; |
| 6606 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6607 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6608 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6609 | break; |
| 6610 | } |
| 6611 | } |
| 6612 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6613 | } |
| 6614 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6615 | /* 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] | 6616 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6617 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6618 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6619 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6620 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6621 | * after the offset. The new pointer is returned. |
| 6622 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6623 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6624 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6625 | { |
| 6626 | int end; |
| 6627 | unsigned char c; |
| 6628 | |
| 6629 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6630 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6631 | return ptr; |
| 6632 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6633 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6634 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6635 | while (ptr < len && ptr < bsize) { |
| 6636 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6637 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6638 | if (out->len > end - 2) |
| 6639 | break; |
| 6640 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6641 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6642 | if (out->len > end - 3) |
| 6643 | break; |
| 6644 | out->str[out->len++] = '\\'; |
| 6645 | switch (c) { |
| 6646 | case '\t': c = 't'; break; |
| 6647 | case '\n': c = 'n'; break; |
| 6648 | case '\r': c = 'r'; break; |
| 6649 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6650 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6651 | } |
| 6652 | out->str[out->len++] = c; |
| 6653 | } else { |
| 6654 | if (out->len > end - 5) |
| 6655 | break; |
| 6656 | out->str[out->len++] = '\\'; |
| 6657 | out->str[out->len++] = 'x'; |
| 6658 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6659 | out->str[out->len++] = hextab[c & 0xF]; |
| 6660 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6661 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6662 | /* we had a line break, let's return now */ |
| 6663 | out->str[out->len++] = '\n'; |
| 6664 | *line = ptr; |
| 6665 | return ptr; |
| 6666 | } |
| 6667 | } |
| 6668 | /* we have an incomplete line, we return it as-is */ |
| 6669 | out->str[out->len++] = '\n'; |
| 6670 | return ptr; |
| 6671 | } |
| 6672 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6673 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6674 | * It returns 0 if the output buffer is full and it needs |
| 6675 | * to be called again, otherwise non-zero. |
| 6676 | */ |
| 6677 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6678 | { |
| 6679 | struct appctx *appctx = __objt_appctx(si->end); |
| 6680 | struct dns_resolvers *presolvers; |
| 6681 | struct dns_nameserver *pnameserver; |
| 6682 | |
| 6683 | chunk_reset(&trash); |
| 6684 | |
| 6685 | switch (appctx->st2) { |
| 6686 | case STAT_ST_INIT: |
| 6687 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6688 | /* fall through */ |
| 6689 | |
| 6690 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6691 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6692 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6693 | } |
| 6694 | else { |
| 6695 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6696 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6697 | continue; |
| 6698 | |
| 6699 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6700 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6701 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6702 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6703 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6704 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6705 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6706 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6707 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6708 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6709 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6710 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6711 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6712 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6713 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6714 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6715 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6716 | } |
| 6717 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6718 | } |
| 6719 | |
| 6720 | /* display response */ |
| 6721 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6722 | /* let's try again later from this session. We add ourselves into |
| 6723 | * this session's users so that it can remove us upon termination. |
| 6724 | */ |
| 6725 | si->flags |= SI_FL_WAIT_ROOM; |
| 6726 | return 0; |
| 6727 | } |
| 6728 | |
| 6729 | appctx->st2 = STAT_ST_FIN; |
| 6730 | /* fall through */ |
| 6731 | |
| 6732 | default: |
| 6733 | appctx->st2 = STAT_ST_FIN; |
| 6734 | return 1; |
| 6735 | } |
| 6736 | } |
| 6737 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6738 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6739 | * 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] | 6740 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6741 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6742 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6743 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6744 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6745 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6746 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6747 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6748 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6749 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6750 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6751 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6752 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6753 | /* the function had not been called yet, let's prepare the |
| 6754 | * buffer for a response. |
| 6755 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6756 | struct tm tm; |
| 6757 | |
| 6758 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6759 | 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] | 6760 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6761 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6762 | error_snapshot_id); |
| 6763 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6764 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6765 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6766 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6767 | return 0; |
| 6768 | } |
| 6769 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6770 | appctx->ctx.errors.px = proxy; |
| 6771 | appctx->ctx.errors.buf = 0; |
| 6772 | appctx->ctx.errors.bol = 0; |
| 6773 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | /* we have two inner loops here, one for the proxy, the other one for |
| 6777 | * the buffer. |
| 6778 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6779 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6780 | struct error_snapshot *es; |
| 6781 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6782 | if (appctx->ctx.errors.buf == 0) |
| 6783 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6784 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6785 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6786 | |
| 6787 | if (!es->when.tv_sec) |
| 6788 | goto next; |
| 6789 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6790 | if (appctx->ctx.errors.iid >= 0 && |
| 6791 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6792 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6793 | goto next; |
| 6794 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6795 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6796 | /* just print headers now */ |
| 6797 | |
| 6798 | char pn[INET6_ADDRSTRLEN]; |
| 6799 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6800 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6801 | |
| 6802 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6803 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6804 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6805 | 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] | 6806 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6807 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6808 | case AF_INET: |
| 6809 | case AF_INET6: |
| 6810 | port = get_host_port(&es->src); |
| 6811 | break; |
| 6812 | default: |
| 6813 | port = 0; |
| 6814 | } |
| 6815 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6816 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6817 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6818 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6819 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6820 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6821 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6822 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6823 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6824 | break; |
| 6825 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6826 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6827 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6828 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6829 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6830 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6831 | break; |
| 6832 | } |
| 6833 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6834 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6835 | ", server %s (#%d), event #%u\n" |
| 6836 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6837 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6838 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6839 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6840 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6841 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6842 | es->ev_id, |
| 6843 | pn, port, es->sid, es->s_flags, |
| 6844 | es->state, es->m_flags, es->t_flags, |
| 6845 | es->m_clen, es->m_blen, |
| 6846 | es->b_flags, es->b_out, es->b_tot, |
| 6847 | es->len, es->b_wrap, es->pos); |
| 6848 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6849 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6850 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6851 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6852 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6853 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6854 | appctx->ctx.errors.ptr = 0; |
| 6855 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6856 | } |
| 6857 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6858 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6859 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6860 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6861 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6862 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6863 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6864 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6865 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6866 | goto next; |
| 6867 | } |
| 6868 | |
| 6869 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6870 | while (appctx->ctx.errors.ptr < es->len && appctx->ctx.errors.ptr < sizeof(es->buf)) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6871 | int newptr; |
| 6872 | int newline; |
| 6873 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6874 | newline = appctx->ctx.errors.bol; |
| 6875 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6876 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6877 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6878 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6879 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6880 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6881 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6882 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6883 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6884 | appctx->ctx.errors.ptr = newptr; |
| 6885 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6886 | }; |
| 6887 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6888 | appctx->ctx.errors.bol = 0; |
| 6889 | appctx->ctx.errors.ptr = -1; |
| 6890 | appctx->ctx.errors.buf++; |
| 6891 | if (appctx->ctx.errors.buf > 1) { |
| 6892 | appctx->ctx.errors.buf = 0; |
| 6893 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6894 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 6895 | } |
| 6896 | |
| 6897 | /* dump complete */ |
| 6898 | return 1; |
| 6899 | } |
| 6900 | |
| 6901 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 6902 | * if the output buffer is full and it needs to be called again, otherwise |
| 6903 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 6904 | */ |
| 6905 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 6906 | { |
| 6907 | struct appctx *appctx = __objt_appctx(si->end); |
| 6908 | |
| 6909 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 6910 | return 1; |
| 6911 | |
| 6912 | chunk_reset(&trash); |
| 6913 | |
| 6914 | /* we have two inner loops here, one for the proxy, the other one for |
| 6915 | * the buffer. |
| 6916 | */ |
| 6917 | while (*appctx->ctx.env.var) { |
| 6918 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 6919 | |
| 6920 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6921 | si_applet_cant_put(si); |
| 6922 | return 0; |
| 6923 | } |
| 6924 | if (appctx->st2 == STAT_ST_END) |
| 6925 | break; |
| 6926 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6927 | } |
| 6928 | |
| 6929 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6930 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6931 | } |
| 6932 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6933 | /* parse the "level" argument on the bind lines */ |
| 6934 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6935 | { |
| 6936 | if (!*args[cur_arg + 1]) { |
| 6937 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6938 | return ERR_ALERT | ERR_FATAL; |
| 6939 | } |
| 6940 | |
| 6941 | if (!strcmp(args[cur_arg+1], "user")) |
| 6942 | conf->level = ACCESS_LVL_USER; |
| 6943 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6944 | conf->level = ACCESS_LVL_OPER; |
| 6945 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 6946 | conf->level = ACCESS_LVL_ADMIN; |
| 6947 | else { |
| 6948 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 6949 | args[cur_arg], args[cur_arg+1]); |
| 6950 | return ERR_ALERT | ERR_FATAL; |
| 6951 | } |
| 6952 | |
| 6953 | return 0; |
| 6954 | } |
| 6955 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6956 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6957 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6958 | .name = "<STATS>", /* used for logging */ |
| 6959 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 6960 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6961 | }; |
| 6962 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 6963 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6964 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6965 | .name = "<CLI>", /* used for logging */ |
| 6966 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6967 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 6968 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6969 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 6970 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6971 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 6972 | { 0, NULL, NULL }, |
| 6973 | }}; |
| 6974 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6975 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 6976 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 6977 | { NULL, NULL, 0 }, |
| 6978 | }}; |
| 6979 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6980 | __attribute__((constructor)) |
| 6981 | static void __dumpstats_module_init(void) |
| 6982 | { |
| 6983 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6984 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 6985 | } |
| 6986 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 6987 | /* |
| 6988 | * Local variables: |
| 6989 | * c-indent-level: 8 |
| 6990 | * c-basic-offset: 8 |
| 6991 | * End: |
| 6992 | */ |