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 | |
Willy Tarreau | 8e20514 | 2016-01-04 17:23:25 +0100 | [diff] [blame] | 257 | /* Stats fields for CSV output. For any field added here, please add the text |
| 258 | * representation in the stat_field_names array below. Please only append at the end, |
| 259 | * before the ST_F_TOTAL_FIELDS entry, and never insert anything in the middle |
| 260 | * nor at the beginning. |
| 261 | */ |
| 262 | enum stat_field { |
| 263 | ST_F_PXNAME, |
| 264 | ST_F_SVNAME, |
| 265 | ST_F_QCUR, |
| 266 | ST_F_QMAX, |
| 267 | ST_F_SCUR, |
| 268 | ST_F_SMAX, |
| 269 | ST_F_SLIM, |
| 270 | ST_F_STOT, |
| 271 | ST_F_BIN , |
| 272 | ST_F_BOUT, |
| 273 | ST_F_DREQ, |
| 274 | ST_F_DRESP, |
| 275 | ST_F_EREQ, |
| 276 | ST_F_ECON, |
| 277 | ST_F_ERESP, |
| 278 | ST_F_WRETR, |
| 279 | ST_F_WREDIS, |
| 280 | ST_F_STATUS, |
| 281 | ST_F_WEIGHT, |
| 282 | ST_F_ACT, |
| 283 | ST_F_BCK, |
| 284 | ST_F_CHKFAIL, |
| 285 | ST_F_CHKDOWN, |
| 286 | ST_F_LASTCHG, |
| 287 | ST_F_DOWNTIME, |
| 288 | ST_F_QLIMIT, |
| 289 | ST_F_PID, |
| 290 | ST_F_IID, |
| 291 | ST_F_SID, |
| 292 | ST_F_THROTTLE, |
| 293 | ST_F_LBTOT, |
| 294 | ST_F_TRACKED, |
| 295 | ST_F_TYPE, |
| 296 | ST_F_RATE, |
| 297 | ST_F_RATE_LIM, |
| 298 | ST_F_RATE_MAX, |
| 299 | ST_F_CHECK_STATUS, |
| 300 | ST_F_CHECK_CODE, |
| 301 | ST_F_CHECK_DURATION, |
| 302 | ST_F_HRSP_1XX, |
| 303 | ST_F_HRSP_2XX, |
| 304 | ST_F_HRSP_3XX, |
| 305 | ST_F_HRSP_4XX, |
| 306 | ST_F_HRSP_5XX, |
| 307 | ST_F_HRSP_OTHER, |
| 308 | ST_F_HANAFAIL, |
| 309 | ST_F_REQ_RATE, |
| 310 | ST_F_REQ_RATE_MAX, |
| 311 | ST_F_REQ_TOT, |
| 312 | ST_F_CLI_ABRT, |
| 313 | ST_F_SRV_ABRT, |
| 314 | ST_F_COMP_IN, |
| 315 | ST_F_COMP_OUT, |
| 316 | ST_F_COMP_BYP, |
| 317 | ST_F_COMP_RSP, |
| 318 | ST_F_LASTSESS, |
| 319 | ST_F_LAST_CHK, |
| 320 | ST_F_LAST_AGT, |
| 321 | ST_F_QTIME, |
| 322 | ST_F_CTIME, |
| 323 | ST_F_RTIME, |
| 324 | ST_F_TTIME, |
| 325 | |
| 326 | /* must always be the last one */ |
| 327 | ST_F_TOTAL_FIELDS |
| 328 | }; |
| 329 | |
| 330 | /* These are the field names for each ST_F_* field position. Please pay attention |
| 331 | * to always use the exact same name except that the strings must be lower case |
| 332 | * while the enum entries must be upper case. |
| 333 | */ |
| 334 | const char *stat_field_names[ST_F_TOTAL_FIELDS] = { |
| 335 | [ST_F_PXNAME] = "pxname", |
| 336 | [ST_F_SVNAME] = "svname", |
| 337 | [ST_F_QCUR] = "qcur", |
| 338 | [ST_F_QMAX] = "qmax", |
| 339 | [ST_F_SCUR] = "scur", |
| 340 | [ST_F_SMAX] = "smax", |
| 341 | [ST_F_SLIM] = "slim", |
| 342 | [ST_F_STOT] = "stot", |
| 343 | [ST_F_BIN] = "bin", |
| 344 | [ST_F_BOUT] = "bout", |
| 345 | [ST_F_DREQ] = "dreq", |
| 346 | [ST_F_DRESP] = "dresp", |
| 347 | [ST_F_EREQ] = "ereq", |
| 348 | [ST_F_ECON] = "econ", |
| 349 | [ST_F_ERESP] = "eresp", |
| 350 | [ST_F_WRETR] = "wretr", |
| 351 | [ST_F_WREDIS] = "wredis", |
| 352 | [ST_F_STATUS] = "status", |
| 353 | [ST_F_WEIGHT] = "weight", |
| 354 | [ST_F_ACT] = "act", |
| 355 | [ST_F_BCK] = "bck", |
| 356 | [ST_F_CHKFAIL] = "chkfail", |
| 357 | [ST_F_CHKDOWN] = "chkdown", |
| 358 | [ST_F_LASTCHG] = "lastchg", |
| 359 | [ST_F_DOWNTIME] = "downtime", |
| 360 | [ST_F_QLIMIT] = "qlimit", |
| 361 | [ST_F_PID] = "pid", |
| 362 | [ST_F_IID] = "iid", |
| 363 | [ST_F_SID] = "sid", |
| 364 | [ST_F_THROTTLE] = "throttle", |
| 365 | [ST_F_LBTOT] = "lbtot", |
| 366 | [ST_F_TRACKED] = "tracked", |
| 367 | [ST_F_TYPE] = "type", |
| 368 | [ST_F_RATE] = "rate", |
| 369 | [ST_F_RATE_LIM] = "rate_lim", |
| 370 | [ST_F_RATE_MAX] = "rate_max", |
| 371 | [ST_F_CHECK_STATUS] = "check_status", |
| 372 | [ST_F_CHECK_CODE] = "check_code", |
| 373 | [ST_F_CHECK_DURATION] = "check_duration", |
| 374 | [ST_F_HRSP_1XX] = "hrsp_1xx", |
| 375 | [ST_F_HRSP_2XX] = "hrsp_2xx", |
| 376 | [ST_F_HRSP_3XX] = "hrsp_3xx", |
| 377 | [ST_F_HRSP_4XX] = "hrsp_4xx", |
| 378 | [ST_F_HRSP_5XX] = "hrsp_5xx", |
| 379 | [ST_F_HRSP_OTHER] = "hrsp_other", |
| 380 | [ST_F_HANAFAIL] = "hanafail", |
| 381 | [ST_F_REQ_RATE] = "req_rate", |
| 382 | [ST_F_REQ_RATE_MAX] = "req_rate_max", |
| 383 | [ST_F_REQ_TOT] = "req_tot", |
| 384 | [ST_F_CLI_ABRT] = "cli_abrt", |
| 385 | [ST_F_SRV_ABRT] = "srv_abrt", |
| 386 | [ST_F_COMP_IN] = "comp_in", |
| 387 | [ST_F_COMP_OUT] = "comp_out", |
| 388 | [ST_F_COMP_BYP] = "comp_byp", |
| 389 | [ST_F_COMP_RSP] = "comp_rsp", |
| 390 | [ST_F_LASTSESS] = "lastsess", |
| 391 | [ST_F_LAST_CHK] = "last_chk", |
| 392 | [ST_F_LAST_AGT] = "last_agt", |
| 393 | [ST_F_QTIME] = "qtime", |
| 394 | [ST_F_CTIME] = "ctime", |
| 395 | [ST_F_RTIME] = "rtime", |
| 396 | [ST_F_TTIME] = "ttime", |
| 397 | }; |
| 398 | |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 399 | /* one line of stats */ |
| 400 | static struct field stats[ST_F_TOTAL_FIELDS]; |
| 401 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 402 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 403 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 404 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 405 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 406 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 407 | 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] | 408 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 409 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 410 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 411 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 412 | 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] | 413 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 414 | static int stats_pats_list(struct stream_interface *si); |
| 415 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 416 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 417 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 418 | static int stats_tlskeys_list(struct stream_interface *si); |
| 419 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 420 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 421 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 422 | static void dump_servers_state(struct proxy *backend, struct chunk *buf); |
| 423 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 424 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 425 | * cli_io_handler() |
| 426 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 427 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 428 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 429 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 430 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 431 | * -> stats_dump_stat_to_buffer() // "show stat" |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 432 | * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 433 | * -> stats_dump_csv_header() |
| 434 | * -> stats_dump_proxy_to_buffer() |
| 435 | * -> stats_dump_fe_stats() |
| 436 | * -> stats_dump_li_stats() |
| 437 | * -> stats_dump_sv_stats() |
| 438 | * -> stats_dump_be_stats() |
| 439 | * |
| 440 | * http_stats_io_handler() |
| 441 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 442 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 443 | * -> stats_dump_html_head() // emits the HTML headers |
| 444 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 445 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 446 | * -> stats_dump_html_px_hdr() |
| 447 | * -> stats_dump_fe_stats() |
| 448 | * -> stats_dump_li_stats() |
| 449 | * -> stats_dump_sv_stats() |
| 450 | * -> stats_dump_be_stats() |
| 451 | * -> stats_dump_html_px_end() |
| 452 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 453 | */ |
| 454 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 455 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 456 | |
| 457 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 458 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 459 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 460 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 461 | " help : this message\n" |
| 462 | " prompt : toggle interactive mode with prompt\n" |
| 463 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 464 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 465 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 466 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 467 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 468 | " show stat : report counters for each proxy and server\n" |
| 469 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 470 | " 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] | 471 | " 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] | 472 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 473 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 474 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 475 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 476 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 477 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 478 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 479 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 480 | " disable : put a server or frontend in maintenance mode\n" |
| 481 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 482 | " 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] | 483 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 484 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 485 | " add acl : add acl entry\n" |
| 486 | " del acl : delete acl entry\n" |
| 487 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 488 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 489 | " get map : reports the keys and values matching a sample for a map\n" |
| 490 | " set map : modify map entry\n" |
| 491 | " add map : add map entry\n" |
| 492 | " del map : delete map entry\n" |
| 493 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 494 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 495 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 496 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 497 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 498 | "Permission denied\n" |
| 499 | ""; |
| 500 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 501 | /* data transmission states for the stats responses */ |
| 502 | enum { |
| 503 | STAT_ST_INIT = 0, |
| 504 | STAT_ST_HEAD, |
| 505 | STAT_ST_INFO, |
| 506 | STAT_ST_LIST, |
| 507 | STAT_ST_END, |
| 508 | STAT_ST_FIN, |
| 509 | }; |
| 510 | |
| 511 | /* data transmission states for the stats responses inside a proxy */ |
| 512 | enum { |
| 513 | STAT_PX_ST_INIT = 0, |
| 514 | STAT_PX_ST_TH, |
| 515 | STAT_PX_ST_FE, |
| 516 | STAT_PX_ST_LI, |
| 517 | STAT_PX_ST_SV, |
| 518 | STAT_PX_ST_BE, |
| 519 | STAT_PX_ST_END, |
| 520 | STAT_PX_ST_FIN, |
| 521 | }; |
| 522 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 523 | extern const char *stat_status_codes[]; |
| 524 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 525 | /* allocate a new stats frontend named <name>, and return it |
| 526 | * (or NULL in case of lack of memory). |
| 527 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 528 | 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] | 529 | { |
| 530 | struct proxy *fe; |
| 531 | |
| 532 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 533 | if (!fe) |
| 534 | return NULL; |
| 535 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 536 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 537 | fe->next = proxy; |
| 538 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 539 | fe->last_change = now.tv_sec; |
| 540 | fe->id = strdup("GLOBAL"); |
| 541 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 542 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 543 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 544 | fe->conf.file = strdup(file); |
| 545 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 546 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 547 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 548 | |
| 549 | /* the stats frontend is the only one able to assign ID #0 */ |
| 550 | fe->conf.id.key = fe->uuid = 0; |
| 551 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 552 | return fe; |
| 553 | } |
| 554 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 555 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 556 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 557 | * error message into the <err> buffer which will be preallocated. The trailing |
| 558 | * '\n' must not be written. The function must be called with <args> pointing to |
| 559 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 560 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 561 | 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] | 562 | struct proxy *defpx, const char *file, int line, |
| 563 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 564 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 565 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 566 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 567 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 568 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 569 | int cur_arg; |
| 570 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 571 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 572 | 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] | 573 | return -1; |
| 574 | } |
| 575 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 576 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 577 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 578 | 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] | 579 | return -1; |
| 580 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 581 | } |
| 582 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 583 | 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] | 584 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 585 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 586 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 587 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 588 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 589 | return -1; |
| 590 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 591 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 592 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 593 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 594 | static int bind_dumped; |
| 595 | struct bind_kw *kw; |
| 596 | |
| 597 | kw = bind_find_kw(args[cur_arg]); |
| 598 | if (kw) { |
| 599 | if (!kw->parse) { |
| 600 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 601 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 602 | return -1; |
| 603 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 604 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 605 | 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] | 606 | if (err && *err) |
| 607 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 608 | else |
| 609 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 610 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 611 | return -1; |
| 612 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 613 | |
| 614 | cur_arg += 1 + kw->skip; |
| 615 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 616 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 617 | |
| 618 | if (!bind_dumped) { |
| 619 | bind_dump_kws(err); |
| 620 | indent_msg(err, 4); |
| 621 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 622 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 623 | |
| 624 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 625 | args[0], args[1], args[cur_arg], |
| 626 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 627 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 628 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 629 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 630 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 631 | l->maxconn = global.stats_fe->maxconn; |
| 632 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 633 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 634 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 635 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 636 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 637 | l->nice = -64; /* we want to boost priority for local stats */ |
| 638 | global.maxsock += l->maxconn; |
| 639 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 640 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 641 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 642 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 643 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 644 | |
| 645 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 646 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 647 | return -1; |
| 648 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 649 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 650 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 651 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 652 | return -1; |
| 653 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 654 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 655 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 656 | 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] | 657 | return -1; |
| 658 | } |
| 659 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 660 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 661 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 662 | else if (!strcmp(args[1], "maxconn")) { |
| 663 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 664 | |
| 665 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 666 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 667 | return -1; |
| 668 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 669 | |
| 670 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 671 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 672 | 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] | 673 | return -1; |
| 674 | } |
| 675 | } |
| 676 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 677 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 678 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 679 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 680 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 681 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 682 | if (!global.stats_fe) { |
| 683 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 684 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 685 | return -1; |
| 686 | } |
| 687 | } |
| 688 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 689 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 690 | unsigned int low, high; |
| 691 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 692 | if (strcmp(args[cur_arg], "all") == 0) { |
| 693 | set = 0; |
| 694 | break; |
| 695 | } |
| 696 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 697 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 698 | } |
| 699 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 700 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 701 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 702 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 703 | char *dash = strchr(args[cur_arg], '-'); |
| 704 | |
| 705 | low = high = str2uic(args[cur_arg]); |
| 706 | if (dash) |
| 707 | high = str2uic(dash + 1); |
| 708 | |
| 709 | if (high < low) { |
| 710 | unsigned int swap = low; |
| 711 | low = high; |
| 712 | high = swap; |
| 713 | } |
| 714 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 715 | if (low < 1 || high > LONGBITS) { |
| 716 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 717 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 718 | return -1; |
| 719 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 720 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 721 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 722 | } |
| 723 | else { |
| 724 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 725 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 726 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 727 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 728 | } |
| 729 | cur_arg++; |
| 730 | } |
| 731 | global.stats_fe->bind_proc = set; |
| 732 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 733 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 734 | 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] | 735 | return -1; |
| 736 | } |
| 737 | return 0; |
| 738 | } |
| 739 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 740 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 741 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 742 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 743 | * 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] | 744 | */ |
| 745 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 746 | { |
Willy Tarreau | f614229 | 2016-01-04 17:24:29 +0100 | [diff] [blame] | 747 | int field; |
| 748 | |
| 749 | chunk_appendf(&trash, "# "); |
| 750 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) |
| 751 | chunk_appendf(&trash, "%s,", stat_field_names[field]); |
| 752 | |
| 753 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 754 | } |
| 755 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 756 | /* print a string of text buffer to <out>. The format is : |
| 757 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 758 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 759 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 760 | */ |
| 761 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 762 | { |
| 763 | unsigned char c; |
| 764 | int ptr = 0; |
| 765 | |
| 766 | while (buf[ptr] && ptr < bsize) { |
| 767 | c = buf[ptr]; |
| 768 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 769 | if (out->len > out->size - 1) |
| 770 | break; |
| 771 | out->str[out->len++] = c; |
| 772 | } |
| 773 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 774 | if (out->len > out->size - 2) |
| 775 | break; |
| 776 | out->str[out->len++] = '\\'; |
| 777 | switch (c) { |
| 778 | case ' ': c = ' '; break; |
| 779 | case '\t': c = 't'; break; |
| 780 | case '\n': c = 'n'; break; |
| 781 | case '\r': c = 'r'; break; |
| 782 | case '\e': c = 'e'; break; |
| 783 | case '\\': c = '\\'; break; |
| 784 | } |
| 785 | out->str[out->len++] = c; |
| 786 | } |
| 787 | else { |
| 788 | if (out->len > out->size - 4) |
| 789 | break; |
| 790 | out->str[out->len++] = '\\'; |
| 791 | out->str[out->len++] = 'x'; |
| 792 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 793 | out->str[out->len++] = hextab[c & 0xF]; |
| 794 | } |
| 795 | ptr++; |
| 796 | } |
| 797 | |
| 798 | return ptr; |
| 799 | } |
| 800 | |
| 801 | /* print a buffer in hexa. |
| 802 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 803 | */ |
| 804 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 805 | { |
| 806 | unsigned char c; |
| 807 | int ptr = 0; |
| 808 | |
| 809 | while (ptr < bsize) { |
| 810 | c = buf[ptr]; |
| 811 | |
| 812 | if (out->len > out->size - 2) |
| 813 | break; |
| 814 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 815 | out->str[out->len++] = hextab[c & 0xF]; |
| 816 | |
| 817 | ptr++; |
| 818 | } |
| 819 | return ptr; |
| 820 | } |
| 821 | |
| 822 | /* Dump the status of a table to a stream interface's |
| 823 | * read buffer. It returns 0 if the output buffer is full |
| 824 | * and needs to be called again, otherwise non-zero. |
| 825 | */ |
| 826 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 827 | struct proxy *proxy, struct proxy *target) |
| 828 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 829 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 830 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 831 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 832 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 833 | |
| 834 | /* any other information should be dumped here */ |
| 835 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 836 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 837 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 838 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 839 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 840 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 841 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 842 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 843 | |
| 844 | return 1; |
| 845 | } |
| 846 | |
| 847 | /* Dump the a table entry to a stream interface's |
| 848 | * read buffer. It returns 0 if the output buffer is full |
| 849 | * and needs to be called again, otherwise non-zero. |
| 850 | */ |
| 851 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 852 | struct proxy *proxy, struct stksess *entry) |
| 853 | { |
| 854 | int dt; |
| 855 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 856 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 857 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 858 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 859 | char addr[INET_ADDRSTRLEN]; |
| 860 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 861 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 862 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 863 | else if (proxy->table.type == SMP_T_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 864 | char addr[INET6_ADDRSTRLEN]; |
| 865 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 866 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 867 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 868 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 869 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 870 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 871 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 872 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 873 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 874 | } |
| 875 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 876 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 877 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 878 | } |
| 879 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 880 | 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] | 881 | |
| 882 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 883 | void *ptr; |
| 884 | |
| 885 | if (proxy->table.data_ofs[dt] == 0) |
| 886 | continue; |
| 887 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 888 | 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] | 889 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 890 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 891 | |
| 892 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 893 | switch (stktable_data_types[dt].std_type) { |
| 894 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 895 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 896 | break; |
| 897 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 898 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 899 | break; |
| 900 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 901 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 902 | break; |
| 903 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 904 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 905 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 906 | proxy->table.data_arg[dt].u)); |
| 907 | break; |
| 908 | } |
| 909 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 910 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 911 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 912 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 913 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 914 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 915 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 916 | |
| 917 | return 1; |
| 918 | } |
| 919 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 920 | 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] | 921 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 922 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 923 | struct appctx *appctx = __objt_appctx(si->end); |
| 924 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 925 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 926 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 927 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 928 | long long value; |
| 929 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 930 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 931 | void *ptr; |
| 932 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 933 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 934 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 935 | |
| 936 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 937 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 938 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 939 | return; |
| 940 | } |
| 941 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 942 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 943 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 944 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 945 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 946 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 947 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 948 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 949 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 950 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 951 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 952 | { |
| 953 | char *endptr; |
| 954 | unsigned long val; |
| 955 | errno = 0; |
| 956 | val = strtoul(args[4], &endptr, 10); |
| 957 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 958 | (errno != 0 && val == 0) || endptr == args[4] || |
| 959 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 960 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 961 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 962 | return; |
| 963 | } |
| 964 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 965 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 966 | break; |
| 967 | } |
| 968 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 969 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 970 | static_table_key->key = args[4]; |
| 971 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 972 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 973 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 974 | switch (action) { |
| 975 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 976 | 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] | 977 | break; |
| 978 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 979 | 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] | 980 | break; |
| 981 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 982 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 983 | break; |
| 984 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 985 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 986 | return; |
| 987 | } |
| 988 | |
| 989 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 990 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 991 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 992 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 993 | return; |
| 994 | } |
| 995 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 996 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 997 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 998 | switch (action) { |
| 999 | case STAT_CLI_O_TAB: |
| 1000 | if (!ts) |
| 1001 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1002 | chunk_reset(&trash); |
| 1003 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1004 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1005 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1006 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1007 | |
| 1008 | case STAT_CLI_O_CLR: |
| 1009 | if (!ts) |
| 1010 | return; |
| 1011 | if (ts->ref_cnt) { |
| 1012 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1013 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 1014 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1015 | return; |
| 1016 | } |
| 1017 | stksess_kill(&px->table, ts); |
| 1018 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1019 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1020 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1021 | if (ts) |
| 1022 | stktable_touch(&px->table, ts, 1); |
| 1023 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 1024 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1025 | if (!ts) { |
| 1026 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1027 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 1028 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1029 | return; |
| 1030 | } |
| 1031 | stktable_store(&px->table, ts, 1); |
| 1032 | } |
| 1033 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1034 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 1035 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1036 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 1037 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 1042 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1043 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 1044 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1045 | return; |
| 1046 | } |
| 1047 | |
| 1048 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1049 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 1050 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1051 | return; |
| 1052 | } |
| 1053 | |
| 1054 | 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] | 1055 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 1056 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1057 | return; |
| 1058 | } |
| 1059 | |
| 1060 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 1061 | |
| 1062 | switch (stktable_data_types[data_type].std_type) { |
| 1063 | case STD_T_SINT: |
| 1064 | stktable_data_cast(ptr, std_t_sint) = value; |
| 1065 | break; |
| 1066 | case STD_T_UINT: |
| 1067 | stktable_data_cast(ptr, std_t_uint) = value; |
| 1068 | break; |
| 1069 | case STD_T_ULL: |
| 1070 | stktable_data_cast(ptr, std_t_ull) = value; |
| 1071 | break; |
| 1072 | case STD_T_FRQP: |
| 1073 | /* We set both the current and previous values. That way |
| 1074 | * the reported frequency is stable during all the period |
| 1075 | * then slowly fades out. This allows external tools to |
| 1076 | * push measures without having to update them too often. |
| 1077 | */ |
| 1078 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 1079 | frqp->curr_tick = now_ms; |
| 1080 | frqp->prev_ctr = 0; |
| 1081 | frqp->curr_ctr = value; |
| 1082 | break; |
| 1083 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1084 | } |
| 1085 | break; |
| 1086 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1087 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1088 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 1089 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1090 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1091 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1092 | } |
| 1093 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1094 | 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] | 1095 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1096 | struct appctx *appctx = __objt_appctx(si->end); |
| 1097 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 1098 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1099 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 1100 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1101 | return; |
| 1102 | } |
| 1103 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1104 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1105 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 1106 | if (appctx->ctx.table.data_type < 0) { |
| 1107 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 1108 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1109 | return; |
| 1110 | } |
| 1111 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1112 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 1113 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 1114 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1115 | return; |
| 1116 | } |
| 1117 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1118 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 1119 | if (appctx->ctx.table.data_op < 0) { |
| 1120 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 1121 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1122 | return; |
| 1123 | } |
| 1124 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1125 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 1126 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 1127 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1128 | return; |
| 1129 | } |
| 1130 | } |
| 1131 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1132 | 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] | 1133 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1134 | struct appctx *appctx = __objt_appctx(si->end); |
| 1135 | |
| 1136 | appctx->ctx.table.data_type = -1; |
| 1137 | appctx->st2 = STAT_ST_INIT; |
| 1138 | appctx->ctx.table.target = NULL; |
| 1139 | appctx->ctx.table.proxy = NULL; |
| 1140 | appctx->ctx.table.entry = NULL; |
| 1141 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1142 | |
| 1143 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 1144 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1145 | if (!appctx->ctx.table.target) { |
| 1146 | appctx->ctx.cli.msg = "No such table\n"; |
| 1147 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1148 | return; |
| 1149 | } |
| 1150 | } |
| 1151 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1152 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1153 | goto err_args; |
| 1154 | return; |
| 1155 | } |
| 1156 | |
| 1157 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1158 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1159 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1160 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1161 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1162 | goto err_args; |
| 1163 | |
| 1164 | return; |
| 1165 | |
| 1166 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1167 | switch (action) { |
| 1168 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1169 | 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] | 1170 | break; |
| 1171 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1172 | 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] | 1173 | break; |
| 1174 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1175 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1176 | break; |
| 1177 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1178 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1179 | } |
| 1180 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1181 | /* 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] | 1182 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1183 | * level to be admin. |
| 1184 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1185 | 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] | 1186 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1187 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1188 | struct proxy *px; |
| 1189 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1190 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1191 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1192 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1193 | return NULL; |
| 1194 | } |
| 1195 | |
| 1196 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1197 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 1198 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1199 | return NULL; |
| 1200 | } |
| 1201 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 1202 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1203 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1204 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 1205 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1206 | return NULL; |
| 1207 | } |
| 1208 | return px; |
| 1209 | } |
| 1210 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1211 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 1212 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1213 | * 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] | 1214 | * the <arg> is modified to remove the '/'. |
| 1215 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1216 | 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] | 1217 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1218 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1219 | struct proxy *px; |
| 1220 | struct server *sv; |
| 1221 | char *line; |
| 1222 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1223 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1224 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1225 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1226 | return NULL; |
| 1227 | } |
| 1228 | |
| 1229 | /* split "backend/server" and make <line> point to server */ |
| 1230 | for (line = arg; *line; line++) |
| 1231 | if (*line == '/') { |
| 1232 | *line++ = '\0'; |
| 1233 | break; |
| 1234 | } |
| 1235 | |
| 1236 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1237 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1238 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1239 | return NULL; |
| 1240 | } |
| 1241 | |
| 1242 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1243 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1244 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1245 | return NULL; |
| 1246 | } |
| 1247 | |
| 1248 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1249 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 1250 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1251 | return NULL; |
| 1252 | } |
| 1253 | |
| 1254 | return sv; |
| 1255 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1256 | |
| 1257 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1258 | * each reference. The variable <getnext> must contain the current node, |
| 1259 | * <end> point to the root node. |
| 1260 | */ |
| 1261 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1262 | static inline |
| 1263 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1264 | { |
| 1265 | struct tls_keys_ref *ref = getnext; |
| 1266 | |
| 1267 | while (1) { |
| 1268 | |
| 1269 | /* Get next list entry. */ |
| 1270 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1271 | |
| 1272 | /* If the entry is the last of the list, return NULL. */ |
| 1273 | if (&ref->list == end) |
| 1274 | return NULL; |
| 1275 | |
| 1276 | return ref; |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | static inline |
| 1281 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1282 | { |
| 1283 | int id; |
| 1284 | char *error; |
| 1285 | |
| 1286 | /* If the reference starts by a '#', this is numeric id. */ |
| 1287 | if (reference[0] == '#') { |
| 1288 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1289 | id = strtol(reference + 1, &error, 10); |
| 1290 | if (*error != '\0') |
| 1291 | return NULL; |
| 1292 | |
| 1293 | /* Perform the unique id lookup. */ |
| 1294 | return tlskeys_ref_lookupid(id); |
| 1295 | } |
| 1296 | |
| 1297 | /* Perform the string lookup. */ |
| 1298 | return tlskeys_ref_lookup(reference); |
| 1299 | } |
| 1300 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1301 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1302 | /* This function is used with map and acl management. It permits to browse |
| 1303 | * each reference. The variable <getnext> must contain the current node, |
| 1304 | * <end> point to the root node and the <flags> permit to filter required |
| 1305 | * nodes. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1306 | */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1307 | static inline |
| 1308 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1309 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1310 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1311 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1312 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1313 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1314 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1315 | /* Get next list entry. */ |
| 1316 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1317 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1318 | /* If the entry is the last of the list, return NULL. */ |
| 1319 | if (&ref->list == end) |
| 1320 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1321 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1322 | /* If the entry match the flag, return it. */ |
| 1323 | if (ref->flags & flags) |
| 1324 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1325 | } |
| 1326 | } |
| 1327 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1328 | static inline |
| 1329 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1330 | { |
| 1331 | int id; |
| 1332 | char *error; |
| 1333 | |
| 1334 | /* If the reference starts by a '#', this is numeric id. */ |
| 1335 | if (reference[0] == '#') { |
| 1336 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1337 | id = strtol(reference + 1, &error, 10); |
| 1338 | if (*error != '\0') |
| 1339 | return NULL; |
| 1340 | |
| 1341 | /* Perform the unique id lookup. */ |
| 1342 | return pat_ref_lookupid(id); |
| 1343 | } |
| 1344 | |
| 1345 | /* Perform the string lookup. */ |
| 1346 | return pat_ref_lookup(reference); |
| 1347 | } |
| 1348 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1349 | /* This function is used with map and acl management. It permits to browse |
| 1350 | * each reference. |
| 1351 | */ |
| 1352 | static inline |
| 1353 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1354 | { |
| 1355 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1356 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1357 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1358 | return NULL; |
| 1359 | return expr; |
| 1360 | } |
| 1361 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1362 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1363 | * 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] | 1364 | * 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] | 1365 | * designating the function which will have to process the request, which can |
| 1366 | * 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] | 1367 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1368 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1369 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1370 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1371 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1372 | char *args[MAX_STATS_ARGS + 1]; |
| 1373 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1374 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1375 | |
| 1376 | while (isspace((unsigned char)*line)) |
| 1377 | line++; |
| 1378 | |
| 1379 | arg = 0; |
| 1380 | args[arg] = line; |
| 1381 | |
| 1382 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1383 | if (*line == '\\') { |
| 1384 | line++; |
| 1385 | if (*line == '\0') |
| 1386 | break; |
| 1387 | } |
| 1388 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1389 | *line++ = '\0'; |
| 1390 | |
| 1391 | while (isspace((unsigned char)*line)) |
| 1392 | line++; |
| 1393 | |
| 1394 | args[++arg] = line; |
| 1395 | continue; |
| 1396 | } |
| 1397 | |
| 1398 | line++; |
| 1399 | } |
| 1400 | |
| 1401 | while (++arg <= MAX_STATS_ARGS) |
| 1402 | args[arg] = line; |
| 1403 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1404 | /* remove \ */ |
| 1405 | arg = 0; |
| 1406 | while (*args[arg] != '\0') { |
| 1407 | j = 0; |
| 1408 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1409 | if (args[arg][i] == '\\') |
| 1410 | continue; |
| 1411 | args[arg][j] = args[arg][i]; |
| 1412 | j++; |
| 1413 | } |
| 1414 | args[arg][j] = '\0'; |
| 1415 | arg++; |
| 1416 | } |
| 1417 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1418 | appctx->ctx.stats.scope_str = 0; |
| 1419 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1420 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1421 | if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1422 | if (strcmp(args[1], "backend") == 0) { |
| 1423 | appctx->st2 = STAT_ST_INIT; |
| 1424 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1425 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1426 | else if (strcmp(args[1], "env") == 0) { |
| 1427 | extern char **environ; |
| 1428 | |
| 1429 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1430 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1431 | appctx->st0 = STAT_CLI_PRINT; |
| 1432 | return 1; |
| 1433 | } |
| 1434 | appctx->ctx.env.var = environ; |
| 1435 | appctx->st2 = STAT_ST_INIT; |
| 1436 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1437 | |
| 1438 | if (*args[2]) { |
| 1439 | int len = strlen(args[2]); |
| 1440 | |
| 1441 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1442 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1443 | (*appctx->ctx.env.var)[len] == '=') |
| 1444 | break; |
| 1445 | } |
| 1446 | if (!*appctx->ctx.env.var) { |
| 1447 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1448 | appctx->st0 = STAT_CLI_PRINT; |
| 1449 | return 1; |
| 1450 | } |
| 1451 | appctx->st2 = STAT_ST_END; |
| 1452 | } |
| 1453 | } |
| 1454 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1455 | if (strcmp(args[2], "resolvers") == 0) { |
| 1456 | struct dns_resolvers *presolvers; |
| 1457 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1458 | if (*args[3]) { |
| 1459 | appctx->ctx.resolvers.ptr = NULL; |
| 1460 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1461 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1462 | appctx->ctx.resolvers.ptr = presolvers; |
| 1463 | break; |
| 1464 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1465 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1466 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1467 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1468 | appctx->st0 = STAT_CLI_PRINT; |
| 1469 | return 1; |
| 1470 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | appctx->st2 = STAT_ST_INIT; |
| 1474 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1475 | return 1; |
| 1476 | } |
| 1477 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1478 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1479 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1480 | appctx->ctx.stats.type = atoi(args[3]); |
| 1481 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1482 | } |
| 1483 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1484 | appctx->st2 = STAT_ST_INIT; |
| 1485 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1486 | } |
| 1487 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1488 | appctx->st2 = STAT_ST_INIT; |
| 1489 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1490 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1491 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
| 1492 | appctx->ctx.server_state.backend = NULL; |
| 1493 | |
| 1494 | /* check if a backend name has been provided */ |
| 1495 | if (*args[3]) { |
| 1496 | /* read server state from local file */ |
| 1497 | appctx->ctx.server_state.backend = proxy_be_by_name(args[3]); |
| 1498 | |
| 1499 | if (appctx->ctx.server_state.backend == NULL) { |
| 1500 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1501 | appctx->st0 = STAT_CLI_PRINT; |
| 1502 | return 1; |
| 1503 | } |
| 1504 | } |
| 1505 | appctx->st2 = STAT_ST_INIT; |
| 1506 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1507 | return 1; |
| 1508 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1509 | else if (strcmp(args[1], "pools") == 0) { |
| 1510 | appctx->st2 = STAT_ST_INIT; |
| 1511 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1512 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1513 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1514 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1515 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1516 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1517 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1518 | return 1; |
| 1519 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1520 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1521 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1522 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1523 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1524 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1525 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1526 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1527 | appctx->ctx.sess.pos = 0; |
| 1528 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1529 | } |
| 1530 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1531 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1532 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1533 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1534 | return 1; |
| 1535 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1536 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1537 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1538 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1539 | appctx->ctx.errors.iid = -1; |
| 1540 | appctx->ctx.errors.px = NULL; |
| 1541 | appctx->st2 = STAT_ST_INIT; |
| 1542 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1543 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1544 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1545 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1546 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1547 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1548 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1549 | appctx->st2 = STAT_ST_INIT; |
| 1550 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1551 | #else |
| 1552 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1553 | "that doesn't support specifying TLS ticket keys\n"; |
| 1554 | appctx->st0 = STAT_CLI_PRINT; |
| 1555 | #endif |
| 1556 | return 1; |
| 1557 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1558 | else if (strcmp(args[1], "map") == 0 || |
| 1559 | strcmp(args[1], "acl") == 0) { |
| 1560 | |
| 1561 | /* Set ACL or MAP flags. */ |
| 1562 | if (args[1][0] == 'm') |
| 1563 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1564 | else |
| 1565 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1566 | |
| 1567 | /* no parameter: display all map avalaible */ |
| 1568 | if (!*args[2]) { |
| 1569 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1570 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1571 | return 1; |
| 1572 | } |
| 1573 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1574 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1575 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1576 | if (!appctx->ctx.map.ref || |
| 1577 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1578 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1579 | 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] | 1580 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1581 | 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] | 1582 | appctx->st0 = STAT_CLI_PRINT; |
| 1583 | return 1; |
| 1584 | } |
| 1585 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1586 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1587 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1588 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1589 | return 0; |
| 1590 | } |
| 1591 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1592 | else if (strcmp(args[0], "clear") == 0) { |
| 1593 | if (strcmp(args[1], "counters") == 0) { |
| 1594 | struct proxy *px; |
| 1595 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1596 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1597 | int clrall = 0; |
| 1598 | |
| 1599 | if (strcmp(args[2], "all") == 0) |
| 1600 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1601 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1602 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1603 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1604 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1605 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1606 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1607 | return 1; |
| 1608 | } |
| 1609 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1610 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1611 | if (clrall) { |
| 1612 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1613 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1614 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1615 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1616 | px->be_counters.conn_max = 0; |
| 1617 | px->be_counters.p.http.rps_max = 0; |
| 1618 | px->be_counters.sps_max = 0; |
| 1619 | px->be_counters.cps_max = 0; |
| 1620 | px->be_counters.nbpend_max = 0; |
| 1621 | |
| 1622 | px->fe_counters.conn_max = 0; |
| 1623 | px->fe_counters.p.http.rps_max = 0; |
| 1624 | px->fe_counters.sps_max = 0; |
| 1625 | px->fe_counters.cps_max = 0; |
| 1626 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1627 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1628 | |
| 1629 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1630 | if (clrall) |
| 1631 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1632 | else { |
| 1633 | sv->counters.cur_sess_max = 0; |
| 1634 | sv->counters.nbpend_max = 0; |
| 1635 | sv->counters.sps_max = 0; |
| 1636 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1637 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1638 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1639 | if (li->counters) { |
| 1640 | if (clrall) |
| 1641 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1642 | else |
| 1643 | li->counters->conn_max = 0; |
| 1644 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1645 | } |
| 1646 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1647 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1648 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1649 | return 1; |
| 1650 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1651 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1652 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1653 | /* end of processing */ |
| 1654 | return 1; |
| 1655 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1656 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1657 | /* Set ACL or MAP flags. */ |
| 1658 | if (args[1][0] == 'm') |
| 1659 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1660 | else |
| 1661 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1662 | |
| 1663 | /* no parameter */ |
| 1664 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1665 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1666 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1667 | else |
| 1668 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1669 | appctx->st0 = STAT_CLI_PRINT; |
| 1670 | return 1; |
| 1671 | } |
| 1672 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1673 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1674 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1675 | if (!appctx->ctx.map.ref || |
| 1676 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1677 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1678 | 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] | 1679 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1680 | 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] | 1681 | appctx->st0 = STAT_CLI_PRINT; |
| 1682 | return 1; |
| 1683 | } |
| 1684 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1685 | /* Clear all. */ |
| 1686 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1687 | |
| 1688 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1689 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1690 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1691 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1692 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1693 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1694 | return 0; |
| 1695 | } |
| 1696 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1697 | else if (strcmp(args[0], "get") == 0) { |
| 1698 | if (strcmp(args[1], "weight") == 0) { |
| 1699 | struct proxy *px; |
| 1700 | struct server *sv; |
| 1701 | |
| 1702 | /* split "backend/server" and make <line> point to server */ |
| 1703 | for (line = args[2]; *line; line++) |
| 1704 | if (*line == '/') { |
| 1705 | *line++ = '\0'; |
| 1706 | break; |
| 1707 | } |
| 1708 | |
| 1709 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1710 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1711 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1712 | return 1; |
| 1713 | } |
| 1714 | |
| 1715 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1716 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1717 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1718 | return 1; |
| 1719 | } |
| 1720 | |
| 1721 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1722 | 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] | 1723 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1724 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1725 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1726 | return 1; |
| 1727 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1728 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1729 | /* Set flags. */ |
| 1730 | if (args[1][0] == 'm') |
| 1731 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1732 | else |
| 1733 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1734 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1735 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1736 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1737 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1738 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1739 | else |
| 1740 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1741 | appctx->st0 = STAT_CLI_PRINT; |
| 1742 | return 1; |
| 1743 | } |
| 1744 | |
| 1745 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1746 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1747 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1748 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1749 | 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] | 1750 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1751 | 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] | 1752 | appctx->st0 = STAT_CLI_PRINT; |
| 1753 | return 1; |
| 1754 | } |
| 1755 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1756 | /* copy input string. The string must be allocated because |
| 1757 | * it may be used over multiple iterations. It's released |
| 1758 | * at the end and upon abort anyway. |
| 1759 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1760 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1761 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1762 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1763 | if (!appctx->ctx.map.chunk.str) { |
| 1764 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1765 | appctx->st0 = STAT_CLI_PRINT; |
| 1766 | return 1; |
| 1767 | } |
| 1768 | |
| 1769 | /* prepare response */ |
| 1770 | appctx->st2 = STAT_ST_INIT; |
| 1771 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1772 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1773 | else { /* not "get weight" */ |
| 1774 | return 0; |
| 1775 | } |
| 1776 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1777 | else if (strcmp(args[0], "set") == 0) { |
| 1778 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1779 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1780 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1781 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1782 | sv = expect_server_admin(s, si, args[2]); |
| 1783 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1784 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1785 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1786 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1787 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1788 | appctx->ctx.cli.msg = warning; |
| 1789 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1790 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1791 | return 1; |
| 1792 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1793 | else if (strcmp(args[1], "server") == 0) { |
| 1794 | struct server *sv; |
| 1795 | const char *warning; |
| 1796 | |
| 1797 | sv = expect_server_admin(s, si, args[2]); |
| 1798 | if (!sv) |
| 1799 | return 1; |
| 1800 | |
| 1801 | if (strcmp(args[3], "weight") == 0) { |
| 1802 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1803 | if (warning) { |
| 1804 | appctx->ctx.cli.msg = warning; |
| 1805 | appctx->st0 = STAT_CLI_PRINT; |
| 1806 | } |
| 1807 | } |
| 1808 | else if (strcmp(args[3], "state") == 0) { |
| 1809 | if (strcmp(args[4], "ready") == 0) |
| 1810 | srv_adm_set_ready(sv); |
| 1811 | else if (strcmp(args[4], "drain") == 0) |
| 1812 | srv_adm_set_drain(sv); |
| 1813 | else if (strcmp(args[4], "maint") == 0) |
| 1814 | srv_adm_set_maint(sv); |
| 1815 | else { |
| 1816 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1817 | appctx->st0 = STAT_CLI_PRINT; |
| 1818 | } |
| 1819 | } |
| 1820 | else if (strcmp(args[3], "health") == 0) { |
| 1821 | if (sv->track) { |
| 1822 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1823 | appctx->st0 = STAT_CLI_PRINT; |
| 1824 | } |
| 1825 | else if (strcmp(args[4], "up") == 0) { |
| 1826 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1827 | srv_set_running(sv, "changed from CLI"); |
| 1828 | } |
| 1829 | else if (strcmp(args[4], "stopping") == 0) { |
| 1830 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1831 | srv_set_stopping(sv, "changed from CLI"); |
| 1832 | } |
| 1833 | else if (strcmp(args[4], "down") == 0) { |
| 1834 | sv->check.health = 0; |
| 1835 | srv_set_stopped(sv, "changed from CLI"); |
| 1836 | } |
| 1837 | else { |
| 1838 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1839 | appctx->st0 = STAT_CLI_PRINT; |
| 1840 | } |
| 1841 | } |
| 1842 | else if (strcmp(args[3], "agent") == 0) { |
| 1843 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1844 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1845 | appctx->st0 = STAT_CLI_PRINT; |
| 1846 | } |
| 1847 | else if (strcmp(args[4], "up") == 0) { |
| 1848 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1849 | srv_set_running(sv, "changed from CLI"); |
| 1850 | } |
| 1851 | else if (strcmp(args[4], "down") == 0) { |
| 1852 | sv->agent.health = 0; |
| 1853 | srv_set_stopped(sv, "changed from CLI"); |
| 1854 | } |
| 1855 | else { |
| 1856 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1857 | appctx->st0 = STAT_CLI_PRINT; |
| 1858 | } |
| 1859 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1860 | else if (strcmp(args[3], "addr") == 0) { |
Thierry Fournier | 09a9178 | 2016-02-24 08:25:39 +0100 | [diff] [blame] | 1861 | warning = server_parse_addr_change_request(sv, args[4], "stats command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1862 | if (warning) { |
| 1863 | appctx->ctx.cli.msg = warning; |
| 1864 | appctx->st0 = STAT_CLI_PRINT; |
| 1865 | } |
| 1866 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1867 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1868 | 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] | 1869 | appctx->st0 = STAT_CLI_PRINT; |
| 1870 | } |
| 1871 | return 1; |
| 1872 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1873 | else if (strcmp(args[1], "timeout") == 0) { |
| 1874 | if (strcmp(args[2], "cli") == 0) { |
| 1875 | unsigned timeout; |
| 1876 | const char *res; |
| 1877 | |
| 1878 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1879 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1880 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1881 | return 1; |
| 1882 | } |
| 1883 | |
| 1884 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1885 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1886 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1887 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1888 | return 1; |
| 1889 | } |
| 1890 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1891 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1892 | return 1; |
| 1893 | } |
| 1894 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1895 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1896 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1897 | return 1; |
| 1898 | } |
| 1899 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1900 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1901 | if (strcmp(args[2], "frontend") == 0) { |
| 1902 | struct proxy *px; |
| 1903 | struct listener *l; |
| 1904 | int v; |
| 1905 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1906 | px = expect_frontend_admin(s, si, args[3]); |
| 1907 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1908 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1909 | |
| 1910 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1911 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1912 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1913 | return 1; |
| 1914 | } |
| 1915 | |
| 1916 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1917 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1918 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1919 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1920 | return 1; |
| 1921 | } |
| 1922 | |
| 1923 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1924 | * its listeners. The blocked ones will be dequeued. |
| 1925 | */ |
| 1926 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1927 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1928 | l->maxconn = v; |
| 1929 | if (l->state == LI_FULL) |
| 1930 | resume_listener(l); |
| 1931 | } |
| 1932 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1933 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1934 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1935 | |
| 1936 | return 1; |
| 1937 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1938 | else if (strcmp(args[2], "server") == 0) { |
| 1939 | struct server *sv; |
| 1940 | int v; |
| 1941 | |
| 1942 | sv = expect_server_admin(s, si, args[3]); |
| 1943 | if (!sv) |
| 1944 | return 1; |
| 1945 | |
| 1946 | if (!*args[4]) { |
| 1947 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1948 | appctx->st0 = STAT_CLI_PRINT; |
| 1949 | return 1; |
| 1950 | } |
| 1951 | |
| 1952 | v = atoi(args[4]); |
| 1953 | if (v < 0) { |
| 1954 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1955 | appctx->st0 = STAT_CLI_PRINT; |
| 1956 | return 1; |
| 1957 | } |
| 1958 | |
| 1959 | if (sv->maxconn == sv->minconn) { // static maxconn |
| 1960 | sv->maxconn = sv->minconn = v; |
| 1961 | } else { // dynamic maxconn |
| 1962 | sv->maxconn = v; |
| 1963 | } |
| 1964 | |
| 1965 | if (may_dequeue_tasks(sv, sv->proxy)) |
| 1966 | process_srv_queue(sv); |
| 1967 | |
| 1968 | return 1; |
| 1969 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1970 | else if (strcmp(args[2], "global") == 0) { |
| 1971 | int v; |
| 1972 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1973 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1974 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1975 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1976 | return 1; |
| 1977 | } |
| 1978 | |
| 1979 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1980 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1981 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1982 | return 1; |
| 1983 | } |
| 1984 | |
| 1985 | v = atoi(args[3]); |
| 1986 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1987 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1988 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1989 | return 1; |
| 1990 | } |
| 1991 | |
| 1992 | /* check for unlimited values */ |
| 1993 | if (v <= 0) |
| 1994 | v = global.hardmaxconn; |
| 1995 | |
| 1996 | global.maxconn = v; |
| 1997 | |
| 1998 | /* Dequeues all of the listeners waiting for a resource */ |
| 1999 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2000 | dequeue_all_listeners(&global_listener_queue); |
| 2001 | |
| 2002 | return 1; |
| 2003 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 2004 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 2005 | 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] | 2006 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 2007 | return 1; |
| 2008 | } |
| 2009 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2010 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 2011 | if (strcmp(args[2], "connections") == 0) { |
| 2012 | if (strcmp(args[3], "global") == 0) { |
| 2013 | int v; |
| 2014 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2015 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2016 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2017 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2018 | return 1; |
| 2019 | } |
| 2020 | |
| 2021 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2022 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2023 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2024 | return 1; |
| 2025 | } |
| 2026 | |
| 2027 | v = atoi(args[4]); |
| 2028 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2029 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2030 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2031 | return 1; |
| 2032 | } |
| 2033 | |
| 2034 | global.cps_lim = v; |
| 2035 | |
| 2036 | /* Dequeues all of the listeners waiting for a resource */ |
| 2037 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2038 | dequeue_all_listeners(&global_listener_queue); |
| 2039 | |
| 2040 | return 1; |
| 2041 | } |
| 2042 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2043 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 2044 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2045 | return 1; |
| 2046 | } |
| 2047 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2048 | else if (strcmp(args[2], "sessions") == 0) { |
| 2049 | if (strcmp(args[3], "global") == 0) { |
| 2050 | int v; |
| 2051 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2052 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2053 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2054 | appctx->st0 = STAT_CLI_PRINT; |
| 2055 | return 1; |
| 2056 | } |
| 2057 | |
| 2058 | if (!*args[4]) { |
| 2059 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2060 | appctx->st0 = STAT_CLI_PRINT; |
| 2061 | return 1; |
| 2062 | } |
| 2063 | |
| 2064 | v = atoi(args[4]); |
| 2065 | if (v < 0) { |
| 2066 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2067 | appctx->st0 = STAT_CLI_PRINT; |
| 2068 | return 1; |
| 2069 | } |
| 2070 | |
| 2071 | global.sps_lim = v; |
| 2072 | |
| 2073 | /* Dequeues all of the listeners waiting for a resource */ |
| 2074 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2075 | dequeue_all_listeners(&global_listener_queue); |
| 2076 | |
| 2077 | return 1; |
| 2078 | } |
| 2079 | else { |
| 2080 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 2081 | appctx->st0 = STAT_CLI_PRINT; |
| 2082 | return 1; |
| 2083 | } |
| 2084 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2085 | #ifdef USE_OPENSSL |
| 2086 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 2087 | if (strcmp(args[3], "global") == 0) { |
| 2088 | int v; |
| 2089 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2090 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2091 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2092 | appctx->st0 = STAT_CLI_PRINT; |
| 2093 | return 1; |
| 2094 | } |
| 2095 | |
| 2096 | if (!*args[4]) { |
| 2097 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2098 | appctx->st0 = STAT_CLI_PRINT; |
| 2099 | return 1; |
| 2100 | } |
| 2101 | |
| 2102 | v = atoi(args[4]); |
| 2103 | if (v < 0) { |
| 2104 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2105 | appctx->st0 = STAT_CLI_PRINT; |
| 2106 | return 1; |
| 2107 | } |
| 2108 | |
| 2109 | global.ssl_lim = v; |
| 2110 | |
| 2111 | /* Dequeues all of the listeners waiting for a resource */ |
| 2112 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2113 | dequeue_all_listeners(&global_listener_queue); |
| 2114 | |
| 2115 | return 1; |
| 2116 | } |
| 2117 | else { |
| 2118 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 2119 | appctx->st0 = STAT_CLI_PRINT; |
| 2120 | return 1; |
| 2121 | } |
| 2122 | } |
| 2123 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2124 | else if (strcmp(args[2], "http-compression") == 0) { |
| 2125 | if (strcmp(args[3], "global") == 0) { |
| 2126 | int v; |
| 2127 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 2128 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 2129 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2130 | appctx->st0 = STAT_CLI_PRINT; |
| 2131 | return 1; |
| 2132 | } |
| 2133 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2134 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2135 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 2136 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2137 | return 1; |
| 2138 | } |
| 2139 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2140 | v = atoi(args[4]); |
| 2141 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 2142 | } |
| 2143 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2144 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 2145 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2146 | return 1; |
| 2147 | } |
| 2148 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2149 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2150 | 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] | 2151 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2152 | return 1; |
| 2153 | } |
| 2154 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 2155 | else if (strcmp(args[1], "table") == 0) { |
| 2156 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 2157 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2158 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2159 | char *err; |
| 2160 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2161 | /* Set flags. */ |
| 2162 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2163 | |
| 2164 | /* Expect three parameters: map name, key and new value. */ |
| 2165 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 2166 | 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] | 2167 | appctx->st0 = STAT_CLI_PRINT; |
| 2168 | return 1; |
| 2169 | } |
| 2170 | |
| 2171 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2172 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2173 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2174 | 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] | 2175 | appctx->st0 = STAT_CLI_PRINT; |
| 2176 | return 1; |
| 2177 | } |
| 2178 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2179 | /* If the entry identifier start with a '#', it is considered as |
| 2180 | * pointer id |
| 2181 | */ |
| 2182 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2183 | struct pat_ref_elt *ref; |
| 2184 | long long int conv; |
| 2185 | char *error; |
| 2186 | |
| 2187 | /* Convert argument to integer value. */ |
| 2188 | conv = strtoll(&args[3][1], &error, 16); |
| 2189 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2190 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2191 | appctx->st0 = STAT_CLI_PRINT; |
| 2192 | return 1; |
| 2193 | } |
| 2194 | |
| 2195 | /* Convert and check integer to pointer. */ |
| 2196 | ref = (struct pat_ref_elt *)(long)conv; |
| 2197 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2198 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2199 | appctx->st0 = STAT_CLI_PRINT; |
| 2200 | return 1; |
| 2201 | } |
| 2202 | |
| 2203 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2204 | err = NULL; |
| 2205 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 2206 | if (err) |
| 2207 | memprintf(&err, "%s.\n", err); |
| 2208 | appctx->ctx.cli.err = err; |
| 2209 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2210 | return 1; |
| 2211 | } |
| 2212 | } |
| 2213 | else { |
| 2214 | /* Else, use the entry identifier as pattern |
| 2215 | * string, and update the value. |
| 2216 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2217 | err = NULL; |
| 2218 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 2219 | if (err) |
| 2220 | memprintf(&err, "%s.\n", err); |
| 2221 | appctx->ctx.cli.err = err; |
| 2222 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2223 | return 1; |
| 2224 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2227 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2228 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2229 | return 1; |
| 2230 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2231 | #ifdef USE_OPENSSL |
| 2232 | else if (strcmp(args[1], "ssl") == 0) { |
| 2233 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 2234 | #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] | 2235 | char *err = NULL; |
| 2236 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 2237 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2238 | if (!*args[3]) { |
| 2239 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 2240 | appctx->st0 = STAT_CLI_PRINT; |
| 2241 | return 1; |
| 2242 | } |
| 2243 | |
| 2244 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 2245 | if (trash.len < 0) { |
| 2246 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 2247 | appctx->st0 = STAT_CLI_PRINT; |
| 2248 | return 1; |
| 2249 | } |
| 2250 | |
| 2251 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 2252 | if (err) { |
| 2253 | memprintf(&err, "%s.\n", err); |
| 2254 | appctx->ctx.cli.err = err; |
| 2255 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 2256 | } |
| 2257 | return 1; |
| 2258 | } |
| 2259 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2260 | appctx->st0 = STAT_CLI_PRINT; |
| 2261 | return 1; |
| 2262 | #else |
| 2263 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2264 | appctx->st0 = STAT_CLI_PRINT; |
| 2265 | return 1; |
| 2266 | #endif |
| 2267 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2268 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2269 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2270 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2271 | if (!*args[3] || !*args[4]) { |
| 2272 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2273 | appctx->st0 = STAT_CLI_PRINT; |
| 2274 | return 1; |
| 2275 | } |
| 2276 | |
| 2277 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2278 | if(!appctx->ctx.tlskeys.ref) { |
| 2279 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2280 | appctx->st0 = STAT_CLI_PRINT; |
| 2281 | return 1; |
| 2282 | } |
| 2283 | |
| 2284 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2285 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2286 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2287 | appctx->st0 = STAT_CLI_PRINT; |
| 2288 | return 1; |
| 2289 | } |
| 2290 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2291 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2292 | 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] | 2293 | |
| 2294 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2295 | appctx->st0 = STAT_CLI_PRINT; |
| 2296 | return 1; |
| 2297 | #else |
| 2298 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2299 | "that doesn't support specifying TLS ticket keys\n"; |
| 2300 | appctx->st0 = STAT_CLI_PRINT; |
| 2301 | return 1; |
| 2302 | #endif |
| 2303 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2304 | else { |
| 2305 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2306 | appctx->st0 = STAT_CLI_PRINT; |
| 2307 | return 1; |
| 2308 | } |
| 2309 | } |
| 2310 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2311 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2312 | return 0; |
| 2313 | } |
| 2314 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2315 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2316 | if (strcmp(args[1], "agent") == 0) { |
| 2317 | struct server *sv; |
| 2318 | |
| 2319 | sv = expect_server_admin(s, si, args[2]); |
| 2320 | if (!sv) |
| 2321 | return 1; |
| 2322 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2323 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2324 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2325 | appctx->st0 = STAT_CLI_PRINT; |
| 2326 | return 1; |
| 2327 | } |
| 2328 | |
| 2329 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2330 | return 1; |
| 2331 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2332 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2333 | struct server *sv; |
| 2334 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2335 | sv = expect_server_admin(s, si, args[2]); |
| 2336 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2337 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2338 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2339 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2340 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2341 | appctx->st0 = STAT_CLI_PRINT; |
| 2342 | return 1; |
| 2343 | } |
| 2344 | |
| 2345 | sv->check.state |= CHK_ST_ENABLED; |
| 2346 | return 1; |
| 2347 | } |
| 2348 | else if (strcmp(args[1], "server") == 0) { |
| 2349 | struct server *sv; |
| 2350 | |
| 2351 | sv = expect_server_admin(s, si, args[2]); |
| 2352 | if (!sv) |
| 2353 | return 1; |
| 2354 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2355 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2356 | return 1; |
| 2357 | } |
| 2358 | else if (strcmp(args[1], "frontend") == 0) { |
| 2359 | struct proxy *px; |
| 2360 | |
| 2361 | px = expect_frontend_admin(s, si, args[2]); |
| 2362 | if (!px) |
| 2363 | return 1; |
| 2364 | |
| 2365 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2366 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2367 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2368 | return 1; |
| 2369 | } |
| 2370 | |
| 2371 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2372 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2373 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2374 | return 1; |
| 2375 | } |
| 2376 | |
| 2377 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2378 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2379 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2380 | return 1; |
| 2381 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2382 | return 1; |
| 2383 | } |
| 2384 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2385 | 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] | 2386 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2387 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2388 | } |
| 2389 | } |
| 2390 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2391 | if (strcmp(args[1], "agent") == 0) { |
| 2392 | struct server *sv; |
| 2393 | |
| 2394 | sv = expect_server_admin(s, si, args[2]); |
| 2395 | if (!sv) |
| 2396 | return 1; |
| 2397 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2398 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2399 | return 1; |
| 2400 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2401 | else if (strcmp(args[1], "health") == 0) { |
| 2402 | struct server *sv; |
| 2403 | |
| 2404 | sv = expect_server_admin(s, si, args[2]); |
| 2405 | if (!sv) |
| 2406 | return 1; |
| 2407 | |
| 2408 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2409 | return 1; |
| 2410 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2411 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2412 | struct server *sv; |
| 2413 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2414 | sv = expect_server_admin(s, si, args[2]); |
| 2415 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2416 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2417 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2418 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2419 | return 1; |
| 2420 | } |
| 2421 | else if (strcmp(args[1], "frontend") == 0) { |
| 2422 | struct proxy *px; |
| 2423 | |
| 2424 | px = expect_frontend_admin(s, si, args[2]); |
| 2425 | if (!px) |
| 2426 | return 1; |
| 2427 | |
| 2428 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2429 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2430 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2431 | return 1; |
| 2432 | } |
| 2433 | |
| 2434 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2435 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2436 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2437 | return 1; |
| 2438 | } |
| 2439 | |
| 2440 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2441 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2442 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2443 | return 1; |
| 2444 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2445 | return 1; |
| 2446 | } |
| 2447 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2448 | 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] | 2449 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2450 | return 1; |
| 2451 | } |
| 2452 | } |
| 2453 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2454 | if (strcmp(args[1], "frontend") == 0) { |
| 2455 | struct proxy *px; |
| 2456 | |
| 2457 | px = expect_frontend_admin(s, si, args[2]); |
| 2458 | if (!px) |
| 2459 | return 1; |
| 2460 | |
| 2461 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2462 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2463 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2464 | return 1; |
| 2465 | } |
| 2466 | |
| 2467 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2468 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2469 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2470 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2471 | stop_proxy(px); |
| 2472 | return 1; |
| 2473 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2474 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2475 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2476 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2477 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2478 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2479 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2480 | return 1; |
| 2481 | } |
| 2482 | |
| 2483 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2484 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2485 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2486 | return 1; |
| 2487 | } |
| 2488 | |
| 2489 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2490 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2491 | /* first, look for the requested stream in the stream table */ |
| 2492 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2493 | if (sess == ptr) |
| 2494 | break; |
| 2495 | } |
| 2496 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2497 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2498 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2499 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2500 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2501 | return 1; |
| 2502 | } |
| 2503 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2504 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2505 | return 1; |
| 2506 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2507 | else if (strcmp(args[1], "sessions") == 0) { |
| 2508 | if (strcmp(args[2], "server") == 0) { |
| 2509 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2510 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2511 | |
| 2512 | sv = expect_server_admin(s, si, args[3]); |
| 2513 | if (!sv) |
| 2514 | return 1; |
| 2515 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2516 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2517 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2518 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2519 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2520 | |
| 2521 | return 1; |
| 2522 | } |
| 2523 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2524 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2525 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2526 | return 1; |
| 2527 | } |
| 2528 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2529 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2530 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2531 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2532 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2533 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2534 | } |
| 2535 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2536 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2537 | if (args[1][0] == 'm') |
| 2538 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2539 | else |
| 2540 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2541 | |
| 2542 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2543 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2544 | if (!*args[2] || !*args[3]) { |
| 2545 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2546 | appctx->st0 = STAT_CLI_PRINT; |
| 2547 | return 1; |
| 2548 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2549 | } |
| 2550 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2551 | else { |
| 2552 | if (!*args[2] || !*args[3]) { |
| 2553 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2554 | appctx->st0 = STAT_CLI_PRINT; |
| 2555 | return 1; |
| 2556 | } |
| 2557 | } |
| 2558 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2559 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2560 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2561 | if (!appctx->ctx.map.ref || |
| 2562 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2563 | 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] | 2564 | appctx->st0 = STAT_CLI_PRINT; |
| 2565 | return 1; |
| 2566 | } |
| 2567 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2568 | /* If the entry identifier start with a '#', it is considered as |
| 2569 | * pointer id |
| 2570 | */ |
| 2571 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2572 | struct pat_ref_elt *ref; |
| 2573 | long long int conv; |
| 2574 | char *error; |
| 2575 | |
| 2576 | /* Convert argument to integer value. */ |
| 2577 | conv = strtoll(&args[3][1], &error, 16); |
| 2578 | if (*error != '\0') { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2579 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2580 | appctx->st0 = STAT_CLI_PRINT; |
| 2581 | return 1; |
| 2582 | } |
| 2583 | |
| 2584 | /* Convert and check integer to pointer. */ |
| 2585 | ref = (struct pat_ref_elt *)(long)conv; |
| 2586 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2587 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2588 | appctx->st0 = STAT_CLI_PRINT; |
| 2589 | return 1; |
| 2590 | } |
| 2591 | |
| 2592 | /* Try to delete the entry. */ |
| 2593 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2594 | /* The entry is not found, send message. */ |
| 2595 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2596 | appctx->st0 = STAT_CLI_PRINT; |
| 2597 | return 1; |
| 2598 | } |
| 2599 | } |
| 2600 | else { |
| 2601 | /* Else, use the entry identifier as pattern |
| 2602 | * string and try to delete the entry. |
| 2603 | */ |
| 2604 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2605 | /* The entry is not found, send message. */ |
| 2606 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2607 | appctx->st0 = STAT_CLI_PRINT; |
| 2608 | return 1; |
| 2609 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2610 | } |
| 2611 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2612 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2613 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2614 | return 1; |
| 2615 | } |
| 2616 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2617 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2618 | appctx->st0 = STAT_CLI_PRINT; |
| 2619 | return 1; |
| 2620 | } |
| 2621 | } |
| 2622 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2623 | if (strcmp(args[1], "map") == 0 || |
| 2624 | strcmp(args[1], "acl") == 0) { |
| 2625 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2626 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2627 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2628 | /* Set flags. */ |
| 2629 | if (args[1][0] == 'm') |
| 2630 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2631 | else |
| 2632 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2633 | |
| 2634 | /* If the keywork is "map", we expect three parameters, if it |
| 2635 | * is "acl", we expect only two parameters |
| 2636 | */ |
| 2637 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2638 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2639 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2640 | appctx->st0 = STAT_CLI_PRINT; |
| 2641 | return 1; |
| 2642 | } |
| 2643 | } |
| 2644 | else { |
| 2645 | if (!*args[2] || !*args[3]) { |
| 2646 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2647 | appctx->st0 = STAT_CLI_PRINT; |
| 2648 | return 1; |
| 2649 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2650 | } |
| 2651 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2652 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2653 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2654 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2655 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2656 | 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] | 2657 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2658 | 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] | 2659 | appctx->st0 = STAT_CLI_PRINT; |
| 2660 | return 1; |
| 2661 | } |
| 2662 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2663 | /* The command "add acl" is prohibited if the reference |
| 2664 | * use samples. |
| 2665 | */ |
| 2666 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2667 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2668 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2669 | "You must use the command 'add map' to add values.\n"; |
| 2670 | appctx->st0 = STAT_CLI_PRINT; |
| 2671 | return 1; |
| 2672 | } |
| 2673 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2674 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2675 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2676 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2677 | 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] | 2678 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2679 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2680 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2681 | if (err) |
| 2682 | memprintf(&err, "%s.\n", err); |
| 2683 | appctx->ctx.cli.err = err; |
| 2684 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2685 | return 1; |
| 2686 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2687 | |
| 2688 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2689 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2690 | return 1; |
| 2691 | } |
| 2692 | else { /* unknown "del" parameter */ |
| 2693 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2694 | appctx->st0 = STAT_CLI_PRINT; |
| 2695 | return 1; |
| 2696 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2697 | } |
| 2698 | 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] | 2699 | return 0; |
| 2700 | } |
| 2701 | return 1; |
| 2702 | } |
| 2703 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2704 | /* 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] | 2705 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2706 | * state machine handling requests and various responses. We read a request, |
| 2707 | * 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] | 2708 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2709 | * 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] | 2710 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2711 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2712 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2713 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2714 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2715 | struct channel *req = si_oc(si); |
| 2716 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2717 | int reql; |
| 2718 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2719 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2720 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2721 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2722 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2723 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2724 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2725 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2726 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2727 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2728 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2729 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2730 | /* Let's close for real now. We just close the request |
| 2731 | * side, the conditions below will complete if needed. |
| 2732 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2733 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2734 | break; |
| 2735 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2736 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2737 | /* ensure we have some output room left in the event we |
| 2738 | * would want to return some info right after parsing. |
| 2739 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2740 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2741 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2742 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2743 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2744 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2745 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2746 | if (reql <= 0) { /* closed or EOL not found */ |
| 2747 | if (reql == 0) |
| 2748 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2749 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2750 | continue; |
| 2751 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2752 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2753 | /* seek for a possible semi-colon. If we find one, we |
| 2754 | * replace it with an LF and skip only this part. |
| 2755 | */ |
| 2756 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2757 | if (trash.str[len] == ';') { |
| 2758 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2759 | reql = len + 1; |
| 2760 | break; |
| 2761 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2762 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2763 | /* now it is time to check that we have a full line, |
| 2764 | * remove the trailing \n and possibly \r, then cut the |
| 2765 | * line. |
| 2766 | */ |
| 2767 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2768 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2769 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2770 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2771 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2772 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2773 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2774 | len--; |
| 2775 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2776 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2777 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2778 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2779 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2780 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2781 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2782 | continue; |
| 2783 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2784 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2785 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2786 | else if (strcmp(trash.str, "help") == 0 || |
| 2787 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2788 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2789 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2790 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2791 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2792 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2793 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2794 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2795 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2796 | /* if prompt is disabled, print help on empty lines, |
| 2797 | * so that the user at least knows how to enable |
| 2798 | * prompt and find help. |
| 2799 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2800 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2801 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2805 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2806 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2807 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2808 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2809 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2810 | case STAT_CLI_PROMPT: |
| 2811 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2812 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2813 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2814 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2815 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2816 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2817 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2818 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2819 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2820 | free(appctx->ctx.cli.err); |
| 2821 | appctx->st0 = STAT_CLI_PROMPT; |
| 2822 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2823 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2824 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2825 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2826 | case STAT_CLI_O_BACKEND: |
| 2827 | if (stats_dump_backend_to_buffer(si)) |
| 2828 | appctx->st0 = STAT_CLI_PROMPT; |
| 2829 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2830 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2831 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2832 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2833 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2834 | case STAT_CLI_O_SERVERS_STATE: |
| 2835 | if (stats_dump_servers_state_to_buffer(si)) |
| 2836 | appctx->st0 = STAT_CLI_PROMPT; |
| 2837 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2838 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2839 | if (stats_dump_stat_to_buffer(si, NULL)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2840 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2841 | break; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2842 | case STAT_CLI_O_RESOLVERS: |
| 2843 | if (stats_dump_resolvers_to_buffer(si)) |
| 2844 | appctx->st0 = STAT_CLI_PROMPT; |
| 2845 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2846 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2847 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2848 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2849 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2850 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2851 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2852 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2853 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2854 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2855 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2856 | if (stats_table_request(si, appctx->st0)) |
| 2857 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2858 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2859 | case STAT_CLI_O_PATS: |
| 2860 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2861 | appctx->st0 = STAT_CLI_PROMPT; |
| 2862 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2863 | case STAT_CLI_O_PAT: |
| 2864 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2865 | appctx->st0 = STAT_CLI_PROMPT; |
| 2866 | break; |
| 2867 | case STAT_CLI_O_MLOOK: |
| 2868 | if (stats_map_lookup(si)) |
| 2869 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2870 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2871 | case STAT_CLI_O_POOLS: |
| 2872 | if (stats_dump_pools_to_buffer(si)) |
| 2873 | appctx->st0 = STAT_CLI_PROMPT; |
| 2874 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2875 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2876 | case STAT_CLI_O_TLSK: |
| 2877 | if (stats_tlskeys_list(si)) |
| 2878 | appctx->st0 = STAT_CLI_PROMPT; |
| 2879 | break; |
| 2880 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2881 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2882 | if (stats_dump_env_to_buffer(si)) |
| 2883 | appctx->st0 = STAT_CLI_PROMPT; |
| 2884 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2885 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2886 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2887 | break; |
| 2888 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2889 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2890 | /* 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] | 2891 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2892 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2893 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2894 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2895 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2896 | } |
| 2897 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2898 | /* 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] | 2899 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2900 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2901 | |
| 2902 | /* Now we close the output if one of the writers did so, |
| 2903 | * or if we're not in interactive mode and the request |
| 2904 | * buffer is empty. This still allows pipelined requests |
| 2905 | * to be sent in non-interactive mode. |
| 2906 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2907 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2908 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2909 | continue; |
| 2910 | } |
| 2911 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2912 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2913 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2914 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2915 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2916 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2917 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2918 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2919 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2920 | /* 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] | 2921 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2922 | * we forward the close to the request side so that it flows upstream to |
| 2923 | * the client. |
| 2924 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2925 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2926 | } |
| 2927 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2928 | 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] | 2929 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2930 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2931 | /* We have no more processing to do, and nothing more to send, and |
| 2932 | * the client side has closed. So we'll forward this state downstream |
| 2933 | * on the response buffer. |
| 2934 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2935 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2936 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2937 | } |
| 2938 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2939 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2940 | 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] | 2941 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2942 | 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] | 2943 | } |
| 2944 | |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2945 | /* Emits a stats field without any surrounding element and properly encoded to |
| 2946 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 2947 | */ |
| 2948 | static int stats_emit_raw_data_field(struct chunk *out, const struct field *f) |
| 2949 | { |
| 2950 | switch (field_format(f, 0)) { |
| 2951 | case FF_EMPTY: return 1; |
| 2952 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 2953 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 2954 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 2955 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 2956 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 2957 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 2958 | } |
| 2959 | } |
| 2960 | |
Willy Tarreau | bf95cba | 2016-01-11 18:27:29 +0100 | [diff] [blame] | 2961 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
| 2962 | static int stats_dump_info_fields(struct chunk *out, const struct field *info) |
| 2963 | { |
| 2964 | int field; |
| 2965 | |
| 2966 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 2967 | if (!field_format(info, field)) |
| 2968 | continue; |
| 2969 | |
| 2970 | if (!chunk_appendf(out, "%s: ", info_field_names[field])) |
| 2971 | return 0; |
| 2972 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 2973 | return 0; |
| 2974 | if (!chunk_strcat(out, "\n")) |
| 2975 | return 0; |
| 2976 | } |
| 2977 | return 1; |
| 2978 | } |
| 2979 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2980 | /* This function dumps information onto the stream interface's read buffer. |
| 2981 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2982 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2983 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2984 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2985 | { |
| 2986 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2987 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2988 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2989 | #ifdef USE_OPENSSL |
| 2990 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2991 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 2992 | int ssl_reuse = 0; |
| 2993 | |
| 2994 | if (ssl_key_rate < ssl_sess_rate) { |
| 2995 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 2996 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 2997 | } |
| 2998 | #endif |
| 2999 | |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 3000 | chunk_reset(out); |
| 3001 | memset(&info, 0, sizeof(info)); |
| 3002 | |
| 3003 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
| 3004 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION); |
| 3005 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE); |
| 3006 | |
| 3007 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 3008 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 3009 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 3010 | |
| 3011 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 3012 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 3013 | |
| 3014 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 3015 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 3016 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 3017 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 3018 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 3019 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 3020 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 3021 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 3022 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 3023 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 3024 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 3025 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 3026 | #ifdef USE_OPENSSL |
| 3027 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 3028 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 3029 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 3030 | #endif |
| 3031 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 3032 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 3033 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 3034 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 3035 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 3036 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 3037 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 3038 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 3039 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 3040 | |
| 3041 | #ifdef USE_OPENSSL |
| 3042 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3043 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3044 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3045 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3046 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3047 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3048 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3049 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3050 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3051 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3052 | #endif |
| 3053 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3054 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3055 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3056 | #ifdef USE_ZLIB |
| 3057 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3058 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3059 | #endif |
| 3060 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
| 3061 | info[INF_RUN_QUEUE] = mkf_u32(0, run_queue_cur); |
| 3062 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct); |
| 3063 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3064 | if (global.desc) |
| 3065 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
| 3066 | |
Willy Tarreau | 1b4ba1e | 2016-01-11 18:29:04 +0100 | [diff] [blame] | 3067 | chunk_reset(&trash); |
| 3068 | stats_dump_info_fields(&trash, info); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3069 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3070 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3071 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3072 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3073 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3074 | |
| 3075 | return 1; |
| 3076 | } |
| 3077 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3078 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 3079 | * These information are all the parameters which may change during HAProxy runtime. |
| 3080 | * By default, we only export to the last known server state file format. |
| 3081 | * These information can be used at next startup to recover same level of server state. |
| 3082 | */ |
| 3083 | static void dump_servers_state(struct proxy *backend, struct chunk *buf) |
| 3084 | { |
| 3085 | struct server *srv; |
| 3086 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 3087 | time_t srv_time_since_last_change; |
| 3088 | int bk_f_forced_id, srv_f_forced_id; |
| 3089 | |
| 3090 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 3091 | if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1)))) |
| 3092 | return; |
| 3093 | |
| 3094 | srv = backend->srv; |
| 3095 | |
| 3096 | while (srv) { |
| 3097 | srv_addr[0] = '\0'; |
| 3098 | srv_time_since_last_change = 0; |
| 3099 | bk_f_forced_id = 0; |
| 3100 | srv_f_forced_id = 0; |
| 3101 | |
| 3102 | switch (srv->addr.ss_family) { |
| 3103 | case AF_INET: |
| 3104 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 3105 | srv_addr, INET_ADDRSTRLEN + 1); |
| 3106 | break; |
| 3107 | case AF_INET6: |
| 3108 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 3109 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 3110 | break; |
| 3111 | } |
| 3112 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
| 3113 | bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0; |
| 3114 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 3115 | |
| 3116 | chunk_appendf(buf, |
| 3117 | "%d %s " |
| 3118 | "%d %s %s " |
| 3119 | "%d %d %d %d %ld " |
| 3120 | "%d %d %d %d %d " |
| 3121 | "%d %d" |
| 3122 | "\n", |
| 3123 | backend->uuid, backend->id, |
| 3124 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 3125 | 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] | 3126 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 3127 | bk_f_forced_id, srv_f_forced_id); |
| 3128 | |
| 3129 | srv = srv->next; |
| 3130 | } |
| 3131 | } |
| 3132 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3133 | /* Parses backend list and simply report backend names */ |
| 3134 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 3135 | { |
| 3136 | extern struct proxy *proxy; |
| 3137 | struct proxy *curproxy; |
| 3138 | |
| 3139 | chunk_reset(&trash); |
| 3140 | chunk_printf(&trash, "# name\n"); |
| 3141 | |
| 3142 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3143 | /* looking for backends only */ |
| 3144 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3145 | continue; |
| 3146 | |
| 3147 | /* we don't want to list a backend which is bound to this process */ |
| 3148 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 3149 | continue; |
| 3150 | |
| 3151 | chunk_appendf(&trash, "%s\n", curproxy->id); |
| 3152 | } |
| 3153 | |
| 3154 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3155 | si_applet_cant_put(si); |
| 3156 | return 0; |
| 3157 | } |
| 3158 | |
| 3159 | return 1; |
| 3160 | } |
| 3161 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3162 | /* Parses backend list or simply use backend name provided by the user to return |
| 3163 | * states of servers to stdout. |
| 3164 | */ |
| 3165 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 3166 | { |
| 3167 | struct appctx *appctx = __objt_appctx(si->end); |
| 3168 | extern struct proxy *proxy; |
| 3169 | struct proxy *curproxy; |
| 3170 | |
| 3171 | chunk_reset(&trash); |
| 3172 | |
| 3173 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3174 | |
| 3175 | if (appctx->ctx.server_state.backend) { |
| 3176 | dump_servers_state(appctx->ctx.server_state.backend, &trash); |
| 3177 | } |
| 3178 | else { |
| 3179 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3180 | /* servers are only in backends */ |
| 3181 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3182 | continue; |
| 3183 | |
| 3184 | dump_servers_state(curproxy, &trash); |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3189 | si_applet_cant_put(si); |
| 3190 | return 0; |
| 3191 | } |
| 3192 | |
| 3193 | return 1; |
| 3194 | } |
| 3195 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3196 | /* This function dumps memory usage information onto the stream interface's |
| 3197 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3198 | * completion. No state is used. |
| 3199 | */ |
| 3200 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3201 | { |
| 3202 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3203 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3204 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3205 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3206 | } |
Willy Tarreau | 82a8602 | 2016-01-04 19:04:18 +0100 | [diff] [blame] | 3207 | return 1; |
| 3208 | } |
| 3209 | |
| 3210 | /* Dump all fields from <stats> into <out> using CSV format */ |
| 3211 | static int stats_dump_fields_csv(struct chunk *out, const struct field *stats) |
| 3212 | { |
| 3213 | int field; |
| 3214 | |
| 3215 | for (field = 0; field < ST_F_TOTAL_FIELDS; field++) { |
| 3216 | if (!stats_emit_raw_data_field(out, &stats[field])) |
| 3217 | return 0; |
| 3218 | if (!chunk_strcat(out, ",")) |
| 3219 | return 0; |
| 3220 | } |
| 3221 | chunk_strcat(&trash, "\n"); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3222 | return 1; |
| 3223 | } |
| 3224 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3225 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 3226 | * the state from stream interface <si>. The caller is responsible for clearing |
| 3227 | * 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] | 3228 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3229 | 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] | 3230 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3231 | struct appctx *appctx = __objt_appctx(si->end); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3232 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3233 | if (!(px->cap & PR_CAP_FE)) |
| 3234 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3235 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3236 | 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] | 3237 | return 0; |
| 3238 | |
Willy Tarreau | 9e56107 | 2016-01-04 19:36:41 +0100 | [diff] [blame^] | 3239 | memset(&stats, 0, sizeof(stats)); |
| 3240 | |
| 3241 | stats[ST_F_PXNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, px->id); |
| 3242 | stats[ST_F_SVNAME] = mkf_str(FO_KEY|FN_NAME|FS_SERVICE, "FRONTEND"); |
| 3243 | stats[ST_F_SCUR] = mkf_u32(0, px->feconn); |
| 3244 | stats[ST_F_SMAX] = mkf_u32(FN_MAX, px->fe_counters.conn_max); |
| 3245 | stats[ST_F_SLIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->maxconn); |
| 3246 | stats[ST_F_STOT] = mkf_u64(FN_COUNTER, px->fe_counters.cum_sess); |
| 3247 | stats[ST_F_BIN] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_in); |
| 3248 | stats[ST_F_BOUT] = mkf_u64(FN_COUNTER, px->fe_counters.bytes_out); |
| 3249 | stats[ST_F_DREQ] = mkf_u64(FN_COUNTER, px->fe_counters.denied_req); |
| 3250 | stats[ST_F_DRESP] = mkf_u64(FN_COUNTER, px->fe_counters.denied_resp); |
| 3251 | stats[ST_F_EREQ] = mkf_u64(FN_COUNTER, px->fe_counters.failed_req); |
| 3252 | stats[ST_F_STATUS] = mkf_str(FO_STATUS, px->state == PR_STREADY ? "OPEN" : px->state == PR_STFULL ? "FULL" : "STOP"); |
| 3253 | stats[ST_F_PID] = mkf_u32(FO_KEY, relative_pid); |
| 3254 | stats[ST_F_IID] = mkf_u32(FO_KEY|FS_SERVICE, px->uuid); |
| 3255 | stats[ST_F_SID] = mkf_u32(FO_KEY|FS_SERVICE, 0); |
| 3256 | stats[ST_F_TYPE] = mkf_u32(FO_CONFIG|FS_SERVICE, STATS_TYPE_FE); |
| 3257 | stats[ST_F_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_sess_per_sec)); |
| 3258 | stats[ST_F_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, px->fe_sps_lim); |
| 3259 | stats[ST_F_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.sps_max); |
| 3260 | |
| 3261 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3262 | if (px->mode == PR_MODE_HTTP) { |
| 3263 | stats[ST_F_HRSP_1XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[1]); |
| 3264 | stats[ST_F_HRSP_2XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[2]); |
| 3265 | stats[ST_F_HRSP_3XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[3]); |
| 3266 | stats[ST_F_HRSP_4XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[4]); |
| 3267 | stats[ST_F_HRSP_5XX] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[5]); |
| 3268 | stats[ST_F_HRSP_OTHER] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.rsp[0]); |
| 3269 | } |
| 3270 | |
| 3271 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3272 | stats[ST_F_REQ_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&px->fe_req_per_sec)); |
| 3273 | stats[ST_F_REQ_RATE_MAX] = mkf_u32(FN_MAX, px->fe_counters.p.http.rps_max); |
| 3274 | stats[ST_F_REQ_TOT] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.cum_req); |
| 3275 | |
| 3276 | /* compression: in, out, bypassed, responses */ |
| 3277 | stats[ST_F_COMP_IN] = mkf_u64(FN_COUNTER, px->fe_counters.comp_in); |
| 3278 | stats[ST_F_COMP_OUT] = mkf_u64(FN_COUNTER, px->fe_counters.comp_out); |
| 3279 | stats[ST_F_COMP_BYP] = mkf_u64(FN_COUNTER, px->fe_counters.comp_byp); |
| 3280 | stats[ST_F_COMP_RSP] = mkf_u64(FN_COUNTER, px->fe_counters.p.http.comp_rsp); |
| 3281 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3282 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3283 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3284 | /* name, queue */ |
| 3285 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3286 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3287 | 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] | 3288 | /* Column sub-heading for Enable or Disable server */ |
| 3289 | chunk_appendf(&trash, "<td></td>"); |
| 3290 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3291 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3292 | chunk_appendf(&trash, |
| 3293 | "<td class=ac>" |
| 3294 | "<a name=\"%s/Frontend\"></a>" |
| 3295 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3296 | "<td colspan=3></td>" |
| 3297 | "", |
| 3298 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3299 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3300 | chunk_appendf(&trash, |
| 3301 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3302 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3303 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3304 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3305 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3306 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 3307 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 3308 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3309 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3310 | if (px->mode == PR_MODE_HTTP) |
| 3311 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3312 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3313 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3314 | |
| 3315 | chunk_appendf(&trash, |
| 3316 | "</table></div></u></td>" |
| 3317 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3318 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3319 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3320 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3321 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3322 | U2H(px->fe_counters.sps_max), |
| 3323 | U2H(px->fe_counters.cps_max), |
| 3324 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3325 | |
| 3326 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3327 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3328 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3329 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3330 | |
| 3331 | chunk_appendf(&trash, |
| 3332 | "</table></div></u></td>" |
| 3333 | /* sessions rate : limit */ |
| 3334 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3335 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3336 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3337 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3338 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3339 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3340 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3341 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3342 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3343 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3344 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 3345 | U2H(px->fe_counters.cum_sess), |
| 3346 | U2H(px->fe_counters.cum_conn), |
| 3347 | U2H(px->fe_counters.cum_sess)); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3348 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3349 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3350 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3351 | chunk_appendf(&trash, |
| 3352 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3353 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3354 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3355 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3356 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3357 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3358 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3359 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3360 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3361 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3362 | U2H(px->fe_counters.p.http.cum_req), |
| 3363 | U2H(px->fe_counters.p.http.rsp[1]), |
| 3364 | U2H(px->fe_counters.p.http.rsp[2]), |
| 3365 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3366 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3367 | (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] | 3368 | U2H(px->fe_counters.p.http.rsp[3]), |
| 3369 | U2H(px->fe_counters.p.http.rsp[4]), |
| 3370 | U2H(px->fe_counters.p.http.rsp[5]), |
| 3371 | U2H(px->fe_counters.p.http.rsp[0]), |
| 3372 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3373 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3374 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3375 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3376 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3377 | /* sessions: lbtot, lastsess */ |
| 3378 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3379 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3380 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3381 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3382 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3383 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3384 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3385 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3386 | "<td>%s%s<div class=tips><table class=det>" |
| 3387 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3388 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3389 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3390 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3391 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3392 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3393 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3394 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3395 | U2H(px->fe_counters.bytes_out), |
| 3396 | U2H(px->fe_counters.comp_in), |
| 3397 | U2H(px->fe_counters.comp_out), |
| 3398 | px->fe_counters.comp_in ? (int)(px->fe_counters.comp_out * 100 / px->fe_counters.comp_in) : 0, |
| 3399 | U2H(px->fe_counters.comp_byp), |
| 3400 | U2H(px->fe_counters.comp_in - px->fe_counters.comp_out), |
| 3401 | 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] | 3402 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3403 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3404 | chunk_appendf(&trash, |
| 3405 | /* denied: req, resp */ |
| 3406 | "<td>%s</td><td>%s</td>" |
| 3407 | /* errors : request, connect, response */ |
| 3408 | "<td>%s</td><td></td><td></td>" |
| 3409 | /* warnings: retries, redispatches */ |
| 3410 | "<td></td><td></td>" |
| 3411 | /* server status : reflect frontend status */ |
| 3412 | "<td class=ac>%s</td>" |
| 3413 | /* rest of server: nothing */ |
| 3414 | "<td class=ac colspan=8></td></tr>" |
| 3415 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3416 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 3417 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3418 | px->state == PR_STREADY ? "OPEN" : |
| 3419 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3420 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3421 | else { /* CSV mode */ |
Willy Tarreau | 9e56107 | 2016-01-04 19:36:41 +0100 | [diff] [blame^] | 3422 | /* dump everything */ |
| 3423 | stats_dump_fields_csv(&trash, stats); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3424 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3425 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3426 | } |
| 3427 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3428 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 3429 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 3430 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 3431 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3432 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3433 | 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] | 3434 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3435 | struct appctx *appctx = __objt_appctx(si->end); |
| 3436 | |
| 3437 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3438 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3439 | 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] | 3440 | /* Column sub-heading for Enable or Disable server */ |
| 3441 | chunk_appendf(&trash, "<td></td>"); |
| 3442 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3443 | chunk_appendf(&trash, |
| 3444 | /* frontend name, listener name */ |
| 3445 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3446 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3447 | "", |
| 3448 | px->id, l->name, |
| 3449 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3450 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3451 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3452 | if (flags & ST_SHLGNDS) { |
| 3453 | char str[INET6_ADDRSTRLEN]; |
| 3454 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3455 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3456 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3457 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3458 | port = get_host_port(&l->addr); |
| 3459 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 3460 | case AF_INET: |
| 3461 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 3462 | break; |
| 3463 | case AF_INET6: |
| 3464 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 3465 | break; |
| 3466 | case AF_UNIX: |
| 3467 | chunk_appendf(&trash, "unix, "); |
| 3468 | break; |
| 3469 | case -1: |
| 3470 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3471 | break; |
| 3472 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3473 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3474 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3475 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3476 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3477 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3478 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3479 | /* queue */ |
| 3480 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3481 | /* sessions rate: current, max, limit */ |
| 3482 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3483 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3484 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3485 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3486 | /* bytes: in, out */ |
| 3487 | "<td>%s</td><td>%s</td>" |
| 3488 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3489 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3490 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 3491 | 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] | 3492 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3493 | chunk_appendf(&trash, |
| 3494 | /* denied: req, resp */ |
| 3495 | "<td>%s</td><td>%s</td>" |
| 3496 | /* errors: request, connect, response */ |
| 3497 | "<td>%s</td><td></td><td></td>" |
| 3498 | /* warnings: retries, redispatches */ |
| 3499 | "<td></td><td></td>" |
| 3500 | /* server status: reflect listener status */ |
| 3501 | "<td class=ac>%s</td>" |
| 3502 | /* rest of server: nothing */ |
| 3503 | "<td class=ac colspan=8></td></tr>" |
| 3504 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3505 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 3506 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3507 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 3508 | } |
| 3509 | else { /* CSV mode */ |
| 3510 | chunk_appendf(&trash, |
| 3511 | /* pxid, name, queue cur, queue max, */ |
| 3512 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3513 | /* sessions: current, max, limit, total */ |
| 3514 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3515 | /* bytes: in, out */ |
| 3516 | "%lld,%lld," |
| 3517 | /* denied: req, resp */ |
| 3518 | "%lld,%lld," |
| 3519 | /* errors: request, connect, response */ |
| 3520 | "%lld,,," |
| 3521 | /* warnings: retries, redispatches */ |
| 3522 | ",," |
| 3523 | /* server status: reflect listener status */ |
| 3524 | "%s," |
| 3525 | /* rest of server: nothing */ |
| 3526 | ",,,,,,,," |
| 3527 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3528 | "%d,%d,%d,,,,%d," |
| 3529 | /* rate, rate_lim, rate_max */ |
| 3530 | ",,," |
| 3531 | /* check_status, check_code, check_duration */ |
| 3532 | ",,," |
| 3533 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3534 | ",,,,,," |
| 3535 | /* failed health analyses */ |
| 3536 | "," |
| 3537 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3538 | ",,," |
| 3539 | /* errors: cli_aborts, srv_aborts */ |
| 3540 | ",," |
| 3541 | /* compression: in, out, bypassed, comp_rsp */ |
| 3542 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3543 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3544 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3545 | "\n", |
| 3546 | px->id, l->name, |
| 3547 | l->nbconn, l->counters->conn_max, |
| 3548 | l->maxconn, l->counters->cum_conn, |
| 3549 | l->counters->bytes_in, l->counters->bytes_out, |
| 3550 | l->counters->denied_req, l->counters->denied_resp, |
| 3551 | l->counters->failed_req, |
| 3552 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 3553 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 3554 | } |
| 3555 | return 1; |
| 3556 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3557 | |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3558 | enum srv_stats_state { |
| 3559 | SRV_STATS_STATE_DOWN = 0, |
| 3560 | SRV_STATS_STATE_DOWN_AGENT, |
| 3561 | SRV_STATS_STATE_GOING_UP, |
| 3562 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 3563 | SRV_STATS_STATE_UP, |
| 3564 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 3565 | SRV_STATS_STATE_NOLB, |
| 3566 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 3567 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3568 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3569 | SRV_STATS_STATE_NO_CHECK, |
| 3570 | |
| 3571 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 3572 | }; |
| 3573 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3574 | enum srv_stats_colour { |
| 3575 | SRV_STATS_COLOUR_DOWN = 0, |
| 3576 | SRV_STATS_COLOUR_GOING_UP, |
| 3577 | SRV_STATS_COLOUR_GOING_DOWN, |
| 3578 | SRV_STATS_COLOUR_UP, |
| 3579 | SRV_STATS_COLOUR_NOLB, |
| 3580 | SRV_STATS_COLOUR_DRAINING, |
| 3581 | SRV_STATS_COLOUR_NO_CHECK, |
| 3582 | |
| 3583 | SRV_STATS_COLOUR_COUNT, /* Must be last */ |
| 3584 | }; |
| 3585 | |
| 3586 | static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = { |
| 3587 | [SRV_STATS_COLOUR_DOWN] = "down", |
| 3588 | [SRV_STATS_COLOUR_GOING_UP] = "going_up", |
| 3589 | [SRV_STATS_COLOUR_GOING_DOWN] = "going_down", |
| 3590 | [SRV_STATS_COLOUR_UP] = "up", |
| 3591 | [SRV_STATS_COLOUR_NOLB] = "nolb", |
| 3592 | [SRV_STATS_COLOUR_DRAINING] = "draining", |
| 3593 | [SRV_STATS_COLOUR_NO_CHECK] = "no_check", |
| 3594 | }; |
| 3595 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3596 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 3597 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 3598 | * 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] | 3599 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3600 | */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3601 | 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] | 3602 | enum srv_stats_state state, enum srv_stats_colour colour) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3603 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3604 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3605 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3606 | char str[INET6_ADDRSTRLEN]; |
| 3607 | struct chunk src; |
| 3608 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3609 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3610 | /* we have "via" which is the tracked server as described in the configuration, |
| 3611 | * and "ref" which is the checked server and the end of the chain. |
| 3612 | */ |
| 3613 | via = sv->track ? sv->track : sv; |
| 3614 | ref = via; |
| 3615 | while (ref->track) |
| 3616 | ref = ref->track; |
| 3617 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3618 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3619 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3620 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 3621 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 3622 | [SRV_STATS_STATE_GOING_UP] = "DN %d/%d ↑", |
| 3623 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d ↓", |
| 3624 | [SRV_STATS_STATE_UP] = "UP", |
| 3625 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d ↓", |
| 3626 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 3627 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d ↓", |
| 3628 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3629 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3630 | [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3631 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3632 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3633 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3634 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 3635 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3636 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3637 | "<tr class=\"%s_%s\">", |
| 3638 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3639 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3640 | 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] | 3641 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3642 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3643 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3644 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3645 | chunk_appendf(&trash, |
| 3646 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3647 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3648 | "", |
| 3649 | px->id, sv->id, |
| 3650 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3651 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3652 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3653 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3654 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3655 | |
| 3656 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3657 | case AF_INET: |
| 3658 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3659 | break; |
| 3660 | case AF_INET6: |
| 3661 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3662 | break; |
| 3663 | case AF_UNIX: |
| 3664 | chunk_appendf(&trash, "unix, "); |
| 3665 | break; |
| 3666 | case -1: |
| 3667 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3668 | break; |
| 3669 | default: /* address family not supported */ |
| 3670 | break; |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3671 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3672 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3673 | /* id */ |
| 3674 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3675 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3676 | /* cookie */ |
| 3677 | if (sv->cookie) { |
| 3678 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3679 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3680 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3681 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3682 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3683 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3684 | } |
| 3685 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3686 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3687 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3688 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3689 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3690 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3691 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3692 | /* sessions rate : current, max, limit */ |
| 3693 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3694 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3695 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3696 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3697 | 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] | 3698 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3699 | |
| 3700 | chunk_appendf(&trash, |
| 3701 | /* sessions: current, max, limit, total */ |
| 3702 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3703 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3704 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3705 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3706 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3707 | U2H(sv->counters.cum_sess), |
| 3708 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3709 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3710 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3711 | if (px->mode == PR_MODE_HTTP) { |
| 3712 | unsigned long long tot; |
| 3713 | for (tot = i = 0; i < 6; i++) |
| 3714 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3715 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3716 | chunk_appendf(&trash, |
| 3717 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3718 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3719 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3720 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3721 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3722 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3723 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3724 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3725 | U2H(tot), |
| 3726 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3727 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3728 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3729 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3730 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3731 | 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] | 3732 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3733 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3734 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3735 | 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))); |
| 3736 | 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))); |
| 3737 | if (px->mode == PR_MODE_HTTP) |
| 3738 | 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))); |
| 3739 | 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))); |
| 3740 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3741 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3742 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3743 | /* sessions: lbtot, last */ |
| 3744 | "<td>%s</td><td>%s</td>", |
| 3745 | U2H(sv->counters.cum_lbconn), |
| 3746 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3747 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3748 | chunk_appendf(&trash, |
| 3749 | /* bytes : in, out */ |
| 3750 | "<td>%s</td><td>%s</td>" |
| 3751 | /* denied: req, resp */ |
| 3752 | "<td></td><td>%s</td>" |
| 3753 | /* errors : request, connect */ |
| 3754 | "<td></td><td>%s</td>" |
| 3755 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3756 | "<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] | 3757 | /* warnings: retries, redispatches */ |
| 3758 | "<td>%lld</td><td>%lld</td>" |
| 3759 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3760 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3761 | U2H(sv->counters.failed_secu), |
| 3762 | U2H(sv->counters.failed_conns), |
| 3763 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3764 | sv->counters.cli_aborts, |
| 3765 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3766 | sv->counters.retries, sv->counters.redispatches); |
| 3767 | |
| 3768 | /* status, lest check */ |
| 3769 | chunk_appendf(&trash, "<td class=ac>"); |
| 3770 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3771 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3772 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3773 | chunk_appendf(&trash, "MAINT"); |
| 3774 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3775 | 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] | 3776 | 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] | 3777 | /* DOWN (agent) */ |
| 3778 | 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] | 3779 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3780 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3781 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3782 | chunk_appendf(&trash, |
| 3783 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3784 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3785 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3786 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3787 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3788 | if ((sv->state == SRV_ST_STOPPED) && |
| 3789 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3790 | chunk_appendf(&trash, |
| 3791 | "</td><td class=ac><u> %s%s", |
| 3792 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3793 | get_check_status_info(sv->agent.status)); |
| 3794 | |
| 3795 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3796 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3797 | |
| 3798 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3799 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3800 | |
| 3801 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3802 | get_check_status_description(sv->agent.status)); |
| 3803 | if (*sv->agent.desc) { |
| 3804 | chunk_appendf(&trash, ": "); |
| 3805 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3806 | chunk_htmlencode(&trash, &src); |
| 3807 | } |
| 3808 | chunk_appendf(&trash, "</div></u>"); |
| 3809 | } |
| 3810 | 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] | 3811 | chunk_appendf(&trash, |
| 3812 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3813 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3814 | get_check_status_info(sv->check.status)); |
| 3815 | |
| 3816 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3817 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3818 | |
| 3819 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3820 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3821 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3822 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3823 | get_check_status_description(sv->check.status)); |
| 3824 | if (*sv->check.desc) { |
| 3825 | chunk_appendf(&trash, ": "); |
| 3826 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3827 | chunk_htmlencode(&trash, &src); |
| 3828 | } |
| 3829 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3830 | } |
| 3831 | else |
| 3832 | chunk_appendf(&trash, "</td><td>"); |
| 3833 | |
| 3834 | chunk_appendf(&trash, |
| 3835 | /* weight */ |
| 3836 | "</td><td class=ac>%d</td>" |
| 3837 | /* act, bck */ |
| 3838 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3839 | "", |
| 3840 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3841 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3842 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3843 | |
| 3844 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3845 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3846 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3847 | |
| 3848 | if (ref->observe) |
| 3849 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3850 | |
| 3851 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3852 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3853 | "<td>%lld</td><td>%s</td>" |
| 3854 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3855 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3856 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3857 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3858 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3859 | /* tracking a server */ |
| 3860 | chunk_appendf(&trash, |
| 3861 | "<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] | 3862 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3863 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3864 | else |
| 3865 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3866 | |
| 3867 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3868 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3869 | 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] | 3870 | else |
| 3871 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3872 | } |
| 3873 | else { /* CSV mode */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3874 | struct chunk *out = get_trash_chunk(); |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3875 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3876 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3877 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3878 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3879 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3880 | [SRV_STATS_STATE_UP] = "UP,", |
| 3881 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3882 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3883 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3884 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Raghu Udiyar | 0d6b7a4 | 2016-02-05 22:30:11 +0530 | [diff] [blame] | 3885 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent),", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3886 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3887 | }; |
| 3888 | |
| 3889 | chunk_appendf(&trash, |
| 3890 | /* pxid, name */ |
| 3891 | "%s,%s," |
| 3892 | /* queue : current, max */ |
| 3893 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3894 | /* sessions : current, max, limit, total */ |
| 3895 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3896 | /* bytes : in, out */ |
| 3897 | "%lld,%lld," |
| 3898 | /* denied: req, resp */ |
| 3899 | ",%lld," |
| 3900 | /* errors : request, connect, response */ |
| 3901 | ",%lld,%lld," |
| 3902 | /* warnings: retries, redispatches */ |
| 3903 | "%lld,%lld," |
| 3904 | "", |
| 3905 | px->id, sv->id, |
| 3906 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3907 | 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] | 3908 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3909 | sv->counters.failed_secu, |
| 3910 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3911 | sv->counters.retries, sv->counters.redispatches); |
| 3912 | |
| 3913 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3914 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3915 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3916 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3917 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3918 | else |
| 3919 | chunk_appendf(&trash, |
| 3920 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3921 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3922 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3923 | |
| 3924 | chunk_appendf(&trash, |
| 3925 | /* weight, active, backup */ |
| 3926 | "%d,%d,%d," |
| 3927 | "", |
| 3928 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3929 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3930 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3931 | |
| 3932 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3933 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3934 | chunk_appendf(&trash, |
| 3935 | "%lld,%lld,%d,%d,", |
| 3936 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3937 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3938 | else |
| 3939 | chunk_appendf(&trash, ",,,,"); |
| 3940 | |
| 3941 | /* queue limit, pid, iid, sid, */ |
| 3942 | chunk_appendf(&trash, |
| 3943 | "%s," |
| 3944 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3945 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3946 | relative_pid, px->uuid, sv->puid); |
| 3947 | |
| 3948 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3949 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3950 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3951 | |
| 3952 | /* sessions: lbtot */ |
| 3953 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3954 | |
| 3955 | /* tracked */ |
| 3956 | if (sv->track) |
| 3957 | chunk_appendf(&trash, "%s/%s,", |
| 3958 | sv->track->proxy->id, sv->track->id); |
| 3959 | else |
| 3960 | chunk_appendf(&trash, ","); |
| 3961 | |
| 3962 | /* type */ |
| 3963 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3964 | |
| 3965 | /* rate */ |
| 3966 | chunk_appendf(&trash, "%u,,%u,", |
| 3967 | read_freq_ctr(&sv->sess_per_sec), |
| 3968 | sv->counters.sps_max); |
| 3969 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3970 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3971 | /* check_status */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3972 | 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] | 3973 | |
| 3974 | /* check_code */ |
| 3975 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3976 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3977 | else |
| 3978 | chunk_appendf(&trash, ","); |
| 3979 | |
| 3980 | /* check_duration */ |
| 3981 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3982 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3983 | else |
| 3984 | chunk_appendf(&trash, ","); |
| 3985 | |
| 3986 | } |
| 3987 | else |
| 3988 | chunk_appendf(&trash, ",,,"); |
| 3989 | |
| 3990 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3991 | if (px->mode == PR_MODE_HTTP) { |
| 3992 | for (i=1; i<6; i++) |
| 3993 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 3994 | |
| 3995 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 3996 | } |
| 3997 | else |
| 3998 | chunk_appendf(&trash, ",,,,,,"); |
| 3999 | |
| 4000 | /* failed health analyses */ |
| 4001 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 4002 | |
| 4003 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 4004 | chunk_appendf(&trash, ",,,"); |
| 4005 | |
| 4006 | /* errors: cli_aborts, srv_aborts */ |
| 4007 | chunk_appendf(&trash, "%lld,%lld,", |
| 4008 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 4009 | |
| 4010 | /* compression: in, out, bypassed, comp_rsp */ |
| 4011 | chunk_appendf(&trash, ",,,,"); |
| 4012 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4013 | /* lastsess */ |
| 4014 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 4015 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 4016 | /* capture of last check and agent statuses */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 4017 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : ""); |
| 4018 | 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] | 4019 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4020 | /* qtime, ctime, rtime, ttime, */ |
| 4021 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 4022 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 4023 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 4024 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 4025 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 4026 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4027 | /* finish with EOL */ |
| 4028 | chunk_appendf(&trash, "\n"); |
| 4029 | } |
| 4030 | return 1; |
| 4031 | } |
| 4032 | |
| 4033 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 4034 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 4035 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4036 | */ |
| 4037 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 4038 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4039 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4040 | struct chunk src; |
| 4041 | int i; |
| 4042 | |
| 4043 | if (!(px->cap & PR_CAP_BE)) |
| 4044 | return 0; |
| 4045 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4046 | 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] | 4047 | return 0; |
| 4048 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4049 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4050 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4051 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4052 | /* Column sub-heading for Enable or Disable server */ |
| 4053 | chunk_appendf(&trash, "<td></td>"); |
| 4054 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4055 | chunk_appendf(&trash, |
| 4056 | "<td class=ac>" |
| 4057 | /* name */ |
| 4058 | "%s<a name=\"%s/Backend\"></a>" |
| 4059 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 4060 | "", |
| 4061 | (flags & ST_SHLGNDS)?"<u>":"", |
| 4062 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4063 | |
| 4064 | if (flags & ST_SHLGNDS) { |
| 4065 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4066 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4067 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 4068 | |
| 4069 | /* cookie */ |
| 4070 | if (px->cookie_name) { |
| 4071 | chunk_appendf(&trash, ", cookie: '"); |
| 4072 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 4073 | chunk_htmlencode(&trash, &src); |
| 4074 | chunk_appendf(&trash, "'"); |
| 4075 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4076 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4080 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4081 | /* queue : current, max */ |
| 4082 | "<td>%s</td><td>%s</td><td></td>" |
| 4083 | /* sessions rate : current, max, limit */ |
| 4084 | "<td>%s</td><td>%s</td><td></td>" |
| 4085 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4086 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4087 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 4088 | 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] | 4089 | |
| 4090 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4091 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4092 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4093 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4094 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4095 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4096 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 4097 | U2H(px->be_counters.cum_conn), |
| 4098 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4099 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4100 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4101 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4102 | chunk_appendf(&trash, |
| 4103 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 4104 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 4105 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 4106 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4107 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 4108 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 4109 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 4110 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 4111 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4112 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4113 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4114 | U2H(px->be_counters.p.http.cum_req), |
| 4115 | U2H(px->be_counters.p.http.rsp[1]), |
| 4116 | U2H(px->be_counters.p.http.rsp[2]), |
| 4117 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4118 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4119 | (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] | 4120 | U2H(px->be_counters.p.http.rsp[3]), |
| 4121 | U2H(px->be_counters.p.http.rsp[4]), |
| 4122 | U2H(px->be_counters.p.http.rsp[5]), |
| 4123 | U2H(px->be_counters.p.http.rsp[0]), |
| 4124 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4125 | } |
| 4126 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4127 | 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))); |
| 4128 | 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))); |
| 4129 | if (px->mode == PR_MODE_HTTP) |
| 4130 | 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))); |
| 4131 | 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))); |
| 4132 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4133 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4134 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4135 | /* sessions: lbtot, last */ |
| 4136 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4137 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4138 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4139 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4140 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4141 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4142 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4143 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4144 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4145 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 4146 | "<td>%s%s<div class=tips><table class=det>" |
| 4147 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 4148 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 4149 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4150 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 4151 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4152 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4153 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4154 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 4155 | U2H(px->be_counters.bytes_out), |
| 4156 | U2H(px->be_counters.comp_in), |
| 4157 | U2H(px->be_counters.comp_out), |
| 4158 | px->be_counters.comp_in ? (int)(px->be_counters.comp_out * 100 / px->be_counters.comp_in) : 0, |
| 4159 | U2H(px->be_counters.comp_byp), |
| 4160 | U2H(px->be_counters.comp_in - px->be_counters.comp_out), |
| 4161 | 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] | 4162 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 4163 | |
| 4164 | chunk_appendf(&trash, |
| 4165 | /* denied: req, resp */ |
| 4166 | "<td>%s</td><td>%s</td>" |
| 4167 | /* errors : request, connect */ |
| 4168 | "<td></td><td>%s</td>" |
| 4169 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4170 | "<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] | 4171 | /* warnings: retries, redispatches */ |
| 4172 | "<td>%lld</td><td>%lld</td>" |
| 4173 | /* backend status: reflect backend status (up/down): we display UP |
| 4174 | * if the backend has known working servers or if it has no server at |
| 4175 | * all (eg: for stats). Then we display the total weight, number of |
| 4176 | * active and backups. */ |
| 4177 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 4178 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 4179 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4180 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 4181 | U2H(px->be_counters.failed_conns), |
| 4182 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4183 | px->be_counters.cli_aborts, |
| 4184 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4185 | px->be_counters.retries, px->be_counters.redispatches, |
| 4186 | human_time(now.tv_sec - px->last_change, 1), |
| 4187 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 4188 | "<font color=\"red\"><b>DOWN</b></font>", |
| 4189 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 4190 | px->srv_act, px->srv_bck); |
| 4191 | |
| 4192 | chunk_appendf(&trash, |
| 4193 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 4194 | "<td class=ac> </td><td>%d</td>" |
| 4195 | "<td>%s</td>" |
| 4196 | "<td></td>" |
| 4197 | "</tr>", |
| 4198 | px->down_trans, |
| 4199 | px->srv?human_time(be_downtime(px), 1):" "); |
| 4200 | } |
| 4201 | else { /* CSV mode */ |
| 4202 | chunk_appendf(&trash, |
| 4203 | /* pxid, name */ |
| 4204 | "%s,BACKEND," |
| 4205 | /* queue : current, max */ |
| 4206 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4207 | /* sessions : current, max, limit, total */ |
| 4208 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4209 | /* bytes : in, out */ |
| 4210 | "%lld,%lld," |
| 4211 | /* denied: req, resp */ |
| 4212 | "%lld,%lld," |
| 4213 | /* errors : request, connect, response */ |
| 4214 | ",%lld,%lld," |
| 4215 | /* warnings: retries, redispatches */ |
| 4216 | "%lld,%lld," |
| 4217 | /* backend status: reflect backend status (up/down): we display UP |
| 4218 | * if the backend has known working servers or if it has no server at |
| 4219 | * all (eg: for stats). Then we display the total weight, number of |
| 4220 | * active and backups. */ |
| 4221 | "%s," |
| 4222 | "%d,%d,%d," |
| 4223 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 4224 | ",%d,%d,%d,," |
| 4225 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 4226 | "%d,%d,0,,%lld,,%d," |
| 4227 | /* rate, rate_lim, rate_max, */ |
| 4228 | "%u,,%u," |
| 4229 | /* check_status, check_code, check_duration */ |
| 4230 | ",,,", |
| 4231 | px->id, |
| 4232 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 4233 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 4234 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 4235 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 4236 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 4237 | px->be_counters.retries, px->be_counters.redispatches, |
| 4238 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 4239 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 4240 | px->srv_act, px->srv_bck, |
| 4241 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 4242 | px->srv?be_downtime(px):0, |
| 4243 | relative_pid, px->uuid, |
| 4244 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 4245 | read_freq_ctr(&px->be_sess_per_sec), |
| 4246 | px->be_counters.sps_max); |
| 4247 | |
| 4248 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4249 | if (px->mode == PR_MODE_HTTP) { |
| 4250 | for (i=1; i<6; i++) |
| 4251 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 4252 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 4253 | } |
| 4254 | else |
| 4255 | chunk_appendf(&trash, ",,,,,,"); |
| 4256 | |
| 4257 | /* failed health analyses */ |
| 4258 | chunk_appendf(&trash, ","); |
| 4259 | |
| 4260 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 4261 | chunk_appendf(&trash, ",,,"); |
| 4262 | |
| 4263 | /* errors: cli_aborts, srv_aborts */ |
| 4264 | chunk_appendf(&trash, "%lld,%lld,", |
| 4265 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 4266 | |
| 4267 | /* compression: in, out, bypassed */ |
| 4268 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 4269 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 4270 | |
| 4271 | /* compression: comp_rsp */ |
| 4272 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 4273 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 4274 | /* lastsess, last_chk, last_agt, */ |
| 4275 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4276 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4277 | /* qtime, ctime, rtime, ttime, */ |
| 4278 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 4279 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 4280 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 4281 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 4282 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4283 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4284 | /* finish with EOL */ |
| 4285 | chunk_appendf(&trash, "\n"); |
| 4286 | } |
| 4287 | return 1; |
| 4288 | } |
| 4289 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4290 | /* 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] | 4291 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4292 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4293 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4294 | 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] | 4295 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4296 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4297 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4298 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4299 | 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] | 4300 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4301 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4302 | /* 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] | 4303 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4304 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4305 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4306 | 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] | 4307 | 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] | 4308 | } |
| 4309 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4310 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4311 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4312 | } |
| 4313 | |
| 4314 | /* print a new table */ |
| 4315 | chunk_appendf(&trash, |
| 4316 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4317 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4318 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4319 | |
| 4320 | chunk_appendf(&trash, |
| 4321 | "<a name=\"%s\"></a>%s" |
| 4322 | "<a class=px href=\"#%s\">%s</a>", |
| 4323 | px->id, |
| 4324 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4325 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4326 | |
| 4327 | if (uri->flags & ST_SHLGNDS) { |
| 4328 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4329 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4330 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4331 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4332 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4336 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4337 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4338 | "</tr>\n" |
| 4339 | "</table>\n" |
| 4340 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4341 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4342 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4343 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4344 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4345 | 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] | 4346 | /* Column heading for Enable or Disable server */ |
| 4347 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4348 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4349 | |
| 4350 | chunk_appendf(&trash, |
| 4351 | "<th rowspan=2></th>" |
| 4352 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4353 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4354 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4355 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4356 | "<th colspan=9>Server</th>" |
| 4357 | "</tr>\n" |
| 4358 | "<tr class=\"titre\">" |
| 4359 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4360 | "<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] | 4361 | "<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] | 4362 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4363 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4364 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4365 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4366 | "<th>Thrtle</th>\n" |
| 4367 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4368 | } |
| 4369 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4370 | /* 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] | 4371 | * 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] | 4372 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4373 | 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] | 4374 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4375 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4376 | chunk_appendf(&trash, "</table>"); |
| 4377 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4378 | 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] | 4379 | /* close the form used to enable/disable this proxy servers */ |
| 4380 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4381 | "Choose the action to perform on the checked servers : " |
| 4382 | "<select name=action>" |
| 4383 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4384 | "<option value=\"ready\">Set state to READY</option>" |
| 4385 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4386 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4387 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4388 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4389 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4390 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4391 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4392 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4393 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4394 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4395 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4396 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4397 | "</select>" |
| 4398 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4399 | " <input type=\"submit\" value=\"Apply\">" |
| 4400 | "</form>", |
| 4401 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4405 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4406 | |
| 4407 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4408 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4409 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4410 | * buffer space, or non-zero if everything completed. This function is used |
| 4411 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4412 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4413 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4414 | 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] | 4415 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4416 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4417 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4418 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4419 | 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] | 4420 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4421 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4422 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4423 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4424 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4425 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4426 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4427 | if (uri && uri->scope) { |
| 4428 | /* we have a limited scope, we have to check the proxy name */ |
| 4429 | struct stat_scope *scope; |
| 4430 | int len; |
| 4431 | |
| 4432 | len = strlen(px->id); |
| 4433 | scope = uri->scope; |
| 4434 | |
| 4435 | while (scope) { |
| 4436 | /* match exact proxy name */ |
| 4437 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4438 | break; |
| 4439 | |
| 4440 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4441 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4442 | break; |
| 4443 | scope = scope->next; |
| 4444 | } |
| 4445 | |
| 4446 | /* proxy name not found : don't dump anything */ |
| 4447 | if (scope == NULL) |
| 4448 | return 1; |
| 4449 | } |
| 4450 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4451 | /* if the user has requested a limited output and the proxy |
| 4452 | * name does not match, skip it. |
| 4453 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4454 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4455 | 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] | 4456 | return 1; |
| 4457 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4458 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4459 | (appctx->ctx.stats.iid != -1) && |
| 4460 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4461 | return 1; |
| 4462 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4463 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4464 | /* fall through */ |
| 4465 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4466 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4467 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4468 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4469 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4470 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4471 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4472 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4473 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4474 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4475 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4476 | /* fall through */ |
| 4477 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4478 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4479 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4480 | if (stats_dump_fe_stats(si, px)) { |
| 4481 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4482 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4483 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4484 | } |
| 4485 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4486 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4487 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4488 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4489 | /* fall through */ |
| 4490 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4491 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4492 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4493 | 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] | 4494 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4495 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4496 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4497 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4498 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4499 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4500 | if (!l->counters) |
| 4501 | continue; |
| 4502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4503 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4504 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4505 | break; |
| 4506 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4507 | 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] | 4508 | continue; |
| 4509 | } |
| 4510 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4511 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4512 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 4513 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4514 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4515 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4516 | } |
| 4517 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4518 | } |
| 4519 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4520 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4521 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4522 | /* fall through */ |
| 4523 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4524 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4525 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4526 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4527 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4528 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4529 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4530 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4531 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4532 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4533 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4534 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4535 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4536 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4537 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4538 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4539 | break; |
| 4540 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4541 | 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] | 4542 | continue; |
| 4543 | } |
| 4544 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4545 | svs = sv; |
| 4546 | while (svs->track) |
| 4547 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4548 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4549 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4550 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4551 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4552 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4553 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4554 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4555 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4556 | sv_colour = SRV_STATS_COLOUR_UP; |
| 4557 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4558 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4559 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 4560 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 4561 | |
| 4562 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4563 | if (svs->agent.state & CHK_ST_ENABLED) |
| 4564 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4565 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4566 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4567 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4568 | sv_state = SRV_STATS_STATE_DRAIN; |
| 4569 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4570 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4571 | 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] | 4572 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4573 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 4574 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4575 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4576 | else if (sv->state == SRV_ST_STOPPING) { |
| 4577 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4578 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4579 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4580 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 4581 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4582 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4583 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4584 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4585 | } |
| 4586 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4587 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4588 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4589 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4590 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4591 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4592 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4593 | } 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] | 4594 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4595 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 4596 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4597 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4598 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4599 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4600 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4601 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4602 | 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] | 4603 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4604 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4605 | continue; |
| 4606 | } |
| 4607 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4608 | 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] | 4609 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4610 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4611 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4612 | } |
| 4613 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4614 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4615 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4616 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4617 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4618 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4619 | case STAT_PX_ST_BE: |
| 4620 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4621 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 4622 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4623 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4624 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4625 | } |
| 4626 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4627 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4628 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4629 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4630 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4631 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4632 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4633 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4634 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4635 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4636 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4637 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4638 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4639 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4640 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4641 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4642 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4643 | case STAT_PX_ST_FIN: |
| 4644 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4645 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4646 | default: |
| 4647 | /* unknown state, we should put an abort() here ! */ |
| 4648 | return 1; |
| 4649 | } |
| 4650 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4651 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4652 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4653 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4654 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4655 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4656 | { |
| 4657 | /* WARNING! This must fit in the first buffer !!! */ |
| 4658 | chunk_appendf(&trash, |
| 4659 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4660 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4661 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4662 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4663 | "<style type=\"text/css\"><!--\n" |
| 4664 | "body {" |
| 4665 | " font-family: arial, helvetica, sans-serif;" |
| 4666 | " font-size: 12px;" |
| 4667 | " font-weight: normal;" |
| 4668 | " color: black;" |
| 4669 | " background: white;" |
| 4670 | "}\n" |
| 4671 | "th,td {" |
| 4672 | " font-size: 10px;" |
| 4673 | "}\n" |
| 4674 | "h1 {" |
| 4675 | " font-size: x-large;" |
| 4676 | " margin-bottom: 0.5em;" |
| 4677 | "}\n" |
| 4678 | "h2 {" |
| 4679 | " font-family: helvetica, arial;" |
| 4680 | " font-size: x-large;" |
| 4681 | " font-weight: bold;" |
| 4682 | " font-style: italic;" |
| 4683 | " color: #6020a0;" |
| 4684 | " margin-top: 0em;" |
| 4685 | " margin-bottom: 0em;" |
| 4686 | "}\n" |
| 4687 | "h3 {" |
| 4688 | " font-family: helvetica, arial;" |
| 4689 | " font-size: 16px;" |
| 4690 | " font-weight: bold;" |
| 4691 | " color: #b00040;" |
| 4692 | " background: #e8e8d0;" |
| 4693 | " margin-top: 0em;" |
| 4694 | " margin-bottom: 0em;" |
| 4695 | "}\n" |
| 4696 | "li {" |
| 4697 | " margin-top: 0.25em;" |
| 4698 | " margin-right: 2em;" |
| 4699 | "}\n" |
| 4700 | ".hr {margin-top: 0.25em;" |
| 4701 | " border-color: black;" |
| 4702 | " border-bottom-style: solid;" |
| 4703 | "}\n" |
| 4704 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4705 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4706 | ".frontend {background: #e8e8d0;}\n" |
| 4707 | ".socket {background: #d0d0d0;}\n" |
| 4708 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4709 | ".active_down {background: #ff9090;}\n" |
| 4710 | ".active_going_up {background: #ffd020;}\n" |
| 4711 | ".active_going_down {background: #ffffa0;}\n" |
| 4712 | ".active_up {background: #c0ffc0;}\n" |
| 4713 | ".active_nolb {background: #20a0ff;}\n" |
| 4714 | ".active_draining {background: #20a0FF;}\n" |
| 4715 | ".active_no_check {background: #e0e0e0;}\n" |
| 4716 | ".backup_down {background: #ff9090;}\n" |
| 4717 | ".backup_going_up {background: #ff80ff;}\n" |
| 4718 | ".backup_going_down {background: #c060ff;}\n" |
| 4719 | ".backup_up {background: #b0d0ff;}\n" |
| 4720 | ".backup_nolb {background: #90b0e0;}\n" |
| 4721 | ".backup_draining {background: #cc9900;}\n" |
| 4722 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4723 | ".maintain {background: #c07820;}\n" |
| 4724 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4725 | "\n" |
| 4726 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4727 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4728 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4729 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4730 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4731 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4732 | "\n" |
| 4733 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4734 | "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" |
| 4735 | "table.tbl td.ac { text-align: center;}\n" |
| 4736 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4737 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4738 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4739 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4740 | "\n" |
| 4741 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4742 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4743 | "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] | 4744 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4745 | "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] | 4746 | "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] | 4747 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4748 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4749 | " display:block;\n" |
| 4750 | " visibility:hidden;\n" |
| 4751 | " z-index:2147483647;\n" |
| 4752 | " position:absolute;\n" |
| 4753 | " padding:2px 4px 3px;\n" |
| 4754 | " background:#f0f060; color:#000000;\n" |
| 4755 | " border:1px solid #7040c0;\n" |
| 4756 | " white-space:nowrap;\n" |
| 4757 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4758 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4759 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4760 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4761 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4762 | "-->\n" |
| 4763 | "</style></head>\n", |
| 4764 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4765 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4766 | ); |
| 4767 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4768 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4769 | /* 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] | 4770 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4771 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4772 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4773 | 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] | 4774 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4775 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4776 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4777 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4778 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4779 | /* WARNING! this has to fit the first packet too. |
| 4780 | * We are around 3.5 kB, add adding entries will |
| 4781 | * become tricky if we want to support 4kB buffers ! |
| 4782 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4783 | chunk_appendf(&trash, |
| 4784 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4785 | PRODUCT_NAME "%s</a></h1>\n" |
| 4786 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4787 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4788 | "<h3>> General process information</h3>\n" |
| 4789 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4790 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4791 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4792 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4793 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4794 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4795 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4796 | "</td><td align=\"center\" nowrap>\n" |
| 4797 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4798 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4799 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4800 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4801 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4802 | "<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] | 4803 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4804 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4805 | "<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] | 4806 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4807 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4808 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4809 | "</tr><tr>\n" |
| 4810 | "<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] | 4811 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4812 | "<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] | 4813 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4814 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4815 | "</td>" |
| 4816 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4817 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4818 | "", |
| 4819 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4820 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4821 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4822 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4823 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4824 | pid, relative_pid, global.nbproc, |
| 4825 | up / 86400, (up % 86400) / 3600, |
| 4826 | (up % 3600) / 60, (up % 60), |
| 4827 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4828 | global.rlimit_memmax ? " MB" : "", |
| 4829 | global.rlimit_nofile, |
| 4830 | global.maxsock, global.maxconn, global.maxpipes, |
| 4831 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4832 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4833 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4834 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4835 | /* 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] | 4836 | 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] | 4837 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4838 | |
| 4839 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4840 | "<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] | 4841 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4842 | STAT_SCOPE_TXT_MAXLEN); |
| 4843 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4844 | /* 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] | 4845 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4846 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4847 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4848 | 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] | 4849 | 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] | 4850 | } |
| 4851 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4852 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4853 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4854 | "<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] | 4855 | uri->uri_prefix, |
| 4856 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4857 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4858 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4859 | else |
| 4860 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4861 | "<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] | 4862 | uri->uri_prefix, |
| 4863 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4864 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4865 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4866 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4867 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4868 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4869 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4870 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4871 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4872 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4873 | "", |
| 4874 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4875 | else |
| 4876 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4877 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4878 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4879 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4880 | ";norefresh", |
| 4881 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4882 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4883 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4884 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4885 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4886 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4887 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4888 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4889 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4890 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4891 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4892 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4893 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4894 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4895 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4896 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4897 | chunk_appendf(&trash, |
| 4898 | "</ul></td>" |
| 4899 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4900 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4901 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4902 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4903 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4904 | "</ul>" |
| 4905 | "</td>" |
| 4906 | "</tr></table>\n" |
| 4907 | "" |
| 4908 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4909 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4910 | if (appctx->ctx.stats.st_code) { |
| 4911 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4912 | case STAT_STATUS_DONE: |
| 4913 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4914 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4915 | "<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] | 4916 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4917 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4918 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4919 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4920 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4921 | break; |
| 4922 | case STAT_STATUS_NONE: |
| 4923 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4924 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4925 | "<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] | 4926 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4927 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4928 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4929 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4930 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4931 | break; |
| 4932 | case STAT_STATUS_PART: |
| 4933 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4934 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4935 | "<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] | 4936 | "Action partially processed.<br>" |
| 4937 | "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] | 4938 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4939 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4940 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4941 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4942 | break; |
| 4943 | case STAT_STATUS_ERRP: |
| 4944 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4945 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4946 | "<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] | 4947 | "Action not processed because of invalid parameters." |
| 4948 | "<ul>" |
| 4949 | "<li>The action is maybe unknown.</li>" |
| 4950 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4951 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4952 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4953 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4954 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4955 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4956 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4957 | break; |
| 4958 | case STAT_STATUS_EXCD: |
| 4959 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4960 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4961 | "<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] | 4962 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4963 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4964 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4965 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4966 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4967 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4968 | break; |
| 4969 | case STAT_STATUS_DENY: |
| 4970 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4971 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4972 | "<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] | 4973 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4974 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4975 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4976 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4977 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4978 | break; |
| 4979 | default: |
| 4980 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4981 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4982 | "<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] | 4983 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4984 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4985 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4986 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4987 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4988 | } |
| 4989 | chunk_appendf(&trash, "<p>\n"); |
| 4990 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4991 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4992 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4993 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 4994 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4995 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4996 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4997 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4998 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4999 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5000 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5001 | /* This function dumps statistics onto the stream interface's read buffer in |
| 5002 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5003 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 5004 | * 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] | 5005 | * 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] | 5006 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5007 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5008 | 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] | 5009 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5010 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5011 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5012 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5013 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5014 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5015 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5016 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5017 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5018 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5019 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 5020 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5021 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5022 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5023 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 5024 | else |
| 5025 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 5026 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5027 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5028 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5029 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5030 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5031 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5032 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5033 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5034 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5035 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5036 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5037 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5038 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5039 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5040 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5041 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5042 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5043 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5044 | appctx->ctx.stats.px = proxy; |
| 5045 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 5046 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5047 | /* fall through */ |
| 5048 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5049 | case STAT_ST_LIST: |
| 5050 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5051 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5052 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5053 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5054 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5055 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5056 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5057 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5058 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5059 | 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] | 5060 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5061 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5062 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5063 | appctx->ctx.stats.px = px->next; |
| 5064 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5065 | } |
| 5066 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5067 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5068 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5069 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5070 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5071 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5072 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5073 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5074 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5075 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5076 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5077 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5078 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5079 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5080 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5081 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5082 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5083 | case STAT_ST_FIN: |
| 5084 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5085 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5086 | default: |
| 5087 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5088 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5089 | return -1; |
| 5090 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5091 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5092 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5093 | /* We reached the stats page through a POST request. The appctx is |
| 5094 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5095 | * Parse the posted data and enable/disable servers if necessary. |
| 5096 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5097 | */ |
| 5098 | static int stats_process_http_post(struct stream_interface *si) |
| 5099 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5100 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5101 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5102 | |
| 5103 | struct proxy *px = NULL; |
| 5104 | struct server *sv = NULL; |
| 5105 | |
| 5106 | char key[LINESIZE]; |
| 5107 | int action = ST_ADM_ACTION_NONE; |
| 5108 | int reprocess = 0; |
| 5109 | |
| 5110 | int total_servers = 0; |
| 5111 | int altered_servers = 0; |
| 5112 | |
| 5113 | char *first_param, *cur_param, *next_param, *end_params; |
| 5114 | char *st_cur_param = NULL; |
| 5115 | char *st_next_param = NULL; |
| 5116 | |
| 5117 | struct chunk *temp; |
| 5118 | int reql; |
| 5119 | |
| 5120 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5121 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5122 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5123 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5124 | goto out; |
| 5125 | } |
| 5126 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5127 | 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] | 5128 | if (reql <= 0) { |
| 5129 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5130 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5131 | return 0; |
| 5132 | } |
| 5133 | |
| 5134 | first_param = temp->str; |
| 5135 | end_params = temp->str + reql; |
| 5136 | cur_param = next_param = end_params; |
| 5137 | *end_params = '\0'; |
| 5138 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5139 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5140 | |
| 5141 | /* |
| 5142 | * Parse the parameters in reverse order to only store the last value. |
| 5143 | * From the html form, the backend and the action are at the end. |
| 5144 | */ |
| 5145 | while (cur_param > first_param) { |
| 5146 | char *value; |
| 5147 | int poffset, plen; |
| 5148 | |
| 5149 | cur_param--; |
| 5150 | |
| 5151 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5152 | reprocess_servers: |
| 5153 | /* Parse the key */ |
| 5154 | poffset = (cur_param != first_param ? 1 : 0); |
| 5155 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5156 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5157 | strncpy(key, cur_param + poffset, plen); |
| 5158 | key[plen - 1] = '\0'; |
| 5159 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5160 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5161 | goto out; |
| 5162 | } |
| 5163 | |
| 5164 | /* Parse the value */ |
| 5165 | value = key; |
| 5166 | while (*value != '\0' && *value != '=') { |
| 5167 | value++; |
| 5168 | } |
| 5169 | if (*value == '=') { |
| 5170 | /* Ok, a value is found, we can mark the end of the key */ |
| 5171 | *value++ = '\0'; |
| 5172 | } |
| 5173 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5174 | break; |
| 5175 | |
| 5176 | /* Now we can check the key to see what to do */ |
| 5177 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5178 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5179 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5180 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5181 | goto out; |
| 5182 | } |
| 5183 | } |
| 5184 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5185 | if (strcmp(value, "ready") == 0) { |
| 5186 | action = ST_ADM_ACTION_READY; |
| 5187 | } |
| 5188 | else if (strcmp(value, "drain") == 0) { |
| 5189 | action = ST_ADM_ACTION_DRAIN; |
| 5190 | } |
| 5191 | else if (strcmp(value, "maint") == 0) { |
| 5192 | action = ST_ADM_ACTION_MAINT; |
| 5193 | } |
| 5194 | else if (strcmp(value, "shutdown") == 0) { |
| 5195 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5196 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5197 | else if (strcmp(value, "dhlth") == 0) { |
| 5198 | action = ST_ADM_ACTION_DHLTH; |
| 5199 | } |
| 5200 | else if (strcmp(value, "ehlth") == 0) { |
| 5201 | action = ST_ADM_ACTION_EHLTH; |
| 5202 | } |
| 5203 | else if (strcmp(value, "hrunn") == 0) { |
| 5204 | action = ST_ADM_ACTION_HRUNN; |
| 5205 | } |
| 5206 | else if (strcmp(value, "hnolb") == 0) { |
| 5207 | action = ST_ADM_ACTION_HNOLB; |
| 5208 | } |
| 5209 | else if (strcmp(value, "hdown") == 0) { |
| 5210 | action = ST_ADM_ACTION_HDOWN; |
| 5211 | } |
| 5212 | else if (strcmp(value, "dagent") == 0) { |
| 5213 | action = ST_ADM_ACTION_DAGENT; |
| 5214 | } |
| 5215 | else if (strcmp(value, "eagent") == 0) { |
| 5216 | action = ST_ADM_ACTION_EAGENT; |
| 5217 | } |
| 5218 | else if (strcmp(value, "arunn") == 0) { |
| 5219 | action = ST_ADM_ACTION_ARUNN; |
| 5220 | } |
| 5221 | else if (strcmp(value, "adown") == 0) { |
| 5222 | action = ST_ADM_ACTION_ADOWN; |
| 5223 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5224 | /* else these are the old supported methods */ |
| 5225 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5226 | action = ST_ADM_ACTION_DISABLE; |
| 5227 | } |
| 5228 | else if (strcmp(value, "enable") == 0) { |
| 5229 | action = ST_ADM_ACTION_ENABLE; |
| 5230 | } |
| 5231 | else if (strcmp(value, "stop") == 0) { |
| 5232 | action = ST_ADM_ACTION_STOP; |
| 5233 | } |
| 5234 | else if (strcmp(value, "start") == 0) { |
| 5235 | action = ST_ADM_ACTION_START; |
| 5236 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5237 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5238 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5239 | goto out; |
| 5240 | } |
| 5241 | } |
| 5242 | else if (strcmp(key, "s") == 0) { |
| 5243 | if (!(px && action)) { |
| 5244 | /* |
| 5245 | * Indicates that we'll need to reprocess the parameters |
| 5246 | * as soon as backend and action are known |
| 5247 | */ |
| 5248 | if (!reprocess) { |
| 5249 | st_cur_param = cur_param; |
| 5250 | st_next_param = next_param; |
| 5251 | } |
| 5252 | reprocess = 1; |
| 5253 | } |
| 5254 | else if ((sv = findserver(px, value)) != NULL) { |
| 5255 | switch (action) { |
| 5256 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5257 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5258 | altered_servers++; |
| 5259 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5260 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5261 | } |
| 5262 | break; |
| 5263 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5264 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5265 | altered_servers++; |
| 5266 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5267 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5268 | } |
| 5269 | break; |
| 5270 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5271 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5272 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5273 | altered_servers++; |
| 5274 | total_servers++; |
| 5275 | } |
| 5276 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5277 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5278 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5279 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5280 | altered_servers++; |
| 5281 | total_servers++; |
| 5282 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5283 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5284 | case ST_ADM_ACTION_DHLTH: |
| 5285 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5286 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5287 | altered_servers++; |
| 5288 | total_servers++; |
| 5289 | } |
| 5290 | break; |
| 5291 | case ST_ADM_ACTION_EHLTH: |
| 5292 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5293 | sv->check.state |= CHK_ST_ENABLED; |
| 5294 | altered_servers++; |
| 5295 | total_servers++; |
| 5296 | } |
| 5297 | break; |
| 5298 | case ST_ADM_ACTION_HRUNN: |
| 5299 | if (!(sv->track)) { |
| 5300 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5301 | srv_set_running(sv, "changed from Web interface"); |
| 5302 | altered_servers++; |
| 5303 | total_servers++; |
| 5304 | } |
| 5305 | break; |
| 5306 | case ST_ADM_ACTION_HNOLB: |
| 5307 | if (!(sv->track)) { |
| 5308 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5309 | srv_set_stopping(sv, "changed from Web interface"); |
| 5310 | altered_servers++; |
| 5311 | total_servers++; |
| 5312 | } |
| 5313 | break; |
| 5314 | case ST_ADM_ACTION_HDOWN: |
| 5315 | if (!(sv->track)) { |
| 5316 | sv->check.health = 0; |
| 5317 | srv_set_stopped(sv, "changed from Web interface"); |
| 5318 | altered_servers++; |
| 5319 | total_servers++; |
| 5320 | } |
| 5321 | break; |
| 5322 | case ST_ADM_ACTION_DAGENT: |
| 5323 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5324 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5325 | altered_servers++; |
| 5326 | total_servers++; |
| 5327 | } |
| 5328 | break; |
| 5329 | case ST_ADM_ACTION_EAGENT: |
| 5330 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5331 | sv->agent.state |= CHK_ST_ENABLED; |
| 5332 | altered_servers++; |
| 5333 | total_servers++; |
| 5334 | } |
| 5335 | break; |
| 5336 | case ST_ADM_ACTION_ARUNN: |
| 5337 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5338 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5339 | srv_set_running(sv, "changed from Web interface"); |
| 5340 | altered_servers++; |
| 5341 | total_servers++; |
| 5342 | } |
| 5343 | break; |
| 5344 | case ST_ADM_ACTION_ADOWN: |
| 5345 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5346 | sv->agent.health = 0; |
| 5347 | srv_set_stopped(sv, "changed from Web interface"); |
| 5348 | altered_servers++; |
| 5349 | total_servers++; |
| 5350 | } |
| 5351 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5352 | case ST_ADM_ACTION_READY: |
| 5353 | srv_adm_set_ready(sv); |
| 5354 | altered_servers++; |
| 5355 | total_servers++; |
| 5356 | break; |
| 5357 | case ST_ADM_ACTION_DRAIN: |
| 5358 | srv_adm_set_drain(sv); |
| 5359 | altered_servers++; |
| 5360 | total_servers++; |
| 5361 | break; |
| 5362 | case ST_ADM_ACTION_MAINT: |
| 5363 | srv_adm_set_maint(sv); |
| 5364 | altered_servers++; |
| 5365 | total_servers++; |
| 5366 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5367 | case ST_ADM_ACTION_SHUTDOWN: |
| 5368 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5369 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5370 | |
| 5371 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5372 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5373 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5374 | |
| 5375 | altered_servers++; |
| 5376 | total_servers++; |
| 5377 | } |
| 5378 | break; |
| 5379 | } |
| 5380 | } else { |
| 5381 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5382 | total_servers++; |
| 5383 | } |
| 5384 | } |
| 5385 | if (reprocess && px && action) { |
| 5386 | /* Now, we know the backend and the action chosen by the user. |
| 5387 | * We can safely restart from the first server parameter |
| 5388 | * to reprocess them |
| 5389 | */ |
| 5390 | cur_param = st_cur_param; |
| 5391 | next_param = st_next_param; |
| 5392 | reprocess = 0; |
| 5393 | goto reprocess_servers; |
| 5394 | } |
| 5395 | |
| 5396 | next_param = cur_param; |
| 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5401 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5402 | } |
| 5403 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5404 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5405 | } |
| 5406 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5407 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5408 | } |
| 5409 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5410 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5411 | } |
| 5412 | out: |
| 5413 | return 1; |
| 5414 | } |
| 5415 | |
| 5416 | |
| 5417 | static int stats_send_http_headers(struct stream_interface *si) |
| 5418 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5419 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5420 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5421 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5422 | |
| 5423 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5424 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5425 | "Cache-Control: no-cache\r\n" |
| 5426 | "Connection: close\r\n" |
| 5427 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5428 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5429 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5430 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5431 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5432 | uri->refresh); |
| 5433 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5434 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5435 | |
| 5436 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5437 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5438 | else |
| 5439 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5440 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5441 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5442 | s->logs.tv_request = now; |
| 5443 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5444 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5445 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5446 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5447 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5448 | |
| 5449 | return 1; |
| 5450 | } |
| 5451 | |
| 5452 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5453 | { |
| 5454 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5455 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5456 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5457 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5458 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5459 | /* 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] | 5460 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5461 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5462 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5463 | 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] | 5464 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5465 | } |
| 5466 | |
| 5467 | /* We don't want to land on the posted stats page because a refresh will |
| 5468 | * repost the data. We don't want this to happen on accident so we redirect |
| 5469 | * the browse to the stats page with a GET. |
| 5470 | */ |
| 5471 | chunk_printf(&trash, |
| 5472 | "HTTP/1.1 303 See Other\r\n" |
| 5473 | "Cache-Control: no-cache\r\n" |
| 5474 | "Content-Type: text/plain\r\n" |
| 5475 | "Connection: close\r\n" |
| 5476 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5477 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5478 | "\r\n", |
| 5479 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5480 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5481 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5482 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5483 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5484 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5485 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5486 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5487 | scope_txt); |
| 5488 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5489 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5490 | s->logs.tv_request = now; |
| 5491 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5492 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5493 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5494 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5495 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5496 | |
| 5497 | return 1; |
| 5498 | } |
| 5499 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5500 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5501 | * 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] | 5502 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5503 | * automatically unregisters itself once transfer is complete. |
| 5504 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5505 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5506 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5507 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5508 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5509 | struct channel *req = si_oc(si); |
| 5510 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5511 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5512 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5513 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5514 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5515 | /* check that the output is not closed */ |
| 5516 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5517 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5518 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5519 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5520 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5521 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5522 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5523 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5524 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5525 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5526 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5527 | } |
| 5528 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5529 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5530 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5531 | unsigned int data_len; |
| 5532 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5533 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5534 | |
| 5535 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5536 | /* One difficulty we're facing is that we must prevent |
| 5537 | * the input data from being automatically forwarded to |
| 5538 | * the output area. For this, we temporarily disable |
| 5539 | * forwarding on the channel. |
| 5540 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5541 | last_fwd = si_ic(si)->to_forward; |
| 5542 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5543 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5544 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5545 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5546 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5547 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5548 | } |
| 5549 | } |
| 5550 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5551 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5552 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5553 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5554 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5555 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5556 | |
| 5557 | /* Now we must either adjust or remove the chunk size. This is |
| 5558 | * not easy because the chunk size might wrap at the end of the |
| 5559 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5560 | * the size, then restore the buffer's contents. Note that we can |
| 5561 | * only do that because no forwarding is scheduled on the stats |
| 5562 | * applet. |
| 5563 | */ |
| 5564 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5565 | si_ic(si)->total -= (last_len - prev_len); |
| 5566 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5567 | |
| 5568 | if (last_len != data_len) { |
| 5569 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5570 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5571 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5572 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5573 | si_ic(si)->total += (last_len - data_len); |
| 5574 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5575 | } |
| 5576 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5577 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5578 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5579 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5580 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5581 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5582 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5583 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5584 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5585 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5586 | } |
| 5587 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5588 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5589 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5590 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5591 | } |
| 5592 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5593 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5594 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5595 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5596 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5597 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5598 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5599 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5600 | } |
| 5601 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5602 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5603 | res->flags |= CF_READ_NULL; |
| 5604 | si_shutr(si); |
| 5605 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5606 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5607 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5608 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5609 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5610 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5611 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5612 | si_shutr(si); |
| 5613 | res->flags |= CF_READ_NULL; |
| 5614 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5615 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5616 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5617 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5618 | } |
| 5619 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5620 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5621 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5622 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5623 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5624 | return "NONE"; |
| 5625 | return conn->ctrl->name; |
| 5626 | } |
| 5627 | |
| 5628 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5629 | { |
| 5630 | static char ptr[17]; |
| 5631 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5632 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5633 | return "NONE"; |
| 5634 | |
| 5635 | if (conn->xprt == &raw_sock) |
| 5636 | return "RAW"; |
| 5637 | |
| 5638 | #ifdef USE_OPENSSL |
| 5639 | if (conn->xprt == &ssl_sock) |
| 5640 | return "SSL"; |
| 5641 | #endif |
| 5642 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5643 | return ptr; |
| 5644 | } |
| 5645 | |
| 5646 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5647 | { |
| 5648 | static char ptr[17]; |
| 5649 | |
| 5650 | if (!conn->data) |
| 5651 | return "NONE"; |
| 5652 | |
| 5653 | if (conn->data == &sess_conn_cb) |
| 5654 | return "SESS"; |
| 5655 | |
| 5656 | if (conn->data == &si_conn_cb) |
| 5657 | return "STRM"; |
| 5658 | |
| 5659 | if (conn->data == &check_conn_cb) |
| 5660 | return "CHCK"; |
| 5661 | |
| 5662 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5663 | return ptr; |
| 5664 | } |
| 5665 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5666 | /* This function dumps a complete stream state onto the stream interface's |
| 5667 | * 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] | 5668 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5669 | * 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] | 5670 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5671 | 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] | 5672 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5673 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5674 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5675 | extern const char *monthname[12]; |
| 5676 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5677 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5678 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5679 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5680 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5681 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5682 | 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] | 5683 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5684 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5685 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5686 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5687 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5688 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5689 | appctx->ctx.sess.uid = 0; |
| 5690 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5691 | return 1; |
| 5692 | } |
| 5693 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5694 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5695 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5696 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5697 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5698 | /* fall through */ |
| 5699 | |
| 5700 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5701 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5702 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5703 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5704 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5705 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5706 | 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] | 5707 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5708 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5709 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5710 | conn = objt_conn(strm_orig(sess)); |
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) { |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5712 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5713 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5714 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5715 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5716 | break; |
| 5717 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5718 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5719 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 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"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5723 | break; |
| 5724 | } |
| 5725 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5726 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5727 | " 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] | 5728 | 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] | 5729 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5730 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5731 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5732 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5733 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5734 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5735 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5736 | if (conn) |
| 5737 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5738 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5739 | 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] | 5740 | case AF_INET: |
| 5741 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5742 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5743 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5744 | break; |
| 5745 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5746 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5747 | break; |
| 5748 | default: |
| 5749 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5750 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5751 | break; |
| 5752 | } |
| 5753 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5754 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5755 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5756 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5757 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5758 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5759 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5760 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5761 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5762 | conn = objt_conn(sess->si[1].end); |
| 5763 | if (conn) |
| 5764 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5765 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5766 | 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] | 5767 | case AF_INET: |
| 5768 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5769 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5770 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5771 | break; |
| 5772 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5773 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5774 | break; |
| 5775 | default: |
| 5776 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5777 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5778 | break; |
| 5779 | } |
| 5780 | |
| 5781 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5782 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5783 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5784 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5785 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5786 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5787 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5788 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5789 | if (conn) |
| 5790 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5791 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5792 | 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] | 5793 | case AF_INET: |
| 5794 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5795 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5796 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5797 | break; |
| 5798 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5799 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5800 | break; |
| 5801 | default: |
| 5802 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5803 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5804 | break; |
| 5805 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5806 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5807 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5808 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5809 | sess->task, |
| 5810 | sess->task->state, |
| 5811 | sess->task->nice, sess->task->calls, |
| 5812 | sess->task->expire ? |
| 5813 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5814 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5815 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5816 | task_in_rq(sess->task) ? ", running" : ""); |
| 5817 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5818 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5819 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5820 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5821 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5822 | if (sess->txn) |
| 5823 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5824 | " 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] | 5825 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5826 | 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] | 5827 | |
| 5828 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5829 | " 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] | 5830 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5831 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5832 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5833 | obj_type_name(sess->si[0].end), |
| 5834 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5835 | sess->si[0].exp ? |
| 5836 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5837 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5838 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5839 | sess->si[0].err_type); |
| 5840 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5841 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5842 | " 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] | 5843 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5844 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5845 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5846 | obj_type_name(sess->si[1].end), |
| 5847 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5848 | sess->si[1].exp ? |
| 5849 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5850 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5851 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5852 | sess->si[1].err_type); |
| 5853 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5854 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5855 | chunk_appendf(&trash, |
| 5856 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5857 | conn, |
| 5858 | get_conn_ctrl_name(conn), |
| 5859 | get_conn_xprt_name(conn), |
| 5860 | get_conn_data_name(conn), |
| 5861 | obj_type_name(conn->target), |
| 5862 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5863 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5864 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5865 | " 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] | 5866 | conn->flags, |
| 5867 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5868 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5869 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5870 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5871 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5872 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5873 | chunk_appendf(&trash, |
| 5874 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5875 | tmpctx, |
| 5876 | tmpctx->st0, |
| 5877 | tmpctx->st1, |
| 5878 | tmpctx->st2, |
| 5879 | tmpctx->applet->name); |
| 5880 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5881 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5882 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5883 | chunk_appendf(&trash, |
| 5884 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5885 | conn, |
| 5886 | get_conn_ctrl_name(conn), |
| 5887 | get_conn_xprt_name(conn), |
| 5888 | get_conn_data_name(conn), |
| 5889 | obj_type_name(conn->target), |
| 5890 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5891 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5892 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 5893 | " 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] | 5894 | conn->flags, |
| 5895 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5896 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5897 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5898 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5899 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5900 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5901 | chunk_appendf(&trash, |
| 5902 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5903 | tmpctx, |
| 5904 | tmpctx->st0, |
| 5905 | tmpctx->st1, |
| 5906 | tmpctx->st2, |
| 5907 | tmpctx->applet->name); |
| 5908 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5909 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5910 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5911 | " 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] | 5912 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5913 | &sess->req, |
| 5914 | sess->req.flags, sess->req.analysers, |
| 5915 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5916 | sess->req.to_forward, sess->req.total, |
| 5917 | sess->req.analyse_exp ? |
| 5918 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5919 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5920 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5921 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5922 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5923 | sess->req.rex ? |
| 5924 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5925 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5926 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5927 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5928 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5929 | " 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] | 5930 | sess->req.wex ? |
| 5931 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5932 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5933 | sess->req.buf, |
| 5934 | sess->req.buf->data, sess->req.buf->o, |
| 5935 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5936 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5937 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5938 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5939 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5940 | " 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] | 5941 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5942 | &sess->res, |
| 5943 | sess->res.flags, sess->res.analysers, |
| 5944 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5945 | sess->res.to_forward, sess->res.total, |
| 5946 | sess->res.analyse_exp ? |
| 5947 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5948 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5949 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5950 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5951 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5952 | sess->res.rex ? |
| 5953 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5954 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5955 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5956 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5957 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5958 | " 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] | 5959 | sess->res.wex ? |
| 5960 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5961 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5962 | sess->res.buf, |
| 5963 | sess->res.buf->data, sess->res.buf->o, |
| 5964 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5965 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5966 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5967 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5968 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5969 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5970 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5971 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5972 | |
| 5973 | /* use other states to dump the contents */ |
| 5974 | } |
| 5975 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5976 | appctx->ctx.sess.uid = 0; |
| 5977 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5978 | return 1; |
| 5979 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5980 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 5981 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 5982 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 5983 | struct appctx *appctx = __objt_appctx(si->end); |
| 5984 | |
| 5985 | switch (appctx->st2) { |
| 5986 | case STAT_ST_INIT: |
| 5987 | /* Display the column headers. If the message cannot be sent, |
| 5988 | * quit the fucntion with returning 0. The function is called |
| 5989 | * later and restart at the state "STAT_ST_INIT". |
| 5990 | */ |
| 5991 | chunk_reset(&trash); |
| 5992 | chunk_appendf(&trash, "# id (file)\n"); |
| 5993 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 5994 | si_applet_cant_put(si); |
| 5995 | return 0; |
| 5996 | } |
| 5997 | |
| 5998 | /* Now, we start the browsing of the references lists. |
| 5999 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6000 | * avalaible field of this pointer is <list>. It is used with the function |
| 6001 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 6002 | */ |
| 6003 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 6004 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6005 | |
| 6006 | appctx->st2 = STAT_ST_LIST; |
| 6007 | /* fall through */ |
| 6008 | |
| 6009 | case STAT_ST_LIST: |
| 6010 | while (appctx->ctx.tlskeys.ref) { |
| 6011 | chunk_reset(&trash); |
| 6012 | |
| 6013 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 6014 | appctx->ctx.tlskeys.ref->filename); |
| 6015 | |
| 6016 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6017 | /* let's try again later from this stream. We add ourselves into |
| 6018 | * this stream's users so that it can remove us upon termination. |
| 6019 | */ |
| 6020 | si_applet_cant_put(si); |
| 6021 | return 0; |
| 6022 | } |
| 6023 | |
| 6024 | /* get next list entry and check the end of the list */ |
| 6025 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6026 | } |
| 6027 | |
| 6028 | appctx->st2 = STAT_ST_FIN; |
| 6029 | /* fall through */ |
| 6030 | |
| 6031 | default: |
| 6032 | appctx->st2 = STAT_ST_FIN; |
| 6033 | return 1; |
| 6034 | } |
| 6035 | return 0; |
| 6036 | } |
| 6037 | #endif |
| 6038 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6039 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6040 | { |
| 6041 | struct appctx *appctx = __objt_appctx(si->end); |
| 6042 | |
| 6043 | switch (appctx->st2) { |
| 6044 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6045 | /* Display the column headers. If the message cannot be sent, |
| 6046 | * quit the fucntion with returning 0. The function is called |
| 6047 | * later and restart at the state "STAT_ST_INIT". |
| 6048 | */ |
| 6049 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 6050 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6051 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6052 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6053 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6054 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6055 | |
| 6056 | /* Now, we start the browsing of the references lists. |
| 6057 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6058 | * avalaible field of this pointer is <list>. It is used with the function |
| 6059 | * pat_list_get_next() for retruning the first avalaible entry |
| 6060 | */ |
| 6061 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6062 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6063 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6064 | appctx->st2 = STAT_ST_LIST; |
| 6065 | /* fall through */ |
| 6066 | |
| 6067 | case STAT_ST_LIST: |
| 6068 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6069 | chunk_reset(&trash); |
| 6070 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6071 | /* Build messages. If the reference is used by another category than |
| 6072 | * the listed categorie, display the information in the massage. |
| 6073 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6074 | 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] | 6075 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6076 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6077 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6078 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6079 | /* let's try again later from this stream. We add ourselves into |
| 6080 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6081 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6082 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6083 | return 0; |
| 6084 | } |
| 6085 | |
| 6086 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6087 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6088 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6089 | } |
| 6090 | |
| 6091 | appctx->st2 = STAT_ST_FIN; |
| 6092 | /* fall through */ |
| 6093 | |
| 6094 | default: |
| 6095 | appctx->st2 = STAT_ST_FIN; |
| 6096 | return 1; |
| 6097 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6098 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6099 | } |
| 6100 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6101 | static int stats_map_lookup(struct stream_interface *si) |
| 6102 | { |
| 6103 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6104 | struct sample sample; |
| 6105 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6106 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6107 | |
| 6108 | switch (appctx->st2) { |
| 6109 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6110 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6111 | 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] | 6112 | 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] | 6113 | appctx->st2 = STAT_ST_LIST; |
| 6114 | /* fall through */ |
| 6115 | |
| 6116 | case STAT_ST_LIST: |
| 6117 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6118 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6119 | /* initialise chunk to build new message */ |
| 6120 | chunk_reset(&trash); |
| 6121 | |
| 6122 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6123 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6124 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6125 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6126 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6127 | if (appctx->ctx.map.expr->pat_head->match && |
| 6128 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6129 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6130 | else |
| 6131 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6132 | |
| 6133 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6134 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6135 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6136 | break; |
| 6137 | if (match_method >= PAT_MATCH_NUM) |
| 6138 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6139 | else |
| 6140 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6141 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6142 | /* case sensitive */ |
| 6143 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6144 | chunk_appendf(&trash, ", case=insensitive"); |
| 6145 | else |
| 6146 | chunk_appendf(&trash, ", case=sensitive"); |
| 6147 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6148 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6149 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6150 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6151 | chunk_appendf(&trash, ", found=no"); |
| 6152 | else |
| 6153 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6154 | } |
| 6155 | |
| 6156 | /* Display match and match info */ |
| 6157 | else { |
| 6158 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6159 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6160 | chunk_appendf(&trash, ", found=yes"); |
| 6161 | else |
| 6162 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6163 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6164 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6165 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6166 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6167 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6168 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6169 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6170 | /* display pattern */ |
| 6171 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6172 | if (pat->ref && pat->ref->pattern) |
| 6173 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6174 | else |
| 6175 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6176 | } |
| 6177 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6178 | if (pat->ref && pat->ref->pattern) |
| 6179 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6180 | else |
| 6181 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6182 | } |
| 6183 | |
| 6184 | /* display return value */ |
| 6185 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6186 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6187 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6188 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6189 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6190 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6191 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6192 | } |
| 6193 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6194 | chunk_appendf(&trash, "\n"); |
| 6195 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6196 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6197 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6198 | /* let's try again later from this stream. We add ourselves into |
| 6199 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6200 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6201 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6202 | return 0; |
| 6203 | } |
| 6204 | |
| 6205 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6206 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6207 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6208 | } |
| 6209 | |
| 6210 | appctx->st2 = STAT_ST_FIN; |
| 6211 | /* fall through */ |
| 6212 | |
| 6213 | default: |
| 6214 | appctx->st2 = STAT_ST_FIN; |
| 6215 | free(appctx->ctx.map.chunk.str); |
| 6216 | return 1; |
| 6217 | } |
| 6218 | } |
| 6219 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6220 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6221 | { |
| 6222 | struct appctx *appctx = __objt_appctx(si->end); |
| 6223 | |
| 6224 | switch (appctx->st2) { |
| 6225 | |
| 6226 | case STAT_ST_INIT: |
| 6227 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6228 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6229 | struct pat_ref_elt *, list); |
| 6230 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6231 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6232 | appctx->st2 = STAT_ST_LIST; |
| 6233 | /* fall through */ |
| 6234 | |
| 6235 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6236 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6237 | chunk_reset(&trash); |
| 6238 | |
| 6239 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6240 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6241 | chunk_appendf(&trash, "%p %s %s\n", |
| 6242 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6243 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6244 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6245 | chunk_appendf(&trash, "%p %s\n", |
| 6246 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6247 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6248 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6249 | /* let's try again later from this stream. We add ourselves into |
| 6250 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6251 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6252 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6253 | return 0; |
| 6254 | } |
| 6255 | |
| 6256 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6257 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6258 | struct pat_ref_elt *, list); |
| 6259 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6260 | break; |
| 6261 | } |
| 6262 | |
| 6263 | appctx->st2 = STAT_ST_FIN; |
| 6264 | /* fall through */ |
| 6265 | |
| 6266 | default: |
| 6267 | appctx->st2 = STAT_ST_FIN; |
| 6268 | return 1; |
| 6269 | } |
| 6270 | } |
| 6271 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6272 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6273 | * 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] | 6274 | * to be called again, otherwise non-zero. It is designed to be called |
| 6275 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6276 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6277 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6278 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6279 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6280 | struct connection *conn; |
| 6281 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6282 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6283 | /* 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] | 6284 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6285 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6286 | if (appctx->st2 == STAT_ST_LIST) { |
| 6287 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6288 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6289 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6290 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6291 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6292 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6293 | } |
| 6294 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6295 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6296 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6297 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6298 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6299 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6300 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6301 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6302 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6303 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6304 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6305 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6306 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6307 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6308 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6309 | /* fall through */ |
| 6310 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6311 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6312 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6313 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6314 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6315 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6319 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6320 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6321 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6322 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6323 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6324 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6325 | if (appctx->ctx.sess.target) { |
| 6326 | 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] | 6327 | goto next_sess; |
| 6328 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6329 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6330 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6331 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6332 | return 0; |
| 6333 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6334 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6335 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6336 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6337 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6338 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6339 | break; |
| 6340 | } |
| 6341 | else |
| 6342 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6343 | } |
| 6344 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6345 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6346 | "%p: proto=%s", |
| 6347 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6348 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6349 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6350 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6351 | 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] | 6352 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6353 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6354 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6355 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6356 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6357 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6358 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6359 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6360 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6361 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6362 | break; |
| 6363 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6364 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6365 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6366 | strm_li(curr_sess)->luid, |
| 6367 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6368 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6369 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6370 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6371 | break; |
| 6372 | } |
| 6373 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6374 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6375 | " ts=%02x age=%s calls=%d", |
| 6376 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6377 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6378 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6379 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6380 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6381 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6382 | curr_sess->req.flags, |
| 6383 | curr_sess->req.buf->i, |
| 6384 | curr_sess->req.analysers, |
| 6385 | curr_sess->req.rex ? |
| 6386 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6387 | TICKS_TO_MS(1000)) : ""); |
| 6388 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6389 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6390 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6391 | curr_sess->req.wex ? |
| 6392 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6393 | TICKS_TO_MS(1000)) : ""); |
| 6394 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6395 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6396 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6397 | curr_sess->req.analyse_exp ? |
| 6398 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6399 | TICKS_TO_MS(1000)) : ""); |
| 6400 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6401 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6402 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6403 | curr_sess->res.flags, |
| 6404 | curr_sess->res.buf->i, |
| 6405 | curr_sess->res.analysers, |
| 6406 | curr_sess->res.rex ? |
| 6407 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6408 | TICKS_TO_MS(1000)) : ""); |
| 6409 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6410 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6411 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6412 | curr_sess->res.wex ? |
| 6413 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6414 | TICKS_TO_MS(1000)) : ""); |
| 6415 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6416 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6417 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6418 | curr_sess->res.analyse_exp ? |
| 6419 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6420 | TICKS_TO_MS(1000)) : ""); |
| 6421 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6422 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6423 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6424 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6425 | curr_sess->si[0].state, |
| 6426 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6427 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6428 | curr_sess->si[0].exp ? |
| 6429 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6430 | TICKS_TO_MS(1000)) : ""); |
| 6431 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6432 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6433 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6434 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6435 | curr_sess->si[1].state, |
| 6436 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6437 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6438 | curr_sess->si[1].exp ? |
| 6439 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6440 | TICKS_TO_MS(1000)) : ""); |
| 6441 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6442 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6443 | " exp=%s", |
| 6444 | curr_sess->task->expire ? |
| 6445 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6446 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6447 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6448 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6449 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6450 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6451 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6452 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6453 | /* let's try again later from this stream. We add ourselves into |
| 6454 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6455 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6456 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6457 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6458 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6459 | } |
| 6460 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6461 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6462 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6463 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6464 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6465 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6466 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6467 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6468 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6469 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6470 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6471 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6472 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6473 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6474 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6475 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6476 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6477 | appctx->ctx.sess.target = NULL; |
| 6478 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6479 | return 1; |
| 6480 | } |
| 6481 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6482 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6483 | /* fall through */ |
| 6484 | |
| 6485 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6486 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6487 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6488 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6489 | } |
| 6490 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6491 | /* This is called when the stream interface is closed. For instance, upon an |
| 6492 | * 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] | 6493 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6494 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6495 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6496 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6497 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6498 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6499 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6500 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6501 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6502 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6503 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6504 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6505 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6506 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6507 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6508 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6509 | } |
| 6510 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6511 | /* This function is used to either dump tables states (when action is set |
| 6512 | * 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] | 6513 | * It returns 0 if the output buffer is full and it needs to be called |
| 6514 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6515 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6516 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6517 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6518 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6519 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6520 | struct ebmb_node *eb; |
| 6521 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6522 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6523 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6524 | |
| 6525 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6526 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6527 | * - STAT_ST_INIT : the first call |
| 6528 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6529 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6530 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6531 | * and the entry pointer points to the next entry to be dumped, |
| 6532 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6533 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6534 | * data though. |
| 6535 | */ |
| 6536 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6537 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6538 | /* 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] | 6539 | if (appctx->st2 == STAT_ST_LIST) { |
| 6540 | appctx->ctx.table.entry->ref_cnt--; |
| 6541 | 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] | 6542 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6543 | return 1; |
| 6544 | } |
| 6545 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6546 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6547 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6548 | while (appctx->st2 != STAT_ST_FIN) { |
| 6549 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6550 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6551 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6552 | if (!appctx->ctx.table.proxy) |
| 6553 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6554 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6555 | appctx->ctx.table.entry = NULL; |
| 6556 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6557 | break; |
| 6558 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6559 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6560 | if (!appctx->ctx.table.proxy || |
| 6561 | (appctx->ctx.table.target && |
| 6562 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6563 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6564 | break; |
| 6565 | } |
| 6566 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6567 | if (appctx->ctx.table.proxy->table.size) { |
| 6568 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6569 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6570 | return 0; |
| 6571 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6572 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6573 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6574 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6575 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6576 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6577 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6578 | appctx->ctx.table.entry->ref_cnt++; |
| 6579 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6580 | break; |
| 6581 | } |
| 6582 | } |
| 6583 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6584 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6585 | break; |
| 6586 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6587 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6588 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6589 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6590 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6591 | /* we're filtering on some data contents */ |
| 6592 | void *ptr; |
| 6593 | long long data; |
| 6594 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6595 | dt = appctx->ctx.table.data_type; |
| 6596 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6597 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6598 | dt); |
| 6599 | |
| 6600 | data = 0; |
| 6601 | switch (stktable_data_types[dt].std_type) { |
| 6602 | case STD_T_SINT: |
| 6603 | data = stktable_data_cast(ptr, std_t_sint); |
| 6604 | break; |
| 6605 | case STD_T_UINT: |
| 6606 | data = stktable_data_cast(ptr, std_t_uint); |
| 6607 | break; |
| 6608 | case STD_T_ULL: |
| 6609 | data = stktable_data_cast(ptr, std_t_ull); |
| 6610 | break; |
| 6611 | case STD_T_FRQP: |
| 6612 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6613 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6614 | break; |
| 6615 | } |
| 6616 | |
| 6617 | /* 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] | 6618 | if ((data < appctx->ctx.table.value && |
| 6619 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6620 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6621 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6622 | (data == appctx->ctx.table.value && |
| 6623 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6624 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6625 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6626 | (data > appctx->ctx.table.value && |
| 6627 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6628 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6629 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6630 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6631 | } |
| 6632 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6633 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6634 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6635 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6636 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6637 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6638 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6639 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6640 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6641 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6642 | struct stksess *old = appctx->ctx.table.entry; |
| 6643 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6644 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6645 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6646 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6647 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6648 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6649 | break; |
| 6650 | } |
| 6651 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6652 | |
| 6653 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6654 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6655 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6656 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6657 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6658 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6659 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6660 | break; |
| 6661 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6662 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6663 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6664 | break; |
| 6665 | } |
| 6666 | } |
| 6667 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6668 | } |
| 6669 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6670 | /* 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] | 6671 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6672 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6673 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6674 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6675 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6676 | * after the offset. The new pointer is returned. |
| 6677 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6678 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6679 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6680 | { |
| 6681 | int end; |
| 6682 | unsigned char c; |
| 6683 | |
| 6684 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6685 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6686 | return ptr; |
| 6687 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6688 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6689 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6690 | while (ptr < len && ptr < bsize) { |
| 6691 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6692 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6693 | if (out->len > end - 2) |
| 6694 | break; |
| 6695 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6696 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6697 | if (out->len > end - 3) |
| 6698 | break; |
| 6699 | out->str[out->len++] = '\\'; |
| 6700 | switch (c) { |
| 6701 | case '\t': c = 't'; break; |
| 6702 | case '\n': c = 'n'; break; |
| 6703 | case '\r': c = 'r'; break; |
| 6704 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6705 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6706 | } |
| 6707 | out->str[out->len++] = c; |
| 6708 | } else { |
| 6709 | if (out->len > end - 5) |
| 6710 | break; |
| 6711 | out->str[out->len++] = '\\'; |
| 6712 | out->str[out->len++] = 'x'; |
| 6713 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6714 | out->str[out->len++] = hextab[c & 0xF]; |
| 6715 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6716 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6717 | /* we had a line break, let's return now */ |
| 6718 | out->str[out->len++] = '\n'; |
| 6719 | *line = ptr; |
| 6720 | return ptr; |
| 6721 | } |
| 6722 | } |
| 6723 | /* we have an incomplete line, we return it as-is */ |
| 6724 | out->str[out->len++] = '\n'; |
| 6725 | return ptr; |
| 6726 | } |
| 6727 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6728 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6729 | * It returns 0 if the output buffer is full and it needs |
| 6730 | * to be called again, otherwise non-zero. |
| 6731 | */ |
| 6732 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6733 | { |
| 6734 | struct appctx *appctx = __objt_appctx(si->end); |
| 6735 | struct dns_resolvers *presolvers; |
| 6736 | struct dns_nameserver *pnameserver; |
| 6737 | |
| 6738 | chunk_reset(&trash); |
| 6739 | |
| 6740 | switch (appctx->st2) { |
| 6741 | case STAT_ST_INIT: |
| 6742 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6743 | /* fall through */ |
| 6744 | |
| 6745 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6746 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6747 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6748 | } |
| 6749 | else { |
| 6750 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6751 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6752 | continue; |
| 6753 | |
| 6754 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6755 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6756 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6757 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6758 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6759 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6760 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6761 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6762 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6763 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6764 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6765 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6766 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6767 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6768 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6769 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6770 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6771 | } |
| 6772 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6773 | } |
| 6774 | |
| 6775 | /* display response */ |
| 6776 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6777 | /* let's try again later from this session. We add ourselves into |
| 6778 | * this session's users so that it can remove us upon termination. |
| 6779 | */ |
| 6780 | si->flags |= SI_FL_WAIT_ROOM; |
| 6781 | return 0; |
| 6782 | } |
| 6783 | |
| 6784 | appctx->st2 = STAT_ST_FIN; |
| 6785 | /* fall through */ |
| 6786 | |
| 6787 | default: |
| 6788 | appctx->st2 = STAT_ST_FIN; |
| 6789 | return 1; |
| 6790 | } |
| 6791 | } |
| 6792 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6793 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6794 | * 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] | 6795 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6796 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6797 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6798 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6799 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6800 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6801 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6802 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6803 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6804 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6805 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6806 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6807 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6808 | /* the function had not been called yet, let's prepare the |
| 6809 | * buffer for a response. |
| 6810 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6811 | struct tm tm; |
| 6812 | |
| 6813 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6814 | 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] | 6815 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6816 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6817 | error_snapshot_id); |
| 6818 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6819 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6820 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6821 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6822 | return 0; |
| 6823 | } |
| 6824 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6825 | appctx->ctx.errors.px = proxy; |
| 6826 | appctx->ctx.errors.buf = 0; |
| 6827 | appctx->ctx.errors.bol = 0; |
| 6828 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6829 | } |
| 6830 | |
| 6831 | /* we have two inner loops here, one for the proxy, the other one for |
| 6832 | * the buffer. |
| 6833 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6834 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6835 | struct error_snapshot *es; |
| 6836 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6837 | if (appctx->ctx.errors.buf == 0) |
| 6838 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6839 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6840 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6841 | |
| 6842 | if (!es->when.tv_sec) |
| 6843 | goto next; |
| 6844 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6845 | if (appctx->ctx.errors.iid >= 0 && |
| 6846 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6847 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6848 | goto next; |
| 6849 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6850 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6851 | /* just print headers now */ |
| 6852 | |
| 6853 | char pn[INET6_ADDRSTRLEN]; |
| 6854 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6855 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6856 | |
| 6857 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6858 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6859 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6860 | 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] | 6861 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6862 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6863 | case AF_INET: |
| 6864 | case AF_INET6: |
| 6865 | port = get_host_port(&es->src); |
| 6866 | break; |
| 6867 | default: |
| 6868 | port = 0; |
| 6869 | } |
| 6870 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6871 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6872 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6873 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6874 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6875 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6876 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6877 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6878 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6879 | break; |
| 6880 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6881 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6882 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6883 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6884 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6885 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6886 | break; |
| 6887 | } |
| 6888 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6889 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6890 | ", server %s (#%d), event #%u\n" |
| 6891 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6892 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6893 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6894 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6895 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6896 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6897 | es->ev_id, |
| 6898 | pn, port, es->sid, es->s_flags, |
| 6899 | es->state, es->m_flags, es->t_flags, |
| 6900 | es->m_clen, es->m_blen, |
| 6901 | es->b_flags, es->b_out, es->b_tot, |
| 6902 | es->len, es->b_wrap, es->pos); |
| 6903 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6904 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6905 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6906 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6907 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6908 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6909 | appctx->ctx.errors.ptr = 0; |
| 6910 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6911 | } |
| 6912 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6913 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6914 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6915 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6916 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6917 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6918 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6919 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6920 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6921 | goto next; |
| 6922 | } |
| 6923 | |
| 6924 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6925 | 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] | 6926 | int newptr; |
| 6927 | int newline; |
| 6928 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6929 | newline = appctx->ctx.errors.bol; |
| 6930 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6931 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6932 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6933 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6934 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6935 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6936 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6937 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6938 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6939 | appctx->ctx.errors.ptr = newptr; |
| 6940 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6941 | }; |
| 6942 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6943 | appctx->ctx.errors.bol = 0; |
| 6944 | appctx->ctx.errors.ptr = -1; |
| 6945 | appctx->ctx.errors.buf++; |
| 6946 | if (appctx->ctx.errors.buf > 1) { |
| 6947 | appctx->ctx.errors.buf = 0; |
| 6948 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6949 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | /* dump complete */ |
| 6953 | return 1; |
| 6954 | } |
| 6955 | |
| 6956 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 6957 | * if the output buffer is full and it needs to be called again, otherwise |
| 6958 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 6959 | */ |
| 6960 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 6961 | { |
| 6962 | struct appctx *appctx = __objt_appctx(si->end); |
| 6963 | |
| 6964 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 6965 | return 1; |
| 6966 | |
| 6967 | chunk_reset(&trash); |
| 6968 | |
| 6969 | /* we have two inner loops here, one for the proxy, the other one for |
| 6970 | * the buffer. |
| 6971 | */ |
| 6972 | while (*appctx->ctx.env.var) { |
| 6973 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 6974 | |
| 6975 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6976 | si_applet_cant_put(si); |
| 6977 | return 0; |
| 6978 | } |
| 6979 | if (appctx->st2 == STAT_ST_END) |
| 6980 | break; |
| 6981 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6982 | } |
| 6983 | |
| 6984 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6985 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6986 | } |
| 6987 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 6988 | /* parse the "level" argument on the bind lines */ |
| 6989 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 6990 | { |
| 6991 | if (!*args[cur_arg + 1]) { |
| 6992 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 6993 | return ERR_ALERT | ERR_FATAL; |
| 6994 | } |
| 6995 | |
| 6996 | if (!strcmp(args[cur_arg+1], "user")) |
| 6997 | conf->level = ACCESS_LVL_USER; |
| 6998 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 6999 | conf->level = ACCESS_LVL_OPER; |
| 7000 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 7001 | conf->level = ACCESS_LVL_ADMIN; |
| 7002 | else { |
| 7003 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 7004 | args[cur_arg], args[cur_arg+1]); |
| 7005 | return ERR_ALERT | ERR_FATAL; |
| 7006 | } |
| 7007 | |
| 7008 | return 0; |
| 7009 | } |
| 7010 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7011 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7012 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7013 | .name = "<STATS>", /* used for logging */ |
| 7014 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 7015 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7016 | }; |
| 7017 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7018 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7019 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7020 | .name = "<CLI>", /* used for logging */ |
| 7021 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 7022 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7023 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 7024 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 7025 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7026 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 7027 | { 0, NULL, NULL }, |
| 7028 | }}; |
| 7029 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7030 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 7031 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 7032 | { NULL, NULL, 0 }, |
| 7033 | }}; |
| 7034 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7035 | __attribute__((constructor)) |
| 7036 | static void __dumpstats_module_init(void) |
| 7037 | { |
| 7038 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7039 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7040 | } |
| 7041 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 7042 | /* |
| 7043 | * Local variables: |
| 7044 | * c-indent-level: 8 |
| 7045 | * c-basic-offset: 8 |
| 7046 | * End: |
| 7047 | */ |