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 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 399 | static int stats_dump_backend_to_buffer(struct stream_interface *si); |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 400 | static int stats_dump_env_to_buffer(struct stream_interface *si); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 401 | static int stats_dump_info_to_buffer(struct stream_interface *si); |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 402 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 403 | static int stats_dump_pools_to_buffer(struct stream_interface *si); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 404 | 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] | 405 | static int stats_dump_sess_to_buffer(struct stream_interface *si); |
| 406 | static int stats_dump_errors_to_buffer(struct stream_interface *si); |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 407 | static int stats_table_request(struct stream_interface *si, int show); |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 408 | static int stats_dump_proxy_to_buffer(struct stream_interface *si, struct proxy *px, struct uri_auth *uri); |
| 409 | 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] | 410 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 411 | static int stats_pats_list(struct stream_interface *si); |
| 412 | static int stats_pat_list(struct stream_interface *si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 413 | static int stats_map_lookup(struct stream_interface *si); |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 414 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 415 | static int stats_tlskeys_list(struct stream_interface *si); |
| 416 | #endif |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 417 | static void cli_release_handler(struct appctx *appctx); |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 418 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 419 | static void dump_servers_state(struct proxy *backend, struct chunk *buf); |
| 420 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 421 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 422 | * cli_io_handler() |
| 423 | * -> stats_dump_sess_to_buffer() // "show sess" |
| 424 | * -> stats_dump_errors_to_buffer() // "show errors" |
| 425 | * -> stats_dump_info_to_buffer() // "show info" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 426 | * -> stats_dump_backend_to_buffer() // "show backend" |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 427 | * -> stats_dump_servers_state_to_buffer() // "show servers state [<backend name>]" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 428 | * -> stats_dump_stat_to_buffer() // "show stat" |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 429 | * -> stats_dump_resolvers_to_buffer() // "show stat resolver <id>" |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 430 | * -> stats_dump_csv_header() |
| 431 | * -> stats_dump_proxy_to_buffer() |
| 432 | * -> stats_dump_fe_stats() |
| 433 | * -> stats_dump_li_stats() |
| 434 | * -> stats_dump_sv_stats() |
| 435 | * -> stats_dump_be_stats() |
| 436 | * |
| 437 | * http_stats_io_handler() |
| 438 | * -> stats_dump_stat_to_buffer() // same as above, but used for CSV or HTML |
| 439 | * -> stats_dump_csv_header() // emits the CSV headers (same as above) |
| 440 | * -> stats_dump_html_head() // emits the HTML headers |
| 441 | * -> stats_dump_html_info() // emits the equivalent of "show info" at the top |
| 442 | * -> stats_dump_proxy_to_buffer() // same as above, valid for CSV and HTML |
| 443 | * -> stats_dump_html_px_hdr() |
| 444 | * -> stats_dump_fe_stats() |
| 445 | * -> stats_dump_li_stats() |
| 446 | * -> stats_dump_sv_stats() |
| 447 | * -> stats_dump_be_stats() |
| 448 | * -> stats_dump_html_px_end() |
| 449 | * -> stats_dump_html_end() // emits HTML trailer |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 450 | */ |
| 451 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 452 | static struct applet cli_applet; |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 453 | |
| 454 | static const char stats_sock_usage_msg[] = |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 455 | "Unknown command. Please enter one of the following commands only :\n" |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 456 | " clear counters : clear max statistics counters (add 'all' for all counters)\n" |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 457 | " clear table : remove an entry from a table\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 458 | " help : this message\n" |
| 459 | " prompt : toggle interactive mode with prompt\n" |
| 460 | " quit : disconnect\n" |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 461 | " show backend : list backends in the current running config\n" |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 462 | " show env [var] : dump environment variables known to the process\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 463 | " show info : report information about the running process\n" |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 464 | " show pools : report information about the memory pools usage\n" |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 465 | " show stat : report counters for each proxy and server\n" |
| 466 | " show errors : report last request and response errors for each proxy\n" |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 467 | " 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] | 468 | " 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] | 469 | " show servers state [id]: dump volatile server information (for backend <id>)\n" |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 470 | " get weight : report a server's current weight\n" |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 471 | " set weight : change a server's weight\n" |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 472 | " set server : change a server's state, weight or address\n" |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 473 | " set table [id] : update or create a table entry's data\n" |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 474 | " set timeout : change a timeout setting\n" |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 475 | " set maxconn : change a maxconn setting\n" |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 476 | " set rate-limit : change a rate limiting value\n" |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 477 | " disable : put a server or frontend in maintenance mode\n" |
| 478 | " enable : re-enable a server or frontend which is in maintenance mode\n" |
| 479 | " 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] | 480 | " show acl [id] : report avalaible acls or dump an acl's contents\n" |
| 481 | " get acl : reports the patterns matching a sample for an ACL\n" |
| 482 | " add acl : add acl entry\n" |
| 483 | " del acl : delete acl entry\n" |
| 484 | " clear acl <id> : clear the content of this acl\n" |
Thierry FOURNIER | 1432a0c | 2014-03-11 13:42:38 +0100 | [diff] [blame] | 485 | " show map [id] : report avalaible maps or dump a map's contents\n" |
| 486 | " get map : reports the keys and values matching a sample for a map\n" |
| 487 | " set map : modify map entry\n" |
| 488 | " add map : add map entry\n" |
| 489 | " del map : delete map entry\n" |
| 490 | " clear map <id> : clear the content of this map\n" |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 491 | " set ssl <stmt> : set statement for ssl\n" |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 492 | ""; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 493 | |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 494 | static const char stats_permission_denied_msg[] = |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 495 | "Permission denied\n" |
| 496 | ""; |
| 497 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 498 | /* data transmission states for the stats responses */ |
| 499 | enum { |
| 500 | STAT_ST_INIT = 0, |
| 501 | STAT_ST_HEAD, |
| 502 | STAT_ST_INFO, |
| 503 | STAT_ST_LIST, |
| 504 | STAT_ST_END, |
| 505 | STAT_ST_FIN, |
| 506 | }; |
| 507 | |
| 508 | /* data transmission states for the stats responses inside a proxy */ |
| 509 | enum { |
| 510 | STAT_PX_ST_INIT = 0, |
| 511 | STAT_PX_ST_TH, |
| 512 | STAT_PX_ST_FE, |
| 513 | STAT_PX_ST_LI, |
| 514 | STAT_PX_ST_SV, |
| 515 | STAT_PX_ST_BE, |
| 516 | STAT_PX_ST_END, |
| 517 | STAT_PX_ST_FIN, |
| 518 | }; |
| 519 | |
Cyril Bonté | 19979e1 | 2012-04-04 12:57:21 +0200 | [diff] [blame] | 520 | extern const char *stat_status_codes[]; |
| 521 | |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 522 | /* allocate a new stats frontend named <name>, and return it |
| 523 | * (or NULL in case of lack of memory). |
| 524 | */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 525 | 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] | 526 | { |
| 527 | struct proxy *fe; |
| 528 | |
| 529 | fe = (struct proxy *)calloc(1, sizeof(struct proxy)); |
| 530 | if (!fe) |
| 531 | return NULL; |
| 532 | |
Willy Tarreau | 237250c | 2011-07-29 01:49:03 +0200 | [diff] [blame] | 533 | init_new_proxy(fe); |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 534 | fe->next = proxy; |
| 535 | proxy = fe; |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 536 | fe->last_change = now.tv_sec; |
| 537 | fe->id = strdup("GLOBAL"); |
| 538 | fe->cap = PR_CAP_FE; |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 539 | fe->maxconn = 10; /* default to 10 concurrent connections */ |
| 540 | fe->timeout.client = MS_TO_TICKS(10000); /* default timeout of 10 seconds */ |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 541 | fe->conf.file = strdup(file); |
| 542 | fe->conf.line = line; |
Willy Tarreau | 32b60d4 | 2015-03-13 16:14:57 +0100 | [diff] [blame] | 543 | fe->accept = frontend_accept; |
Willy Tarreau | f87ab94 | 2015-03-13 15:55:16 +0100 | [diff] [blame] | 544 | fe->default_target = &cli_applet.obj_type; |
Willy Tarreau | 050536d | 2012-10-04 08:47:34 +0200 | [diff] [blame] | 545 | |
| 546 | /* the stats frontend is the only one able to assign ID #0 */ |
| 547 | fe->conf.id.key = fe->uuid = 0; |
| 548 | eb32_insert(&used_proxy_id, &fe->conf.id); |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 549 | return fe; |
| 550 | } |
| 551 | |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 552 | /* This function parses a "stats" statement in the "global" section. It returns |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 553 | * -1 if there is any error, otherwise zero. If it returns -1, it will write an |
| 554 | * error message into the <err> buffer which will be preallocated. The trailing |
| 555 | * '\n' must not be written. The function must be called with <args> pointing to |
| 556 | * the first word after "stats". |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 557 | */ |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 558 | 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] | 559 | struct proxy *defpx, const char *file, int line, |
| 560 | char **err) |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 561 | { |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 562 | struct bind_conf *bind_conf; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 563 | struct listener *l; |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 564 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 565 | if (!strcmp(args[1], "socket")) { |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 566 | int cur_arg; |
| 567 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 568 | if (*args[2] == 0) { |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 569 | 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] | 570 | return -1; |
| 571 | } |
| 572 | |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 573 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 574 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 575 | 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] | 576 | return -1; |
| 577 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 578 | } |
| 579 | |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 580 | 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] | 581 | bind_conf->level = ACCESS_LVL_OPER; /* default access level */ |
Willy Tarreau | 4348fad | 2012-09-20 16:48:07 +0200 | [diff] [blame] | 582 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 583 | if (!str2listener(args[2], global.stats_fe, bind_conf, file, line, err)) { |
| 584 | memprintf(err, "parsing [%s:%d] : '%s %s' : %s\n", |
| 585 | file, line, args[0], args[1], err && *err ? *err : "error"); |
| 586 | return -1; |
| 587 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 588 | |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 589 | cur_arg = 3; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 590 | while (*args[cur_arg]) { |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 591 | static int bind_dumped; |
| 592 | struct bind_kw *kw; |
| 593 | |
| 594 | kw = bind_find_kw(args[cur_arg]); |
| 595 | if (kw) { |
| 596 | if (!kw->parse) { |
| 597 | memprintf(err, "'%s %s' : '%s' option is not implemented in this version (check build options).", |
| 598 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 599 | return -1; |
| 600 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 601 | |
Willy Tarreau | 061b5de | 2015-10-13 15:06:57 +0200 | [diff] [blame] | 602 | 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] | 603 | if (err && *err) |
| 604 | memprintf(err, "'%s %s' : '%s'", args[0], args[1], *err); |
| 605 | else |
| 606 | memprintf(err, "'%s %s' : error encountered while processing '%s'", |
| 607 | args[0], args[1], args[cur_arg]); |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 608 | return -1; |
| 609 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 610 | |
| 611 | cur_arg += 1 + kw->skip; |
| 612 | continue; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 613 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 614 | |
| 615 | if (!bind_dumped) { |
| 616 | bind_dump_kws(err); |
| 617 | indent_msg(err, 4); |
| 618 | bind_dumped = 1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 619 | } |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 620 | |
| 621 | memprintf(err, "'%s %s' : unknown keyword '%s'.%s%s", |
| 622 | args[0], args[1], args[cur_arg], |
| 623 | err && *err ? " Registered keywords :" : "", err && *err ? *err : ""); |
| 624 | return -1; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 625 | } |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 626 | |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 627 | list_for_each_entry(l, &bind_conf->listeners, by_bind) { |
| 628 | l->maxconn = global.stats_fe->maxconn; |
| 629 | l->backlog = global.stats_fe->backlog; |
Willy Tarreau | 9903f0e | 2015-04-04 18:50:31 +0200 | [diff] [blame] | 630 | l->accept = session_accept_fd; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 631 | l->handler = process_stream; |
Willy Tarreau | 10b688f | 2015-03-13 16:43:12 +0100 | [diff] [blame] | 632 | l->default_target = global.stats_fe->default_target; |
Willy Tarreau | c53d422 | 2012-09-20 20:19:28 +0200 | [diff] [blame] | 633 | l->options |= LI_O_UNLIMITED; /* don't make the peers subject to global limits */ |
| 634 | l->nice = -64; /* we want to boost priority for local stats */ |
| 635 | global.maxsock += l->maxconn; |
| 636 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 637 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 638 | else if (!strcmp(args[1], "timeout")) { |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 639 | unsigned timeout; |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 640 | const char *res = parse_time_err(args[2], &timeout, TIME_UNIT_MS); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 641 | |
| 642 | if (res) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 643 | memprintf(err, "'%s %s' : unexpected character '%c'", args[0], args[1], *res); |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 644 | return -1; |
| 645 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 646 | |
Willy Tarreau | b3f32f5 | 2007-12-02 22:15:14 +0100 | [diff] [blame] | 647 | if (!timeout) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 648 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 649 | return -1; |
| 650 | } |
Willy Tarreau | 07e9e64 | 2010-08-17 21:48:17 +0200 | [diff] [blame] | 651 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 652 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 653 | 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] | 654 | return -1; |
| 655 | } |
| 656 | } |
Willy Tarreau | 89a6313 | 2009-08-16 17:41:45 +0200 | [diff] [blame] | 657 | global.stats_fe->timeout.client = MS_TO_TICKS(timeout); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 658 | } |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 659 | else if (!strcmp(args[1], "maxconn")) { |
| 660 | int maxconn = atol(args[2]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 661 | |
| 662 | if (maxconn <= 0) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 663 | memprintf(err, "'%s %s' expects a positive value", args[0], args[1]); |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 664 | return -1; |
| 665 | } |
Willy Tarreau | c2adf8b | 2011-09-07 12:13:34 +0200 | [diff] [blame] | 666 | |
| 667 | if (!global.stats_fe) { |
Willy Tarreau | a020fbd | 2012-09-18 20:05:00 +0200 | [diff] [blame] | 668 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
Willy Tarreau | 0a3dd74 | 2012-05-08 19:47:01 +0200 | [diff] [blame] | 669 | 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] | 670 | return -1; |
| 671 | } |
| 672 | } |
| 673 | global.stats_fe->maxconn = maxconn; |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 674 | } |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 675 | else if (!strcmp(args[1], "bind-process")) { /* enable the socket only on some processes */ |
| 676 | int cur_arg = 2; |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 677 | unsigned long set = 0; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 678 | |
Willy Tarreau | 9131957 | 2013-04-20 09:48:50 +0200 | [diff] [blame] | 679 | if (!global.stats_fe) { |
| 680 | if ((global.stats_fe = alloc_stats_fe("GLOBAL", file, line)) == NULL) { |
| 681 | memprintf(err, "'%s %s' : out of memory trying to allocate a frontend", args[0], args[1]); |
| 682 | return -1; |
| 683 | } |
| 684 | } |
| 685 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 686 | while (*args[cur_arg]) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 687 | unsigned int low, high; |
| 688 | |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 689 | if (strcmp(args[cur_arg], "all") == 0) { |
| 690 | set = 0; |
| 691 | break; |
| 692 | } |
| 693 | else if (strcmp(args[cur_arg], "odd") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 694 | set |= ~0UL/3UL; /* 0x555....555 */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 695 | } |
| 696 | else if (strcmp(args[cur_arg], "even") == 0) { |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 697 | set |= (~0UL/3UL) << 1; /* 0xAAA...AAA */ |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 698 | } |
Willy Tarreau | 83d84cf | 2012-11-22 01:04:31 +0100 | [diff] [blame] | 699 | else if (isdigit((int)*args[cur_arg])) { |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 700 | char *dash = strchr(args[cur_arg], '-'); |
| 701 | |
| 702 | low = high = str2uic(args[cur_arg]); |
| 703 | if (dash) |
| 704 | high = str2uic(dash + 1); |
| 705 | |
| 706 | if (high < low) { |
| 707 | unsigned int swap = low; |
| 708 | low = high; |
| 709 | high = swap; |
| 710 | } |
| 711 | |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 712 | if (low < 1 || high > LONGBITS) { |
| 713 | memprintf(err, "'%s %s' supports process numbers from 1 to %d.\n", |
| 714 | args[0], args[1], LONGBITS); |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 715 | return -1; |
| 716 | } |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 717 | while (low <= high) |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 718 | set |= 1UL << (low++ - 1); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 719 | } |
| 720 | else { |
| 721 | memprintf(err, |
Willy Tarreau | a9db57e | 2013-01-18 11:29:29 +0100 | [diff] [blame] | 722 | "'%s %s' expects 'all', 'odd', 'even', or a list of process ranges with numbers from 1 to %d.\n", |
| 723 | args[0], args[1], LONGBITS); |
Willy Tarreau | 110ecc1 | 2012-11-15 17:50:01 +0100 | [diff] [blame] | 724 | return -1; |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 725 | } |
| 726 | cur_arg++; |
| 727 | } |
| 728 | global.stats_fe->bind_proc = set; |
| 729 | } |
Willy Tarreau | fbee713 | 2007-10-18 13:53:22 +0200 | [diff] [blame] | 730 | else { |
Willy Tarreau | 35b7b16 | 2012-10-22 23:17:18 +0200 | [diff] [blame] | 731 | 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] | 732 | return -1; |
| 733 | } |
| 734 | return 0; |
| 735 | } |
| 736 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 737 | /* Dumps the stats CSV header to the trash buffer which. The caller is responsible |
| 738 | * for clearing it if needed. |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 739 | * NOTE: Some tools happen to rely on the field position instead of its name, |
| 740 | * 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] | 741 | */ |
| 742 | static void stats_dump_csv_header() |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 743 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 744 | chunk_appendf(&trash, |
| 745 | "# pxname,svname," |
| 746 | "qcur,qmax," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 747 | "scur,smax,slim,stot," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 748 | "bin,bout," |
| 749 | "dreq,dresp," |
| 750 | "ereq,econ,eresp," |
| 751 | "wretr,wredis," |
| 752 | "status,weight,act,bck," |
| 753 | "chkfail,chkdown,lastchg,downtime,qlimit," |
| 754 | "pid,iid,sid,throttle,lbtot,tracked,type," |
| 755 | "rate,rate_lim,rate_max," |
| 756 | "check_status,check_code,check_duration," |
| 757 | "hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail," |
| 758 | "req_rate,req_rate_max,req_tot," |
| 759 | "cli_abrt,srv_abrt," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 760 | "comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 761 | "\n"); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 762 | } |
| 763 | |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 764 | /* print a string of text buffer to <out>. The format is : |
| 765 | * Non-printable chars \t, \n, \r and \e are * encoded in C format. |
| 766 | * Other non-printable chars are encoded "\xHH". Space and '\' are also escaped. |
| 767 | * Print stopped if null char or <bsize> is reached, or if no more place in the chunk. |
| 768 | */ |
| 769 | static int dump_text(struct chunk *out, const char *buf, int bsize) |
| 770 | { |
| 771 | unsigned char c; |
| 772 | int ptr = 0; |
| 773 | |
| 774 | while (buf[ptr] && ptr < bsize) { |
| 775 | c = buf[ptr]; |
| 776 | if (isprint(c) && isascii(c) && c != '\\' && c != ' ') { |
| 777 | if (out->len > out->size - 1) |
| 778 | break; |
| 779 | out->str[out->len++] = c; |
| 780 | } |
| 781 | else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\' || c == ' ') { |
| 782 | if (out->len > out->size - 2) |
| 783 | break; |
| 784 | out->str[out->len++] = '\\'; |
| 785 | switch (c) { |
| 786 | case ' ': c = ' '; break; |
| 787 | case '\t': c = 't'; break; |
| 788 | case '\n': c = 'n'; break; |
| 789 | case '\r': c = 'r'; break; |
| 790 | case '\e': c = 'e'; break; |
| 791 | case '\\': c = '\\'; break; |
| 792 | } |
| 793 | out->str[out->len++] = c; |
| 794 | } |
| 795 | else { |
| 796 | if (out->len > out->size - 4) |
| 797 | break; |
| 798 | out->str[out->len++] = '\\'; |
| 799 | out->str[out->len++] = 'x'; |
| 800 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 801 | out->str[out->len++] = hextab[c & 0xF]; |
| 802 | } |
| 803 | ptr++; |
| 804 | } |
| 805 | |
| 806 | return ptr; |
| 807 | } |
| 808 | |
| 809 | /* print a buffer in hexa. |
| 810 | * Print stopped if <bsize> is reached, or if no more place in the chunk. |
| 811 | */ |
| 812 | static int dump_binary(struct chunk *out, const char *buf, int bsize) |
| 813 | { |
| 814 | unsigned char c; |
| 815 | int ptr = 0; |
| 816 | |
| 817 | while (ptr < bsize) { |
| 818 | c = buf[ptr]; |
| 819 | |
| 820 | if (out->len > out->size - 2) |
| 821 | break; |
| 822 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 823 | out->str[out->len++] = hextab[c & 0xF]; |
| 824 | |
| 825 | ptr++; |
| 826 | } |
| 827 | return ptr; |
| 828 | } |
| 829 | |
| 830 | /* Dump the status of a table to a stream interface's |
| 831 | * read buffer. It returns 0 if the output buffer is full |
| 832 | * and needs to be called again, otherwise non-zero. |
| 833 | */ |
| 834 | static int stats_dump_table_head_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 835 | struct proxy *proxy, struct proxy *target) |
| 836 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 837 | struct stream *s = si_strm(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 838 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 839 | chunk_appendf(msg, "# table: %s, type: %s, size:%d, used:%d\n", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 840 | proxy->id, stktable_types[proxy->table.type].kw, proxy->table.size, proxy->table.current); |
| 841 | |
| 842 | /* any other information should be dumped here */ |
| 843 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 844 | if (target && strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 845 | chunk_appendf(msg, "# contents not dumped due to insufficient privileges\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 846 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 847 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 848 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 849 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 850 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 851 | |
| 852 | return 1; |
| 853 | } |
| 854 | |
| 855 | /* Dump the a table entry to a stream interface's |
| 856 | * read buffer. It returns 0 if the output buffer is full |
| 857 | * and needs to be called again, otherwise non-zero. |
| 858 | */ |
| 859 | static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_interface *si, |
| 860 | struct proxy *proxy, struct stksess *entry) |
| 861 | { |
| 862 | int dt; |
| 863 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 864 | chunk_appendf(msg, "%p:", entry); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 865 | |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 866 | if (proxy->table.type == SMP_T_IPV4) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 867 | char addr[INET_ADDRSTRLEN]; |
| 868 | inet_ntop(AF_INET, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 869 | chunk_appendf(msg, " key=%s", addr); |
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_IPV6) { |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 872 | char addr[INET6_ADDRSTRLEN]; |
| 873 | inet_ntop(AF_INET6, (const void *)&entry->key.key, addr, sizeof(addr)); |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 874 | chunk_appendf(msg, " key=%s", addr); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 875 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 876 | else if (proxy->table.type == SMP_T_SINT) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 877 | chunk_appendf(msg, " key=%u", *(unsigned int *)entry->key.key); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 878 | } |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 879 | else if (proxy->table.type == SMP_T_STR) { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 880 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 881 | dump_text(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 882 | } |
| 883 | else { |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 884 | chunk_appendf(msg, " key="); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 885 | dump_binary(msg, (const char *)entry->key.key, proxy->table.key_size); |
| 886 | } |
| 887 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 888 | 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] | 889 | |
| 890 | for (dt = 0; dt < STKTABLE_DATA_TYPES; dt++) { |
| 891 | void *ptr; |
| 892 | |
| 893 | if (proxy->table.data_ofs[dt] == 0) |
| 894 | continue; |
| 895 | if (stktable_data_types[dt].arg_type == ARG_T_DELAY) |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 896 | 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] | 897 | else |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 898 | chunk_appendf(msg, " %s=", stktable_data_types[dt].name); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 899 | |
| 900 | ptr = stktable_data_ptr(&proxy->table, entry, dt); |
| 901 | switch (stktable_data_types[dt].std_type) { |
| 902 | case STD_T_SINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 903 | chunk_appendf(msg, "%d", stktable_data_cast(ptr, std_t_sint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 904 | break; |
| 905 | case STD_T_UINT: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 906 | chunk_appendf(msg, "%u", stktable_data_cast(ptr, std_t_uint)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 907 | break; |
| 908 | case STD_T_ULL: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 909 | chunk_appendf(msg, "%lld", stktable_data_cast(ptr, std_t_ull)); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 910 | break; |
| 911 | case STD_T_FRQP: |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 912 | chunk_appendf(msg, "%d", |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 913 | read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
| 914 | proxy->table.data_arg[dt].u)); |
| 915 | break; |
| 916 | } |
| 917 | } |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 918 | chunk_appendf(msg, "\n"); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 919 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 920 | if (bi_putchk(si_ic(si), msg) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 921 | si_applet_cant_put(si); |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 922 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 923 | } |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 924 | |
| 925 | return 1; |
| 926 | } |
| 927 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 928 | 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] | 929 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 930 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 931 | struct appctx *appctx = __objt_appctx(si->end); |
| 932 | struct proxy *px = appctx->ctx.table.target; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 933 | struct stksess *ts; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 934 | uint32_t uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 935 | unsigned char ip6_key[sizeof(struct in6_addr)]; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 936 | long long value; |
| 937 | int data_type; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 938 | int cur_arg; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 939 | void *ptr; |
| 940 | struct freq_ctr_period *frqp; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 941 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 942 | appctx->st0 = STAT_CLI_OUTPUT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 943 | |
| 944 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 945 | appctx->ctx.cli.msg = "Key value expected\n"; |
| 946 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 947 | return; |
| 948 | } |
| 949 | |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 950 | switch (px->table.type) { |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 951 | case SMP_T_IPV4: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 952 | uint32_key = htonl(inetaddr_host(args[4])); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 953 | static_table_key->key = &uint32_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 954 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 955 | case SMP_T_IPV6: |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 956 | inet_pton(AF_INET6, args[4], ip6_key); |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 957 | static_table_key->key = &ip6_key; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 958 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 959 | case SMP_T_SINT: |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 960 | { |
| 961 | char *endptr; |
| 962 | unsigned long val; |
| 963 | errno = 0; |
| 964 | val = strtoul(args[4], &endptr, 10); |
| 965 | if ((errno == ERANGE && val == ULONG_MAX) || |
| 966 | (errno != 0 && val == 0) || endptr == args[4] || |
| 967 | val > 0xffffffff) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 968 | appctx->ctx.cli.msg = "Invalid key\n"; |
| 969 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 970 | return; |
| 971 | } |
| 972 | uint32_key = (uint32_t) val; |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 973 | static_table_key->key = &uint32_key; |
Simon Horman | cec9a22 | 2011-06-15 15:18:51 +0900 | [diff] [blame] | 974 | break; |
| 975 | } |
| 976 | break; |
Thierry FOURNIER | 5d24ebc | 2015-07-24 08:46:42 +0200 | [diff] [blame] | 977 | case SMP_T_STR: |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 978 | static_table_key->key = args[4]; |
| 979 | static_table_key->key_len = strlen(args[4]); |
Simon Horman | 619e3cc | 2011-06-15 15:18:52 +0900 | [diff] [blame] | 980 | break; |
Simon Horman | c5b89f6 | 2011-06-15 15:18:50 +0900 | [diff] [blame] | 981 | default: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 982 | switch (action) { |
| 983 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 984 | 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] | 985 | break; |
| 986 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 987 | 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] | 988 | break; |
| 989 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 990 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 991 | break; |
| 992 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 993 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 994 | return; |
| 995 | } |
| 996 | |
| 997 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 998 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 999 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1000 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1001 | return; |
| 1002 | } |
| 1003 | |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 1004 | ts = stktable_lookup_key(&px->table, static_table_key); |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1005 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1006 | switch (action) { |
| 1007 | case STAT_CLI_O_TAB: |
| 1008 | if (!ts) |
| 1009 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1010 | chunk_reset(&trash); |
| 1011 | if (!stats_dump_table_head_to_buffer(&trash, si, px, px)) |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1012 | return; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1013 | stats_dump_table_entry_to_buffer(&trash, si, px, ts); |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1014 | return; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1015 | |
| 1016 | case STAT_CLI_O_CLR: |
| 1017 | if (!ts) |
| 1018 | return; |
| 1019 | if (ts->ref_cnt) { |
| 1020 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1021 | appctx->ctx.cli.msg = "Entry currently in use, cannot remove\n"; |
| 1022 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1023 | return; |
| 1024 | } |
| 1025 | stksess_kill(&px->table, ts); |
| 1026 | break; |
Simon Horman | 17bce34 | 2011-06-15 15:18:47 +0900 | [diff] [blame] | 1027 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1028 | case STAT_CLI_O_SET: |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1029 | if (ts) |
| 1030 | stktable_touch(&px->table, ts, 1); |
| 1031 | else { |
Willy Tarreau | 0711541 | 2012-10-29 21:56:59 +0100 | [diff] [blame] | 1032 | ts = stksess_new(&px->table, static_table_key); |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1033 | if (!ts) { |
| 1034 | /* don't delete an entry which is currently referenced */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1035 | appctx->ctx.cli.msg = "Unable to allocate a new entry\n"; |
| 1036 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1037 | return; |
| 1038 | } |
| 1039 | stktable_store(&px->table, ts, 1); |
| 1040 | } |
| 1041 | |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1042 | for (cur_arg = 5; *args[cur_arg]; cur_arg += 2) { |
| 1043 | if (strncmp(args[cur_arg], "data.", 5) != 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1044 | appctx->ctx.cli.msg = "\"data.<type>\" followed by a value expected\n"; |
| 1045 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1046 | return; |
| 1047 | } |
| 1048 | |
| 1049 | data_type = stktable_get_data_type(args[cur_arg] + 5); |
| 1050 | if (data_type < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1051 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 1052 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1053 | return; |
| 1054 | } |
| 1055 | |
| 1056 | if (!px->table.data_ofs[data_type]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1057 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 1058 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1059 | return; |
| 1060 | } |
| 1061 | |
| 1062 | 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] | 1063 | appctx->ctx.cli.msg = "Require a valid integer value to store\n"; |
| 1064 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 47060b6 | 2013-08-01 21:11:42 +0200 | [diff] [blame] | 1065 | return; |
| 1066 | } |
| 1067 | |
| 1068 | ptr = stktable_data_ptr(&px->table, ts, data_type); |
| 1069 | |
| 1070 | switch (stktable_data_types[data_type].std_type) { |
| 1071 | case STD_T_SINT: |
| 1072 | stktable_data_cast(ptr, std_t_sint) = value; |
| 1073 | break; |
| 1074 | case STD_T_UINT: |
| 1075 | stktable_data_cast(ptr, std_t_uint) = value; |
| 1076 | break; |
| 1077 | case STD_T_ULL: |
| 1078 | stktable_data_cast(ptr, std_t_ull) = value; |
| 1079 | break; |
| 1080 | case STD_T_FRQP: |
| 1081 | /* We set both the current and previous values. That way |
| 1082 | * the reported frequency is stable during all the period |
| 1083 | * then slowly fades out. This allows external tools to |
| 1084 | * push measures without having to update them too often. |
| 1085 | */ |
| 1086 | frqp = &stktable_data_cast(ptr, std_t_frqp); |
| 1087 | frqp->curr_tick = now_ms; |
| 1088 | frqp->prev_ctr = 0; |
| 1089 | frqp->curr_ctr = value; |
| 1090 | break; |
| 1091 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1092 | } |
| 1093 | break; |
| 1094 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1095 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1096 | appctx->ctx.cli.msg = "Unknown action\n"; |
| 1097 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1098 | break; |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1099 | } |
Simon Horman | 121f305 | 2011-06-15 15:18:46 +0900 | [diff] [blame] | 1100 | } |
| 1101 | |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1102 | 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] | 1103 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1104 | struct appctx *appctx = __objt_appctx(si->end); |
| 1105 | |
Willy Tarreau | 04b3a19 | 2013-04-13 09:41:37 +0200 | [diff] [blame] | 1106 | if (action != STAT_CLI_O_TAB && action != STAT_CLI_O_CLR) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1107 | appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; |
| 1108 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1109 | return; |
| 1110 | } |
| 1111 | |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1112 | /* condition on stored data value */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1113 | appctx->ctx.table.data_type = stktable_get_data_type(args[3] + 5); |
| 1114 | if (appctx->ctx.table.data_type < 0) { |
| 1115 | appctx->ctx.cli.msg = "Unknown data type\n"; |
| 1116 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1117 | return; |
| 1118 | } |
| 1119 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1120 | if (!((struct proxy *)appctx->ctx.table.target)->table.data_ofs[appctx->ctx.table.data_type]) { |
| 1121 | appctx->ctx.cli.msg = "Data type not stored in this table\n"; |
| 1122 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1123 | return; |
| 1124 | } |
| 1125 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1126 | appctx->ctx.table.data_op = get_std_op(args[4]); |
| 1127 | if (appctx->ctx.table.data_op < 0) { |
| 1128 | appctx->ctx.cli.msg = "Require and operator among \"eq\", \"ne\", \"le\", \"ge\", \"lt\", \"gt\"\n"; |
| 1129 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1130 | return; |
| 1131 | } |
| 1132 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1133 | if (!*args[5] || strl2llrc(args[5], strlen(args[5]), &appctx->ctx.table.value) != 0) { |
| 1134 | appctx->ctx.cli.msg = "Require a valid integer value to compare against\n"; |
| 1135 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1136 | return; |
| 1137 | } |
| 1138 | } |
| 1139 | |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1140 | 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] | 1141 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1142 | struct appctx *appctx = __objt_appctx(si->end); |
| 1143 | |
| 1144 | appctx->ctx.table.data_type = -1; |
| 1145 | appctx->st2 = STAT_ST_INIT; |
| 1146 | appctx->ctx.table.target = NULL; |
| 1147 | appctx->ctx.table.proxy = NULL; |
| 1148 | appctx->ctx.table.entry = NULL; |
| 1149 | appctx->st0 = action; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1150 | |
| 1151 | if (*args[2]) { |
Willy Tarreau | e2dc1fa | 2015-05-26 12:08:07 +0200 | [diff] [blame] | 1152 | appctx->ctx.table.target = proxy_tbl_by_name(args[2]); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1153 | if (!appctx->ctx.table.target) { |
| 1154 | appctx->ctx.cli.msg = "No such table\n"; |
| 1155 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1156 | return; |
| 1157 | } |
| 1158 | } |
| 1159 | else { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1160 | if (action != STAT_CLI_O_TAB) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1161 | goto err_args; |
| 1162 | return; |
| 1163 | } |
| 1164 | |
| 1165 | if (strcmp(args[3], "key") == 0) |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1166 | stats_sock_table_key_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1167 | else if (strncmp(args[3], "data.", 5) == 0) |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 1168 | stats_sock_table_data_request(si, args, action); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 1169 | else if (*args[3]) |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1170 | goto err_args; |
| 1171 | |
| 1172 | return; |
| 1173 | |
| 1174 | err_args: |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1175 | switch (action) { |
| 1176 | case STAT_CLI_O_TAB: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1177 | 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] | 1178 | break; |
| 1179 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1180 | 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] | 1181 | break; |
| 1182 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1183 | appctx->ctx.cli.msg = "Unknown action\n"; |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1184 | break; |
| 1185 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1186 | appctx->st0 = STAT_CLI_PRINT; |
Simon Horman | d5b9fd9 | 2011-06-15 15:18:48 +0900 | [diff] [blame] | 1187 | } |
| 1188 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1189 | /* 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] | 1190 | * adequate error messages and returns NULL. This function also expects the stream |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1191 | * level to be admin. |
| 1192 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1193 | 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] | 1194 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1195 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1196 | struct proxy *px; |
| 1197 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1198 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1199 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1200 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1201 | return NULL; |
| 1202 | } |
| 1203 | |
| 1204 | if (!*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1205 | appctx->ctx.cli.msg = "A frontend name is expected.\n"; |
| 1206 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1207 | return NULL; |
| 1208 | } |
| 1209 | |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 1210 | px = proxy_fe_by_name(arg); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1211 | if (!px) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1212 | appctx->ctx.cli.msg = "No such frontend.\n"; |
| 1213 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1214 | return NULL; |
| 1215 | } |
| 1216 | return px; |
| 1217 | } |
| 1218 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1219 | /* Expects to find a backend and a server in <arg> under the form <backend>/<server>, |
| 1220 | * and returns the pointer to the server. Otherwise, display adequate error messages |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1221 | * 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] | 1222 | * the <arg> is modified to remove the '/'. |
| 1223 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1224 | 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] | 1225 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1226 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1227 | struct proxy *px; |
| 1228 | struct server *sv; |
| 1229 | char *line; |
| 1230 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1231 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1232 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1233 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1234 | return NULL; |
| 1235 | } |
| 1236 | |
| 1237 | /* split "backend/server" and make <line> point to server */ |
| 1238 | for (line = arg; *line; line++) |
| 1239 | if (*line == '/') { |
| 1240 | *line++ = '\0'; |
| 1241 | break; |
| 1242 | } |
| 1243 | |
| 1244 | if (!*line || !*arg) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1245 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1246 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1247 | return NULL; |
| 1248 | } |
| 1249 | |
| 1250 | if (!get_backend_server(arg, line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1251 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1252 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1253 | return NULL; |
| 1254 | } |
| 1255 | |
| 1256 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1257 | appctx->ctx.cli.msg = "Proxy is disabled.\n"; |
| 1258 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1259 | return NULL; |
| 1260 | } |
| 1261 | |
| 1262 | return sv; |
| 1263 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1264 | |
| 1265 | /* This function is used with TLS ticket keys management. It permits to browse |
| 1266 | * each reference. The variable <getnext> must contain the current node, |
| 1267 | * <end> point to the root node. |
| 1268 | */ |
| 1269 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1270 | static inline |
| 1271 | struct tls_keys_ref *tlskeys_list_get_next(struct tls_keys_ref *getnext, struct list *end) |
| 1272 | { |
| 1273 | struct tls_keys_ref *ref = getnext; |
| 1274 | |
| 1275 | while (1) { |
| 1276 | |
| 1277 | /* Get next list entry. */ |
| 1278 | ref = LIST_NEXT(&ref->list, struct tls_keys_ref *, list); |
| 1279 | |
| 1280 | /* If the entry is the last of the list, return NULL. */ |
| 1281 | if (&ref->list == end) |
| 1282 | return NULL; |
| 1283 | |
| 1284 | return ref; |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | static inline |
| 1289 | struct tls_keys_ref *tlskeys_ref_lookup_ref(const char *reference) |
| 1290 | { |
| 1291 | int id; |
| 1292 | char *error; |
| 1293 | |
| 1294 | /* If the reference starts by a '#', this is numeric id. */ |
| 1295 | if (reference[0] == '#') { |
| 1296 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1297 | id = strtol(reference + 1, &error, 10); |
| 1298 | if (*error != '\0') |
| 1299 | return NULL; |
| 1300 | |
| 1301 | /* Perform the unique id lookup. */ |
| 1302 | return tlskeys_ref_lookupid(id); |
| 1303 | } |
| 1304 | |
| 1305 | /* Perform the string lookup. */ |
| 1306 | return tlskeys_ref_lookup(reference); |
| 1307 | } |
| 1308 | #endif |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1309 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1310 | /* This function is used with map and acl management. It permits to browse |
| 1311 | * each reference. The variable <getnext> must contain the current node, |
| 1312 | * <end> point to the root node and the <flags> permit to filter required |
| 1313 | * nodes. |
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 | static inline |
| 1316 | struct pat_ref *pat_list_get_next(struct pat_ref *getnext, struct list *end, |
| 1317 | unsigned int flags) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1318 | { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1319 | struct pat_ref *ref = getnext; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1320 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1321 | while (1) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1322 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1323 | /* Get next list entry. */ |
| 1324 | ref = LIST_NEXT(&ref->list, struct pat_ref *, list); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1325 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1326 | /* If the entry is the last of the list, return NULL. */ |
| 1327 | if (&ref->list == end) |
| 1328 | return NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1329 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1330 | /* If the entry match the flag, return it. */ |
| 1331 | if (ref->flags & flags) |
| 1332 | return ref; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1336 | static inline |
| 1337 | struct pat_ref *pat_ref_lookup_ref(const char *reference) |
| 1338 | { |
| 1339 | int id; |
| 1340 | char *error; |
| 1341 | |
| 1342 | /* If the reference starts by a '#', this is numeric id. */ |
| 1343 | if (reference[0] == '#') { |
| 1344 | /* Try to convert the numeric id. If the conversion fails, the lookup fails. */ |
| 1345 | id = strtol(reference + 1, &error, 10); |
| 1346 | if (*error != '\0') |
| 1347 | return NULL; |
| 1348 | |
| 1349 | /* Perform the unique id lookup. */ |
| 1350 | return pat_ref_lookupid(id); |
| 1351 | } |
| 1352 | |
| 1353 | /* Perform the string lookup. */ |
| 1354 | return pat_ref_lookup(reference); |
| 1355 | } |
| 1356 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1357 | /* This function is used with map and acl management. It permits to browse |
| 1358 | * each reference. |
| 1359 | */ |
| 1360 | static inline |
| 1361 | struct pattern_expr *pat_expr_get_next(struct pattern_expr *getnext, struct list *end) |
| 1362 | { |
| 1363 | struct pattern_expr *expr; |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 1364 | expr = LIST_NEXT(&getnext->list, struct pattern_expr *, list); |
| 1365 | if (&expr->list == end) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1366 | return NULL; |
| 1367 | return expr; |
| 1368 | } |
| 1369 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 1370 | /* Processes the stats interpreter on the statistics socket. This function is |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 1371 | * 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] | 1372 | * 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] | 1373 | * designating the function which will have to process the request, which can |
| 1374 | * 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] | 1375 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 1376 | static int stats_sock_parse_request(struct stream_interface *si, char *line) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1377 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1378 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1379 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1380 | char *args[MAX_STATS_ARGS + 1]; |
| 1381 | int arg; |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1382 | int i, j; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1383 | |
| 1384 | while (isspace((unsigned char)*line)) |
| 1385 | line++; |
| 1386 | |
| 1387 | arg = 0; |
| 1388 | args[arg] = line; |
| 1389 | |
| 1390 | while (*line && arg < MAX_STATS_ARGS) { |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1391 | if (*line == '\\') { |
| 1392 | line++; |
| 1393 | if (*line == '\0') |
| 1394 | break; |
| 1395 | } |
| 1396 | else if (isspace((unsigned char)*line)) { |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1397 | *line++ = '\0'; |
| 1398 | |
| 1399 | while (isspace((unsigned char)*line)) |
| 1400 | line++; |
| 1401 | |
| 1402 | args[++arg] = line; |
| 1403 | continue; |
| 1404 | } |
| 1405 | |
| 1406 | line++; |
| 1407 | } |
| 1408 | |
| 1409 | while (++arg <= MAX_STATS_ARGS) |
| 1410 | args[arg] = line; |
| 1411 | |
Thierry FOURNIER | 48bcfda | 2013-12-10 18:54:58 +0100 | [diff] [blame] | 1412 | /* remove \ */ |
| 1413 | arg = 0; |
| 1414 | while (*args[arg] != '\0') { |
| 1415 | j = 0; |
| 1416 | for (i=0; args[arg][i] != '\0'; i++) { |
| 1417 | if (args[arg][i] == '\\') |
| 1418 | continue; |
| 1419 | args[arg][j] = args[arg][i]; |
| 1420 | j++; |
| 1421 | } |
| 1422 | args[arg][j] = '\0'; |
| 1423 | arg++; |
| 1424 | } |
| 1425 | |
Willy Tarreau | 6bcb95d | 2015-05-04 18:07:56 +0200 | [diff] [blame] | 1426 | appctx->ctx.stats.scope_str = 0; |
| 1427 | appctx->ctx.stats.scope_len = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1428 | appctx->ctx.stats.flags = 0; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1429 | if (strcmp(args[0], "show") == 0) { |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 1430 | if (strcmp(args[1], "backend") == 0) { |
| 1431 | appctx->st2 = STAT_ST_INIT; |
| 1432 | appctx->st0 = STAT_CLI_O_BACKEND; |
| 1433 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 1434 | else if (strcmp(args[1], "env") == 0) { |
| 1435 | extern char **environ; |
| 1436 | |
| 1437 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
| 1438 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1439 | appctx->st0 = STAT_CLI_PRINT; |
| 1440 | return 1; |
| 1441 | } |
| 1442 | appctx->ctx.env.var = environ; |
| 1443 | appctx->st2 = STAT_ST_INIT; |
| 1444 | appctx->st0 = STAT_CLI_O_ENV; // stats_dump_env_to_buffer |
| 1445 | |
| 1446 | if (*args[2]) { |
| 1447 | int len = strlen(args[2]); |
| 1448 | |
| 1449 | for (; *appctx->ctx.env.var; appctx->ctx.env.var++) { |
| 1450 | if (strncmp(*appctx->ctx.env.var, args[2], len) == 0 && |
| 1451 | (*appctx->ctx.env.var)[len] == '=') |
| 1452 | break; |
| 1453 | } |
| 1454 | if (!*appctx->ctx.env.var) { |
| 1455 | appctx->ctx.cli.msg = "Variable not found\n"; |
| 1456 | appctx->st0 = STAT_CLI_PRINT; |
| 1457 | return 1; |
| 1458 | } |
| 1459 | appctx->st2 = STAT_ST_END; |
| 1460 | } |
| 1461 | } |
| 1462 | else if (strcmp(args[1], "stat") == 0) { |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1463 | if (strcmp(args[2], "resolvers") == 0) { |
| 1464 | struct dns_resolvers *presolvers; |
| 1465 | |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1466 | if (*args[3]) { |
| 1467 | appctx->ctx.resolvers.ptr = NULL; |
| 1468 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 1469 | if (strcmp(presolvers->id, args[3]) == 0) { |
| 1470 | appctx->ctx.resolvers.ptr = presolvers; |
| 1471 | break; |
| 1472 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1473 | } |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 1474 | if (appctx->ctx.resolvers.ptr == NULL) { |
| 1475 | appctx->ctx.cli.msg = "Can't find that resolvers section\n"; |
| 1476 | appctx->st0 = STAT_CLI_PRINT; |
| 1477 | return 1; |
| 1478 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | appctx->st2 = STAT_ST_INIT; |
| 1482 | appctx->st0 = STAT_CLI_O_RESOLVERS; |
| 1483 | return 1; |
| 1484 | } |
| 1485 | else if (*args[2] && *args[3] && *args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1486 | appctx->ctx.stats.flags |= STAT_BOUND; |
| 1487 | appctx->ctx.stats.iid = atoi(args[2]); |
| 1488 | appctx->ctx.stats.type = atoi(args[3]); |
| 1489 | appctx->ctx.stats.sid = atoi(args[4]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1490 | } |
| 1491 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1492 | appctx->st2 = STAT_ST_INIT; |
| 1493 | appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1494 | } |
| 1495 | else if (strcmp(args[1], "info") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1496 | appctx->st2 = STAT_ST_INIT; |
| 1497 | appctx->st0 = STAT_CLI_O_INFO; // stats_dump_info_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1498 | } |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 1499 | else if (strcmp(args[1], "servers") == 0 && strcmp(args[2], "state") == 0) { |
| 1500 | appctx->ctx.server_state.backend = NULL; |
| 1501 | |
| 1502 | /* check if a backend name has been provided */ |
| 1503 | if (*args[3]) { |
| 1504 | /* read server state from local file */ |
| 1505 | appctx->ctx.server_state.backend = proxy_be_by_name(args[3]); |
| 1506 | |
| 1507 | if (appctx->ctx.server_state.backend == NULL) { |
| 1508 | appctx->ctx.cli.msg = "Can't find backend.\n"; |
| 1509 | appctx->st0 = STAT_CLI_PRINT; |
| 1510 | return 1; |
| 1511 | } |
| 1512 | } |
| 1513 | appctx->st2 = STAT_ST_INIT; |
| 1514 | appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer |
| 1515 | return 1; |
| 1516 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 1517 | else if (strcmp(args[1], "pools") == 0) { |
| 1518 | appctx->st2 = STAT_ST_INIT; |
| 1519 | appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer |
| 1520 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1521 | else if (strcmp(args[1], "sess") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1522 | appctx->st2 = STAT_ST_INIT; |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1523 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1524 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1525 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1526 | return 1; |
| 1527 | } |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1528 | if (*args[2] && strcmp(args[2], "all") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1529 | appctx->ctx.sess.target = (void *)-1; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 1530 | else if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1531 | appctx->ctx.sess.target = (void *)strtoul(args[2], NULL, 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 1532 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1533 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 1534 | appctx->ctx.sess.section = 0; /* start with stream status */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1535 | appctx->ctx.sess.pos = 0; |
| 1536 | appctx->st0 = STAT_CLI_O_SESS; // stats_dump_sess_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1537 | } |
| 1538 | else if (strcmp(args[1], "errors") == 0) { |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1539 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1540 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1541 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1542 | return 1; |
| 1543 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1544 | if (*args[2]) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1545 | appctx->ctx.errors.iid = atoi(args[2]); |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1546 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1547 | appctx->ctx.errors.iid = -1; |
| 1548 | appctx->ctx.errors.px = NULL; |
| 1549 | appctx->st2 = STAT_ST_INIT; |
| 1550 | appctx->st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1551 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1552 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1553 | stats_sock_table_request(si, args, STAT_CLI_O_TAB); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 1554 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 1555 | else if (strcmp(args[1], "tls-keys") == 0) { |
| 1556 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 1557 | appctx->st2 = STAT_ST_INIT; |
| 1558 | appctx->st0 = STAT_CLI_O_TLSK; |
| 1559 | #else |
| 1560 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 1561 | "that doesn't support specifying TLS ticket keys\n"; |
| 1562 | appctx->st0 = STAT_CLI_PRINT; |
| 1563 | #endif |
| 1564 | return 1; |
| 1565 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1566 | else if (strcmp(args[1], "map") == 0 || |
| 1567 | strcmp(args[1], "acl") == 0) { |
| 1568 | |
| 1569 | /* Set ACL or MAP flags. */ |
| 1570 | if (args[1][0] == 'm') |
| 1571 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1572 | else |
| 1573 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1574 | |
| 1575 | /* no parameter: display all map avalaible */ |
| 1576 | if (!*args[2]) { |
| 1577 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1578 | appctx->st0 = STAT_CLI_O_PATS; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1579 | return 1; |
| 1580 | } |
| 1581 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1582 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1583 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1584 | if (!appctx->ctx.map.ref || |
| 1585 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1586 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1587 | 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] | 1588 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1589 | 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] | 1590 | appctx->st0 = STAT_CLI_PRINT; |
| 1591 | return 1; |
| 1592 | } |
| 1593 | appctx->st2 = STAT_ST_INIT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1594 | appctx->st0 = STAT_CLI_O_PAT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1595 | } |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 1596 | else { /* neither "stat" nor "info" nor "sess" nor "errors" nor "table" */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 1597 | return 0; |
| 1598 | } |
| 1599 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1600 | else if (strcmp(args[0], "clear") == 0) { |
| 1601 | if (strcmp(args[1], "counters") == 0) { |
| 1602 | struct proxy *px; |
| 1603 | struct server *sv; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1604 | struct listener *li; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1605 | int clrall = 0; |
| 1606 | |
| 1607 | if (strcmp(args[2], "all") == 0) |
| 1608 | clrall = 1; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1609 | |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1610 | /* check permissions */ |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1611 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER || |
| 1612 | (clrall && strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1613 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1614 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 6162db2 | 2009-10-10 17:13:00 +0200 | [diff] [blame] | 1615 | return 1; |
| 1616 | } |
| 1617 | |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1618 | for (px = proxy; px; px = px->next) { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1619 | if (clrall) { |
| 1620 | memset(&px->be_counters, 0, sizeof(px->be_counters)); |
| 1621 | memset(&px->fe_counters, 0, sizeof(px->fe_counters)); |
| 1622 | } |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1623 | else { |
Willy Tarreau | 7d0aaf3 | 2011-03-10 23:25:56 +0100 | [diff] [blame] | 1624 | px->be_counters.conn_max = 0; |
| 1625 | px->be_counters.p.http.rps_max = 0; |
| 1626 | px->be_counters.sps_max = 0; |
| 1627 | px->be_counters.cps_max = 0; |
| 1628 | px->be_counters.nbpend_max = 0; |
| 1629 | |
| 1630 | px->fe_counters.conn_max = 0; |
| 1631 | px->fe_counters.p.http.rps_max = 0; |
| 1632 | px->fe_counters.sps_max = 0; |
| 1633 | px->fe_counters.cps_max = 0; |
| 1634 | px->fe_counters.nbpend_max = 0; |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1635 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1636 | |
| 1637 | for (sv = px->srv; sv; sv = sv->next) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1638 | if (clrall) |
| 1639 | memset(&sv->counters, 0, sizeof(sv->counters)); |
| 1640 | else { |
| 1641 | sv->counters.cur_sess_max = 0; |
| 1642 | sv->counters.nbpend_max = 0; |
| 1643 | sv->counters.sps_max = 0; |
| 1644 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 1645 | |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1646 | list_for_each_entry(li, &px->conf.listeners, by_fe) |
Willy Tarreau | 2f6bf2b | 2009-10-10 15:26:26 +0200 | [diff] [blame] | 1647 | if (li->counters) { |
| 1648 | if (clrall) |
| 1649 | memset(li->counters, 0, sizeof(*li->counters)); |
| 1650 | else |
| 1651 | li->counters->conn_max = 0; |
| 1652 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1653 | } |
| 1654 | |
Willy Tarreau | 81c25d0 | 2011-09-07 15:17:21 +0200 | [diff] [blame] | 1655 | global.cps_max = 0; |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 1656 | global.sps_max = 0; |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1657 | return 1; |
| 1658 | } |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1659 | else if (strcmp(args[1], "table") == 0) { |
Willy Tarreau | dec9814 | 2012-06-06 23:37:08 +0200 | [diff] [blame] | 1660 | stats_sock_table_request(si, args, STAT_CLI_O_CLR); |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1661 | /* end of processing */ |
| 1662 | return 1; |
| 1663 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1664 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1665 | /* Set ACL or MAP flags. */ |
| 1666 | if (args[1][0] == 'm') |
| 1667 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1668 | else |
| 1669 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1670 | |
| 1671 | /* no parameter */ |
| 1672 | if (!*args[2]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1673 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1674 | appctx->ctx.cli.msg = "Missing map identifier.\n"; |
| 1675 | else |
| 1676 | appctx->ctx.cli.msg = "Missing ACL identifier.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1677 | appctx->st0 = STAT_CLI_PRINT; |
| 1678 | return 1; |
| 1679 | } |
| 1680 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1681 | /* lookup into the refs and check the map flag */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1682 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1683 | if (!appctx->ctx.map.ref || |
| 1684 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
| 1685 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1686 | 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] | 1687 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1688 | 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] | 1689 | appctx->st0 = STAT_CLI_PRINT; |
| 1690 | return 1; |
| 1691 | } |
| 1692 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1693 | /* Clear all. */ |
| 1694 | pat_ref_prune(appctx->ctx.map.ref); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1695 | |
| 1696 | /* return response */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 1697 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1698 | return 1; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1699 | } |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1700 | else { |
Willy Tarreau | 88ee397 | 2010-07-13 13:48:00 +0200 | [diff] [blame] | 1701 | /* unknown "clear" argument */ |
Krzysztof Piotr Oledzki | 719e726 | 2009-10-04 15:02:46 +0200 | [diff] [blame] | 1702 | return 0; |
| 1703 | } |
| 1704 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1705 | else if (strcmp(args[0], "get") == 0) { |
| 1706 | if (strcmp(args[1], "weight") == 0) { |
| 1707 | struct proxy *px; |
| 1708 | struct server *sv; |
| 1709 | |
| 1710 | /* split "backend/server" and make <line> point to server */ |
| 1711 | for (line = args[2]; *line; line++) |
| 1712 | if (*line == '/') { |
| 1713 | *line++ = '\0'; |
| 1714 | break; |
| 1715 | } |
| 1716 | |
| 1717 | if (!*line) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1718 | appctx->ctx.cli.msg = "Require 'backend/server'.\n"; |
| 1719 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1720 | return 1; |
| 1721 | } |
| 1722 | |
| 1723 | if (!get_backend_server(args[2], line, &px, &sv)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1724 | appctx->ctx.cli.msg = px ? "No such server.\n" : "No such backend.\n"; |
| 1725 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1726 | return 1; |
| 1727 | } |
| 1728 | |
| 1729 | /* return server's effective weight at the moment */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 1730 | 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] | 1731 | if (bi_putstr(si_ic(si), trash.str) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 1732 | si_applet_cant_put(si); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 1733 | |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1734 | return 1; |
| 1735 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1736 | else if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 1737 | /* Set flags. */ |
| 1738 | if (args[1][0] == 'm') |
| 1739 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 1740 | else |
| 1741 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1742 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1743 | /* No parameter. */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1744 | if (!*args[2] || !*args[3]) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1745 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 1746 | appctx->ctx.cli.msg = "Missing map identifier and/or key.\n"; |
| 1747 | else |
| 1748 | appctx->ctx.cli.msg = "Missing ACL identifier and/or key.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1749 | appctx->st0 = STAT_CLI_PRINT; |
| 1750 | return 1; |
| 1751 | } |
| 1752 | |
| 1753 | /* lookup into the maps */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 1754 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1755 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1756 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1757 | 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] | 1758 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 1759 | 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] | 1760 | appctx->st0 = STAT_CLI_PRINT; |
| 1761 | return 1; |
| 1762 | } |
| 1763 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 1764 | /* copy input string. The string must be allocated because |
| 1765 | * it may be used over multiple iterations. It's released |
| 1766 | * at the end and upon abort anyway. |
| 1767 | */ |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 1768 | appctx->ctx.map.chunk.len = strlen(args[3]); |
| 1769 | appctx->ctx.map.chunk.size = appctx->ctx.map.chunk.len + 1; |
| 1770 | appctx->ctx.map.chunk.str = strdup(args[3]); |
| 1771 | if (!appctx->ctx.map.chunk.str) { |
| 1772 | appctx->ctx.cli.msg = "Out of memory error.\n"; |
| 1773 | appctx->st0 = STAT_CLI_PRINT; |
| 1774 | return 1; |
| 1775 | } |
| 1776 | |
| 1777 | /* prepare response */ |
| 1778 | appctx->st2 = STAT_ST_INIT; |
| 1779 | appctx->st0 = STAT_CLI_O_MLOOK; |
| 1780 | } |
Willy Tarreau | 38338fa | 2009-10-10 18:37:29 +0200 | [diff] [blame] | 1781 | else { /* not "get weight" */ |
| 1782 | return 0; |
| 1783 | } |
| 1784 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1785 | else if (strcmp(args[0], "set") == 0) { |
| 1786 | if (strcmp(args[1], "weight") == 0) { |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1787 | struct server *sv; |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1788 | const char *warning; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1789 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 1790 | sv = expect_server_admin(s, si, args[2]); |
| 1791 | if (!sv) |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1792 | return 1; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1793 | |
Simon Horman | 7d09b9a | 2013-02-12 10:45:51 +0900 | [diff] [blame] | 1794 | warning = server_parse_weight_change_request(sv, args[3]); |
| 1795 | if (warning) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1796 | appctx->ctx.cli.msg = warning; |
| 1797 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1798 | } |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 1799 | return 1; |
| 1800 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1801 | else if (strcmp(args[1], "server") == 0) { |
| 1802 | struct server *sv; |
| 1803 | const char *warning; |
| 1804 | |
| 1805 | sv = expect_server_admin(s, si, args[2]); |
| 1806 | if (!sv) |
| 1807 | return 1; |
| 1808 | |
| 1809 | if (strcmp(args[3], "weight") == 0) { |
| 1810 | warning = server_parse_weight_change_request(sv, args[4]); |
| 1811 | if (warning) { |
| 1812 | appctx->ctx.cli.msg = warning; |
| 1813 | appctx->st0 = STAT_CLI_PRINT; |
| 1814 | } |
| 1815 | } |
| 1816 | else if (strcmp(args[3], "state") == 0) { |
| 1817 | if (strcmp(args[4], "ready") == 0) |
| 1818 | srv_adm_set_ready(sv); |
| 1819 | else if (strcmp(args[4], "drain") == 0) |
| 1820 | srv_adm_set_drain(sv); |
| 1821 | else if (strcmp(args[4], "maint") == 0) |
| 1822 | srv_adm_set_maint(sv); |
| 1823 | else { |
| 1824 | appctx->ctx.cli.msg = "'set server <srv> state' expects 'ready', 'drain' and 'maint'.\n"; |
| 1825 | appctx->st0 = STAT_CLI_PRINT; |
| 1826 | } |
| 1827 | } |
| 1828 | else if (strcmp(args[3], "health") == 0) { |
| 1829 | if (sv->track) { |
| 1830 | appctx->ctx.cli.msg = "cannot change health on a tracking server.\n"; |
| 1831 | appctx->st0 = STAT_CLI_PRINT; |
| 1832 | } |
| 1833 | else if (strcmp(args[4], "up") == 0) { |
| 1834 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1835 | srv_set_running(sv, "changed from CLI"); |
| 1836 | } |
| 1837 | else if (strcmp(args[4], "stopping") == 0) { |
| 1838 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 1839 | srv_set_stopping(sv, "changed from CLI"); |
| 1840 | } |
| 1841 | else if (strcmp(args[4], "down") == 0) { |
| 1842 | sv->check.health = 0; |
| 1843 | srv_set_stopped(sv, "changed from CLI"); |
| 1844 | } |
| 1845 | else { |
| 1846 | appctx->ctx.cli.msg = "'set server <srv> health' expects 'up', 'stopping', or 'down'.\n"; |
| 1847 | appctx->st0 = STAT_CLI_PRINT; |
| 1848 | } |
| 1849 | } |
| 1850 | else if (strcmp(args[3], "agent") == 0) { |
| 1851 | if (!(sv->agent.state & CHK_ST_ENABLED)) { |
| 1852 | appctx->ctx.cli.msg = "agent checks are not enabled on this server.\n"; |
| 1853 | appctx->st0 = STAT_CLI_PRINT; |
| 1854 | } |
| 1855 | else if (strcmp(args[4], "up") == 0) { |
| 1856 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 1857 | srv_set_running(sv, "changed from CLI"); |
| 1858 | } |
| 1859 | else if (strcmp(args[4], "down") == 0) { |
| 1860 | sv->agent.health = 0; |
| 1861 | srv_set_stopped(sv, "changed from CLI"); |
| 1862 | } |
| 1863 | else { |
| 1864 | appctx->ctx.cli.msg = "'set server <srv> agent' expects 'up' or 'down'.\n"; |
| 1865 | appctx->st0 = STAT_CLI_PRINT; |
| 1866 | } |
| 1867 | } |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1868 | else if (strcmp(args[3], "addr") == 0) { |
Thierry Fournier | 09a9178 | 2016-02-24 08:25:39 +0100 | [diff] [blame] | 1869 | warning = server_parse_addr_change_request(sv, args[4], "stats command"); |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1870 | if (warning) { |
| 1871 | appctx->ctx.cli.msg = warning; |
| 1872 | appctx->st0 = STAT_CLI_PRINT; |
| 1873 | } |
| 1874 | } |
Willy Tarreau | 2a4b70f | 2014-05-22 18:42:35 +0200 | [diff] [blame] | 1875 | else { |
Baptiste Assmann | 3d8f831 | 2015-04-13 22:54:33 +0200 | [diff] [blame] | 1876 | 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] | 1877 | appctx->st0 = STAT_CLI_PRINT; |
| 1878 | } |
| 1879 | return 1; |
| 1880 | } |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1881 | else if (strcmp(args[1], "timeout") == 0) { |
| 1882 | if (strcmp(args[2], "cli") == 0) { |
| 1883 | unsigned timeout; |
| 1884 | const char *res; |
| 1885 | |
| 1886 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1887 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1888 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1889 | return 1; |
| 1890 | } |
| 1891 | |
| 1892 | res = parse_time_err(args[3], &timeout, TIME_UNIT_S); |
| 1893 | if (res || timeout < 1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1894 | appctx->ctx.cli.msg = "Invalid timeout value.\n"; |
| 1895 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1896 | return 1; |
| 1897 | } |
| 1898 | |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 1899 | s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000); |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1900 | return 1; |
| 1901 | } |
| 1902 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1903 | appctx->ctx.cli.msg = "'set timeout' only supports 'cli'.\n"; |
| 1904 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 1905 | return 1; |
| 1906 | } |
| 1907 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1908 | else if (strcmp(args[1], "maxconn") == 0) { |
| 1909 | if (strcmp(args[2], "frontend") == 0) { |
| 1910 | struct proxy *px; |
| 1911 | struct listener *l; |
| 1912 | int v; |
| 1913 | |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 1914 | px = expect_frontend_admin(s, si, args[3]); |
| 1915 | if (!px) |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1916 | return 1; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1917 | |
| 1918 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1919 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1920 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1921 | return 1; |
| 1922 | } |
| 1923 | |
| 1924 | v = atoi(args[4]); |
Willy Tarreau | 3c7a79d | 2012-09-26 21:07:15 +0200 | [diff] [blame] | 1925 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1926 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1927 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1928 | return 1; |
| 1929 | } |
| 1930 | |
| 1931 | /* OK, the value is fine, so we assign it to the proxy and to all of |
| 1932 | * its listeners. The blocked ones will be dequeued. |
| 1933 | */ |
| 1934 | px->maxconn = v; |
Willy Tarreau | a7944ad | 2012-09-26 21:03:11 +0200 | [diff] [blame] | 1935 | list_for_each_entry(l, &px->conf.listeners, by_fe) { |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1936 | l->maxconn = v; |
| 1937 | if (l->state == LI_FULL) |
| 1938 | resume_listener(l); |
| 1939 | } |
| 1940 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1941 | if (px->maxconn > px->feconn && !LIST_ISEMPTY(&strm_fe(s)->listener_queue)) |
| 1942 | dequeue_all_listeners(&strm_fe(s)->listener_queue); |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 1943 | |
| 1944 | return 1; |
| 1945 | } |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 1946 | else if (strcmp(args[2], "server") == 0) { |
| 1947 | struct server *sv; |
| 1948 | int v; |
| 1949 | |
| 1950 | sv = expect_server_admin(s, si, args[3]); |
| 1951 | if (!sv) |
| 1952 | return 1; |
| 1953 | |
| 1954 | if (!*args[4]) { |
| 1955 | appctx->ctx.cli.msg = "Integer value expected.\n"; |
| 1956 | appctx->st0 = STAT_CLI_PRINT; |
| 1957 | return 1; |
| 1958 | } |
| 1959 | |
| 1960 | v = atoi(args[4]); |
| 1961 | if (v < 0) { |
| 1962 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1963 | appctx->st0 = STAT_CLI_PRINT; |
| 1964 | return 1; |
| 1965 | } |
| 1966 | |
| 1967 | if (sv->maxconn == sv->minconn) { // static maxconn |
| 1968 | sv->maxconn = sv->minconn = v; |
| 1969 | } else { // dynamic maxconn |
| 1970 | sv->maxconn = v; |
| 1971 | } |
| 1972 | |
| 1973 | if (may_dequeue_tasks(sv, sv->proxy)) |
| 1974 | process_srv_queue(sv); |
| 1975 | |
| 1976 | return 1; |
| 1977 | } |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1978 | else if (strcmp(args[2], "global") == 0) { |
| 1979 | int v; |
| 1980 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 1981 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1982 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 1983 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1984 | return 1; |
| 1985 | } |
| 1986 | |
| 1987 | if (!*args[3]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1988 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 1989 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1990 | return 1; |
| 1991 | } |
| 1992 | |
| 1993 | v = atoi(args[3]); |
| 1994 | if (v > global.hardmaxconn) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 1995 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 1996 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 91886b6 | 2011-09-07 14:38:31 +0200 | [diff] [blame] | 1997 | return 1; |
| 1998 | } |
| 1999 | |
| 2000 | /* check for unlimited values */ |
| 2001 | if (v <= 0) |
| 2002 | v = global.hardmaxconn; |
| 2003 | |
| 2004 | global.maxconn = v; |
| 2005 | |
| 2006 | /* Dequeues all of the listeners waiting for a resource */ |
| 2007 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2008 | dequeue_all_listeners(&global_listener_queue); |
| 2009 | |
| 2010 | return 1; |
| 2011 | } |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 2012 | else { |
Andrew Hayworth | edb93a7 | 2015-10-27 21:46:25 +0000 | [diff] [blame] | 2013 | 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] | 2014 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 2a0f4d2 | 2011-08-02 11:49:05 +0200 | [diff] [blame] | 2015 | return 1; |
| 2016 | } |
| 2017 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2018 | else if (strcmp(args[1], "rate-limit") == 0) { |
| 2019 | if (strcmp(args[2], "connections") == 0) { |
| 2020 | if (strcmp(args[3], "global") == 0) { |
| 2021 | int v; |
| 2022 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2023 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2024 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2025 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2026 | return 1; |
| 2027 | } |
| 2028 | |
| 2029 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2030 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2031 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2032 | return 1; |
| 2033 | } |
| 2034 | |
| 2035 | v = atoi(args[4]); |
| 2036 | if (v < 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2037 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2038 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2039 | return 1; |
| 2040 | } |
| 2041 | |
| 2042 | global.cps_lim = v; |
| 2043 | |
| 2044 | /* Dequeues all of the listeners waiting for a resource */ |
| 2045 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2046 | dequeue_all_listeners(&global_listener_queue); |
| 2047 | |
| 2048 | return 1; |
| 2049 | } |
| 2050 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2051 | appctx->ctx.cli.msg = "'set rate-limit connections' only supports 'global'.\n"; |
| 2052 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2053 | return 1; |
| 2054 | } |
| 2055 | } |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2056 | else if (strcmp(args[2], "sessions") == 0) { |
| 2057 | if (strcmp(args[3], "global") == 0) { |
| 2058 | int v; |
| 2059 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2060 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 93e7c00 | 2013-10-07 18:51:07 +0200 | [diff] [blame] | 2061 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2062 | appctx->st0 = STAT_CLI_PRINT; |
| 2063 | return 1; |
| 2064 | } |
| 2065 | |
| 2066 | if (!*args[4]) { |
| 2067 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2068 | appctx->st0 = STAT_CLI_PRINT; |
| 2069 | return 1; |
| 2070 | } |
| 2071 | |
| 2072 | v = atoi(args[4]); |
| 2073 | if (v < 0) { |
| 2074 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2075 | appctx->st0 = STAT_CLI_PRINT; |
| 2076 | return 1; |
| 2077 | } |
| 2078 | |
| 2079 | global.sps_lim = v; |
| 2080 | |
| 2081 | /* Dequeues all of the listeners waiting for a resource */ |
| 2082 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2083 | dequeue_all_listeners(&global_listener_queue); |
| 2084 | |
| 2085 | return 1; |
| 2086 | } |
| 2087 | else { |
| 2088 | appctx->ctx.cli.msg = "'set rate-limit sessions' only supports 'global'.\n"; |
| 2089 | appctx->st0 = STAT_CLI_PRINT; |
| 2090 | return 1; |
| 2091 | } |
| 2092 | } |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2093 | #ifdef USE_OPENSSL |
| 2094 | else if (strcmp(args[2], "ssl-sessions") == 0) { |
| 2095 | if (strcmp(args[3], "global") == 0) { |
| 2096 | int v; |
| 2097 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2098 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2099 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2100 | appctx->st0 = STAT_CLI_PRINT; |
| 2101 | return 1; |
| 2102 | } |
| 2103 | |
| 2104 | if (!*args[4]) { |
| 2105 | appctx->ctx.cli.msg = "Expects an integer value.\n"; |
| 2106 | appctx->st0 = STAT_CLI_PRINT; |
| 2107 | return 1; |
| 2108 | } |
| 2109 | |
| 2110 | v = atoi(args[4]); |
| 2111 | if (v < 0) { |
| 2112 | appctx->ctx.cli.msg = "Value out of range.\n"; |
| 2113 | appctx->st0 = STAT_CLI_PRINT; |
| 2114 | return 1; |
| 2115 | } |
| 2116 | |
| 2117 | global.ssl_lim = v; |
| 2118 | |
| 2119 | /* Dequeues all of the listeners waiting for a resource */ |
| 2120 | if (!LIST_ISEMPTY(&global_listener_queue)) |
| 2121 | dequeue_all_listeners(&global_listener_queue); |
| 2122 | |
| 2123 | return 1; |
| 2124 | } |
| 2125 | else { |
| 2126 | appctx->ctx.cli.msg = "'set rate-limit ssl-sessions' only supports 'global'.\n"; |
| 2127 | appctx->st0 = STAT_CLI_PRINT; |
| 2128 | return 1; |
| 2129 | } |
| 2130 | } |
| 2131 | #endif |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2132 | else if (strcmp(args[2], "http-compression") == 0) { |
| 2133 | if (strcmp(args[3], "global") == 0) { |
| 2134 | int v; |
| 2135 | |
Willy Tarreau | a1c2b2c | 2015-11-26 18:32:39 +0100 | [diff] [blame] | 2136 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
| 2137 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2138 | appctx->st0 = STAT_CLI_PRINT; |
| 2139 | return 1; |
| 2140 | } |
| 2141 | |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2142 | if (!*args[4]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2143 | appctx->ctx.cli.msg = "Expects a maximum input byte rate in kB/s.\n"; |
| 2144 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 85d47f9 | 2012-11-21 00:29:50 +0100 | [diff] [blame] | 2145 | return 1; |
| 2146 | } |
| 2147 | |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2148 | v = atoi(args[4]); |
| 2149 | global.comp_rate_lim = v * 1024; /* Kilo to bytes. */ |
| 2150 | } |
| 2151 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2152 | appctx->ctx.cli.msg = "'set rate-limit http-compression' only supports 'global'.\n"; |
| 2153 | appctx->st0 = STAT_CLI_PRINT; |
William Lallemand | d85f917 | 2012-11-09 17:05:39 +0100 | [diff] [blame] | 2154 | return 1; |
| 2155 | } |
| 2156 | } |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2157 | else { |
Willy Tarreau | e43d532 | 2013-10-07 20:01:52 +0200 | [diff] [blame] | 2158 | 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] | 2159 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | f5b2287 | 2011-09-07 16:13:44 +0200 | [diff] [blame] | 2160 | return 1; |
| 2161 | } |
| 2162 | } |
Willy Tarreau | 654694e | 2012-06-07 01:03:16 +0200 | [diff] [blame] | 2163 | else if (strcmp(args[1], "table") == 0) { |
| 2164 | stats_sock_table_request(si, args, STAT_CLI_O_SET); |
| 2165 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2166 | else if (strcmp(args[1], "map") == 0) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2167 | char *err; |
| 2168 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2169 | /* Set flags. */ |
| 2170 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2171 | |
| 2172 | /* Expect three parameters: map name, key and new value. */ |
| 2173 | if (!*args[2] || !*args[3] || !*args[4]) { |
Thierry FOURNIER | d572343 | 2014-03-11 13:52:44 +0100 | [diff] [blame] | 2174 | 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] | 2175 | appctx->st0 = STAT_CLI_PRINT; |
| 2176 | return 1; |
| 2177 | } |
| 2178 | |
| 2179 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2180 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2181 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2182 | 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] | 2183 | appctx->st0 = STAT_CLI_PRINT; |
| 2184 | return 1; |
| 2185 | } |
| 2186 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2187 | /* If the entry identifier start with a '#', it is considered as |
| 2188 | * pointer id |
| 2189 | */ |
| 2190 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2191 | struct pat_ref_elt *ref; |
| 2192 | long long int conv; |
| 2193 | char *error; |
| 2194 | |
| 2195 | /* Convert argument to integer value. */ |
| 2196 | conv = strtoll(&args[3][1], &error, 16); |
| 2197 | if (*error != '\0') { |
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 | /* Convert and check integer to pointer. */ |
| 2204 | ref = (struct pat_ref_elt *)(long)conv; |
| 2205 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2206 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2207 | appctx->st0 = STAT_CLI_PRINT; |
| 2208 | return 1; |
| 2209 | } |
| 2210 | |
| 2211 | /* Try to delete the entry. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2212 | err = NULL; |
| 2213 | if (!pat_ref_set_by_id(appctx->ctx.map.ref, ref, args[4], &err)) { |
| 2214 | if (err) |
| 2215 | memprintf(&err, "%s.\n", err); |
| 2216 | appctx->ctx.cli.err = err; |
| 2217 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2218 | return 1; |
| 2219 | } |
| 2220 | } |
| 2221 | else { |
| 2222 | /* Else, use the entry identifier as pattern |
| 2223 | * string, and update the value. |
| 2224 | */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2225 | err = NULL; |
| 2226 | if (!pat_ref_set(appctx->ctx.map.ref, args[3], args[4], &err)) { |
| 2227 | if (err) |
| 2228 | memprintf(&err, "%s.\n", err); |
| 2229 | appctx->ctx.cli.err = err; |
| 2230 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2231 | return 1; |
| 2232 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2233 | } |
| 2234 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2235 | /* The set is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2236 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2237 | return 1; |
| 2238 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2239 | #ifdef USE_OPENSSL |
| 2240 | else if (strcmp(args[1], "ssl") == 0) { |
| 2241 | if (strcmp(args[2], "ocsp-response") == 0) { |
Lukas Tribus | e4e30f7 | 2014-12-09 16:32:51 +0100 | [diff] [blame] | 2242 | #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] | 2243 | char *err = NULL; |
| 2244 | |
Emeric Brun | af4ef74 | 2014-06-19 14:10:45 +0200 | [diff] [blame] | 2245 | /* Expect one parameter: the new response in base64 encoding */ |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2246 | if (!*args[3]) { |
| 2247 | appctx->ctx.cli.msg = "'set ssl ocsp-response' expects response in base64 encoding.\n"; |
| 2248 | appctx->st0 = STAT_CLI_PRINT; |
| 2249 | return 1; |
| 2250 | } |
| 2251 | |
| 2252 | trash.len = base64dec(args[3], strlen(args[3]), trash.str, trash.size); |
| 2253 | if (trash.len < 0) { |
| 2254 | appctx->ctx.cli.msg = "'set ssl ocsp-response' received invalid base64 encoded response.\n"; |
| 2255 | appctx->st0 = STAT_CLI_PRINT; |
| 2256 | return 1; |
| 2257 | } |
| 2258 | |
| 2259 | if (ssl_sock_update_ocsp_response(&trash, &err)) { |
| 2260 | if (err) { |
| 2261 | memprintf(&err, "%s.\n", err); |
| 2262 | appctx->ctx.cli.err = err; |
| 2263 | appctx->st0 = STAT_CLI_PRINT_FREE; |
| 2264 | } |
| 2265 | return 1; |
| 2266 | } |
| 2267 | appctx->ctx.cli.msg = "OCSP Response updated!"; |
| 2268 | appctx->st0 = STAT_CLI_PRINT; |
| 2269 | return 1; |
| 2270 | #else |
| 2271 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL that doesn't support OCSP stapling.\n"; |
| 2272 | appctx->st0 = STAT_CLI_PRINT; |
| 2273 | return 1; |
| 2274 | #endif |
| 2275 | } |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2276 | else if (strcmp(args[2], "tls-key") == 0) { |
| 2277 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2278 | /* Expect two parameters: the filename and the new new TLS key in encoding */ |
| 2279 | if (!*args[3] || !*args[4]) { |
| 2280 | appctx->ctx.cli.msg = "'set ssl tls-key' expects a filename and the new TLS key in base64 encoding.\n"; |
| 2281 | appctx->st0 = STAT_CLI_PRINT; |
| 2282 | return 1; |
| 2283 | } |
| 2284 | |
| 2285 | appctx->ctx.tlskeys.ref = tlskeys_ref_lookup_ref(args[3]); |
| 2286 | if(!appctx->ctx.tlskeys.ref) { |
| 2287 | appctx->ctx.cli.msg = "'set ssl tls-key' unable to locate referenced filename\n"; |
| 2288 | appctx->st0 = STAT_CLI_PRINT; |
| 2289 | return 1; |
| 2290 | } |
| 2291 | |
| 2292 | trash.len = base64dec(args[4], strlen(args[4]), trash.str, trash.size); |
| 2293 | if (trash.len != sizeof(struct tls_sess_key)) { |
| 2294 | appctx->ctx.cli.msg = "'set ssl tls-key' received invalid base64 encoded TLS key.\n"; |
| 2295 | appctx->st0 = STAT_CLI_PRINT; |
| 2296 | return 1; |
| 2297 | } |
| 2298 | |
Pradeep Jindal | cc79b00 | 2015-08-20 18:25:17 +0530 | [diff] [blame] | 2299 | memcpy(appctx->ctx.tlskeys.ref->tlskeys + ((appctx->ctx.tlskeys.ref->tls_ticket_enc_index + 2) % TLS_TICKETS_NO), trash.str, trash.len); |
| 2300 | 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] | 2301 | |
| 2302 | appctx->ctx.cli.msg = "TLS ticket key updated!"; |
| 2303 | appctx->st0 = STAT_CLI_PRINT; |
| 2304 | return 1; |
| 2305 | #else |
| 2306 | appctx->ctx.cli.msg = "HAProxy was compiled against a version of OpenSSL " |
| 2307 | "that doesn't support specifying TLS ticket keys\n"; |
| 2308 | appctx->st0 = STAT_CLI_PRINT; |
| 2309 | return 1; |
| 2310 | #endif |
| 2311 | } |
Emeric Brun | 4147b2e | 2014-06-16 18:36:30 +0200 | [diff] [blame] | 2312 | else { |
| 2313 | appctx->ctx.cli.msg = "'set ssl' only supports 'ocsp-response'.\n"; |
| 2314 | appctx->st0 = STAT_CLI_PRINT; |
| 2315 | return 1; |
| 2316 | } |
| 2317 | } |
| 2318 | #endif |
Willy Tarreau | 7aabd11 | 2010-01-26 10:59:06 +0100 | [diff] [blame] | 2319 | else { /* unknown "set" parameter */ |
Willy Tarreau | 4483d43 | 2009-10-10 19:30:08 +0200 | [diff] [blame] | 2320 | return 0; |
| 2321 | } |
| 2322 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2323 | else if (strcmp(args[0], "enable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2324 | if (strcmp(args[1], "agent") == 0) { |
| 2325 | struct server *sv; |
| 2326 | |
| 2327 | sv = expect_server_admin(s, si, args[2]); |
| 2328 | if (!sv) |
| 2329 | return 1; |
| 2330 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2331 | if (!(sv->agent.state & CHK_ST_CONFIGURED)) { |
| 2332 | appctx->ctx.cli.msg = "Agent was not configured on this server, cannot enable.\n"; |
| 2333 | appctx->st0 = STAT_CLI_PRINT; |
| 2334 | return 1; |
| 2335 | } |
| 2336 | |
| 2337 | sv->agent.state |= CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2338 | return 1; |
| 2339 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2340 | else if (strcmp(args[1], "health") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2341 | struct server *sv; |
| 2342 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2343 | sv = expect_server_admin(s, si, args[2]); |
| 2344 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2345 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2346 | |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2347 | if (!(sv->check.state & CHK_ST_CONFIGURED)) { |
| 2348 | appctx->ctx.cli.msg = "Health checks are not configured on this server, cannot enable.\n"; |
| 2349 | appctx->st0 = STAT_CLI_PRINT; |
| 2350 | return 1; |
| 2351 | } |
| 2352 | |
| 2353 | sv->check.state |= CHK_ST_ENABLED; |
| 2354 | return 1; |
| 2355 | } |
| 2356 | else if (strcmp(args[1], "server") == 0) { |
| 2357 | struct server *sv; |
| 2358 | |
| 2359 | sv = expect_server_admin(s, si, args[2]); |
| 2360 | if (!sv) |
| 2361 | return 1; |
| 2362 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2363 | srv_adm_set_ready(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2364 | return 1; |
| 2365 | } |
| 2366 | else if (strcmp(args[1], "frontend") == 0) { |
| 2367 | struct proxy *px; |
| 2368 | |
| 2369 | px = expect_frontend_admin(s, si, args[2]); |
| 2370 | if (!px) |
| 2371 | return 1; |
| 2372 | |
| 2373 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2374 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot enable.\n"; |
| 2375 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2376 | return 1; |
| 2377 | } |
| 2378 | |
| 2379 | if (px->state != PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2380 | appctx->ctx.cli.msg = "Frontend is already enabled.\n"; |
| 2381 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2382 | return 1; |
| 2383 | } |
| 2384 | |
| 2385 | if (!resume_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2386 | appctx->ctx.cli.msg = "Failed to resume frontend, check logs for precise cause (port conflict?).\n"; |
| 2387 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2388 | return 1; |
| 2389 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2390 | return 1; |
| 2391 | } |
| 2392 | else { /* unknown "enable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2393 | 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] | 2394 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2395 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2396 | } |
| 2397 | } |
| 2398 | else if (strcmp(args[0], "disable") == 0) { |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2399 | if (strcmp(args[1], "agent") == 0) { |
| 2400 | struct server *sv; |
| 2401 | |
| 2402 | sv = expect_server_admin(s, si, args[2]); |
| 2403 | if (!sv) |
| 2404 | return 1; |
| 2405 | |
Willy Tarreau | 2e10f5a | 2013-12-11 20:11:55 +0100 | [diff] [blame] | 2406 | sv->agent.state &= ~CHK_ST_ENABLED; |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2407 | return 1; |
| 2408 | } |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2409 | else if (strcmp(args[1], "health") == 0) { |
| 2410 | struct server *sv; |
| 2411 | |
| 2412 | sv = expect_server_admin(s, si, args[2]); |
| 2413 | if (!sv) |
| 2414 | return 1; |
| 2415 | |
| 2416 | sv->check.state &= ~CHK_ST_ENABLED; |
| 2417 | return 1; |
| 2418 | } |
Simon Horman | 671b6f0 | 2013-11-25 10:46:39 +0900 | [diff] [blame] | 2419 | else if (strcmp(args[1], "server") == 0) { |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2420 | struct server *sv; |
| 2421 | |
Willy Tarreau | d52c41e | 2011-09-07 23:41:01 +0200 | [diff] [blame] | 2422 | sv = expect_server_admin(s, si, args[2]); |
| 2423 | if (!sv) |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2424 | return 1; |
Cyril Bonté | 613f0df | 2011-03-03 20:49:04 +0100 | [diff] [blame] | 2425 | |
Willy Tarreau | bfc7b7a | 2014-05-22 16:14:34 +0200 | [diff] [blame] | 2426 | srv_adm_set_maint(sv); |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2427 | return 1; |
| 2428 | } |
| 2429 | else if (strcmp(args[1], "frontend") == 0) { |
| 2430 | struct proxy *px; |
| 2431 | |
| 2432 | px = expect_frontend_admin(s, si, args[2]); |
| 2433 | if (!px) |
| 2434 | return 1; |
| 2435 | |
| 2436 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2437 | appctx->ctx.cli.msg = "Frontend was previously shut down, cannot disable.\n"; |
| 2438 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2439 | return 1; |
| 2440 | } |
| 2441 | |
| 2442 | if (px->state == PR_STPAUSED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2443 | appctx->ctx.cli.msg = "Frontend is already disabled.\n"; |
| 2444 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2445 | return 1; |
| 2446 | } |
| 2447 | |
| 2448 | if (!pause_proxy(px)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2449 | appctx->ctx.cli.msg = "Failed to pause frontend, check logs for precise cause.\n"; |
| 2450 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2451 | return 1; |
| 2452 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2453 | return 1; |
| 2454 | } |
| 2455 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 9b5aecd | 2014-05-23 11:53:10 +0200 | [diff] [blame] | 2456 | 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] | 2457 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2458 | return 1; |
| 2459 | } |
| 2460 | } |
| 2461 | else if (strcmp(args[0], "shutdown") == 0) { |
| 2462 | if (strcmp(args[1], "frontend") == 0) { |
| 2463 | struct proxy *px; |
| 2464 | |
| 2465 | px = expect_frontend_admin(s, si, args[2]); |
| 2466 | if (!px) |
| 2467 | return 1; |
| 2468 | |
| 2469 | if (px->state == PR_STSTOPPED) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2470 | appctx->ctx.cli.msg = "Frontend was already shut down.\n"; |
| 2471 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2472 | return 1; |
| 2473 | } |
| 2474 | |
| 2475 | Warning("Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2476 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2477 | send_log(px, LOG_WARNING, "Proxy %s stopped (FE: %lld conns, BE: %lld conns).\n", |
| 2478 | px->id, px->fe_counters.cum_conn, px->be_counters.cum_conn); |
| 2479 | stop_proxy(px); |
| 2480 | return 1; |
| 2481 | } |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2482 | else if (strcmp(args[1], "session") == 0) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2483 | struct stream *sess, *ptr; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2484 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 2485 | if (strm_li(s)->bind_conf->level < ACCESS_LVL_ADMIN) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2486 | appctx->ctx.cli.msg = stats_permission_denied_msg; |
| 2487 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2488 | return 1; |
| 2489 | } |
| 2490 | |
| 2491 | if (!*args[2]) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2492 | appctx->ctx.cli.msg = "Session pointer expected (use 'show sess').\n"; |
| 2493 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2494 | return 1; |
| 2495 | } |
| 2496 | |
| 2497 | ptr = (void *)strtoul(args[2], NULL, 0); |
| 2498 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2499 | /* first, look for the requested stream in the stream table */ |
| 2500 | list_for_each_entry(sess, &streams, list) { |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2501 | if (sess == ptr) |
| 2502 | break; |
| 2503 | } |
| 2504 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2505 | /* do we have the stream ? */ |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2506 | if (sess != ptr) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2507 | appctx->ctx.cli.msg = "No such session (use 'show sess').\n"; |
| 2508 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2509 | return 1; |
| 2510 | } |
| 2511 | |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2512 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | a295edc | 2011-09-07 23:21:03 +0200 | [diff] [blame] | 2513 | return 1; |
| 2514 | } |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2515 | else if (strcmp(args[1], "sessions") == 0) { |
| 2516 | if (strcmp(args[2], "server") == 0) { |
| 2517 | struct server *sv; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2518 | struct stream *sess, *sess_bck; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2519 | |
| 2520 | sv = expect_server_admin(s, si, args[3]); |
| 2521 | if (!sv) |
| 2522 | return 1; |
| 2523 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 2524 | /* kill all the stream that are on this server */ |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2525 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 2526 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 2527 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2528 | |
| 2529 | return 1; |
| 2530 | } |
| 2531 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2532 | appctx->ctx.cli.msg = "'shutdown sessions' only supports 'server'.\n"; |
| 2533 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 52b2d22 | 2011-09-07 23:48:48 +0200 | [diff] [blame] | 2534 | return 1; |
| 2535 | } |
| 2536 | } |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2537 | else { /* unknown "disable" parameter */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2538 | appctx->ctx.cli.msg = "'shutdown' only supports 'frontend', 'session' and 'sessions'.\n"; |
| 2539 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 532a450 | 2011-09-07 22:37:44 +0200 | [diff] [blame] | 2540 | return 1; |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2541 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2542 | } |
| 2543 | else if (strcmp(args[0], "del") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2544 | if (strcmp(args[1], "map") == 0 || strcmp(args[1], "acl") == 0) { |
| 2545 | if (args[1][0] == 'm') |
| 2546 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2547 | else |
| 2548 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2549 | |
| 2550 | /* Expect two parameters: map name and key. */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2551 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2552 | if (!*args[2] || !*args[3]) { |
| 2553 | appctx->ctx.cli.msg = "This command expects two parameters: map identifier and key.\n"; |
| 2554 | appctx->st0 = STAT_CLI_PRINT; |
| 2555 | return 1; |
| 2556 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2557 | } |
| 2558 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2559 | else { |
| 2560 | if (!*args[2] || !*args[3]) { |
| 2561 | appctx->ctx.cli.msg = "This command expects two parameters: ACL identifier and key.\n"; |
| 2562 | appctx->st0 = STAT_CLI_PRINT; |
| 2563 | return 1; |
| 2564 | } |
| 2565 | } |
| 2566 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2567 | /* Lookup the reference in the maps. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2568 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2569 | if (!appctx->ctx.map.ref || |
| 2570 | !(appctx->ctx.map.ref->flags & appctx->ctx.map.display_flags)) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2571 | 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] | 2572 | appctx->st0 = STAT_CLI_PRINT; |
| 2573 | return 1; |
| 2574 | } |
| 2575 | |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2576 | /* If the entry identifier start with a '#', it is considered as |
| 2577 | * pointer id |
| 2578 | */ |
| 2579 | if (args[3][0] == '#' && args[3][1] == '0' && args[3][2] == 'x') { |
| 2580 | struct pat_ref_elt *ref; |
| 2581 | long long int conv; |
| 2582 | char *error; |
| 2583 | |
| 2584 | /* Convert argument to integer value. */ |
| 2585 | conv = strtoll(&args[3][1], &error, 16); |
| 2586 | if (*error != '\0') { |
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 | /* Convert and check integer to pointer. */ |
| 2593 | ref = (struct pat_ref_elt *)(long)conv; |
| 2594 | if ((long long int)(long)ref != conv) { |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2595 | appctx->ctx.cli.msg = "Malformed identifier. Please use #<id> or <file>.\n"; |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 2596 | appctx->st0 = STAT_CLI_PRINT; |
| 2597 | return 1; |
| 2598 | } |
| 2599 | |
| 2600 | /* Try to delete the entry. */ |
| 2601 | if (!pat_ref_delete_by_id(appctx->ctx.map.ref, ref)) { |
| 2602 | /* The entry is not found, send message. */ |
| 2603 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2604 | appctx->st0 = STAT_CLI_PRINT; |
| 2605 | return 1; |
| 2606 | } |
| 2607 | } |
| 2608 | else { |
| 2609 | /* Else, use the entry identifier as pattern |
| 2610 | * string and try to delete the entry. |
| 2611 | */ |
| 2612 | if (!pat_ref_delete(appctx->ctx.map.ref, args[3])) { |
| 2613 | /* The entry is not found, send message. */ |
| 2614 | appctx->ctx.cli.msg = "Key not found.\n"; |
| 2615 | appctx->st0 = STAT_CLI_PRINT; |
| 2616 | return 1; |
| 2617 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2618 | } |
| 2619 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2620 | /* The deletion is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2621 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2622 | return 1; |
| 2623 | } |
| 2624 | else { /* unknown "del" parameter */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2625 | appctx->ctx.cli.msg = "'del' only supports 'map' or 'acl'.\n"; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2626 | appctx->st0 = STAT_CLI_PRINT; |
| 2627 | return 1; |
| 2628 | } |
| 2629 | } |
| 2630 | else if (strcmp(args[0], "add") == 0) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2631 | if (strcmp(args[1], "map") == 0 || |
| 2632 | strcmp(args[1], "acl") == 0) { |
| 2633 | int ret; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2634 | char *err; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2635 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2636 | /* Set flags. */ |
| 2637 | if (args[1][0] == 'm') |
| 2638 | appctx->ctx.map.display_flags = PAT_REF_MAP; |
| 2639 | else |
| 2640 | appctx->ctx.map.display_flags = PAT_REF_ACL; |
| 2641 | |
| 2642 | /* If the keywork is "map", we expect three parameters, if it |
| 2643 | * is "acl", we expect only two parameters |
| 2644 | */ |
| 2645 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 2646 | if (!*args[2] || !*args[3] || !*args[4]) { |
| 2647 | appctx->ctx.cli.msg = "'add map' expects three parameters: map identifier, key and value.\n"; |
| 2648 | appctx->st0 = STAT_CLI_PRINT; |
| 2649 | return 1; |
| 2650 | } |
| 2651 | } |
| 2652 | else { |
| 2653 | if (!*args[2] || !*args[3]) { |
| 2654 | appctx->ctx.cli.msg = "'add acl' expects two parameters: ACL identifier and pattern.\n"; |
| 2655 | appctx->st0 = STAT_CLI_PRINT; |
| 2656 | return 1; |
| 2657 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2658 | } |
| 2659 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2660 | /* Lookup for the reference. */ |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 2661 | appctx->ctx.map.ref = pat_ref_lookup_ref(args[2]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2662 | if (!appctx->ctx.map.ref) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2663 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2664 | 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] | 2665 | else |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 2666 | 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] | 2667 | appctx->st0 = STAT_CLI_PRINT; |
| 2668 | return 1; |
| 2669 | } |
| 2670 | |
Thierry FOURNIER | 64c585f | 2014-01-29 20:02:36 +0100 | [diff] [blame] | 2671 | /* The command "add acl" is prohibited if the reference |
| 2672 | * use samples. |
| 2673 | */ |
| 2674 | if ((appctx->ctx.map.display_flags & PAT_REF_ACL) && |
| 2675 | (appctx->ctx.map.ref->flags & PAT_REF_SMP)) { |
| 2676 | appctx->ctx.cli.msg = "This ACL is shared with a map containing samples. " |
| 2677 | "You must use the command 'add map' to add values.\n"; |
| 2678 | appctx->st0 = STAT_CLI_PRINT; |
| 2679 | return 1; |
| 2680 | } |
| 2681 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2682 | /* Add value. */ |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2683 | err = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2684 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2685 | 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] | 2686 | else |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 2687 | ret = pat_ref_add(appctx->ctx.map.ref, args[3], NULL, &err); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2688 | if (!ret) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2689 | if (err) |
| 2690 | memprintf(&err, "%s.\n", err); |
| 2691 | appctx->ctx.cli.err = err; |
| 2692 | appctx->st0 = STAT_CLI_PRINT_FREE; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2693 | return 1; |
| 2694 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2695 | |
| 2696 | /* The add is done, send message. */ |
Thierry FOURNIER | 07e78c5 | 2014-12-18 15:28:01 +0100 | [diff] [blame] | 2697 | appctx->st0 = STAT_CLI_PROMPT; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2698 | return 1; |
| 2699 | } |
| 2700 | else { /* unknown "del" parameter */ |
| 2701 | appctx->ctx.cli.msg = "'add' only supports 'map'.\n"; |
| 2702 | appctx->st0 = STAT_CLI_PRINT; |
| 2703 | return 1; |
| 2704 | } |
Cyril Bonté | cd19e51 | 2010-01-31 22:34:03 +0100 | [diff] [blame] | 2705 | } |
| 2706 | 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] | 2707 | return 0; |
| 2708 | } |
| 2709 | return 1; |
| 2710 | } |
| 2711 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2712 | /* 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] | 2713 | * used to processes I/O from/to the stats unix socket. The system relies on a |
| 2714 | * state machine handling requests and various responses. We read a request, |
| 2715 | * 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] | 2716 | * Then we can read again. The state is stored in appctx->st0 and is one of the |
| 2717 | * 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] | 2718 | * or not. |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2719 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2720 | static void cli_io_handler(struct appctx *appctx) |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2721 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 2722 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2723 | struct channel *req = si_oc(si); |
| 2724 | struct channel *res = si_ic(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2725 | int reql; |
| 2726 | int len; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2727 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2728 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 2729 | goto out; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2730 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2731 | while (1) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2732 | if (appctx->st0 == STAT_CLI_INIT) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2733 | /* Stats output not initialized yet */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2734 | memset(&appctx->ctx.stats, 0, sizeof(appctx->ctx.stats)); |
| 2735 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2736 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2737 | else if (appctx->st0 == STAT_CLI_END) { |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2738 | /* Let's close for real now. We just close the request |
| 2739 | * side, the conditions below will complete if needed. |
| 2740 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2741 | si_shutw(si); |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2742 | break; |
| 2743 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2744 | else if (appctx->st0 == STAT_CLI_GETREQ) { |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2745 | /* ensure we have some output room left in the event we |
| 2746 | * would want to return some info right after parsing. |
| 2747 | */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 2748 | if (buffer_almost_full(si_ib(si))) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2749 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2750 | break; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 2751 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 2752 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2753 | reql = bo_getline(si_oc(si), trash.str, trash.size); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2754 | if (reql <= 0) { /* closed or EOL not found */ |
| 2755 | if (reql == 0) |
| 2756 | break; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2757 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2758 | continue; |
| 2759 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2760 | |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2761 | /* seek for a possible semi-colon. If we find one, we |
| 2762 | * replace it with an LF and skip only this part. |
| 2763 | */ |
| 2764 | for (len = 0; len < reql; len++) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2765 | if (trash.str[len] == ';') { |
| 2766 | trash.str[len] = '\n'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2767 | reql = len + 1; |
| 2768 | break; |
| 2769 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2770 | |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2771 | /* now it is time to check that we have a full line, |
| 2772 | * remove the trailing \n and possibly \r, then cut the |
| 2773 | * line. |
| 2774 | */ |
| 2775 | len = reql - 1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2776 | if (trash.str[len] != '\n') { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2777 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2778 | continue; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2779 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2780 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2781 | if (len && trash.str[len-1] == '\r') |
Willy Tarreau | 816fc22 | 2009-10-04 07:36:58 +0200 | [diff] [blame] | 2782 | len--; |
| 2783 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2784 | trash.str[len] = '\0'; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2785 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2786 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2787 | if (len) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2788 | if (strcmp(trash.str, "quit") == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2789 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2790 | continue; |
| 2791 | } |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2792 | else if (strcmp(trash.str, "prompt") == 0) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2793 | appctx->st1 = !appctx->st1; |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 2794 | else if (strcmp(trash.str, "help") == 0 || |
| 2795 | !stats_sock_parse_request(si, trash.str)) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2796 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2797 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2798 | } |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2799 | /* NB: stats_sock_parse_request() may have put |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2800 | * another STAT_CLI_O_* into appctx->st0. |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2801 | */ |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2802 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2803 | else if (!appctx->st1) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2804 | /* if prompt is disabled, print help on empty lines, |
| 2805 | * so that the user at least knows how to enable |
| 2806 | * prompt and find help. |
| 2807 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2808 | appctx->ctx.cli.msg = stats_sock_usage_msg; |
| 2809 | appctx->st0 = STAT_CLI_PRINT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | /* re-adjust req buffer */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2813 | bo_skip(si_oc(si), reql); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2814 | req->flags |= CF_READ_DONTWAIT; /* we plan to read small requests */ |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2815 | } |
Willy Tarreau | 68c00c7 | 2015-09-25 19:21:19 +0200 | [diff] [blame] | 2816 | else { /* output functions */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2817 | switch (appctx->st0) { |
Andrew Hayworth | e32d186 | 2015-10-02 15:08:10 +0000 | [diff] [blame] | 2818 | case STAT_CLI_PROMPT: |
| 2819 | break; |
Willy Tarreau | ea1f5fe | 2009-10-11 23:12:51 +0200 | [diff] [blame] | 2820 | case STAT_CLI_PRINT: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2821 | if (bi_putstr(si_ic(si), appctx->ctx.cli.msg) != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2822 | appctx->st0 = STAT_CLI_PROMPT; |
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); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2825 | break; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2826 | case STAT_CLI_PRINT_FREE: |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2827 | if (bi_putstr(si_ic(si), appctx->ctx.cli.err) != -1) { |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2828 | free(appctx->ctx.cli.err); |
| 2829 | appctx->st0 = STAT_CLI_PROMPT; |
| 2830 | } |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2831 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2832 | si_applet_cant_put(si); |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 2833 | break; |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 2834 | case STAT_CLI_O_BACKEND: |
| 2835 | if (stats_dump_backend_to_buffer(si)) |
| 2836 | appctx->st0 = STAT_CLI_PROMPT; |
| 2837 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2838 | case STAT_CLI_O_INFO: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2839 | if (stats_dump_info_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2840 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2841 | break; |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 2842 | case STAT_CLI_O_SERVERS_STATE: |
| 2843 | if (stats_dump_servers_state_to_buffer(si)) |
| 2844 | appctx->st0 = STAT_CLI_PROMPT; |
| 2845 | break; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2846 | case STAT_CLI_O_STAT: |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2847 | if (stats_dump_stat_to_buffer(si, NULL)) |
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; |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 2850 | case STAT_CLI_O_RESOLVERS: |
| 2851 | if (stats_dump_resolvers_to_buffer(si)) |
| 2852 | appctx->st0 = STAT_CLI_PROMPT; |
| 2853 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2854 | case STAT_CLI_O_SESS: |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2855 | if (stats_dump_sess_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2856 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2857 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2858 | case STAT_CLI_O_ERR: /* errors dump */ |
Willy Tarreau | 5ec29ff | 2011-02-13 15:27:22 +0100 | [diff] [blame] | 2859 | if (stats_dump_errors_to_buffer(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2860 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2861 | break; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2862 | case STAT_CLI_O_TAB: |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 2863 | case STAT_CLI_O_CLR: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2864 | if (stats_table_request(si, appctx->st0)) |
| 2865 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 2866 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2867 | case STAT_CLI_O_PATS: |
| 2868 | if (stats_pats_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2869 | appctx->st0 = STAT_CLI_PROMPT; |
| 2870 | break; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 2871 | case STAT_CLI_O_PAT: |
| 2872 | if (stats_pat_list(si)) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 2873 | appctx->st0 = STAT_CLI_PROMPT; |
| 2874 | break; |
| 2875 | case STAT_CLI_O_MLOOK: |
| 2876 | if (stats_map_lookup(si)) |
| 2877 | appctx->st0 = STAT_CLI_PROMPT; |
Willy Tarreau | 4efb353 | 2014-01-29 12:13:39 +0100 | [diff] [blame] | 2878 | break; |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 2879 | case STAT_CLI_O_POOLS: |
| 2880 | if (stats_dump_pools_to_buffer(si)) |
| 2881 | appctx->st0 = STAT_CLI_PROMPT; |
| 2882 | break; |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 2883 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 2884 | case STAT_CLI_O_TLSK: |
| 2885 | if (stats_tlskeys_list(si)) |
| 2886 | appctx->st0 = STAT_CLI_PROMPT; |
| 2887 | break; |
| 2888 | #endif |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 2889 | case STAT_CLI_O_ENV: /* environment dump */ |
| 2890 | if (stats_dump_env_to_buffer(si)) |
| 2891 | appctx->st0 = STAT_CLI_PROMPT; |
| 2892 | break; |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2893 | default: /* abnormal state */ |
Willy Tarreau | 5cfa3bc | 2015-09-25 20:08:51 +0200 | [diff] [blame] | 2894 | si->flags |= SI_FL_ERR; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2895 | break; |
| 2896 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2897 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2898 | /* 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] | 2899 | if (appctx->st0 == STAT_CLI_PROMPT) { |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 2900 | if (bi_putstr(si_ic(si), appctx->st1 ? "\n> " : "\n") != -1) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2901 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 2902 | else |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 2903 | si_applet_cant_put(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2904 | } |
| 2905 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2906 | /* 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] | 2907 | if (appctx->st0 >= STAT_CLI_OUTPUT) |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2908 | break; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2909 | |
| 2910 | /* Now we close the output if one of the writers did so, |
| 2911 | * or if we're not in interactive mode and the request |
| 2912 | * buffer is empty. This still allows pipelined requests |
| 2913 | * to be sent in non-interactive mode. |
| 2914 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2915 | if ((res->flags & (CF_SHUTW|CF_SHUTW_NOW)) || (!appctx->st1 && !req->buf->o)) { |
| 2916 | appctx->st0 = STAT_CLI_END; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2917 | continue; |
| 2918 | } |
| 2919 | |
Willy Tarreau | f5a885f | 2009-10-04 14:22:18 +0200 | [diff] [blame] | 2920 | /* switch state back to GETREQ to read next requests */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2921 | appctx->st0 = STAT_CLI_GETREQ; |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2922 | } |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2923 | } |
Willy Tarreau | 5ca791d | 2009-08-16 19:06:42 +0200 | [diff] [blame] | 2924 | |
Willy Tarreau | c9e930a | 2015-09-25 20:06:08 +0200 | [diff] [blame] | 2925 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) { |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2926 | DPRINTF(stderr, "%s@%d: si to buf closed. req=%08x, res=%08x, st=%d\n", |
| 2927 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
Aman Gupta | ceafb4a | 2012-04-02 18:57:54 -0700 | [diff] [blame] | 2928 | /* 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] | 2929 | * and nothing more to consume. This is comparable to a broken pipe, so |
| 2930 | * we forward the close to the request side so that it flows upstream to |
| 2931 | * the client. |
| 2932 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2933 | si_shutw(si); |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2934 | } |
| 2935 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 2936 | 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] | 2937 | DPRINTF(stderr, "%s@%d: buf to si closed. req=%08x, res=%08x, st=%d\n", |
| 2938 | __FUNCTION__, __LINE__, req->flags, res->flags, si->state); |
| 2939 | /* We have no more processing to do, and nothing more to send, and |
| 2940 | * the client side has closed. So we'll forward this state downstream |
| 2941 | * on the response buffer. |
| 2942 | */ |
Willy Tarreau | 73b013b | 2012-05-21 16:31:45 +0200 | [diff] [blame] | 2943 | si_shutr(si); |
Willy Tarreau | 03cdb7c | 2012-08-27 23:14:58 +0200 | [diff] [blame] | 2944 | res->flags |= CF_READ_NULL; |
Willy Tarreau | 9a42c0d | 2009-09-22 19:31:03 +0200 | [diff] [blame] | 2945 | } |
| 2946 | |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 2947 | out: |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 2948 | 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] | 2949 | __FUNCTION__, __LINE__, |
Willy Tarreau | 9b28e03 | 2012-10-12 23:49:43 +0200 | [diff] [blame] | 2950 | 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] | 2951 | } |
| 2952 | |
Willy Tarreau | 638d40a | 2016-02-24 23:11:01 +0100 | [diff] [blame] | 2953 | /* Emits a stats field without any surrounding element and properly encoded to |
| 2954 | * resist CSV output. Returns non-zero on success, 0 if the buffer is full. |
| 2955 | */ |
| 2956 | static int stats_emit_raw_data_field(struct chunk *out, const struct field *f) |
| 2957 | { |
| 2958 | switch (field_format(f, 0)) { |
| 2959 | case FF_EMPTY: return 1; |
| 2960 | case FF_S32: return chunk_appendf(out, "%d", f->u.s32); |
| 2961 | case FF_U32: return chunk_appendf(out, "%u", f->u.u32); |
| 2962 | case FF_S64: return chunk_appendf(out, "%lld", (long long)f->u.s64); |
| 2963 | case FF_U64: return chunk_appendf(out, "%llu", (unsigned long long)f->u.u64); |
| 2964 | case FF_STR: return csv_enc_append(field_str(f, 0), 1, out) != NULL; |
| 2965 | default: return chunk_appendf(out, "[INCORRECT_FIELD_TYPE_%08x]", f->type); |
| 2966 | } |
| 2967 | } |
| 2968 | |
Willy Tarreau | bf95cba | 2016-01-11 18:27:29 +0100 | [diff] [blame] | 2969 | /* Dump all fields from <info> into <out> using the "show info" format (name: value) */ |
| 2970 | static int stats_dump_info_fields(struct chunk *out, const struct field *info) |
| 2971 | { |
| 2972 | int field; |
| 2973 | |
| 2974 | for (field = 0; field < INF_TOTAL_FIELDS; field++) { |
| 2975 | if (!field_format(info, field)) |
| 2976 | continue; |
| 2977 | |
| 2978 | if (!chunk_appendf(out, "%s: ", info_field_names[field])) |
| 2979 | return 0; |
| 2980 | if (!stats_emit_raw_data_field(out, &info[field])) |
| 2981 | return 0; |
| 2982 | if (!chunk_strcat(out, "\n")) |
| 2983 | return 0; |
| 2984 | } |
| 2985 | return 1; |
| 2986 | } |
| 2987 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2988 | /* This function dumps information onto the stream interface's read buffer. |
| 2989 | * It returns 0 as long as it does not complete, non-zero upon completion. |
| 2990 | * No state is used. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2991 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 2992 | static int stats_dump_info_to_buffer(struct stream_interface *si) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2993 | { |
| 2994 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 2995 | struct chunk *out = get_trash_chunk(); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 2996 | |
Willy Tarreau | 0c9c272 | 2014-05-28 12:28:58 +0200 | [diff] [blame] | 2997 | #ifdef USE_OPENSSL |
| 2998 | int ssl_sess_rate = read_freq_ctr(&global.ssl_per_sec); |
| 2999 | int ssl_key_rate = read_freq_ctr(&global.ssl_fe_keys_per_sec); |
| 3000 | int ssl_reuse = 0; |
| 3001 | |
| 3002 | if (ssl_key_rate < ssl_sess_rate) { |
| 3003 | /* count the ssl reuse ratio and avoid overflows in both directions */ |
| 3004 | ssl_reuse = 100 - (100 * ssl_key_rate + (ssl_sess_rate - 1) / 2) / ssl_sess_rate; |
| 3005 | } |
| 3006 | #endif |
| 3007 | |
Willy Tarreau | 4529c07 | 2016-01-11 18:17:07 +0100 | [diff] [blame] | 3008 | chunk_reset(out); |
| 3009 | memset(&info, 0, sizeof(info)); |
| 3010 | |
| 3011 | info[INF_NAME] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, PRODUCT_NAME); |
| 3012 | info[INF_VERSION] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_VERSION); |
| 3013 | info[INF_RELEASE_DATE] = mkf_str(FO_PRODUCT|FN_OUTPUT|FS_SERVICE, HAPROXY_DATE); |
| 3014 | |
| 3015 | info[INF_NBPROC] = mkf_u32(FO_CONFIG|FS_SERVICE, global.nbproc); |
| 3016 | info[INF_PROCESS_NUM] = mkf_u32(FO_KEY, relative_pid); |
| 3017 | info[INF_PID] = mkf_u32(FO_STATUS, pid); |
| 3018 | |
| 3019 | info[INF_UPTIME] = mkf_str(FN_DURATION, chunk_newstr(out)); |
| 3020 | chunk_appendf(out, "%ud %uh%02um%02us", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); |
| 3021 | |
| 3022 | info[INF_UPTIME_SEC] = mkf_u32(FN_DURATION, up); |
| 3023 | info[INF_MEMMAX_MB] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_memmax); |
| 3024 | info[INF_POOL_ALLOC_MB] = mkf_u32(0, (unsigned)(pool_total_allocated() / 1048576L)); |
| 3025 | info[INF_POOL_USED_MB] = mkf_u32(0, (unsigned)(pool_total_used() / 1048576L)); |
| 3026 | info[INF_POOL_FAILED] = mkf_u32(FN_COUNTER, pool_total_failures()); |
| 3027 | info[INF_ULIMIT_N] = mkf_u32(FO_CONFIG|FN_LIMIT, global.rlimit_nofile); |
| 3028 | info[INF_MAXSOCK] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxsock); |
| 3029 | info[INF_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxconn); |
| 3030 | info[INF_HARD_MAXCONN] = mkf_u32(FO_CONFIG|FN_LIMIT, global.hardmaxconn); |
| 3031 | info[INF_CURR_CONN] = mkf_u32(0, actconn); |
| 3032 | info[INF_CUM_CONN] = mkf_u32(FN_COUNTER, totalconn); |
| 3033 | info[INF_CUM_REQ] = mkf_u32(FN_COUNTER, global.req_count); |
| 3034 | #ifdef USE_OPENSSL |
| 3035 | info[INF_MAX_SSL_CONNS] = mkf_u32(FN_MAX, global.maxsslconn); |
| 3036 | info[INF_CURR_SSL_CONNS] = mkf_u32(0, sslconns); |
| 3037 | info[INF_CUM_SSL_CONNS] = mkf_u32(FN_COUNTER, totalsslconns); |
| 3038 | #endif |
| 3039 | info[INF_MAXPIPES] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxpipes); |
| 3040 | info[INF_PIPES_USED] = mkf_u32(0, pipes_used); |
| 3041 | info[INF_PIPES_FREE] = mkf_u32(0, pipes_free); |
| 3042 | info[INF_CONN_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.conn_per_sec)); |
| 3043 | info[INF_CONN_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.cps_lim); |
| 3044 | info[INF_MAX_CONN_RATE] = mkf_u32(FN_MAX, global.cps_max); |
| 3045 | info[INF_SESS_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.sess_per_sec)); |
| 3046 | info[INF_SESS_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.sps_lim); |
| 3047 | info[INF_MAX_SESS_RATE] = mkf_u32(FN_RATE, global.sps_max); |
| 3048 | |
| 3049 | #ifdef USE_OPENSSL |
| 3050 | info[INF_SSL_RATE] = mkf_u32(FN_RATE, ssl_sess_rate); |
| 3051 | info[INF_SSL_RATE_LIMIT] = mkf_u32(FO_CONFIG|FN_LIMIT, global.ssl_lim); |
| 3052 | info[INF_MAX_SSL_RATE] = mkf_u32(FN_MAX, global.ssl_max); |
| 3053 | info[INF_SSL_FRONTEND_KEY_RATE] = mkf_u32(0, ssl_key_rate); |
| 3054 | info[INF_SSL_FRONTEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_fe_keys_max); |
| 3055 | info[INF_SSL_FRONTEND_SESSION_REUSE_PCT] = mkf_u32(0, ssl_reuse); |
| 3056 | info[INF_SSL_BACKEND_KEY_RATE] = mkf_u32(FN_RATE, read_freq_ctr(&global.ssl_be_keys_per_sec)); |
| 3057 | info[INF_SSL_BACKEND_MAX_KEY_RATE] = mkf_u32(FN_MAX, global.ssl_be_keys_max); |
| 3058 | info[INF_SSL_CACHE_LOOKUPS] = mkf_u32(FN_COUNTER, global.shctx_lookups); |
| 3059 | info[INF_SSL_CACHE_MISSES] = mkf_u32(FN_COUNTER, global.shctx_misses); |
| 3060 | #endif |
| 3061 | info[INF_COMPRESS_BPS_IN] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_in)); |
| 3062 | info[INF_COMPRESS_BPS_OUT] = mkf_u32(FN_RATE, read_freq_ctr(&global.comp_bps_out)); |
| 3063 | info[INF_COMPRESS_BPS_RATE_LIM] = mkf_u32(FO_CONFIG|FN_LIMIT, global.comp_rate_lim); |
| 3064 | #ifdef USE_ZLIB |
| 3065 | info[INF_ZLIB_MEM_USAGE] = mkf_u32(0, zlib_used_memory); |
| 3066 | info[INF_MAX_ZLIB_MEM_USAGE] = mkf_u32(FO_CONFIG|FN_LIMIT, global.maxzlibmem); |
| 3067 | #endif |
| 3068 | info[INF_TASKS] = mkf_u32(0, nb_tasks_cur); |
| 3069 | info[INF_RUN_QUEUE] = mkf_u32(0, run_queue_cur); |
| 3070 | info[INF_IDLE_PCT] = mkf_u32(FN_AVG, idle_pct); |
| 3071 | info[INF_NODE] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.node); |
| 3072 | if (global.desc) |
| 3073 | info[INF_DESCRIPTION] = mkf_str(FO_CONFIG|FN_OUTPUT|FS_SERVICE, global.desc); |
| 3074 | |
Willy Tarreau | 1b4ba1e | 2016-01-11 18:29:04 +0100 | [diff] [blame] | 3075 | chunk_reset(&trash); |
| 3076 | stats_dump_info_fields(&trash, info); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3077 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3078 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3079 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3080 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3081 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3082 | |
| 3083 | return 1; |
| 3084 | } |
| 3085 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3086 | /* dumps server state information into <buf> for all the servers found in <backend> |
| 3087 | * These information are all the parameters which may change during HAProxy runtime. |
| 3088 | * By default, we only export to the last known server state file format. |
| 3089 | * These information can be used at next startup to recover same level of server state. |
| 3090 | */ |
| 3091 | static void dump_servers_state(struct proxy *backend, struct chunk *buf) |
| 3092 | { |
| 3093 | struct server *srv; |
| 3094 | char srv_addr[INET6_ADDRSTRLEN + 1]; |
| 3095 | time_t srv_time_since_last_change; |
| 3096 | int bk_f_forced_id, srv_f_forced_id; |
| 3097 | |
| 3098 | /* we don't want to report any state if the backend is not enabled on this process */ |
| 3099 | if (backend->bind_proc && !(backend->bind_proc & (1UL << (relative_pid - 1)))) |
| 3100 | return; |
| 3101 | |
| 3102 | srv = backend->srv; |
| 3103 | |
| 3104 | while (srv) { |
| 3105 | srv_addr[0] = '\0'; |
| 3106 | srv_time_since_last_change = 0; |
| 3107 | bk_f_forced_id = 0; |
| 3108 | srv_f_forced_id = 0; |
| 3109 | |
| 3110 | switch (srv->addr.ss_family) { |
| 3111 | case AF_INET: |
| 3112 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in *)&srv->addr)->sin_addr, |
| 3113 | srv_addr, INET_ADDRSTRLEN + 1); |
| 3114 | break; |
| 3115 | case AF_INET6: |
| 3116 | inet_ntop(srv->addr.ss_family, &((struct sockaddr_in6 *)&srv->addr)->sin6_addr, |
| 3117 | srv_addr, INET6_ADDRSTRLEN + 1); |
| 3118 | break; |
| 3119 | } |
| 3120 | srv_time_since_last_change = now.tv_sec - srv->last_change; |
| 3121 | bk_f_forced_id = backend->options & PR_O_FORCED_ID ? 1 : 0; |
| 3122 | srv_f_forced_id = srv->flags & SRV_F_FORCED_ID ? 1 : 0; |
| 3123 | |
| 3124 | chunk_appendf(buf, |
| 3125 | "%d %s " |
| 3126 | "%d %s %s " |
| 3127 | "%d %d %d %d %ld " |
| 3128 | "%d %d %d %d %d " |
| 3129 | "%d %d" |
| 3130 | "\n", |
| 3131 | backend->uuid, backend->id, |
| 3132 | srv->puid, srv->id, srv_addr, |
David Carlier | 081b336 | 2015-11-18 06:10:22 +0000 | [diff] [blame] | 3133 | 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] | 3134 | srv->check.status, srv->check.result, srv->check.health, srv->check.state, srv->agent.state, |
| 3135 | bk_f_forced_id, srv_f_forced_id); |
| 3136 | |
| 3137 | srv = srv->next; |
| 3138 | } |
| 3139 | } |
| 3140 | |
Baptiste Assmann | 9b6857e | 2015-09-18 14:49:12 +0200 | [diff] [blame] | 3141 | /* Parses backend list and simply report backend names */ |
| 3142 | static int stats_dump_backend_to_buffer(struct stream_interface *si) |
| 3143 | { |
| 3144 | extern struct proxy *proxy; |
| 3145 | struct proxy *curproxy; |
| 3146 | |
| 3147 | chunk_reset(&trash); |
| 3148 | chunk_printf(&trash, "# name\n"); |
| 3149 | |
| 3150 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3151 | /* looking for backends only */ |
| 3152 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3153 | continue; |
| 3154 | |
| 3155 | /* we don't want to list a backend which is bound to this process */ |
| 3156 | if (curproxy->bind_proc && !(curproxy->bind_proc & (1UL << (relative_pid - 1)))) |
| 3157 | continue; |
| 3158 | |
| 3159 | chunk_appendf(&trash, "%s\n", curproxy->id); |
| 3160 | } |
| 3161 | |
| 3162 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3163 | si_applet_cant_put(si); |
| 3164 | return 0; |
| 3165 | } |
| 3166 | |
| 3167 | return 1; |
| 3168 | } |
| 3169 | |
Baptiste Assmann | 2828946 | 2015-07-03 08:01:20 +0200 | [diff] [blame] | 3170 | /* Parses backend list or simply use backend name provided by the user to return |
| 3171 | * states of servers to stdout. |
| 3172 | */ |
| 3173 | static int stats_dump_servers_state_to_buffer(struct stream_interface *si) |
| 3174 | { |
| 3175 | struct appctx *appctx = __objt_appctx(si->end); |
| 3176 | extern struct proxy *proxy; |
| 3177 | struct proxy *curproxy; |
| 3178 | |
| 3179 | chunk_reset(&trash); |
| 3180 | |
| 3181 | chunk_printf(&trash, "%d\n# %s\n", SRV_STATE_FILE_VERSION, SRV_STATE_FILE_FIELD_NAMES); |
| 3182 | |
| 3183 | if (appctx->ctx.server_state.backend) { |
| 3184 | dump_servers_state(appctx->ctx.server_state.backend, &trash); |
| 3185 | } |
| 3186 | else { |
| 3187 | for (curproxy = proxy; curproxy != NULL; curproxy = curproxy->next) { |
| 3188 | /* servers are only in backends */ |
| 3189 | if (!(curproxy->cap & PR_CAP_BE)) |
| 3190 | continue; |
| 3191 | |
| 3192 | dump_servers_state(curproxy, &trash); |
| 3193 | } |
| 3194 | } |
| 3195 | |
| 3196 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 3197 | si_applet_cant_put(si); |
| 3198 | return 0; |
| 3199 | } |
| 3200 | |
| 3201 | return 1; |
| 3202 | } |
| 3203 | |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3204 | /* This function dumps memory usage information onto the stream interface's |
| 3205 | * read buffer. It returns 0 as long as it does not complete, non-zero upon |
| 3206 | * completion. No state is used. |
| 3207 | */ |
| 3208 | static int stats_dump_pools_to_buffer(struct stream_interface *si) |
| 3209 | { |
| 3210 | dump_pools_to_trash(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3211 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 3212 | si_applet_cant_put(si); |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3213 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 3214 | } |
Willy Tarreau | 12833bb | 2014-01-28 16:49:56 +0100 | [diff] [blame] | 3215 | return 1; |
| 3216 | } |
| 3217 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3218 | /* Dumps a frontend's line to the trash for the current proxy <px> and uses |
| 3219 | * the state from stream interface <si>. The caller is responsible for clearing |
| 3220 | * 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] | 3221 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3222 | 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] | 3223 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3224 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3225 | int i; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3226 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3227 | if (!(px->cap & PR_CAP_FE)) |
| 3228 | return 0; |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3229 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3230 | 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] | 3231 | return 0; |
| 3232 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3233 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3234 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3235 | /* name, queue */ |
| 3236 | "<tr class=\"frontend\">"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3237 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3238 | 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] | 3239 | /* Column sub-heading for Enable or Disable server */ |
| 3240 | chunk_appendf(&trash, "<td></td>"); |
| 3241 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3242 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3243 | chunk_appendf(&trash, |
| 3244 | "<td class=ac>" |
| 3245 | "<a name=\"%s/Frontend\"></a>" |
| 3246 | "<a class=lfsb href=\"#%s/Frontend\">Frontend</a></td>" |
| 3247 | "<td colspan=3></td>" |
| 3248 | "", |
| 3249 | px->id, px->id); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3250 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3251 | chunk_appendf(&trash, |
| 3252 | /* sessions rate : current */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3253 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3254 | "<tr><th>Current connection rate:</th><td>%s/s</td></tr>" |
| 3255 | "<tr><th>Current session rate:</th><td>%s/s</td></tr>" |
| 3256 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3257 | U2H(read_freq_ctr(&px->fe_sess_per_sec)), |
| 3258 | U2H(read_freq_ctr(&px->fe_conn_per_sec)), |
| 3259 | U2H(read_freq_ctr(&px->fe_sess_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3260 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3261 | if (px->mode == PR_MODE_HTTP) |
| 3262 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3263 | "<tr><th>Current request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3264 | U2H(read_freq_ctr(&px->fe_req_per_sec))); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3265 | |
| 3266 | chunk_appendf(&trash, |
| 3267 | "</table></div></u></td>" |
| 3268 | /* sessions rate : max */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3269 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3270 | "<tr><th>Max connection rate:</th><td>%s/s</td></tr>" |
| 3271 | "<tr><th>Max session rate:</th><td>%s/s</td></tr>" |
| 3272 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3273 | U2H(px->fe_counters.sps_max), |
| 3274 | U2H(px->fe_counters.cps_max), |
| 3275 | U2H(px->fe_counters.sps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3276 | |
| 3277 | if (px->mode == PR_MODE_HTTP) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3278 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3279 | "<tr><th>Max request rate:</th><td>%s/s</td></tr>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3280 | U2H(px->fe_counters.p.http.rps_max)); |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3281 | |
| 3282 | chunk_appendf(&trash, |
| 3283 | "</table></div></u></td>" |
| 3284 | /* sessions rate : limit */ |
| 3285 | "<td>%s</td>", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3286 | LIM2A(px->fe_sps_lim, "-")); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3287 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3288 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3289 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3290 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3291 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3292 | "<tr><th>Cum. connections:</th><td>%s</td></tr>" |
| 3293 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3294 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3295 | U2H(px->feconn), U2H(px->fe_counters.conn_max), U2H(px->maxconn), |
| 3296 | U2H(px->fe_counters.cum_sess), |
| 3297 | U2H(px->fe_counters.cum_conn), |
| 3298 | U2H(px->fe_counters.cum_sess)); |
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 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3301 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3302 | chunk_appendf(&trash, |
| 3303 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 3304 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 3305 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 3306 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3307 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 3308 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 3309 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 3310 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 3311 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
| 3312 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3313 | U2H(px->fe_counters.p.http.cum_req), |
| 3314 | U2H(px->fe_counters.p.http.rsp[1]), |
| 3315 | U2H(px->fe_counters.p.http.rsp[2]), |
| 3316 | U2H(px->fe_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3317 | px->fe_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3318 | (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] | 3319 | U2H(px->fe_counters.p.http.rsp[3]), |
| 3320 | U2H(px->fe_counters.p.http.rsp[4]), |
| 3321 | U2H(px->fe_counters.p.http.rsp[5]), |
| 3322 | U2H(px->fe_counters.p.http.rsp[0]), |
| 3323 | U2H(px->fe_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3324 | } |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3325 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3326 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3327 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3328 | /* sessions: lbtot, lastsess */ |
| 3329 | "<td></td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3330 | /* bytes : in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3331 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3332 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3333 | U2H(px->fe_counters.bytes_in)); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3334 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3335 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3336 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3337 | "<td>%s%s<div class=tips><table class=det>" |
| 3338 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 3339 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 3340 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3341 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 3342 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3343 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3344 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3345 | U2H(px->fe_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 3346 | U2H(px->fe_counters.bytes_out), |
| 3347 | U2H(px->fe_counters.comp_in), |
| 3348 | U2H(px->fe_counters.comp_out), |
| 3349 | px->fe_counters.comp_in ? (int)(px->fe_counters.comp_out * 100 / px->fe_counters.comp_in) : 0, |
| 3350 | U2H(px->fe_counters.comp_byp), |
| 3351 | U2H(px->fe_counters.comp_in - px->fe_counters.comp_out), |
| 3352 | 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] | 3353 | (px->fe_counters.comp_in || px->fe_counters.comp_byp) ? "</u>":""); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3354 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3355 | chunk_appendf(&trash, |
| 3356 | /* denied: req, resp */ |
| 3357 | "<td>%s</td><td>%s</td>" |
| 3358 | /* errors : request, connect, response */ |
| 3359 | "<td>%s</td><td></td><td></td>" |
| 3360 | /* warnings: retries, redispatches */ |
| 3361 | "<td></td><td></td>" |
| 3362 | /* server status : reflect frontend status */ |
| 3363 | "<td class=ac>%s</td>" |
| 3364 | /* rest of server: nothing */ |
| 3365 | "<td class=ac colspan=8></td></tr>" |
| 3366 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3367 | U2H(px->fe_counters.denied_req), U2H(px->fe_counters.denied_resp), |
| 3368 | U2H(px->fe_counters.failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3369 | px->state == PR_STREADY ? "OPEN" : |
| 3370 | px->state == PR_STFULL ? "FULL" : "STOP"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3371 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3372 | else { /* CSV mode */ |
| 3373 | chunk_appendf(&trash, |
| 3374 | /* pxid, name, queue cur, queue max, */ |
| 3375 | "%s,FRONTEND,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3376 | /* sessions : current, max, limit, total */ |
| 3377 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3378 | /* bytes : in, out */ |
| 3379 | "%lld,%lld," |
| 3380 | /* denied: req, resp */ |
| 3381 | "%lld,%lld," |
| 3382 | /* errors : request, connect, response */ |
| 3383 | "%lld,,," |
| 3384 | /* warnings: retries, redispatches */ |
| 3385 | ",," |
| 3386 | /* server status : reflect frontend status */ |
| 3387 | "%s," |
| 3388 | /* rest of server: nothing */ |
| 3389 | ",,,,,,,," |
| 3390 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3391 | "%d,%d,0,,,,%d," |
| 3392 | /* rate, rate_lim, rate_max */ |
| 3393 | "%u,%u,%u," |
| 3394 | /* check_status, check_code, check_duration */ |
| 3395 | ",,,", |
| 3396 | px->id, |
| 3397 | px->feconn, px->fe_counters.conn_max, px->maxconn, px->fe_counters.cum_sess, |
| 3398 | px->fe_counters.bytes_in, px->fe_counters.bytes_out, |
| 3399 | px->fe_counters.denied_req, px->fe_counters.denied_resp, |
| 3400 | px->fe_counters.failed_req, |
| 3401 | px->state == PR_STREADY ? "OPEN" : |
| 3402 | px->state == PR_STFULL ? "FULL" : "STOP", |
| 3403 | relative_pid, px->uuid, STATS_TYPE_FE, |
| 3404 | read_freq_ctr(&px->fe_sess_per_sec), |
| 3405 | px->fe_sps_lim, px->fe_counters.sps_max); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3406 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3407 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3408 | if (px->mode == PR_MODE_HTTP) { |
| 3409 | for (i=1; i<6; i++) |
| 3410 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[i]); |
| 3411 | chunk_appendf(&trash, "%lld,", px->fe_counters.p.http.rsp[0]); |
| 3412 | } |
| 3413 | else |
| 3414 | chunk_appendf(&trash, ",,,,,,"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3415 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3416 | /* failed health analyses */ |
| 3417 | chunk_appendf(&trash, ","); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3418 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3419 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3420 | chunk_appendf(&trash, "%u,%u,%lld,", |
| 3421 | read_freq_ctr(&px->fe_req_per_sec), |
| 3422 | px->fe_counters.p.http.rps_max, px->fe_counters.p.http.cum_req); |
| 3423 | |
| 3424 | /* errors: cli_aborts, srv_aborts */ |
| 3425 | chunk_appendf(&trash, ",,"); |
| 3426 | |
| 3427 | /* compression: in, out, bypassed */ |
| 3428 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 3429 | px->fe_counters.comp_in, px->fe_counters.comp_out, px->fe_counters.comp_byp); |
| 3430 | |
| 3431 | /* compression: comp_rsp */ |
| 3432 | chunk_appendf(&trash, "%lld,", |
| 3433 | px->fe_counters.p.http.comp_rsp); |
| 3434 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3435 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3436 | chunk_appendf(&trash, ",,,,,,,"); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3437 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3438 | /* finish with EOL */ |
| 3439 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3440 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3441 | return 1; |
Willy Tarreau | b0c9bc4 | 2009-10-04 15:56:38 +0200 | [diff] [blame] | 3442 | } |
| 3443 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3444 | /* Dumps a line for listener <l> and proxy <px> to the trash and uses the state |
| 3445 | * from stream interface <si>, and stats flags <flags>. The caller is responsible |
| 3446 | * for clearing the trash if needed. Returns non-zero if it emits anything, zero |
| 3447 | * otherwise. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3448 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3449 | 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] | 3450 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3451 | struct appctx *appctx = __objt_appctx(si->end); |
| 3452 | |
| 3453 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3454 | chunk_appendf(&trash, "<tr class=socket>"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3455 | 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] | 3456 | /* Column sub-heading for Enable or Disable server */ |
| 3457 | chunk_appendf(&trash, "<td></td>"); |
| 3458 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3459 | chunk_appendf(&trash, |
| 3460 | /* frontend name, listener name */ |
| 3461 | "<td class=ac><a name=\"%s/+%s\"></a>%s" |
| 3462 | "<a class=lfsb href=\"#%s/+%s\">%s</a>" |
| 3463 | "", |
| 3464 | px->id, l->name, |
| 3465 | (flags & ST_SHLGNDS)?"<u>":"", |
| 3466 | px->id, l->name, l->name); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3467 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3468 | if (flags & ST_SHLGNDS) { |
| 3469 | char str[INET6_ADDRSTRLEN]; |
| 3470 | int port; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3471 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3472 | chunk_appendf(&trash, "<div class=tips>"); |
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 | port = get_host_port(&l->addr); |
| 3475 | switch (addr_to_str(&l->addr, str, sizeof(str))) { |
| 3476 | case AF_INET: |
| 3477 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, port); |
| 3478 | break; |
| 3479 | case AF_INET6: |
| 3480 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, port); |
| 3481 | break; |
| 3482 | case AF_UNIX: |
| 3483 | chunk_appendf(&trash, "unix, "); |
| 3484 | break; |
| 3485 | case -1: |
| 3486 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3487 | break; |
| 3488 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3489 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3490 | /* id */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3491 | chunk_appendf(&trash, "id: %d</div>", l->luid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3492 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3493 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3494 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3495 | /* queue */ |
| 3496 | "%s</td><td colspan=3></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3497 | /* sessions rate: current, max, limit */ |
| 3498 | "<td colspan=3> </td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3499 | /* sessions: current, max, limit, total, lbtot, lastsess */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3500 | "<td>%s</td><td>%s</td><td>%s</td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3501 | "<td>%s</td><td> </td><td> </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3502 | /* bytes: in, out */ |
| 3503 | "<td>%s</td><td>%s</td>" |
| 3504 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3505 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3506 | U2H(l->nbconn), U2H(l->counters->conn_max), U2H(l->maxconn), |
| 3507 | 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] | 3508 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3509 | chunk_appendf(&trash, |
| 3510 | /* denied: req, resp */ |
| 3511 | "<td>%s</td><td>%s</td>" |
| 3512 | /* errors: request, connect, response */ |
| 3513 | "<td>%s</td><td></td><td></td>" |
| 3514 | /* warnings: retries, redispatches */ |
| 3515 | "<td></td><td></td>" |
| 3516 | /* server status: reflect listener status */ |
| 3517 | "<td class=ac>%s</td>" |
| 3518 | /* rest of server: nothing */ |
| 3519 | "<td class=ac colspan=8></td></tr>" |
| 3520 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3521 | U2H(l->counters->denied_req), U2H(l->counters->denied_resp), |
| 3522 | U2H(l->counters->failed_req), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3523 | (l->nbconn < l->maxconn) ? (l->state == LI_LIMITED) ? "WAITING" : "OPEN" : "FULL"); |
| 3524 | } |
| 3525 | else { /* CSV mode */ |
| 3526 | chunk_appendf(&trash, |
| 3527 | /* pxid, name, queue cur, queue max, */ |
| 3528 | "%s,%s,,," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3529 | /* sessions: current, max, limit, total */ |
| 3530 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3531 | /* bytes: in, out */ |
| 3532 | "%lld,%lld," |
| 3533 | /* denied: req, resp */ |
| 3534 | "%lld,%lld," |
| 3535 | /* errors: request, connect, response */ |
| 3536 | "%lld,,," |
| 3537 | /* warnings: retries, redispatches */ |
| 3538 | ",," |
| 3539 | /* server status: reflect listener status */ |
| 3540 | "%s," |
| 3541 | /* rest of server: nothing */ |
| 3542 | ",,,,,,,," |
| 3543 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 3544 | "%d,%d,%d,,,,%d," |
| 3545 | /* rate, rate_lim, rate_max */ |
| 3546 | ",,," |
| 3547 | /* check_status, check_code, check_duration */ |
| 3548 | ",,," |
| 3549 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3550 | ",,,,,," |
| 3551 | /* failed health analyses */ |
| 3552 | "," |
| 3553 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 3554 | ",,," |
| 3555 | /* errors: cli_aborts, srv_aborts */ |
| 3556 | ",," |
| 3557 | /* compression: in, out, bypassed, comp_rsp */ |
| 3558 | ",,,," |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3559 | /* lastsess, last_chk, last_agt, qtime, ctime, rtime, ttime, */ |
| 3560 | ",,,,,,," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3561 | "\n", |
| 3562 | px->id, l->name, |
| 3563 | l->nbconn, l->counters->conn_max, |
| 3564 | l->maxconn, l->counters->cum_conn, |
| 3565 | l->counters->bytes_in, l->counters->bytes_out, |
| 3566 | l->counters->denied_req, l->counters->denied_resp, |
| 3567 | l->counters->failed_req, |
| 3568 | (l->nbconn < l->maxconn) ? "OPEN" : "FULL", |
| 3569 | relative_pid, px->uuid, l->luid, STATS_TYPE_SO); |
| 3570 | } |
| 3571 | return 1; |
| 3572 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3573 | |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3574 | enum srv_stats_state { |
| 3575 | SRV_STATS_STATE_DOWN = 0, |
| 3576 | SRV_STATS_STATE_DOWN_AGENT, |
| 3577 | SRV_STATS_STATE_GOING_UP, |
| 3578 | SRV_STATS_STATE_UP_GOING_DOWN, |
| 3579 | SRV_STATS_STATE_UP, |
| 3580 | SRV_STATS_STATE_NOLB_GOING_DOWN, |
| 3581 | SRV_STATS_STATE_NOLB, |
| 3582 | SRV_STATS_STATE_DRAIN_GOING_DOWN, |
| 3583 | SRV_STATS_STATE_DRAIN, |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3584 | SRV_STATS_STATE_DRAIN_AGENT, |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3585 | SRV_STATS_STATE_NO_CHECK, |
| 3586 | |
| 3587 | SRV_STATS_STATE_COUNT, /* Must be last */ |
| 3588 | }; |
| 3589 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3590 | enum srv_stats_colour { |
| 3591 | SRV_STATS_COLOUR_DOWN = 0, |
| 3592 | SRV_STATS_COLOUR_GOING_UP, |
| 3593 | SRV_STATS_COLOUR_GOING_DOWN, |
| 3594 | SRV_STATS_COLOUR_UP, |
| 3595 | SRV_STATS_COLOUR_NOLB, |
| 3596 | SRV_STATS_COLOUR_DRAINING, |
| 3597 | SRV_STATS_COLOUR_NO_CHECK, |
| 3598 | |
| 3599 | SRV_STATS_COLOUR_COUNT, /* Must be last */ |
| 3600 | }; |
| 3601 | |
| 3602 | static const char *srv_stats_colour_st[SRV_STATS_COLOUR_COUNT] = { |
| 3603 | [SRV_STATS_COLOUR_DOWN] = "down", |
| 3604 | [SRV_STATS_COLOUR_GOING_UP] = "going_up", |
| 3605 | [SRV_STATS_COLOUR_GOING_DOWN] = "going_down", |
| 3606 | [SRV_STATS_COLOUR_UP] = "up", |
| 3607 | [SRV_STATS_COLOUR_NOLB] = "nolb", |
| 3608 | [SRV_STATS_COLOUR_DRAINING] = "draining", |
| 3609 | [SRV_STATS_COLOUR_NO_CHECK] = "no_check", |
| 3610 | }; |
| 3611 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3612 | /* Dumps a line for server <sv> and proxy <px> to the trash and uses the state |
| 3613 | * from stream interface <si>, stats flags <flags>, and server state <state>. |
| 3614 | * 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] | 3615 | * if it emits anything, zero otherwise. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3616 | */ |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3617 | 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] | 3618 | enum srv_stats_state state, enum srv_stats_colour colour) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3619 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3620 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3621 | struct server *via, *ref; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3622 | char str[INET6_ADDRSTRLEN]; |
| 3623 | struct chunk src; |
| 3624 | int i; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3625 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3626 | /* we have "via" which is the tracked server as described in the configuration, |
| 3627 | * and "ref" which is the checked server and the end of the chain. |
| 3628 | */ |
| 3629 | via = sv->track ? sv->track : sv; |
| 3630 | ref = via; |
| 3631 | while (ref->track) |
| 3632 | ref = ref->track; |
| 3633 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3634 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3635 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3636 | [SRV_STATS_STATE_DOWN] = "DOWN", |
| 3637 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent)", |
| 3638 | [SRV_STATS_STATE_GOING_UP] = "DN %d/%d ↑", |
| 3639 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d ↓", |
| 3640 | [SRV_STATS_STATE_UP] = "UP", |
| 3641 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d ↓", |
| 3642 | [SRV_STATS_STATE_NOLB] = "NOLB", |
| 3643 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d ↓", |
| 3644 | [SRV_STATS_STATE_DRAIN] = "DRAIN", |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 3645 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent)", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3646 | [SRV_STATS_STATE_NO_CHECK] = "<i>no check</i>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3647 | }; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3648 | |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3649 | if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3650 | chunk_appendf(&trash, "<tr class=\"maintain\">"); |
| 3651 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 3652 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 3653 | "<tr class=\"%s_%s\">", |
| 3654 | (sv->flags & SRV_F_BACKUP) ? "backup" : "active", srv_stats_colour_st[colour]); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3655 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 3656 | 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] | 3657 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3658 | "<td><input type=\"checkbox\" name=\"s\" value=\"%s\"></td>", |
| 3659 | sv->id); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3660 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3661 | chunk_appendf(&trash, |
| 3662 | "<td class=ac><a name=\"%s/%s\"></a>%s" |
| 3663 | "<a class=lfsb href=\"#%s/%s\">%s</a>" |
| 3664 | "", |
| 3665 | px->id, sv->id, |
| 3666 | (flags & ST_SHLGNDS) ? "<u>" : "", |
| 3667 | px->id, sv->id, sv->id); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3668 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3669 | if (flags & ST_SHLGNDS) { |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3670 | chunk_appendf(&trash, "<div class=tips>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3671 | |
| 3672 | switch (addr_to_str(&sv->addr, str, sizeof(str))) { |
| 3673 | case AF_INET: |
| 3674 | chunk_appendf(&trash, "IPv4: %s:%d, ", str, get_host_port(&sv->addr)); |
| 3675 | break; |
| 3676 | case AF_INET6: |
| 3677 | chunk_appendf(&trash, "IPv6: [%s]:%d, ", str, get_host_port(&sv->addr)); |
| 3678 | break; |
| 3679 | case AF_UNIX: |
| 3680 | chunk_appendf(&trash, "unix, "); |
| 3681 | break; |
| 3682 | case -1: |
| 3683 | chunk_appendf(&trash, "(%s), ", strerror(errno)); |
| 3684 | break; |
| 3685 | default: /* address family not supported */ |
| 3686 | break; |
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 | /* id */ |
| 3690 | chunk_appendf(&trash, "id: %d", sv->puid); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3691 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3692 | /* cookie */ |
| 3693 | if (sv->cookie) { |
| 3694 | chunk_appendf(&trash, ", cookie: '"); |
Willy Tarreau | 5031e6a | 2007-10-18 11:05:48 +0200 | [diff] [blame] | 3695 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3696 | chunk_initlen(&src, sv->cookie, 0, strlen(sv->cookie)); |
| 3697 | chunk_htmlencode(&trash, &src); |
Willy Tarreau | b1356cf | 2008-12-07 16:06:43 +0100 | [diff] [blame] | 3698 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3699 | chunk_appendf(&trash, "'"); |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 3700 | } |
| 3701 | |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3702 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3703 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3704 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3705 | chunk_appendf(&trash, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3706 | /* queue : current, max, limit */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3707 | "%s</td><td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3708 | /* sessions rate : current, max, limit */ |
| 3709 | "<td>%s</td><td>%s</td><td></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3710 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3711 | (flags & ST_SHLGNDS) ? "</u>" : "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3712 | U2H(sv->nbpend), U2H(sv->counters.nbpend_max), LIM2A(sv->maxqueue, "-"), |
| 3713 | 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] | 3714 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3715 | |
| 3716 | chunk_appendf(&trash, |
| 3717 | /* sessions: current, max, limit, total */ |
| 3718 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3719 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3720 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
| 3721 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3722 | U2H(sv->cur_sess), U2H(sv->counters.cur_sess_max), LIM2A(sv->maxconn, "-"), |
| 3723 | U2H(sv->counters.cum_sess), |
| 3724 | U2H(sv->counters.cum_sess)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3725 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3726 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 3727 | if (px->mode == PR_MODE_HTTP) { |
| 3728 | unsigned long long tot; |
| 3729 | for (tot = i = 0; i < 6; i++) |
| 3730 | tot += sv->counters.p.http.rsp[i]; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3731 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3732 | chunk_appendf(&trash, |
| 3733 | "<tr><th>Cum. HTTP responses:</th><td>%s</td></tr>" |
| 3734 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3735 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3736 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3737 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3738 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3739 | "<tr><th>- other responses:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 3740 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3741 | U2H(tot), |
| 3742 | U2H(sv->counters.p.http.rsp[1]), tot ? (int)(100*sv->counters.p.http.rsp[1] / tot) : 0, |
| 3743 | U2H(sv->counters.p.http.rsp[2]), tot ? (int)(100*sv->counters.p.http.rsp[2] / tot) : 0, |
| 3744 | U2H(sv->counters.p.http.rsp[3]), tot ? (int)(100*sv->counters.p.http.rsp[3] / tot) : 0, |
| 3745 | U2H(sv->counters.p.http.rsp[4]), tot ? (int)(100*sv->counters.p.http.rsp[4] / tot) : 0, |
| 3746 | U2H(sv->counters.p.http.rsp[5]), tot ? (int)(100*sv->counters.p.http.rsp[5] / tot) : 0, |
| 3747 | 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] | 3748 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3749 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 3750 | chunk_appendf(&trash, "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>"); |
| 3751 | 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))); |
| 3752 | 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))); |
| 3753 | if (px->mode == PR_MODE_HTTP) |
| 3754 | 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))); |
| 3755 | 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))); |
| 3756 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3757 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 3758 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 3759 | /* sessions: lbtot, last */ |
| 3760 | "<td>%s</td><td>%s</td>", |
| 3761 | U2H(sv->counters.cum_lbconn), |
| 3762 | human_time(srv_lastsession(sv), 1)); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3763 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3764 | chunk_appendf(&trash, |
| 3765 | /* bytes : in, out */ |
| 3766 | "<td>%s</td><td>%s</td>" |
| 3767 | /* denied: req, resp */ |
| 3768 | "<td></td><td>%s</td>" |
| 3769 | /* errors : request, connect */ |
| 3770 | "<td></td><td>%s</td>" |
| 3771 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3772 | "<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] | 3773 | /* warnings: retries, redispatches */ |
| 3774 | "<td>%lld</td><td>%lld</td>" |
| 3775 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3776 | U2H(sv->counters.bytes_in), U2H(sv->counters.bytes_out), |
| 3777 | U2H(sv->counters.failed_secu), |
| 3778 | U2H(sv->counters.failed_conns), |
| 3779 | U2H(sv->counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3780 | sv->counters.cli_aborts, |
| 3781 | sv->counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3782 | sv->counters.retries, sv->counters.redispatches); |
| 3783 | |
| 3784 | /* status, lest check */ |
| 3785 | chunk_appendf(&trash, "<td class=ac>"); |
| 3786 | |
Willy Tarreau | 2012521 | 2014-05-13 19:44:56 +0200 | [diff] [blame] | 3787 | if (sv->admin & SRV_ADMF_MAINT) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3788 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - sv->last_change, 1)); |
| 3789 | chunk_appendf(&trash, "MAINT"); |
| 3790 | } |
Simon Horman | 0766e44 | 2014-11-12 15:55:54 +0900 | [diff] [blame] | 3791 | 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] | 3792 | 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] | 3793 | /* DOWN (agent) */ |
| 3794 | 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] | 3795 | } |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3796 | else if (ref->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3797 | chunk_appendf(&trash, "%s ", human_time(now.tv_sec - ref->last_change, 1)); |
| 3798 | chunk_appendf(&trash, |
| 3799 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3800 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3801 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 3802 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 3803 | |
Willy Tarreau | cf2924b | 2014-05-23 12:15:15 +0200 | [diff] [blame] | 3804 | if ((sv->state == SRV_ST_STOPPED) && |
| 3805 | ((sv->agent.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) && !(sv->agent.health)) { |
| 3806 | chunk_appendf(&trash, |
| 3807 | "</td><td class=ac><u> %s%s", |
| 3808 | (sv->agent.state & CHK_ST_INPROGRESS) ? "* " : "", |
| 3809 | get_check_status_info(sv->agent.status)); |
| 3810 | |
| 3811 | if (sv->agent.status >= HCHK_STATUS_L57DATA) |
| 3812 | chunk_appendf(&trash, "/%d", sv->agent.code); |
| 3813 | |
| 3814 | if (sv->agent.status >= HCHK_STATUS_CHECKED && sv->agent.duration >= 0) |
| 3815 | chunk_appendf(&trash, " in %lums", sv->agent.duration); |
| 3816 | |
| 3817 | chunk_appendf(&trash, "<div class=tips>%s", |
| 3818 | get_check_status_description(sv->agent.status)); |
| 3819 | if (*sv->agent.desc) { |
| 3820 | chunk_appendf(&trash, ": "); |
| 3821 | chunk_initlen(&src, sv->agent.desc, 0, strlen(sv->agent.desc)); |
| 3822 | chunk_htmlencode(&trash, &src); |
| 3823 | } |
| 3824 | chunk_appendf(&trash, "</div></u>"); |
| 3825 | } |
| 3826 | 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] | 3827 | chunk_appendf(&trash, |
| 3828 | "</td><td class=ac><u> %s%s", |
Willy Tarreau | 2c115e5 | 2013-12-11 19:41:16 +0100 | [diff] [blame] | 3829 | (sv->check.state & CHK_ST_INPROGRESS) ? "* " : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3830 | get_check_status_info(sv->check.status)); |
| 3831 | |
| 3832 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3833 | chunk_appendf(&trash, "/%d", sv->check.code); |
| 3834 | |
| 3835 | if (sv->check.status >= HCHK_STATUS_CHECKED && sv->check.duration >= 0) |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3836 | chunk_appendf(&trash, " in %lums", sv->check.duration); |
| 3837 | |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3838 | chunk_appendf(&trash, "<div class=tips>%s", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3839 | get_check_status_description(sv->check.status)); |
| 3840 | if (*sv->check.desc) { |
| 3841 | chunk_appendf(&trash, ": "); |
| 3842 | chunk_initlen(&src, sv->check.desc, 0, strlen(sv->check.desc)); |
| 3843 | chunk_htmlencode(&trash, &src); |
| 3844 | } |
| 3845 | chunk_appendf(&trash, "</div></u>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3846 | } |
| 3847 | else |
| 3848 | chunk_appendf(&trash, "</td><td>"); |
| 3849 | |
| 3850 | chunk_appendf(&trash, |
| 3851 | /* weight */ |
| 3852 | "</td><td class=ac>%d</td>" |
| 3853 | /* act, bck */ |
| 3854 | "<td class=ac>%s</td><td class=ac>%s</td>" |
| 3855 | "", |
| 3856 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3857 | (sv->flags & SRV_F_BACKUP) ? "-" : "Y", |
| 3858 | (sv->flags & SRV_F_BACKUP) ? "Y" : "-"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3859 | |
| 3860 | /* check failures: unique, fatal, down time */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3861 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3862 | chunk_appendf(&trash, "<td><u>%lld", ref->counters.failed_checks); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3863 | |
| 3864 | if (ref->observe) |
| 3865 | chunk_appendf(&trash, "/%lld", ref->counters.failed_hana); |
| 3866 | |
| 3867 | chunk_appendf(&trash, |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 3868 | "<div class=tips>Failed Health Checks%s</div></u></td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3869 | "<td>%lld</td><td>%s</td>" |
| 3870 | "", |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 3871 | ref->observe ? "/Health Analyses" : "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3872 | ref->counters.down_trans, human_time(srv_downtime(sv), 1)); |
| 3873 | } |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3874 | else if (!(sv->admin & SRV_ADMF_FMAINT) && sv != ref) { |
| 3875 | /* tracking a server */ |
| 3876 | chunk_appendf(&trash, |
| 3877 | "<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] | 3878 | via->proxy->id, via->id, via->proxy->id, via->id); |
Willy Tarreau | f465994 | 2013-11-28 10:50:06 +0100 | [diff] [blame] | 3879 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3880 | else |
| 3881 | chunk_appendf(&trash, "<td colspan=3></td>"); |
| 3882 | |
| 3883 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3884 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3885 | 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] | 3886 | else |
| 3887 | chunk_appendf(&trash, "<td class=ac>-</td></tr>\n"); |
| 3888 | } |
| 3889 | else { /* CSV mode */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3890 | struct chunk *out = get_trash_chunk(); |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3891 | static char *srv_hlt_st[SRV_STATS_STATE_COUNT] = { |
| 3892 | [SRV_STATS_STATE_DOWN] = "DOWN,", |
| 3893 | [SRV_STATS_STATE_DOWN_AGENT] = "DOWN (agent),", |
| 3894 | [SRV_STATS_STATE_GOING_UP] = "DOWN %d/%d,", |
| 3895 | [SRV_STATS_STATE_UP_GOING_DOWN] = "UP %d/%d,", |
| 3896 | [SRV_STATS_STATE_UP] = "UP,", |
| 3897 | [SRV_STATS_STATE_NOLB_GOING_DOWN] = "NOLB %d/%d,", |
| 3898 | [SRV_STATS_STATE_NOLB] = "NOLB,", |
| 3899 | [SRV_STATS_STATE_DRAIN_GOING_DOWN] = "DRAIN %d/%d,", |
| 3900 | [SRV_STATS_STATE_DRAIN] = "DRAIN,", |
Raghu Udiyar | 0d6b7a4 | 2016-02-05 22:30:11 +0530 | [diff] [blame] | 3901 | [SRV_STATS_STATE_DRAIN_AGENT] = "DRAIN (agent),", |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 3902 | [SRV_STATS_STATE_NO_CHECK] = "no check," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3903 | }; |
| 3904 | |
| 3905 | chunk_appendf(&trash, |
| 3906 | /* pxid, name */ |
| 3907 | "%s,%s," |
| 3908 | /* queue : current, max */ |
| 3909 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 3910 | /* sessions : current, max, limit, total */ |
| 3911 | "%d,%d,%s,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3912 | /* bytes : in, out */ |
| 3913 | "%lld,%lld," |
| 3914 | /* denied: req, resp */ |
| 3915 | ",%lld," |
| 3916 | /* errors : request, connect, response */ |
| 3917 | ",%lld,%lld," |
| 3918 | /* warnings: retries, redispatches */ |
| 3919 | "%lld,%lld," |
| 3920 | "", |
| 3921 | px->id, sv->id, |
| 3922 | sv->nbpend, sv->counters.nbpend_max, |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3923 | 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] | 3924 | sv->counters.bytes_in, sv->counters.bytes_out, |
| 3925 | sv->counters.failed_secu, |
| 3926 | sv->counters.failed_conns, sv->counters.failed_resp, |
| 3927 | sv->counters.retries, sv->counters.redispatches); |
| 3928 | |
| 3929 | /* status */ |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3930 | if (sv->admin & SRV_ADMF_IMAINT) |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 3931 | chunk_appendf(&trash, "MAINT (via %s/%s),", via->proxy->id, via->id); |
Willy Tarreau | a0066dd | 2014-05-16 11:25:16 +0200 | [diff] [blame] | 3932 | else if (sv->admin & SRV_ADMF_MAINT) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3933 | chunk_appendf(&trash, "MAINT,"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3934 | else |
| 3935 | chunk_appendf(&trash, |
| 3936 | srv_hlt_st[state], |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3937 | (ref->state != SRV_ST_STOPPED) ? (ref->check.health - ref->check.rise + 1) : (ref->check.health), |
| 3938 | (ref->state != SRV_ST_STOPPED) ? (ref->check.fall) : (ref->check.rise)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3939 | |
| 3940 | chunk_appendf(&trash, |
| 3941 | /* weight, active, backup */ |
| 3942 | "%d,%d,%d," |
| 3943 | "", |
| 3944 | (sv->eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
Willy Tarreau | c93cd16 | 2014-05-13 15:54:22 +0200 | [diff] [blame] | 3945 | (sv->flags & SRV_F_BACKUP) ? 0 : 1, |
| 3946 | (sv->flags & SRV_F_BACKUP) ? 1 : 0); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3947 | |
| 3948 | /* check failures: unique, fatal; last change, total downtime */ |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3949 | if (sv->check.state & CHK_ST_ENABLED) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3950 | chunk_appendf(&trash, |
| 3951 | "%lld,%lld,%d,%d,", |
| 3952 | sv->counters.failed_checks, sv->counters.down_trans, |
| 3953 | (int)(now.tv_sec - sv->last_change), srv_downtime(sv)); |
| 3954 | else |
| 3955 | chunk_appendf(&trash, ",,,,"); |
| 3956 | |
| 3957 | /* queue limit, pid, iid, sid, */ |
| 3958 | chunk_appendf(&trash, |
| 3959 | "%s," |
| 3960 | "%d,%d,%d,", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 3961 | LIM2A(sv->maxqueue, ""), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3962 | relative_pid, px->uuid, sv->puid); |
| 3963 | |
| 3964 | /* throttle */ |
Willy Tarreau | 892337c | 2014-05-13 23:41:20 +0200 | [diff] [blame] | 3965 | if (sv->state == SRV_ST_STARTING && !server_is_draining(sv)) |
Willy Tarreau | d32c399 | 2013-11-21 15:30:45 +0100 | [diff] [blame] | 3966 | chunk_appendf(&trash, "%d", server_throttle_rate(sv)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3967 | |
| 3968 | /* sessions: lbtot */ |
| 3969 | chunk_appendf(&trash, ",%lld,", sv->counters.cum_lbconn); |
| 3970 | |
| 3971 | /* tracked */ |
| 3972 | if (sv->track) |
| 3973 | chunk_appendf(&trash, "%s/%s,", |
| 3974 | sv->track->proxy->id, sv->track->id); |
| 3975 | else |
| 3976 | chunk_appendf(&trash, ","); |
| 3977 | |
| 3978 | /* type */ |
| 3979 | chunk_appendf(&trash, "%d,", STATS_TYPE_SV); |
| 3980 | |
| 3981 | /* rate */ |
| 3982 | chunk_appendf(&trash, "%u,,%u,", |
| 3983 | read_freq_ctr(&sv->sess_per_sec), |
| 3984 | sv->counters.sps_max); |
| 3985 | |
Willy Tarreau | ff5ae35 | 2013-12-11 20:36:34 +0100 | [diff] [blame] | 3986 | if (sv->check.state & CHK_ST_ENABLED) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 3987 | /* check_status */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 3988 | 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] | 3989 | |
| 3990 | /* check_code */ |
| 3991 | if (sv->check.status >= HCHK_STATUS_L57DATA) |
| 3992 | chunk_appendf(&trash, "%u,", sv->check.code); |
| 3993 | else |
| 3994 | chunk_appendf(&trash, ","); |
| 3995 | |
| 3996 | /* check_duration */ |
| 3997 | if (sv->check.status >= HCHK_STATUS_CHECKED) |
| 3998 | chunk_appendf(&trash, "%lu,", sv->check.duration); |
| 3999 | else |
| 4000 | chunk_appendf(&trash, ","); |
| 4001 | |
| 4002 | } |
| 4003 | else |
| 4004 | chunk_appendf(&trash, ",,,"); |
| 4005 | |
| 4006 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4007 | if (px->mode == PR_MODE_HTTP) { |
| 4008 | for (i=1; i<6; i++) |
| 4009 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[i]); |
| 4010 | |
| 4011 | chunk_appendf(&trash, "%lld,", sv->counters.p.http.rsp[0]); |
| 4012 | } |
| 4013 | else |
| 4014 | chunk_appendf(&trash, ",,,,,,"); |
| 4015 | |
| 4016 | /* failed health analyses */ |
| 4017 | chunk_appendf(&trash, "%lld,", sv->counters.failed_hana); |
| 4018 | |
| 4019 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 4020 | chunk_appendf(&trash, ",,,"); |
| 4021 | |
| 4022 | /* errors: cli_aborts, srv_aborts */ |
| 4023 | chunk_appendf(&trash, "%lld,%lld,", |
| 4024 | sv->counters.cli_aborts, sv->counters.srv_aborts); |
| 4025 | |
| 4026 | /* compression: in, out, bypassed, comp_rsp */ |
| 4027 | chunk_appendf(&trash, ",,,,"); |
| 4028 | |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4029 | /* lastsess */ |
| 4030 | chunk_appendf(&trash, "%d,", srv_lastsession(sv)); |
| 4031 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 4032 | /* capture of last check and agent statuses */ |
Thierry FOURNIER | be1ccae | 2015-05-28 16:02:01 +0200 | [diff] [blame] | 4033 | chunk_appendf(&trash, "%s,", ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) == CHK_ST_ENABLED) ? csv_enc(cstr(sv->check.desc), 1, out) : ""); |
| 4034 | 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] | 4035 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4036 | /* qtime, ctime, rtime, ttime, */ |
| 4037 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 4038 | swrate_avg(sv->counters.q_time, TIME_STATS_SAMPLES), |
| 4039 | swrate_avg(sv->counters.c_time, TIME_STATS_SAMPLES), |
| 4040 | swrate_avg(sv->counters.d_time, TIME_STATS_SAMPLES), |
| 4041 | swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES)); |
| 4042 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4043 | /* finish with EOL */ |
| 4044 | chunk_appendf(&trash, "\n"); |
| 4045 | } |
| 4046 | return 1; |
| 4047 | } |
| 4048 | |
| 4049 | /* Dumps a line for backend <px> to the trash for and uses the state from stream |
| 4050 | * interface <si> and stats flags <flags>. The caller is responsible for clearing |
| 4051 | * the trash if needed. Returns non-zero if it emits anything, zero otherwise. |
| 4052 | */ |
| 4053 | static int stats_dump_be_stats(struct stream_interface *si, struct proxy *px, int flags) |
| 4054 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4055 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4056 | struct chunk src; |
| 4057 | int i; |
| 4058 | |
| 4059 | if (!(px->cap & PR_CAP_BE)) |
| 4060 | return 0; |
| 4061 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4062 | 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] | 4063 | return 0; |
| 4064 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4065 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4066 | chunk_appendf(&trash, "<tr class=\"backend\">"); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4067 | if (px->srv && (appctx->ctx.stats.flags & STAT_ADMIN)) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4068 | /* Column sub-heading for Enable or Disable server */ |
| 4069 | chunk_appendf(&trash, "<td></td>"); |
| 4070 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4071 | chunk_appendf(&trash, |
| 4072 | "<td class=ac>" |
| 4073 | /* name */ |
| 4074 | "%s<a name=\"%s/Backend\"></a>" |
| 4075 | "<a class=lfsb href=\"#%s/Backend\">Backend</a>" |
| 4076 | "", |
| 4077 | (flags & ST_SHLGNDS)?"<u>":"", |
| 4078 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4079 | |
| 4080 | if (flags & ST_SHLGNDS) { |
| 4081 | /* balancing */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4082 | chunk_appendf(&trash, "<div class=tips>balancing: %s", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4083 | backend_lb_algo_str(px->lbprm.algo & BE_LB_ALGO)); |
| 4084 | |
| 4085 | /* cookie */ |
| 4086 | if (px->cookie_name) { |
| 4087 | chunk_appendf(&trash, ", cookie: '"); |
| 4088 | chunk_initlen(&src, px->cookie_name, 0, strlen(px->cookie_name)); |
| 4089 | chunk_htmlencode(&trash, &src); |
| 4090 | chunk_appendf(&trash, "'"); |
| 4091 | } |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4092 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4096 | "%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4097 | /* queue : current, max */ |
| 4098 | "<td>%s</td><td>%s</td><td></td>" |
| 4099 | /* sessions rate : current, max, limit */ |
| 4100 | "<td>%s</td><td>%s</td><td></td>" |
| 4101 | "", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4102 | (flags & ST_SHLGNDS)?"</u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4103 | U2H(px->nbpend) /* or px->totpend ? */, U2H(px->be_counters.nbpend_max), |
| 4104 | 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] | 4105 | |
| 4106 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4107 | /* sessions: current, max, limit, total */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4108 | "<td>%s</td><td>%s</td><td>%s</td>" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4109 | "<td><u>%s<div class=tips><table class=det>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4110 | "<tr><th>Cum. sessions:</th><td>%s</td></tr>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4111 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4112 | U2H(px->beconn), U2H(px->be_counters.conn_max), U2H(px->fullconn), |
| 4113 | U2H(px->be_counters.cum_conn), |
| 4114 | U2H(px->be_counters.cum_conn)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4115 | |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4116 | /* http response (via hover): 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4117 | if (px->mode == PR_MODE_HTTP) { |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4118 | chunk_appendf(&trash, |
| 4119 | "<tr><th>Cum. HTTP requests:</th><td>%s</td></tr>" |
| 4120 | "<tr><th>- HTTP 1xx responses:</th><td>%s</td></tr>" |
| 4121 | "<tr><th>- HTTP 2xx responses:</th><td>%s</td></tr>" |
| 4122 | "<tr><th> Compressed 2xx:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4123 | "<tr><th>- HTTP 3xx responses:</th><td>%s</td></tr>" |
| 4124 | "<tr><th>- HTTP 4xx responses:</th><td>%s</td></tr>" |
| 4125 | "<tr><th>- HTTP 5xx responses:</th><td>%s</td></tr>" |
| 4126 | "<tr><th>- other responses:</th><td>%s</td></tr>" |
| 4127 | "<tr><th>Intercepted requests:</th><td>%s</td></tr>" |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4128 | "<tr><th colspan=3>Avg over last 1024 success. conn.</th></tr>" |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4129 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4130 | U2H(px->be_counters.p.http.cum_req), |
| 4131 | U2H(px->be_counters.p.http.rsp[1]), |
| 4132 | U2H(px->be_counters.p.http.rsp[2]), |
| 4133 | U2H(px->be_counters.p.http.comp_rsp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4134 | px->be_counters.p.http.rsp[2] ? |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4135 | (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] | 4136 | U2H(px->be_counters.p.http.rsp[3]), |
| 4137 | U2H(px->be_counters.p.http.rsp[4]), |
| 4138 | U2H(px->be_counters.p.http.rsp[5]), |
| 4139 | U2H(px->be_counters.p.http.rsp[0]), |
| 4140 | U2H(px->be_counters.intercepted_req)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4141 | } |
| 4142 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4143 | 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))); |
| 4144 | 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))); |
| 4145 | if (px->mode == PR_MODE_HTTP) |
| 4146 | 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))); |
| 4147 | 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))); |
| 4148 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4149 | chunk_appendf(&trash, |
Willy Tarreau | 466c9b5 | 2012-12-23 02:25:03 +0100 | [diff] [blame] | 4150 | "</table></div></u></td>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4151 | /* sessions: lbtot, last */ |
| 4152 | "<td>%s</td><td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4153 | /* bytes: in */ |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4154 | "<td>%s</td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4155 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4156 | U2H(px->be_counters.cum_lbconn), |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4157 | human_time(be_lastsession(px), 1), |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4158 | U2H(px->be_counters.bytes_in)); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4159 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4160 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4161 | /* bytes:out + compression stats (via hover): comp_in, comp_out, comp_byp */ |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 4162 | "<td>%s%s<div class=tips><table class=det>" |
| 4163 | "<tr><th>Response bytes in:</th><td>%s</td></tr>" |
| 4164 | "<tr><th>Compression in:</th><td>%s</td></tr>" |
| 4165 | "<tr><th>Compression out:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4166 | "<tr><th>Compression bypass:</th><td>%s</td></tr>" |
| 4167 | "<tr><th>Total bytes saved:</th><td>%s</td><td>(%d%%)</td></tr>" |
| 4168 | "</table></div>%s</td>", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4169 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "<u>":"", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4170 | U2H(px->be_counters.bytes_out), |
Willy Tarreau | 4e5d58e | 2015-07-04 14:35:15 +0200 | [diff] [blame] | 4171 | U2H(px->be_counters.bytes_out), |
| 4172 | U2H(px->be_counters.comp_in), |
| 4173 | U2H(px->be_counters.comp_out), |
| 4174 | px->be_counters.comp_in ? (int)(px->be_counters.comp_out * 100 / px->be_counters.comp_in) : 0, |
| 4175 | U2H(px->be_counters.comp_byp), |
| 4176 | U2H(px->be_counters.comp_in - px->be_counters.comp_out), |
| 4177 | 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] | 4178 | (px->be_counters.comp_in || px->be_counters.comp_byp) ? "</u>":""); |
| 4179 | |
| 4180 | chunk_appendf(&trash, |
| 4181 | /* denied: req, resp */ |
| 4182 | "<td>%s</td><td>%s</td>" |
| 4183 | /* errors : request, connect */ |
| 4184 | "<td></td><td>%s</td>" |
| 4185 | /* errors : response */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4186 | "<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] | 4187 | /* warnings: retries, redispatches */ |
| 4188 | "<td>%lld</td><td>%lld</td>" |
| 4189 | /* backend status: reflect backend status (up/down): we display UP |
| 4190 | * if the backend has known working servers or if it has no server at |
| 4191 | * all (eg: for stats). Then we display the total weight, number of |
| 4192 | * active and backups. */ |
| 4193 | "<td class=ac>%s %s</td><td class=ac> </td><td class=ac>%d</td>" |
| 4194 | "<td class=ac>%d</td><td class=ac>%d</td>" |
| 4195 | "", |
Willy Tarreau | 56adcf2 | 2012-12-23 18:00:29 +0100 | [diff] [blame] | 4196 | U2H(px->be_counters.denied_req), U2H(px->be_counters.denied_resp), |
| 4197 | U2H(px->be_counters.failed_conns), |
| 4198 | U2H(px->be_counters.failed_resp), |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4199 | px->be_counters.cli_aborts, |
| 4200 | px->be_counters.srv_aborts, |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4201 | px->be_counters.retries, px->be_counters.redispatches, |
| 4202 | human_time(now.tv_sec - px->last_change, 1), |
| 4203 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : |
| 4204 | "<font color=\"red\"><b>DOWN</b></font>", |
| 4205 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 4206 | px->srv_act, px->srv_bck); |
| 4207 | |
| 4208 | chunk_appendf(&trash, |
| 4209 | /* rest of backend: nothing, down transitions, total downtime, throttle */ |
| 4210 | "<td class=ac> </td><td>%d</td>" |
| 4211 | "<td>%s</td>" |
| 4212 | "<td></td>" |
| 4213 | "</tr>", |
| 4214 | px->down_trans, |
| 4215 | px->srv?human_time(be_downtime(px), 1):" "); |
| 4216 | } |
| 4217 | else { /* CSV mode */ |
| 4218 | chunk_appendf(&trash, |
| 4219 | /* pxid, name */ |
| 4220 | "%s,BACKEND," |
| 4221 | /* queue : current, max */ |
| 4222 | "%d,%d," |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4223 | /* sessions : current, max, limit, total */ |
| 4224 | "%d,%d,%d,%lld," |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4225 | /* bytes : in, out */ |
| 4226 | "%lld,%lld," |
| 4227 | /* denied: req, resp */ |
| 4228 | "%lld,%lld," |
| 4229 | /* errors : request, connect, response */ |
| 4230 | ",%lld,%lld," |
| 4231 | /* warnings: retries, redispatches */ |
| 4232 | "%lld,%lld," |
| 4233 | /* backend status: reflect backend status (up/down): we display UP |
| 4234 | * if the backend has known working servers or if it has no server at |
| 4235 | * all (eg: for stats). Then we display the total weight, number of |
| 4236 | * active and backups. */ |
| 4237 | "%s," |
| 4238 | "%d,%d,%d," |
| 4239 | /* rest of backend: nothing, down transitions, last change, total downtime */ |
| 4240 | ",%d,%d,%d,," |
| 4241 | /* pid, iid, sid, throttle, lbtot, tracked, type */ |
| 4242 | "%d,%d,0,,%lld,,%d," |
| 4243 | /* rate, rate_lim, rate_max, */ |
| 4244 | "%u,,%u," |
| 4245 | /* check_status, check_code, check_duration */ |
| 4246 | ",,,", |
| 4247 | px->id, |
| 4248 | px->nbpend /* or px->totpend ? */, px->be_counters.nbpend_max, |
| 4249 | px->beconn, px->be_counters.conn_max, px->fullconn, px->be_counters.cum_conn, |
| 4250 | px->be_counters.bytes_in, px->be_counters.bytes_out, |
| 4251 | px->be_counters.denied_req, px->be_counters.denied_resp, |
| 4252 | px->be_counters.failed_conns, px->be_counters.failed_resp, |
| 4253 | px->be_counters.retries, px->be_counters.redispatches, |
| 4254 | (px->lbprm.tot_weight > 0 || !px->srv) ? "UP" : "DOWN", |
| 4255 | (px->lbprm.tot_weight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv, |
| 4256 | px->srv_act, px->srv_bck, |
| 4257 | px->down_trans, (int)(now.tv_sec - px->last_change), |
| 4258 | px->srv?be_downtime(px):0, |
| 4259 | relative_pid, px->uuid, |
| 4260 | px->be_counters.cum_lbconn, STATS_TYPE_BE, |
| 4261 | read_freq_ctr(&px->be_sess_per_sec), |
| 4262 | px->be_counters.sps_max); |
| 4263 | |
| 4264 | /* http response: 1xx, 2xx, 3xx, 4xx, 5xx, other */ |
| 4265 | if (px->mode == PR_MODE_HTTP) { |
| 4266 | for (i=1; i<6; i++) |
| 4267 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[i]); |
| 4268 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.rsp[0]); |
| 4269 | } |
| 4270 | else |
| 4271 | chunk_appendf(&trash, ",,,,,,"); |
| 4272 | |
| 4273 | /* failed health analyses */ |
| 4274 | chunk_appendf(&trash, ","); |
| 4275 | |
| 4276 | /* requests : req_rate, req_rate_max, req_tot, */ |
| 4277 | chunk_appendf(&trash, ",,,"); |
| 4278 | |
| 4279 | /* errors: cli_aborts, srv_aborts */ |
| 4280 | chunk_appendf(&trash, "%lld,%lld,", |
| 4281 | px->be_counters.cli_aborts, px->be_counters.srv_aborts); |
| 4282 | |
| 4283 | /* compression: in, out, bypassed */ |
| 4284 | chunk_appendf(&trash, "%lld,%lld,%lld,", |
| 4285 | px->be_counters.comp_in, px->be_counters.comp_out, px->be_counters.comp_byp); |
| 4286 | |
| 4287 | /* compression: comp_rsp */ |
| 4288 | chunk_appendf(&trash, "%lld,", px->be_counters.p.http.comp_rsp); |
| 4289 | |
Willy Tarreau | a28df3e | 2014-06-16 16:40:14 +0200 | [diff] [blame] | 4290 | /* lastsess, last_chk, last_agt, */ |
| 4291 | chunk_appendf(&trash, "%d,,,", be_lastsession(px)); |
Willy Tarreau | f522f3d | 2014-02-10 22:22:49 +0100 | [diff] [blame] | 4292 | |
Willy Tarreau | f5b1cc3 | 2014-06-17 12:20:59 +0200 | [diff] [blame] | 4293 | /* qtime, ctime, rtime, ttime, */ |
| 4294 | chunk_appendf(&trash, "%u,%u,%u,%u,", |
| 4295 | swrate_avg(px->be_counters.q_time, TIME_STATS_SAMPLES), |
| 4296 | swrate_avg(px->be_counters.c_time, TIME_STATS_SAMPLES), |
| 4297 | swrate_avg(px->be_counters.d_time, TIME_STATS_SAMPLES), |
| 4298 | swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES)); |
| 4299 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4300 | /* finish with EOL */ |
| 4301 | chunk_appendf(&trash, "\n"); |
| 4302 | } |
| 4303 | return 1; |
| 4304 | } |
| 4305 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4306 | /* 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] | 4307 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4308 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4309 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4310 | 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] | 4311 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4312 | struct appctx *appctx = __objt_appctx(si->end); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4313 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
| 4314 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4315 | 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] | 4316 | /* A form to enable/disable this proxy servers */ |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4317 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4318 | /* 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] | 4319 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4320 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4321 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4322 | 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] | 4323 | 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] | 4324 | } |
| 4325 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4326 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4327 | "<form method=\"post\">"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4328 | } |
| 4329 | |
| 4330 | /* print a new table */ |
| 4331 | chunk_appendf(&trash, |
| 4332 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4333 | "<tr class=\"titre\">" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4334 | "<th class=\"pxname\" width=\"10%%\">"); |
| 4335 | |
| 4336 | chunk_appendf(&trash, |
| 4337 | "<a name=\"%s\"></a>%s" |
| 4338 | "<a class=px href=\"#%s\">%s</a>", |
| 4339 | px->id, |
| 4340 | (uri->flags & ST_SHLGNDS) ? "<u>":"", |
| 4341 | px->id, px->id); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4342 | |
| 4343 | if (uri->flags & ST_SHLGNDS) { |
| 4344 | /* cap, mode, id */ |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4345 | chunk_appendf(&trash, "<div class=tips>cap: %s, mode: %s, id: %d", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4346 | proxy_cap_str(px->cap), proxy_mode_str(px->mode), |
| 4347 | px->uuid); |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4348 | chunk_appendf(&trash, "</div>"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | chunk_appendf(&trash, |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4352 | "%s</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4353 | "<th class=\"%s\" width=\"90%%\">%s</th>" |
| 4354 | "</tr>\n" |
| 4355 | "</table>\n" |
| 4356 | "<table class=\"tbl\" width=\"100%%\">\n" |
| 4357 | "<tr class=\"titre\">", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4358 | (uri->flags & ST_SHLGNDS) ? "</u>":"", |
| 4359 | px->desc ? "desc" : "empty", px->desc ? px->desc : ""); |
| 4360 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4361 | 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] | 4362 | /* Column heading for Enable or Disable server */ |
| 4363 | chunk_appendf(&trash, "<th rowspan=2 width=1></th>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4364 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4365 | |
| 4366 | chunk_appendf(&trash, |
| 4367 | "<th rowspan=2></th>" |
| 4368 | "<th colspan=3>Queue</th>" |
Bhaskar Maddala | a20cb85 | 2014-02-03 16:26:46 -0500 | [diff] [blame] | 4369 | "<th colspan=3>Session rate</th><th colspan=6>Sessions</th>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4370 | "<th colspan=2>Bytes</th><th colspan=2>Denied</th>" |
| 4371 | "<th colspan=3>Errors</th><th colspan=2>Warnings</th>" |
| 4372 | "<th colspan=9>Server</th>" |
| 4373 | "</tr>\n" |
| 4374 | "<tr class=\"titre\">" |
| 4375 | "<th>Cur</th><th>Max</th><th>Limit</th>" |
| 4376 | "<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] | 4377 | "<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] | 4378 | "<th>Req</th><th>Resp</th><th>Req</th><th>Conn</th>" |
| 4379 | "<th>Resp</th><th>Retr</th><th>Redis</th>" |
| 4380 | "<th>Status</th><th>LastChk</th><th>Wght</th><th>Act</th>" |
| 4381 | "<th>Bck</th><th>Chk</th><th>Dwn</th><th>Dwntme</th>" |
| 4382 | "<th>Thrtle</th>\n" |
| 4383 | "</tr>"); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4384 | } |
| 4385 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4386 | /* 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] | 4387 | * 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] | 4388 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4389 | 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] | 4390 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4391 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4392 | chunk_appendf(&trash, "</table>"); |
| 4393 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4394 | 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] | 4395 | /* close the form used to enable/disable this proxy servers */ |
| 4396 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4397 | "Choose the action to perform on the checked servers : " |
| 4398 | "<select name=action>" |
| 4399 | "<option value=\"\"></option>" |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 4400 | "<option value=\"ready\">Set state to READY</option>" |
| 4401 | "<option value=\"drain\">Set state to DRAIN</option>" |
Marco Corte | 8c27bca | 2014-07-02 17:49:34 +0200 | [diff] [blame] | 4402 | "<option value=\"maint\">Set state to MAINT</option>" |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 4403 | "<option value=\"dhlth\">Health: disable checks</option>" |
| 4404 | "<option value=\"ehlth\">Health: enable checks</option>" |
| 4405 | "<option value=\"hrunn\">Health: force UP</option>" |
| 4406 | "<option value=\"hnolb\">Health: force NOLB</option>" |
| 4407 | "<option value=\"hdown\">Health: force DOWN</option>" |
| 4408 | "<option value=\"dagent\">Agent: disable checks</option>" |
| 4409 | "<option value=\"eagent\">Agent: enable checks</option>" |
| 4410 | "<option value=\"arunn\">Agent: force UP</option>" |
| 4411 | "<option value=\"adown\">Agent: force DOWN</option>" |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4412 | "<option value=\"shutdown\">Kill Sessions</option>" |
| 4413 | "</select>" |
| 4414 | "<input type=\"hidden\" name=\"b\" value=\"#%d\">" |
| 4415 | " <input type=\"submit\" value=\"Apply\">" |
| 4416 | "</form>", |
| 4417 | px->uuid); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4418 | } |
| 4419 | |
| 4420 | chunk_appendf(&trash, "<p>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4421 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4422 | |
| 4423 | /* |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4424 | * Dumps statistics for a proxy. The output is sent to the stream interface's |
| 4425 | * input buffer. Returns 0 if it had to stop dumping data because of lack of |
| 4426 | * buffer space, or non-zero if everything completed. This function is used |
| 4427 | * both by the CLI and the HTTP entry points, and is able to dump the output |
| 4428 | * in HTML or CSV formats. If the later, <uri> must be NULL. |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4429 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4430 | 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] | 4431 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4432 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 4433 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 4434 | struct channel *rep = si_ic(si); |
Willy Tarreau | 4426770 | 2011-10-28 15:35:33 +0200 | [diff] [blame] | 4435 | 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] | 4436 | struct listener *l; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4437 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 4438 | chunk_reset(&trash); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4439 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4440 | switch (appctx->ctx.stats.px_st) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4441 | case STAT_PX_ST_INIT: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4442 | /* we are on a new proxy */ |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4443 | if (uri && uri->scope) { |
| 4444 | /* we have a limited scope, we have to check the proxy name */ |
| 4445 | struct stat_scope *scope; |
| 4446 | int len; |
| 4447 | |
| 4448 | len = strlen(px->id); |
| 4449 | scope = uri->scope; |
| 4450 | |
| 4451 | while (scope) { |
| 4452 | /* match exact proxy name */ |
| 4453 | if (scope->px_len == len && !memcmp(px->id, scope->px_id, len)) |
| 4454 | break; |
| 4455 | |
| 4456 | /* match '.' which means 'self' proxy */ |
Willy Tarreau | 1388a3a | 2007-10-18 16:38:37 +0200 | [diff] [blame] | 4457 | if (!strcmp(scope->px_id, ".") && px == s->be) |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4458 | break; |
| 4459 | scope = scope->next; |
| 4460 | } |
| 4461 | |
| 4462 | /* proxy name not found : don't dump anything */ |
| 4463 | if (scope == NULL) |
| 4464 | return 1; |
| 4465 | } |
| 4466 | |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4467 | /* if the user has requested a limited output and the proxy |
| 4468 | * name does not match, skip it. |
| 4469 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4470 | if (appctx->ctx.stats.scope_len && |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4471 | 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] | 4472 | return 1; |
| 4473 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4474 | if ((appctx->ctx.stats.flags & STAT_BOUND) && |
| 4475 | (appctx->ctx.stats.iid != -1) && |
| 4476 | (px->uuid != appctx->ctx.stats.iid)) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4477 | return 1; |
| 4478 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4479 | appctx->ctx.stats.px_st = STAT_PX_ST_TH; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4480 | /* fall through */ |
| 4481 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4482 | case STAT_PX_ST_TH: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4483 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4484 | stats_dump_html_px_hdr(si, px, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4485 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4486 | si_applet_cant_put(si); |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4487 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4488 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4489 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4490 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4491 | appctx->ctx.stats.px_st = STAT_PX_ST_FE; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4492 | /* fall through */ |
| 4493 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4494 | case STAT_PX_ST_FE: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4495 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4496 | if (stats_dump_fe_stats(si, px)) { |
| 4497 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4498 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4499 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4500 | } |
| 4501 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4502 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4503 | appctx->ctx.stats.l = px->conf.listeners.n; |
| 4504 | appctx->ctx.stats.px_st = STAT_PX_ST_LI; |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4505 | /* fall through */ |
| 4506 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4507 | case STAT_PX_ST_LI: |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4508 | /* stats.l has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4509 | 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] | 4510 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4511 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4512 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4513 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4514 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4515 | l = LIST_ELEM(appctx->ctx.stats.l, struct listener *, by_fe); |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4516 | if (!l->counters) |
| 4517 | continue; |
| 4518 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4519 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4520 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SO))) |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4521 | break; |
| 4522 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4523 | 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] | 4524 | continue; |
| 4525 | } |
| 4526 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4527 | /* print the frontend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4528 | if (stats_dump_li_stats(si, px, l, uri ? uri->flags : 0)) { |
| 4529 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4530 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4531 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4532 | } |
| 4533 | } |
Krzysztof Piotr Oledzki | aeebf9b | 2009-10-04 15:43:17 +0200 | [diff] [blame] | 4534 | } |
| 4535 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4536 | appctx->ctx.stats.sv = px->srv; /* may be NULL */ |
| 4537 | appctx->ctx.stats.px_st = STAT_PX_ST_SV; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4538 | /* fall through */ |
| 4539 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 4540 | case STAT_PX_ST_SV: |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4541 | /* stats.sv has been initialized above */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4542 | for (; appctx->ctx.stats.sv != NULL; appctx->ctx.stats.sv = sv->next) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4543 | enum srv_stats_state sv_state; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4544 | enum srv_stats_colour sv_colour; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4545 | |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4546 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4547 | si_applet_cant_put(si); |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4548 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 4549 | } |
Willy Tarreau | 4e33d86 | 2009-10-11 23:35:10 +0200 | [diff] [blame] | 4550 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4551 | sv = appctx->ctx.stats.sv; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4552 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4553 | if (appctx->ctx.stats.flags & STAT_BOUND) { |
| 4554 | if (!(appctx->ctx.stats.type & (1 << STATS_TYPE_SV))) |
Krzysztof Piotr Oledzki | 2c6962c | 2008-03-02 02:42:14 +0100 | [diff] [blame] | 4555 | break; |
| 4556 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4557 | 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] | 4558 | continue; |
| 4559 | } |
| 4560 | |
Willy Tarreau | 3209123 | 2014-05-16 13:52:00 +0200 | [diff] [blame] | 4561 | svs = sv; |
| 4562 | while (svs->track) |
| 4563 | svs = svs->track; |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 4564 | |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4565 | if (sv->state == SRV_ST_RUNNING || sv->state == SRV_ST_STARTING) { |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4566 | if ((svs->check.state & CHK_ST_ENABLED) && |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4567 | (svs->check.health < svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4568 | sv_state = SRV_STATS_STATE_UP_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4569 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4570 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4571 | sv_state = SRV_STATS_STATE_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4572 | sv_colour = SRV_STATS_COLOUR_UP; |
| 4573 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4574 | |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4575 | if (sv_state == SRV_STATS_STATE_UP && !svs->uweight) |
| 4576 | sv_colour = SRV_STATS_COLOUR_DRAINING; |
| 4577 | |
| 4578 | if (sv->admin & SRV_ADMF_DRAIN) { |
Simon Horman | b167b6b | 2015-04-23 14:51:29 +0900 | [diff] [blame] | 4579 | if (svs->agent.state & CHK_ST_ENABLED) |
| 4580 | sv_state = SRV_STATS_STATE_DRAIN_AGENT; |
| 4581 | else if (sv_state == SRV_STATS_STATE_UP_GOING_DOWN) |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4582 | sv_state = SRV_STATS_STATE_DRAIN_GOING_DOWN; |
Simon Horman | 4463d19 | 2015-04-23 14:51:28 +0900 | [diff] [blame] | 4583 | else |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4584 | sv_state = SRV_STATS_STATE_DRAIN; |
| 4585 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4586 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4587 | 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] | 4588 | sv_state = SRV_STATS_STATE_NO_CHECK; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4589 | sv_colour = SRV_STATS_COLOUR_NO_CHECK; |
| 4590 | } |
Willy Tarreau | 2ea8193 | 2007-11-30 12:04:38 +0100 | [diff] [blame] | 4591 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4592 | else if (sv->state == SRV_ST_STOPPING) { |
| 4593 | if ((!(sv->check.state & CHK_ST_ENABLED) && !sv->track) || |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4594 | (svs->check.health == svs->check.rise + svs->check.fall - 1)) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4595 | sv_state = SRV_STATS_STATE_NOLB; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4596 | sv_colour = SRV_STATS_COLOUR_NOLB; |
| 4597 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4598 | sv_state = SRV_STATS_STATE_NOLB_GOING_DOWN; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4599 | sv_colour = SRV_STATS_COLOUR_GOING_DOWN; |
| 4600 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4601 | } |
| 4602 | else { /* stopped */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4603 | if ((svs->agent.state & CHK_ST_ENABLED) && !svs->agent.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4604 | sv_state = SRV_STATS_STATE_DOWN_AGENT; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4605 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4606 | } else if ((svs->check.state & CHK_ST_ENABLED) && !svs->check.health) { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4607 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4608 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4609 | } 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] | 4610 | sv_state = SRV_STATS_STATE_GOING_UP; |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4611 | sv_colour = SRV_STATS_COLOUR_GOING_UP; |
| 4612 | } else { |
Simon Horman | 4d2eab6 | 2015-04-23 14:51:26 +0900 | [diff] [blame] | 4613 | sv_state = SRV_STATS_STATE_DOWN; /* DOWN, unchecked */ |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4614 | sv_colour = SRV_STATS_COLOUR_DOWN; |
| 4615 | } |
Willy Tarreau | f4e38b3 | 2014-05-21 15:04:05 +0200 | [diff] [blame] | 4616 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4617 | |
Willy Tarreau | 9638efa | 2014-05-23 11:19:57 +0200 | [diff] [blame] | 4618 | 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] | 4619 | /* do not report servers which are DOWN */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4620 | appctx->ctx.stats.sv = sv->next; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4621 | continue; |
| 4622 | } |
| 4623 | |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4624 | 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] | 4625 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4626 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4627 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4628 | } |
| 4629 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4630 | } /* for sv */ |
Cyril Bonté | 474be41 | 2010-10-12 00:14:36 +0200 | [diff] [blame] | 4631 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4632 | appctx->ctx.stats.px_st = STAT_PX_ST_BE; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4633 | /* fall through */ |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 4634 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4635 | case STAT_PX_ST_BE: |
| 4636 | /* print the backend */ |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4637 | if (stats_dump_be_stats(si, px, uri ? uri->flags : 0)) { |
| 4638 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4639 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4640 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4641 | } |
| 4642 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4643 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4644 | appctx->ctx.stats.px_st = STAT_PX_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4645 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4646 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4647 | case STAT_PX_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4648 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4649 | stats_dump_html_px_end(si, px); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4650 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 4651 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4652 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 4653 | } |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4654 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4655 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4656 | appctx->ctx.stats.px_st = STAT_PX_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4657 | /* fall through */ |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4658 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4659 | case STAT_PX_ST_FIN: |
| 4660 | return 1; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4661 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4662 | default: |
| 4663 | /* unknown state, we should put an abort() here ! */ |
| 4664 | return 1; |
| 4665 | } |
| 4666 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4667 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4668 | /* Dumps the HTTP stats head block to the trash for and uses the per-uri |
| 4669 | * parameters <uri>. The caller is responsible for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4670 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4671 | static void stats_dump_html_head(struct uri_auth *uri) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4672 | { |
| 4673 | /* WARNING! This must fit in the first buffer !!! */ |
| 4674 | chunk_appendf(&trash, |
| 4675 | "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" |
| 4676 | "\"http://www.w3.org/TR/html4/loose.dtd\">\n" |
| 4677 | "<html><head><title>Statistics Report for " PRODUCT_NAME "%s%s</title>\n" |
| 4678 | "<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">\n" |
| 4679 | "<style type=\"text/css\"><!--\n" |
| 4680 | "body {" |
| 4681 | " font-family: arial, helvetica, sans-serif;" |
| 4682 | " font-size: 12px;" |
| 4683 | " font-weight: normal;" |
| 4684 | " color: black;" |
| 4685 | " background: white;" |
| 4686 | "}\n" |
| 4687 | "th,td {" |
| 4688 | " font-size: 10px;" |
| 4689 | "}\n" |
| 4690 | "h1 {" |
| 4691 | " font-size: x-large;" |
| 4692 | " margin-bottom: 0.5em;" |
| 4693 | "}\n" |
| 4694 | "h2 {" |
| 4695 | " font-family: helvetica, arial;" |
| 4696 | " font-size: x-large;" |
| 4697 | " font-weight: bold;" |
| 4698 | " font-style: italic;" |
| 4699 | " color: #6020a0;" |
| 4700 | " margin-top: 0em;" |
| 4701 | " margin-bottom: 0em;" |
| 4702 | "}\n" |
| 4703 | "h3 {" |
| 4704 | " font-family: helvetica, arial;" |
| 4705 | " font-size: 16px;" |
| 4706 | " font-weight: bold;" |
| 4707 | " color: #b00040;" |
| 4708 | " background: #e8e8d0;" |
| 4709 | " margin-top: 0em;" |
| 4710 | " margin-bottom: 0em;" |
| 4711 | "}\n" |
| 4712 | "li {" |
| 4713 | " margin-top: 0.25em;" |
| 4714 | " margin-right: 2em;" |
| 4715 | "}\n" |
| 4716 | ".hr {margin-top: 0.25em;" |
| 4717 | " border-color: black;" |
| 4718 | " border-bottom-style: solid;" |
| 4719 | "}\n" |
| 4720 | ".titre {background: #20D0D0;color: #000000; font-weight: bold; text-align: center;}\n" |
| 4721 | ".total {background: #20D0D0;color: #ffff80;}\n" |
| 4722 | ".frontend {background: #e8e8d0;}\n" |
| 4723 | ".socket {background: #d0d0d0;}\n" |
| 4724 | ".backend {background: #e8e8d0;}\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4725 | ".active_down {background: #ff9090;}\n" |
| 4726 | ".active_going_up {background: #ffd020;}\n" |
| 4727 | ".active_going_down {background: #ffffa0;}\n" |
| 4728 | ".active_up {background: #c0ffc0;}\n" |
| 4729 | ".active_nolb {background: #20a0ff;}\n" |
| 4730 | ".active_draining {background: #20a0FF;}\n" |
| 4731 | ".active_no_check {background: #e0e0e0;}\n" |
| 4732 | ".backup_down {background: #ff9090;}\n" |
| 4733 | ".backup_going_up {background: #ff80ff;}\n" |
| 4734 | ".backup_going_down {background: #c060ff;}\n" |
| 4735 | ".backup_up {background: #b0d0ff;}\n" |
| 4736 | ".backup_nolb {background: #90b0e0;}\n" |
| 4737 | ".backup_draining {background: #cc9900;}\n" |
| 4738 | ".backup_no_check {background: #e0e0e0;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4739 | ".maintain {background: #c07820;}\n" |
| 4740 | ".rls {letter-spacing: 0.2em; margin-right: 1px;}\n" /* right letter spacing (used for grouping digits) */ |
| 4741 | "\n" |
| 4742 | "a.px:link {color: #ffff40; text-decoration: none;}" |
| 4743 | "a.px:visited {color: #ffff40; text-decoration: none;}" |
| 4744 | "a.px:hover {color: #ffffff; text-decoration: none;}" |
| 4745 | "a.lfsb:link {color: #000000; text-decoration: none;}" |
| 4746 | "a.lfsb:visited {color: #000000; text-decoration: none;}" |
| 4747 | "a.lfsb:hover {color: #505050; text-decoration: none;}" |
| 4748 | "\n" |
| 4749 | "table.tbl { border-collapse: collapse; border-style: none;}\n" |
| 4750 | "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" |
| 4751 | "table.tbl td.ac { text-align: center;}\n" |
| 4752 | "table.tbl th { border-width: 1px; border-style: solid solid solid solid; border-color: gray;}\n" |
| 4753 | "table.tbl th.pxname { background: #b00040; color: #ffff40; font-weight: bold; border-style: solid solid none solid; padding: 2px 3px; white-space: nowrap;}\n" |
| 4754 | "table.tbl th.empty { border-style: none; empty-cells: hide; background: white;}\n" |
| 4755 | "table.tbl th.desc { background: white; border-style: solid solid none solid; text-align: left; padding: 2px 3px;}\n" |
| 4756 | "\n" |
| 4757 | "table.lgd { border-collapse: collapse; border-width: 1px; border-style: none none none solid; border-color: black;}\n" |
| 4758 | "table.lgd td { border-width: 1px; border-style: solid solid solid solid; border-color: gray; padding: 2px;}\n" |
| 4759 | "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] | 4760 | "table.det { border-collapse: collapse; border-style: none; }\n" |
| 4761 | "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] | 4762 | "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] | 4763 | "u {text-decoration:none; border-bottom: 1px dotted black;}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4764 | "div.tips {\n" |
Willy Tarreau | e7dbfc6 | 2012-12-23 01:59:23 +0100 | [diff] [blame] | 4765 | " display:block;\n" |
| 4766 | " visibility:hidden;\n" |
| 4767 | " z-index:2147483647;\n" |
| 4768 | " position:absolute;\n" |
| 4769 | " padding:2px 4px 3px;\n" |
| 4770 | " background:#f0f060; color:#000000;\n" |
| 4771 | " border:1px solid #7040c0;\n" |
| 4772 | " white-space:nowrap;\n" |
| 4773 | " font-style:normal;font-size:11px;font-weight:normal;\n" |
| 4774 | " -moz-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;\n" |
| 4775 | " -moz-box-shadow:gray 2px 2px 3px;-webkit-box-shadow:gray 2px 2px 3px;box-shadow:gray 2px 2px 3px;\n" |
| 4776 | "}\n" |
Willy Tarreau | 656a9ce | 2013-04-19 14:41:29 +0200 | [diff] [blame] | 4777 | "u:hover div.tips {visibility:visible;}\n" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4778 | "-->\n" |
| 4779 | "</style></head>\n", |
| 4780 | (uri->flags & ST_SHNODE) ? " on " : "", |
| 4781 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "" |
| 4782 | ); |
| 4783 | } |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4784 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4785 | /* 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] | 4786 | * stream interface <si> and per-uri parameters <uri>. The caller is responsible |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4787 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4788 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 4789 | 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] | 4790 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4791 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4792 | unsigned int up = (now.tv_sec - start_date.tv_sec); |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4793 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Krzysztof Piotr Oledzki | 15514c2 | 2010-01-04 16:03:09 +0100 | [diff] [blame] | 4794 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4795 | /* WARNING! this has to fit the first packet too. |
| 4796 | * We are around 3.5 kB, add adding entries will |
| 4797 | * become tricky if we want to support 4kB buffers ! |
| 4798 | */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4799 | chunk_appendf(&trash, |
| 4800 | "<body><h1><a href=\"" PRODUCT_URL "\" style=\"text-decoration: none;\">" |
| 4801 | PRODUCT_NAME "%s</a></h1>\n" |
| 4802 | "<h2>Statistics Report for pid %d%s%s%s%s</h2>\n" |
| 4803 | "<hr width=\"100%%\" class=\"hr\">\n" |
| 4804 | "<h3>> General process information</h3>\n" |
| 4805 | "<table border=0><tr><td align=\"left\" nowrap width=\"1%%\">\n" |
| 4806 | "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n" |
| 4807 | "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n" |
| 4808 | "<b>system limits:</b> memmax = %s%s; ulimit-n = %d<br>\n" |
| 4809 | "<b>maxsock = </b> %d; <b>maxconn = </b> %d; <b>maxpipes = </b> %d<br>\n" |
| 4810 | "current conns = %d; current pipes = %d/%d; conn rate = %d/sec<br>\n" |
| 4811 | "Running tasks: %d/%d; idle = %d %%<br>\n" |
| 4812 | "</td><td align=\"center\" nowrap>\n" |
| 4813 | "<table class=\"lgd\"><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4814 | "<td class=\"active_up\"> </td><td class=\"noborder\">active UP </td>" |
| 4815 | "<td class=\"backup_up\"> </td><td class=\"noborder\">backup UP </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4816 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4817 | "<td class=\"active_going_down\"></td><td class=\"noborder\">active UP, going down </td>" |
| 4818 | "<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] | 4819 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4820 | "<td class=\"active_going_up\"></td><td class=\"noborder\">active DOWN, going up </td>" |
| 4821 | "<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] | 4822 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4823 | "<td class=\"active_down\"></td><td class=\"noborder\">active or backup DOWN </td>" |
| 4824 | "<td class=\"active_no_check\"></td><td class=\"noborder\">not checked </td>" |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4825 | "</tr><tr>\n" |
| 4826 | "<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] | 4827 | "</tr><tr>\n" |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4828 | "<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] | 4829 | "</tr></table>\n" |
Willy Tarreau | 6b7764a | 2013-12-04 00:43:21 +0100 | [diff] [blame] | 4830 | "Note: \"NOLB\"/\"DRAIN\" = UP with load-balancing disabled." |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4831 | "</td>" |
| 4832 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4833 | "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">" |
| 4834 | "", |
| 4835 | (uri->flags & ST_HIDEVER) ? "" : (STATS_VERSION_STRING), |
| 4836 | pid, (uri->flags & ST_SHNODE) ? " on " : "", |
| 4837 | (uri->flags & ST_SHNODE) ? (uri->node ? uri->node : global.node) : "", |
| 4838 | (uri->flags & ST_SHDESC) ? ": " : "", |
| 4839 | (uri->flags & ST_SHDESC) ? (uri->desc ? uri->desc : global.desc) : "", |
| 4840 | pid, relative_pid, global.nbproc, |
| 4841 | up / 86400, (up % 86400) / 3600, |
| 4842 | (up % 3600) / 60, (up % 60), |
| 4843 | global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited", |
| 4844 | global.rlimit_memmax ? " MB" : "", |
| 4845 | global.rlimit_nofile, |
| 4846 | global.maxsock, global.maxconn, global.maxpipes, |
| 4847 | actconn, pipes_used, pipes_used+pipes_free, read_freq_ctr(&global.conn_per_sec), |
| 4848 | run_queue_cur, nb_tasks_cur, idle_pct |
| 4849 | ); |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 4850 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4851 | /* 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] | 4852 | 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] | 4853 | scope_txt[appctx->ctx.stats.scope_len] = '\0'; |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4854 | |
| 4855 | chunk_appendf(&trash, |
Jeff Buchbinder | 2dbbf4d | 2014-08-29 15:10:08 -0500 | [diff] [blame] | 4856 | "<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] | 4857 | (appctx->ctx.stats.scope_len > 0) ? scope_txt : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4858 | STAT_SCOPE_TXT_MAXLEN); |
| 4859 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4860 | /* 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] | 4861 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4862 | if (appctx->ctx.stats.scope_len) { |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4863 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 4864 | 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] | 4865 | 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] | 4866 | } |
| 4867 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4868 | if (appctx->ctx.stats.flags & STAT_HIDE_DOWN) |
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\">Show all servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4871 | uri->uri_prefix, |
| 4872 | "", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4873 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 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\">Hide 'DOWN' servers</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4878 | uri->uri_prefix, |
| 4879 | ";up", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4880 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4881 | scope_txt); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 4882 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4883 | if (uri->refresh > 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4884 | if (appctx->ctx.stats.flags & STAT_NO_REFRESH) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4885 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4886 | "<li><a href=\"%s%s%s%s\">Enable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4887 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4888 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4889 | "", |
| 4890 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4891 | else |
| 4892 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4893 | "<li><a href=\"%s%s%s%s\">Disable refresh</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4894 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4895 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4896 | ";norefresh", |
| 4897 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4898 | } |
Willy Tarreau | 55bb845 | 2007-10-17 18:44:57 +0200 | [diff] [blame] | 4899 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4900 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4901 | "<li><a href=\"%s%s%s%s\">Refresh now</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4902 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4903 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4904 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4905 | scope_txt); |
Elijah Epifanov | acafc5f | 2007-10-25 20:15:38 +0200 | [diff] [blame] | 4906 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4907 | chunk_appendf(&trash, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4908 | "<li><a href=\"%s;csv%s%s\">CSV export</a><br>\n", |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4909 | uri->uri_prefix, |
de Lafond Guillaume | 88c278f | 2013-04-15 19:27:10 +0200 | [diff] [blame] | 4910 | (uri->refresh > 0) ? ";norefresh" : "", |
| 4911 | scope_txt); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4912 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4913 | chunk_appendf(&trash, |
| 4914 | "</ul></td>" |
| 4915 | "<td align=\"left\" valign=\"top\" nowrap width=\"1%%\">" |
| 4916 | "<b>External resources:</b><ul style=\"margin-top: 0.25em;\">\n" |
| 4917 | "<li><a href=\"" PRODUCT_URL "\">Primary site</a><br>\n" |
| 4918 | "<li><a href=\"" PRODUCT_URL_UPD "\">Updates (v" PRODUCT_BRANCH ")</a><br>\n" |
| 4919 | "<li><a href=\"" PRODUCT_URL_DOC "\">Online manual</a><br>\n" |
| 4920 | "</ul>" |
| 4921 | "</td>" |
| 4922 | "</tr></table>\n" |
| 4923 | "" |
| 4924 | ); |
Willy Tarreau | 4bab24d | 2007-11-30 18:16:29 +0100 | [diff] [blame] | 4925 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4926 | if (appctx->ctx.stats.st_code) { |
| 4927 | switch (appctx->ctx.stats.st_code) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4928 | case STAT_STATUS_DONE: |
| 4929 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4930 | "<p><div class=active_up>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4931 | "<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] | 4932 | "Action processed successfully." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4933 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4934 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4935 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4936 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4937 | break; |
| 4938 | case STAT_STATUS_NONE: |
| 4939 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4940 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4941 | "<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] | 4942 | "Nothing has changed." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4943 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4944 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4945 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4946 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4947 | break; |
| 4948 | case STAT_STATUS_PART: |
| 4949 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4950 | "<p><div class=active_going_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4951 | "<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] | 4952 | "Action partially processed.<br>" |
| 4953 | "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] | 4954 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4955 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4956 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4957 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4958 | break; |
| 4959 | case STAT_STATUS_ERRP: |
| 4960 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4961 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4962 | "<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] | 4963 | "Action not processed because of invalid parameters." |
| 4964 | "<ul>" |
| 4965 | "<li>The action is maybe unknown.</li>" |
| 4966 | "<li>The backend name is probably unknown or ambiguous (duplicated names).</li>" |
| 4967 | "<li>Some server names are probably unknown or ambiguous (duplicated names in the backend).</li>" |
| 4968 | "</ul>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4969 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4970 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4971 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4972 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4973 | break; |
| 4974 | case STAT_STATUS_EXCD: |
| 4975 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4976 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4977 | "<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] | 4978 | "<b>Action not processed : the buffer couldn't store all the data.<br>" |
| 4979 | "You should retry with less servers at a time.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4980 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4981 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4982 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4983 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4984 | break; |
| 4985 | case STAT_STATUS_DENY: |
| 4986 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4987 | "<p><div class=active_down>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4988 | "<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] | 4989 | "<b>Action denied.</b>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4990 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 4991 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 4992 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4993 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 4994 | break; |
| 4995 | default: |
| 4996 | chunk_appendf(&trash, |
Simon Horman | 837bfa7 | 2015-04-23 14:51:27 +0900 | [diff] [blame] | 4997 | "<p><div class=active_no_check>" |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 4998 | "<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] | 4999 | "Unexpected result." |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5000 | "</div>\n", uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5001 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5002 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | ba6be98 | 2013-04-19 12:16:55 +0200 | [diff] [blame] | 5003 | scope_txt); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5004 | } |
| 5005 | chunk_appendf(&trash, "<p>\n"); |
| 5006 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5007 | } |
Krzysztof Piotr Oledzki | c8b16fc | 2008-02-18 01:26:35 +0100 | [diff] [blame] | 5008 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5009 | /* Dumps the HTML stats trailer block to the trash. The caller is responsible |
| 5010 | * for clearing the trash if needed. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5011 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5012 | static void stats_dump_html_end() |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5013 | { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5014 | chunk_appendf(&trash, "</body></html>\n"); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5015 | } |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5016 | |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5017 | /* This function dumps statistics onto the stream interface's read buffer in |
| 5018 | * either CSV or HTML format. <uri> contains some HTML-specific parameters that |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 5019 | * are ignored for CSV format (hence <uri> may be NULL there). It returns 0 if |
| 5020 | * 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] | 5021 | * 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] | 5022 | * used by both the CLI and the HTTP handlers. |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5023 | */ |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5024 | 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] | 5025 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5026 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5027 | struct channel *rep = si_ic(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5028 | struct proxy *px; |
Willy Tarreau | 7f062c4 | 2009-03-05 18:43:00 +0100 | [diff] [blame] | 5029 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5030 | chunk_reset(&trash); |
Krzysztof Piotr Oledzki | 0960541 | 2009-09-23 22:09:24 +0200 | [diff] [blame] | 5031 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5032 | switch (appctx->st2) { |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5033 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5034 | appctx->st2 = STAT_ST_HEAD; /* let's start producing data */ |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5035 | /* fall through */ |
Krzysztof Piotr Oledzki | 97f07b8 | 2009-12-15 22:31:24 +0100 | [diff] [blame] | 5036 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5037 | case STAT_ST_HEAD: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5038 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5039 | stats_dump_html_head(uri); |
Willy Tarreau | 354898b | 2012-12-23 18:15:23 +0100 | [diff] [blame] | 5040 | else |
| 5041 | stats_dump_csv_header(); |
Willy Tarreau | d9b587f | 2010-02-26 10:05:55 +0100 | [diff] [blame] | 5042 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5043 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5044 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5045 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5046 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5047 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5048 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5049 | /* fall through */ |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5050 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5051 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5052 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5053 | stats_dump_html_info(si, uri); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5054 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5055 | si_applet_cant_put(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5056 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5057 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5058 | } |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5059 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5060 | appctx->ctx.stats.px = proxy; |
| 5061 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
| 5062 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5063 | /* fall through */ |
| 5064 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5065 | case STAT_ST_LIST: |
| 5066 | /* dump proxies */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5067 | while (appctx->ctx.stats.px) { |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5068 | if (buffer_almost_full(rep->buf)) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5069 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5070 | return 0; |
Willy Tarreau | d7ad9f5 | 2013-12-31 17:26:25 +0100 | [diff] [blame] | 5071 | } |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5072 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5073 | px = appctx->ctx.stats.px; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5074 | /* skip the disabled proxies, global frontend and non-networked ones */ |
| 5075 | 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] | 5076 | if (stats_dump_proxy_to_buffer(si, px, uri) == 0) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5077 | return 0; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5078 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5079 | appctx->ctx.stats.px = px->next; |
| 5080 | appctx->ctx.stats.px_st = STAT_PX_ST_INIT; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5081 | } |
| 5082 | /* here, we just have reached the last proxy */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5083 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5084 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5085 | /* fall through */ |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5086 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5087 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5088 | if (appctx->ctx.stats.flags & STAT_FMT_HTML) { |
Willy Tarreau | b5ba4ec | 2012-12-22 23:20:30 +0100 | [diff] [blame] | 5089 | stats_dump_html_end(); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5090 | if (bi_putchk(rep, &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5091 | si_applet_cant_put(si); |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5092 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5093 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5094 | } |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5095 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5096 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5097 | /* fall through */ |
Willy Tarreau | 0a6d2ef | 2009-03-29 14:46:01 +0200 | [diff] [blame] | 5098 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5099 | case STAT_ST_FIN: |
| 5100 | return 1; |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5101 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5102 | default: |
| 5103 | /* unknown state ! */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5104 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5105 | return -1; |
| 5106 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5107 | } |
Willy Tarreau | ae52678 | 2010-03-04 20:34:23 +0100 | [diff] [blame] | 5108 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5109 | /* We reached the stats page through a POST request. The appctx is |
| 5110 | * expected to have already been allocated by the caller. |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5111 | * Parse the posted data and enable/disable servers if necessary. |
| 5112 | * Returns 1 if request was parsed or zero if it needs more data. |
| 5113 | */ |
| 5114 | static int stats_process_http_post(struct stream_interface *si) |
| 5115 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5116 | struct stream *s = si_strm(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5117 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5118 | |
| 5119 | struct proxy *px = NULL; |
| 5120 | struct server *sv = NULL; |
| 5121 | |
| 5122 | char key[LINESIZE]; |
| 5123 | int action = ST_ADM_ACTION_NONE; |
| 5124 | int reprocess = 0; |
| 5125 | |
| 5126 | int total_servers = 0; |
| 5127 | int altered_servers = 0; |
| 5128 | |
| 5129 | char *first_param, *cur_param, *next_param, *end_params; |
| 5130 | char *st_cur_param = NULL; |
| 5131 | char *st_next_param = NULL; |
| 5132 | |
| 5133 | struct chunk *temp; |
| 5134 | int reql; |
| 5135 | |
| 5136 | temp = get_trash_chunk(); |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5137 | if (temp->size < s->txn->req.body_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5138 | /* too large request */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5139 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5140 | goto out; |
| 5141 | } |
| 5142 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5143 | 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] | 5144 | if (reql <= 0) { |
| 5145 | /* we need more data */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5146 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5147 | return 0; |
| 5148 | } |
| 5149 | |
| 5150 | first_param = temp->str; |
| 5151 | end_params = temp->str + reql; |
| 5152 | cur_param = next_param = end_params; |
| 5153 | *end_params = '\0'; |
| 5154 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5155 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5156 | |
| 5157 | /* |
| 5158 | * Parse the parameters in reverse order to only store the last value. |
| 5159 | * From the html form, the backend and the action are at the end. |
| 5160 | */ |
| 5161 | while (cur_param > first_param) { |
| 5162 | char *value; |
| 5163 | int poffset, plen; |
| 5164 | |
| 5165 | cur_param--; |
| 5166 | |
| 5167 | if ((*cur_param == '&') || (cur_param == first_param)) { |
| 5168 | reprocess_servers: |
| 5169 | /* Parse the key */ |
| 5170 | poffset = (cur_param != first_param ? 1 : 0); |
| 5171 | plen = next_param - cur_param + (cur_param == first_param ? 1 : 0); |
| 5172 | if ((plen > 0) && (plen <= sizeof(key))) { |
| 5173 | strncpy(key, cur_param + poffset, plen); |
| 5174 | key[plen - 1] = '\0'; |
| 5175 | } else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5176 | appctx->ctx.stats.st_code = STAT_STATUS_EXCD; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5177 | goto out; |
| 5178 | } |
| 5179 | |
| 5180 | /* Parse the value */ |
| 5181 | value = key; |
| 5182 | while (*value != '\0' && *value != '=') { |
| 5183 | value++; |
| 5184 | } |
| 5185 | if (*value == '=') { |
| 5186 | /* Ok, a value is found, we can mark the end of the key */ |
| 5187 | *value++ = '\0'; |
| 5188 | } |
| 5189 | if (url_decode(key) < 0 || url_decode(value) < 0) |
| 5190 | break; |
| 5191 | |
| 5192 | /* Now we can check the key to see what to do */ |
| 5193 | if (!px && (strcmp(key, "b") == 0)) { |
Willy Tarreau | 9e0bb10 | 2015-05-26 11:24:42 +0200 | [diff] [blame] | 5194 | if ((px = proxy_be_by_name(value)) == NULL) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5195 | /* the backend name is unknown or ambiguous (duplicate names) */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5196 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5197 | goto out; |
| 5198 | } |
| 5199 | } |
| 5200 | else if (!action && (strcmp(key, "action") == 0)) { |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5201 | if (strcmp(value, "ready") == 0) { |
| 5202 | action = ST_ADM_ACTION_READY; |
| 5203 | } |
| 5204 | else if (strcmp(value, "drain") == 0) { |
| 5205 | action = ST_ADM_ACTION_DRAIN; |
| 5206 | } |
| 5207 | else if (strcmp(value, "maint") == 0) { |
| 5208 | action = ST_ADM_ACTION_MAINT; |
| 5209 | } |
| 5210 | else if (strcmp(value, "shutdown") == 0) { |
| 5211 | action = ST_ADM_ACTION_SHUTDOWN; |
| 5212 | } |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5213 | else if (strcmp(value, "dhlth") == 0) { |
| 5214 | action = ST_ADM_ACTION_DHLTH; |
| 5215 | } |
| 5216 | else if (strcmp(value, "ehlth") == 0) { |
| 5217 | action = ST_ADM_ACTION_EHLTH; |
| 5218 | } |
| 5219 | else if (strcmp(value, "hrunn") == 0) { |
| 5220 | action = ST_ADM_ACTION_HRUNN; |
| 5221 | } |
| 5222 | else if (strcmp(value, "hnolb") == 0) { |
| 5223 | action = ST_ADM_ACTION_HNOLB; |
| 5224 | } |
| 5225 | else if (strcmp(value, "hdown") == 0) { |
| 5226 | action = ST_ADM_ACTION_HDOWN; |
| 5227 | } |
| 5228 | else if (strcmp(value, "dagent") == 0) { |
| 5229 | action = ST_ADM_ACTION_DAGENT; |
| 5230 | } |
| 5231 | else if (strcmp(value, "eagent") == 0) { |
| 5232 | action = ST_ADM_ACTION_EAGENT; |
| 5233 | } |
| 5234 | else if (strcmp(value, "arunn") == 0) { |
| 5235 | action = ST_ADM_ACTION_ARUNN; |
| 5236 | } |
| 5237 | else if (strcmp(value, "adown") == 0) { |
| 5238 | action = ST_ADM_ACTION_ADOWN; |
| 5239 | } |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5240 | /* else these are the old supported methods */ |
| 5241 | else if (strcmp(value, "disable") == 0) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5242 | action = ST_ADM_ACTION_DISABLE; |
| 5243 | } |
| 5244 | else if (strcmp(value, "enable") == 0) { |
| 5245 | action = ST_ADM_ACTION_ENABLE; |
| 5246 | } |
| 5247 | else if (strcmp(value, "stop") == 0) { |
| 5248 | action = ST_ADM_ACTION_STOP; |
| 5249 | } |
| 5250 | else if (strcmp(value, "start") == 0) { |
| 5251 | action = ST_ADM_ACTION_START; |
| 5252 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5253 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5254 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5255 | goto out; |
| 5256 | } |
| 5257 | } |
| 5258 | else if (strcmp(key, "s") == 0) { |
| 5259 | if (!(px && action)) { |
| 5260 | /* |
| 5261 | * Indicates that we'll need to reprocess the parameters |
| 5262 | * as soon as backend and action are known |
| 5263 | */ |
| 5264 | if (!reprocess) { |
| 5265 | st_cur_param = cur_param; |
| 5266 | st_next_param = next_param; |
| 5267 | } |
| 5268 | reprocess = 1; |
| 5269 | } |
| 5270 | else if ((sv = findserver(px, value)) != NULL) { |
| 5271 | switch (action) { |
| 5272 | case ST_ADM_ACTION_DISABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5273 | if (!(sv->admin & SRV_ADMF_FMAINT)) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5274 | altered_servers++; |
| 5275 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5276 | srv_set_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5277 | } |
| 5278 | break; |
| 5279 | case ST_ADM_ACTION_ENABLE: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5280 | if (sv->admin & SRV_ADMF_FMAINT) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5281 | altered_servers++; |
| 5282 | total_servers++; |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5283 | srv_clr_admin_flag(sv, SRV_ADMF_FMAINT); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5284 | } |
| 5285 | break; |
| 5286 | case ST_ADM_ACTION_STOP: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5287 | if (!(sv->admin & SRV_ADMF_FDRAIN)) { |
| 5288 | srv_set_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5289 | altered_servers++; |
| 5290 | total_servers++; |
| 5291 | } |
| 5292 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5293 | case ST_ADM_ACTION_START: |
Willy Tarreau | fae3a7e | 2014-05-22 17:22:34 +0200 | [diff] [blame] | 5294 | if (sv->admin & SRV_ADMF_FDRAIN) { |
| 5295 | srv_clr_admin_flag(sv, SRV_ADMF_FDRAIN); |
| 5296 | altered_servers++; |
| 5297 | total_servers++; |
| 5298 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5299 | break; |
Willy Tarreau | 248a60e | 2014-05-23 14:59:48 +0200 | [diff] [blame] | 5300 | case ST_ADM_ACTION_DHLTH: |
| 5301 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5302 | sv->check.state &= ~CHK_ST_ENABLED; |
| 5303 | altered_servers++; |
| 5304 | total_servers++; |
| 5305 | } |
| 5306 | break; |
| 5307 | case ST_ADM_ACTION_EHLTH: |
| 5308 | if (sv->check.state & CHK_ST_CONFIGURED) { |
| 5309 | sv->check.state |= CHK_ST_ENABLED; |
| 5310 | altered_servers++; |
| 5311 | total_servers++; |
| 5312 | } |
| 5313 | break; |
| 5314 | case ST_ADM_ACTION_HRUNN: |
| 5315 | if (!(sv->track)) { |
| 5316 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5317 | srv_set_running(sv, "changed from Web interface"); |
| 5318 | altered_servers++; |
| 5319 | total_servers++; |
| 5320 | } |
| 5321 | break; |
| 5322 | case ST_ADM_ACTION_HNOLB: |
| 5323 | if (!(sv->track)) { |
| 5324 | sv->check.health = sv->check.rise + sv->check.fall - 1; |
| 5325 | srv_set_stopping(sv, "changed from Web interface"); |
| 5326 | altered_servers++; |
| 5327 | total_servers++; |
| 5328 | } |
| 5329 | break; |
| 5330 | case ST_ADM_ACTION_HDOWN: |
| 5331 | if (!(sv->track)) { |
| 5332 | sv->check.health = 0; |
| 5333 | srv_set_stopped(sv, "changed from Web interface"); |
| 5334 | altered_servers++; |
| 5335 | total_servers++; |
| 5336 | } |
| 5337 | break; |
| 5338 | case ST_ADM_ACTION_DAGENT: |
| 5339 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5340 | sv->agent.state &= ~CHK_ST_ENABLED; |
| 5341 | altered_servers++; |
| 5342 | total_servers++; |
| 5343 | } |
| 5344 | break; |
| 5345 | case ST_ADM_ACTION_EAGENT: |
| 5346 | if (sv->agent.state & CHK_ST_CONFIGURED) { |
| 5347 | sv->agent.state |= CHK_ST_ENABLED; |
| 5348 | altered_servers++; |
| 5349 | total_servers++; |
| 5350 | } |
| 5351 | break; |
| 5352 | case ST_ADM_ACTION_ARUNN: |
| 5353 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5354 | sv->agent.health = sv->agent.rise + sv->agent.fall - 1; |
| 5355 | srv_set_running(sv, "changed from Web interface"); |
| 5356 | altered_servers++; |
| 5357 | total_servers++; |
| 5358 | } |
| 5359 | break; |
| 5360 | case ST_ADM_ACTION_ADOWN: |
| 5361 | if (sv->agent.state & CHK_ST_ENABLED) { |
| 5362 | sv->agent.health = 0; |
| 5363 | srv_set_stopped(sv, "changed from Web interface"); |
| 5364 | altered_servers++; |
| 5365 | total_servers++; |
| 5366 | } |
| 5367 | break; |
Willy Tarreau | ed7df90 | 2014-05-22 18:04:49 +0200 | [diff] [blame] | 5368 | case ST_ADM_ACTION_READY: |
| 5369 | srv_adm_set_ready(sv); |
| 5370 | altered_servers++; |
| 5371 | total_servers++; |
| 5372 | break; |
| 5373 | case ST_ADM_ACTION_DRAIN: |
| 5374 | srv_adm_set_drain(sv); |
| 5375 | altered_servers++; |
| 5376 | total_servers++; |
| 5377 | break; |
| 5378 | case ST_ADM_ACTION_MAINT: |
| 5379 | srv_adm_set_maint(sv); |
| 5380 | altered_servers++; |
| 5381 | total_servers++; |
| 5382 | break; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5383 | case ST_ADM_ACTION_SHUTDOWN: |
| 5384 | if (px->state != PR_STSTOPPED) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5385 | struct stream *sess, *sess_bck; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5386 | |
| 5387 | list_for_each_entry_safe(sess, sess_bck, &sv->actconns, by_srv) |
| 5388 | if (sess->srv_conn == sv) |
Willy Tarreau | e7dff02 | 2015-04-03 01:14:29 +0200 | [diff] [blame] | 5389 | stream_shutdown(sess, SF_ERR_KILLED); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5390 | |
| 5391 | altered_servers++; |
| 5392 | total_servers++; |
| 5393 | } |
| 5394 | break; |
| 5395 | } |
| 5396 | } else { |
| 5397 | /* the server name is unknown or ambiguous (duplicate names) */ |
| 5398 | total_servers++; |
| 5399 | } |
| 5400 | } |
| 5401 | if (reprocess && px && action) { |
| 5402 | /* Now, we know the backend and the action chosen by the user. |
| 5403 | * We can safely restart from the first server parameter |
| 5404 | * to reprocess them |
| 5405 | */ |
| 5406 | cur_param = st_cur_param; |
| 5407 | next_param = st_next_param; |
| 5408 | reprocess = 0; |
| 5409 | goto reprocess_servers; |
| 5410 | } |
| 5411 | |
| 5412 | next_param = cur_param; |
| 5413 | } |
| 5414 | } |
| 5415 | |
| 5416 | if (total_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5417 | appctx->ctx.stats.st_code = STAT_STATUS_NONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5418 | } |
| 5419 | else if (altered_servers == 0) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5420 | appctx->ctx.stats.st_code = STAT_STATUS_ERRP; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5421 | } |
| 5422 | else if (altered_servers == total_servers) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5423 | appctx->ctx.stats.st_code = STAT_STATUS_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5424 | } |
| 5425 | else { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5426 | appctx->ctx.stats.st_code = STAT_STATUS_PART; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5427 | } |
| 5428 | out: |
| 5429 | return 1; |
| 5430 | } |
| 5431 | |
| 5432 | |
| 5433 | static int stats_send_http_headers(struct stream_interface *si) |
| 5434 | { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5435 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5436 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5437 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5438 | |
| 5439 | chunk_printf(&trash, |
Willy Tarreau | 8b8995f | 2014-04-24 22:51:54 +0200 | [diff] [blame] | 5440 | "HTTP/1.1 200 OK\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5441 | "Cache-Control: no-cache\r\n" |
| 5442 | "Connection: close\r\n" |
| 5443 | "Content-Type: %s\r\n", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5444 | (appctx->ctx.stats.flags & STAT_FMT_HTML) ? "text/html" : "text/plain"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5445 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5446 | if (uri->refresh > 0 && !(appctx->ctx.stats.flags & STAT_NO_REFRESH)) |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5447 | chunk_appendf(&trash, "Refresh: %d\r\n", |
| 5448 | uri->refresh); |
| 5449 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5450 | /* we don't send the CRLF in chunked mode, it will be sent with the first chunk's size */ |
| 5451 | |
| 5452 | if (appctx->ctx.stats.flags & STAT_CHUNKED) |
| 5453 | chunk_appendf(&trash, "Transfer-Encoding: chunked\r\n"); |
| 5454 | else |
| 5455 | chunk_appendf(&trash, "\r\n"); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5456 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5457 | s->txn->status = 200; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5458 | s->logs.tv_request = now; |
| 5459 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5460 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5461 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5462 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5463 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5464 | |
| 5465 | return 1; |
| 5466 | } |
| 5467 | |
| 5468 | static int stats_send_http_redirect(struct stream_interface *si) |
| 5469 | { |
| 5470 | char scope_txt[STAT_SCOPE_TXT_MAXLEN + sizeof STAT_SCOPE_PATTERN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5471 | struct stream *s = si_strm(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5472 | struct uri_auth *uri = s->be->uri_auth; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5473 | struct appctx *appctx = objt_appctx(si->end); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5474 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5475 | /* 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] | 5476 | scope_txt[0] = 0; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5477 | if (appctx->ctx.stats.scope_len) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5478 | strcpy(scope_txt, STAT_SCOPE_PATTERN); |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5479 | 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] | 5480 | scope_txt[strlen(STAT_SCOPE_PATTERN) + appctx->ctx.stats.scope_len] = 0; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5481 | } |
| 5482 | |
| 5483 | /* We don't want to land on the posted stats page because a refresh will |
| 5484 | * repost the data. We don't want this to happen on accident so we redirect |
| 5485 | * the browse to the stats page with a GET. |
| 5486 | */ |
| 5487 | chunk_printf(&trash, |
| 5488 | "HTTP/1.1 303 See Other\r\n" |
| 5489 | "Cache-Control: no-cache\r\n" |
| 5490 | "Content-Type: text/plain\r\n" |
| 5491 | "Connection: close\r\n" |
| 5492 | "Location: %s;st=%s%s%s%s\r\n" |
Willy Tarreau | fdfcc9d | 2016-01-26 13:57:29 +0100 | [diff] [blame] | 5493 | "Content-length: 0\r\n" |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5494 | "\r\n", |
| 5495 | uri->uri_prefix, |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5496 | ((appctx->ctx.stats.st_code > STAT_STATUS_INIT) && |
| 5497 | (appctx->ctx.stats.st_code < STAT_STATUS_SIZE) && |
| 5498 | stat_status_codes[appctx->ctx.stats.st_code]) ? |
| 5499 | stat_status_codes[appctx->ctx.stats.st_code] : |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5500 | stat_status_codes[STAT_STATUS_UNKN], |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5501 | (appctx->ctx.stats.flags & STAT_HIDE_DOWN) ? ";up" : "", |
| 5502 | (appctx->ctx.stats.flags & STAT_NO_REFRESH) ? ";norefresh" : "", |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5503 | scope_txt); |
| 5504 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5505 | s->txn->status = 303; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5506 | s->logs.tv_request = now; |
| 5507 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5508 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5509 | si_applet_cant_put(si); |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5510 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5511 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5512 | |
| 5513 | return 1; |
| 5514 | } |
| 5515 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5516 | /* This I/O handler runs as an applet embedded in a stream interface. It is |
| 5517 | * 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] | 5518 | * appctx->st0 contains the operation in progress (dump, done). The handler |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5519 | * automatically unregisters itself once transfer is complete. |
| 5520 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5521 | static void http_stats_io_handler(struct appctx *appctx) |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5522 | { |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 5523 | struct stream_interface *si = appctx->owner; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5524 | struct stream *s = si_strm(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5525 | struct channel *req = si_oc(si); |
| 5526 | struct channel *res = si_ic(si); |
Willy Tarreau | 55058a7 | 2012-11-21 08:27:21 +0100 | [diff] [blame] | 5527 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5528 | if (unlikely(si->state == SI_ST_DIS || si->state == SI_ST_CLO)) |
| 5529 | goto out; |
Willy Tarreau | 5e16cbc | 2012-11-24 14:54:13 +0100 | [diff] [blame] | 5530 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5531 | /* check that the output is not closed */ |
| 5532 | if (res->flags & (CF_SHUTW|CF_SHUTW_NOW)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5533 | appctx->st0 = STAT_HTTP_DONE; |
Krzysztof Piotr Oledzki | 5fb1882 | 2009-10-13 21:14:09 +0200 | [diff] [blame] | 5534 | |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5535 | /* all states are processed in sequence */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5536 | if (appctx->st0 == STAT_HTTP_HEAD) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5537 | if (stats_send_http_headers(si)) { |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5538 | if (s->txn->meth == HTTP_METH_HEAD) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5539 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5540 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5541 | appctx->st0 = STAT_HTTP_DUMP; |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5542 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5543 | } |
| 5544 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5545 | if (appctx->st0 == STAT_HTTP_DUMP) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5546 | unsigned int prev_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5547 | unsigned int data_len; |
| 5548 | unsigned int last_len; |
Willy Tarreau | cce3648 | 2014-04-24 20:26:41 +0200 | [diff] [blame] | 5549 | unsigned int last_fwd = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5550 | |
| 5551 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5552 | /* One difficulty we're facing is that we must prevent |
| 5553 | * the input data from being automatically forwarded to |
| 5554 | * the output area. For this, we temporarily disable |
| 5555 | * forwarding on the channel. |
| 5556 | */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5557 | last_fwd = si_ic(si)->to_forward; |
| 5558 | si_ic(si)->to_forward = 0; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5559 | chunk_printf(&trash, "\r\n000000\r\n"); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5560 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5561 | si_applet_cant_put(si); |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5562 | si_ic(si)->to_forward = last_fwd; |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5563 | goto out; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5564 | } |
| 5565 | } |
| 5566 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5567 | data_len = si_ib(si)->i; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5568 | if (stats_dump_stat_to_buffer(si, s->be->uri_auth)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5569 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5570 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5571 | last_len = si_ib(si)->i; |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5572 | |
| 5573 | /* Now we must either adjust or remove the chunk size. This is |
| 5574 | * not easy because the chunk size might wrap at the end of the |
| 5575 | * buffer, so we pretend we have nothing in the buffer, we write |
| 5576 | * the size, then restore the buffer's contents. Note that we can |
| 5577 | * only do that because no forwarding is scheduled on the stats |
| 5578 | * applet. |
| 5579 | */ |
| 5580 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5581 | si_ic(si)->total -= (last_len - prev_len); |
| 5582 | si_ib(si)->i -= (last_len - prev_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5583 | |
| 5584 | if (last_len != data_len) { |
| 5585 | chunk_printf(&trash, "\r\n%06x\r\n", (last_len - data_len)); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5586 | if (bi_putchk(si_ic(si), &trash) == -1) |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5587 | si_applet_cant_put(si); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5588 | |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5589 | si_ic(si)->total += (last_len - data_len); |
| 5590 | si_ib(si)->i += (last_len - data_len); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5591 | } |
| 5592 | /* now re-enable forwarding */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5593 | channel_forward(si_ic(si), last_fwd); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5594 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5595 | } |
Cyril Bonté | 70be45d | 2010-10-12 00:14:35 +0200 | [diff] [blame] | 5596 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5597 | if (appctx->st0 == STAT_HTTP_POST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5598 | if (stats_process_http_post(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5599 | appctx->st0 = STAT_HTTP_LAST; |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 5600 | else if (si_oc(si)->flags & CF_SHUTR) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5601 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5602 | } |
| 5603 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5604 | if (appctx->st0 == STAT_HTTP_LAST) { |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5605 | if (stats_send_http_redirect(si)) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5606 | appctx->st0 = STAT_HTTP_DONE; |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5607 | } |
| 5608 | |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5609 | if (appctx->st0 == STAT_HTTP_DONE) { |
| 5610 | if (appctx->ctx.stats.flags & STAT_CHUNKED) { |
| 5611 | chunk_printf(&trash, "\r\n0\r\n\r\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5612 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5613 | si_applet_cant_put(si); |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5614 | goto out; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5615 | } |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5616 | } |
| 5617 | /* eat the whole request */ |
Willy Tarreau | 4e4292b | 2014-11-28 12:18:45 +0100 | [diff] [blame] | 5618 | bo_skip(si_oc(si), si_ob(si)->o); |
Willy Tarreau | af3cf70 | 2014-04-22 22:19:53 +0200 | [diff] [blame] | 5619 | res->flags |= CF_READ_NULL; |
| 5620 | si_shutr(si); |
| 5621 | } |
Willy Tarreau | 347a35d | 2013-11-22 17:51:09 +0100 | [diff] [blame] | 5622 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5623 | if ((res->flags & CF_SHUTR) && (si->state == SI_ST_EST)) |
| 5624 | si_shutw(si); |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5625 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5626 | if (appctx->st0 == STAT_HTTP_DONE) { |
Willy Tarreau | 96d4491 | 2013-11-22 12:25:24 +0100 | [diff] [blame] | 5627 | if ((req->flags & CF_SHUTW) && (si->state == SI_ST_EST)) { |
| 5628 | si_shutr(si); |
| 5629 | res->flags |= CF_READ_NULL; |
| 5630 | } |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5631 | } |
Willy Tarreau | 828824a | 2015-04-19 17:20:03 +0200 | [diff] [blame] | 5632 | out: |
Willy Tarreau | d4da196 | 2015-04-20 01:31:23 +0200 | [diff] [blame] | 5633 | /* just to make gcc happy */ ; |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 5634 | } |
| 5635 | |
Willy Tarreau | d9bdcd5 | 2012-12-22 20:31:10 +0100 | [diff] [blame] | 5636 | |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5637 | static inline const char *get_conn_ctrl_name(const struct connection *conn) |
| 5638 | { |
Willy Tarreau | 3c72872 | 2014-01-23 13:50:42 +0100 | [diff] [blame] | 5639 | if (!conn_ctrl_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5640 | return "NONE"; |
| 5641 | return conn->ctrl->name; |
| 5642 | } |
| 5643 | |
| 5644 | static inline const char *get_conn_xprt_name(const struct connection *conn) |
| 5645 | { |
| 5646 | static char ptr[17]; |
| 5647 | |
Willy Tarreau | aad6938 | 2014-01-23 14:21:42 +0100 | [diff] [blame] | 5648 | if (!conn_xprt_ready(conn)) |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5649 | return "NONE"; |
| 5650 | |
| 5651 | if (conn->xprt == &raw_sock) |
| 5652 | return "RAW"; |
| 5653 | |
| 5654 | #ifdef USE_OPENSSL |
| 5655 | if (conn->xprt == &ssl_sock) |
| 5656 | return "SSL"; |
| 5657 | #endif |
| 5658 | snprintf(ptr, sizeof(ptr), "%p", conn->xprt); |
| 5659 | return ptr; |
| 5660 | } |
| 5661 | |
| 5662 | static inline const char *get_conn_data_name(const struct connection *conn) |
| 5663 | { |
| 5664 | static char ptr[17]; |
| 5665 | |
| 5666 | if (!conn->data) |
| 5667 | return "NONE"; |
| 5668 | |
| 5669 | if (conn->data == &sess_conn_cb) |
| 5670 | return "SESS"; |
| 5671 | |
| 5672 | if (conn->data == &si_conn_cb) |
| 5673 | return "STRM"; |
| 5674 | |
| 5675 | if (conn->data == &check_conn_cb) |
| 5676 | return "CHCK"; |
| 5677 | |
| 5678 | snprintf(ptr, sizeof(ptr), "%p", conn->data); |
| 5679 | return ptr; |
| 5680 | } |
| 5681 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5682 | /* This function dumps a complete stream state onto the stream interface's |
| 5683 | * 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] | 5684 | * 0 if the output buffer is full and it needs to be called again, otherwise |
| 5685 | * 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] | 5686 | */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5687 | 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] | 5688 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5689 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5690 | struct tm tm; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5691 | extern const char *monthname[12]; |
| 5692 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5693 | struct connection *conn; |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5694 | struct appctx *tmpctx; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5695 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5696 | chunk_reset(&trash); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5697 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5698 | 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] | 5699 | /* stream changed, no need to go any further */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5700 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5701 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5702 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5703 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5704 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5705 | appctx->ctx.sess.uid = 0; |
| 5706 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5707 | return 1; |
| 5708 | } |
| 5709 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5710 | switch (appctx->ctx.sess.section) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 5711 | case 0: /* main status of the stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5712 | appctx->ctx.sess.uid = sess->uniq_id; |
| 5713 | appctx->ctx.sess.section = 1; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5714 | /* fall through */ |
| 5715 | |
| 5716 | case 1: |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5717 | get_localtime(sess->logs.accept_date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5718 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5719 | "%p: [%02d/%s/%04d:%02d:%02d:%02d.%06d] id=%u proto=%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5720 | sess, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5721 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 5722 | 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] | 5723 | sess->uniq_id, |
Willy Tarreau | 666f504 | 2015-06-17 19:49:52 +0200 | [diff] [blame] | 5724 | strm_li(sess) ? strm_li(sess)->proto->name : "?"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5725 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5726 | conn = objt_conn(strm_orig(sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5727 | 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] | 5728 | case AF_INET: |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5729 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5730 | chunk_appendf(&trash, " source=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5731 | pn, get_host_port(&conn->addr.from)); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5732 | break; |
| 5733 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5734 | chunk_appendf(&trash, " source=unix:%d\n", strm_li(sess)->luid); |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 5735 | break; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5736 | default: |
| 5737 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5738 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5739 | break; |
| 5740 | } |
| 5741 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5742 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5743 | " 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] | 5744 | 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] | 5745 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5746 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5747 | " frontend=%s (id=%u mode=%s), listener=%s (id=%u)", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5748 | strm_fe(sess)->id, strm_fe(sess)->uuid, strm_fe(sess)->mode ? "http" : "tcp", |
| 5749 | strm_li(sess) ? strm_li(sess)->name ? strm_li(sess)->name : "?" : "?", |
| 5750 | strm_li(sess) ? strm_li(sess)->luid : 0); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5751 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5752 | if (conn) |
| 5753 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5754 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5755 | 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] | 5756 | case AF_INET: |
| 5757 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5758 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5759 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5760 | break; |
| 5761 | case AF_UNIX: |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 5762 | chunk_appendf(&trash, " addr=unix:%d\n", strm_li(sess)->luid); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5763 | break; |
| 5764 | default: |
| 5765 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5766 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5767 | break; |
| 5768 | } |
| 5769 | |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5770 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5771 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5772 | " backend=%s (id=%u mode=%s)", |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5773 | sess->be->id, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5774 | sess->be->uuid, sess->be->mode ? "http" : "tcp"); |
| 5775 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5776 | chunk_appendf(&trash, " backend=<NONE> (id=-1 mode=-)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5777 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5778 | conn = objt_conn(sess->si[1].end); |
| 5779 | if (conn) |
| 5780 | conn_get_from_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5781 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5782 | 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] | 5783 | case AF_INET: |
| 5784 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5785 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5786 | pn, get_host_port(&conn->addr.from)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5787 | break; |
| 5788 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5789 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5790 | break; |
| 5791 | default: |
| 5792 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5793 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5794 | break; |
| 5795 | } |
| 5796 | |
| 5797 | if (sess->be->cap & PR_CAP_BE) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5798 | chunk_appendf(&trash, |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5799 | " server=%s (id=%u)", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 5800 | objt_server(sess->target) ? objt_server(sess->target)->id : "<none>", |
| 5801 | objt_server(sess->target) ? objt_server(sess->target)->puid : 0); |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 5802 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5803 | chunk_appendf(&trash, " server=<NONE> (id=-1)"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5804 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5805 | if (conn) |
| 5806 | conn_get_to_addr(conn); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5807 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5808 | 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] | 5809 | case AF_INET: |
| 5810 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5811 | chunk_appendf(&trash, " addr=%s:%d\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5812 | pn, get_host_port(&conn->addr.to)); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5813 | break; |
| 5814 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5815 | chunk_appendf(&trash, " addr=unix\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5816 | break; |
| 5817 | default: |
| 5818 | /* no more information to print right now */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5819 | chunk_appendf(&trash, "\n"); |
Daniel Schultze | 90690c7 | 2012-03-23 10:53:36 -0700 | [diff] [blame] | 5820 | break; |
| 5821 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5822 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5823 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5824 | " task=%p (state=0x%02x nice=%d calls=%d exp=%s%s", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5825 | sess->task, |
| 5826 | sess->task->state, |
| 5827 | sess->task->nice, sess->task->calls, |
| 5828 | sess->task->expire ? |
| 5829 | tick_is_expired(sess->task->expire, now_ms) ? "<PAST>" : |
| 5830 | human_time(TICKS_TO_MS(sess->task->expire - now_ms), |
| 5831 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5832 | task_in_rq(sess->task) ? ", running" : ""); |
| 5833 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5834 | chunk_appendf(&trash, |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5835 | " age=%s)\n", |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5836 | human_time(now.tv_sec - sess->logs.accept_date.tv_sec, 1)); |
| 5837 | |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5838 | if (sess->txn) |
| 5839 | chunk_appendf(&trash, |
Willy Tarreau | 9841019 | 2014-11-26 18:05:38 +0100 | [diff] [blame] | 5840 | " 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] | 5841 | sess->txn, sess->txn->flags, sess->txn->meth, sess->txn->status, |
| 5842 | 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] | 5843 | |
| 5844 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5845 | " 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] | 5846 | &sess->si[0], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5847 | si_state_str(sess->si[0].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5848 | sess->si[0].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5849 | obj_type_name(sess->si[0].end), |
| 5850 | obj_base_ptr(sess->si[0].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5851 | sess->si[0].exp ? |
| 5852 | tick_is_expired(sess->si[0].exp, now_ms) ? "<PAST>" : |
| 5853 | human_time(TICKS_TO_MS(sess->si[0].exp - now_ms), |
| 5854 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5855 | sess->si[0].err_type); |
| 5856 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5857 | chunk_appendf(&trash, |
Willy Tarreau | 32e3c6a | 2013-10-11 19:34:20 +0200 | [diff] [blame] | 5858 | " 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] | 5859 | &sess->si[1], |
Willy Tarreau | 55e4ecd | 2012-12-08 17:48:47 +0100 | [diff] [blame] | 5860 | si_state_str(sess->si[1].state), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5861 | sess->si[1].flags, |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5862 | obj_type_name(sess->si[1].end), |
| 5863 | obj_base_ptr(sess->si[1].end), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5864 | sess->si[1].exp ? |
| 5865 | tick_is_expired(sess->si[1].exp, now_ms) ? "<PAST>" : |
| 5866 | human_time(TICKS_TO_MS(sess->si[1].exp - now_ms), |
| 5867 | TICKS_TO_MS(1000)) : "<NEVER>", |
| 5868 | sess->si[1].err_type); |
| 5869 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5870 | if ((conn = objt_conn(sess->si[0].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5871 | chunk_appendf(&trash, |
| 5872 | " co0=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5873 | conn, |
| 5874 | get_conn_ctrl_name(conn), |
| 5875 | get_conn_xprt_name(conn), |
| 5876 | get_conn_data_name(conn), |
| 5877 | obj_type_name(conn->target), |
| 5878 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5879 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5880 | chunk_appendf(&trash, |
Willy Tarreau | 16f649c | 2014-01-25 19:10:48 +0100 | [diff] [blame] | 5881 | " 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] | 5882 | conn->flags, |
| 5883 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5884 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5885 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5886 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5887 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5888 | else if ((tmpctx = objt_appctx(sess->si[0].end)) != NULL) { |
| 5889 | chunk_appendf(&trash, |
| 5890 | " app0=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5891 | tmpctx, |
| 5892 | tmpctx->st0, |
| 5893 | tmpctx->st1, |
| 5894 | tmpctx->st2, |
| 5895 | tmpctx->applet->name); |
| 5896 | } |
Willy Tarreau | bc174aa | 2012-11-19 16:10:32 +0100 | [diff] [blame] | 5897 | |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5898 | if ((conn = objt_conn(sess->si[1].end)) != NULL) { |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5899 | chunk_appendf(&trash, |
| 5900 | " co1=%p ctrl=%s xprt=%s data=%s target=%s:%p\n", |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5901 | conn, |
| 5902 | get_conn_ctrl_name(conn), |
| 5903 | get_conn_xprt_name(conn), |
| 5904 | get_conn_data_name(conn), |
| 5905 | obj_type_name(conn->target), |
| 5906 | obj_base_ptr(conn->target)); |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5907 | |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5908 | chunk_appendf(&trash, |
Willy Tarreau | ceeafb5 | 2016-01-25 15:27:17 +0100 | [diff] [blame] | 5909 | " 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] | 5910 | conn->flags, |
| 5911 | conn->t.sock.fd, |
Willy Tarreau | 69a41fa | 2014-01-20 11:02:59 +0100 | [diff] [blame] | 5912 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].state : 0, |
Willy Tarreau | 15a4dec | 2014-01-20 11:09:39 +0100 | [diff] [blame] | 5913 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].cache : 0, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 5914 | conn->t.sock.fd >= 0 ? fdtab[conn->t.sock.fd].updated : 0); |
Willy Tarreau | cf644ed | 2013-09-29 17:19:56 +0200 | [diff] [blame] | 5915 | } |
Willy Tarreau | 284ddbf | 2013-12-01 20:45:00 +0100 | [diff] [blame] | 5916 | else if ((tmpctx = objt_appctx(sess->si[1].end)) != NULL) { |
| 5917 | chunk_appendf(&trash, |
| 5918 | " app1=%p st0=%d st1=%d st2=%d applet=%s\n", |
| 5919 | tmpctx, |
| 5920 | tmpctx->st0, |
| 5921 | tmpctx->st1, |
| 5922 | tmpctx->st2, |
| 5923 | tmpctx->applet->name); |
| 5924 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5925 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5926 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5927 | " 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] | 5928 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5929 | &sess->req, |
| 5930 | sess->req.flags, sess->req.analysers, |
| 5931 | sess->req.pipe ? sess->req.pipe->data : 0, |
| 5932 | sess->req.to_forward, sess->req.total, |
| 5933 | sess->req.analyse_exp ? |
| 5934 | human_time(TICKS_TO_MS(sess->req.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5935 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5936 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5937 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5938 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5939 | sess->req.rex ? |
| 5940 | human_time(TICKS_TO_MS(sess->req.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5941 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5942 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5943 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5944 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5945 | " 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] | 5946 | sess->req.wex ? |
| 5947 | human_time(TICKS_TO_MS(sess->req.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5948 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5949 | sess->req.buf, |
| 5950 | sess->req.buf->data, sess->req.buf->o, |
| 5951 | (int)(sess->req.buf->p - sess->req.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5952 | sess->txn ? sess->txn->req.next : 0, sess->req.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5953 | sess->req.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5954 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5955 | chunk_appendf(&trash, |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5956 | " 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] | 5957 | " an_exp=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5958 | &sess->res, |
| 5959 | sess->res.flags, sess->res.analysers, |
| 5960 | sess->res.pipe ? sess->res.pipe->data : 0, |
| 5961 | sess->res.to_forward, sess->res.total, |
| 5962 | sess->res.analyse_exp ? |
| 5963 | human_time(TICKS_TO_MS(sess->res.analyse_exp - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5964 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5965 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5966 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5967 | " rex=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5968 | sess->res.rex ? |
| 5969 | human_time(TICKS_TO_MS(sess->res.rex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5970 | TICKS_TO_MS(1000)) : "<NEVER>"); |
| 5971 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 5972 | chunk_appendf(&trash, |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5973 | " wex=%s\n" |
Willy Tarreau | 909d517 | 2012-11-26 03:04:41 +0100 | [diff] [blame] | 5974 | " 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] | 5975 | sess->res.wex ? |
| 5976 | human_time(TICKS_TO_MS(sess->res.wex - now_ms), |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5977 | TICKS_TO_MS(1000)) : "<NEVER>", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5978 | sess->res.buf, |
| 5979 | sess->res.buf->data, sess->res.buf->o, |
| 5980 | (int)(sess->res.buf->p - sess->res.buf->data), |
Willy Tarreau | eee5b51 | 2015-04-03 23:46:31 +0200 | [diff] [blame] | 5981 | sess->txn ? sess->txn->rsp.next : 0, sess->res.buf->i, |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 5982 | sess->res.buf->size); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5983 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5984 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 5985 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5986 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 5987 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5988 | |
| 5989 | /* use other states to dump the contents */ |
| 5990 | } |
| 5991 | /* end of dump */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 5992 | appctx->ctx.sess.uid = 0; |
| 5993 | appctx->ctx.sess.section = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 5994 | return 1; |
| 5995 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 5996 | |
Nenad Merdanovic | 200b0fa | 2015-05-09 08:46:01 +0200 | [diff] [blame] | 5997 | #if (defined SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB && TLS_TICKETS_NO > 0) |
| 5998 | static int stats_tlskeys_list(struct stream_interface *si) { |
| 5999 | struct appctx *appctx = __objt_appctx(si->end); |
| 6000 | |
| 6001 | switch (appctx->st2) { |
| 6002 | case STAT_ST_INIT: |
| 6003 | /* Display the column headers. If the message cannot be sent, |
| 6004 | * quit the fucntion with returning 0. The function is called |
| 6005 | * later and restart at the state "STAT_ST_INIT". |
| 6006 | */ |
| 6007 | chunk_reset(&trash); |
| 6008 | chunk_appendf(&trash, "# id (file)\n"); |
| 6009 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6010 | si_applet_cant_put(si); |
| 6011 | return 0; |
| 6012 | } |
| 6013 | |
| 6014 | /* Now, we start the browsing of the references lists. |
| 6015 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6016 | * avalaible field of this pointer is <list>. It is used with the function |
| 6017 | * tlskeys_list_get_next() for retruning the first avalaible entry |
| 6018 | */ |
| 6019 | appctx->ctx.tlskeys.ref = LIST_ELEM(&tlskeys_reference, struct tls_keys_ref *, list); |
| 6020 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6021 | |
| 6022 | appctx->st2 = STAT_ST_LIST; |
| 6023 | /* fall through */ |
| 6024 | |
| 6025 | case STAT_ST_LIST: |
| 6026 | while (appctx->ctx.tlskeys.ref) { |
| 6027 | chunk_reset(&trash); |
| 6028 | |
| 6029 | chunk_appendf(&trash, "%d (%s)\n", appctx->ctx.tlskeys.ref->unique_id, |
| 6030 | appctx->ctx.tlskeys.ref->filename); |
| 6031 | |
| 6032 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6033 | /* let's try again later from this stream. We add ourselves into |
| 6034 | * this stream's users so that it can remove us upon termination. |
| 6035 | */ |
| 6036 | si_applet_cant_put(si); |
| 6037 | return 0; |
| 6038 | } |
| 6039 | |
| 6040 | /* get next list entry and check the end of the list */ |
| 6041 | appctx->ctx.tlskeys.ref = tlskeys_list_get_next(appctx->ctx.tlskeys.ref, &tlskeys_reference); |
| 6042 | } |
| 6043 | |
| 6044 | appctx->st2 = STAT_ST_FIN; |
| 6045 | /* fall through */ |
| 6046 | |
| 6047 | default: |
| 6048 | appctx->st2 = STAT_ST_FIN; |
| 6049 | return 1; |
| 6050 | } |
| 6051 | return 0; |
| 6052 | } |
| 6053 | #endif |
| 6054 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6055 | static int stats_pats_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6056 | { |
| 6057 | struct appctx *appctx = __objt_appctx(si->end); |
| 6058 | |
| 6059 | switch (appctx->st2) { |
| 6060 | case STAT_ST_INIT: |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6061 | /* Display the column headers. If the message cannot be sent, |
| 6062 | * quit the fucntion with returning 0. The function is called |
| 6063 | * later and restart at the state "STAT_ST_INIT". |
| 6064 | */ |
| 6065 | chunk_reset(&trash); |
Thierry FOURNIER | 65ce613 | 2014-03-20 11:42:45 +0100 | [diff] [blame] | 6066 | chunk_appendf(&trash, "# id (file) description\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6067 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6068 | si_applet_cant_put(si); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6069 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6070 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6071 | |
| 6072 | /* Now, we start the browsing of the references lists. |
| 6073 | * Note that the following call to LIST_ELEM return bad pointer. The only |
| 6074 | * avalaible field of this pointer is <list>. It is used with the function |
| 6075 | * pat_list_get_next() for retruning the first avalaible entry |
| 6076 | */ |
| 6077 | appctx->ctx.map.ref = LIST_ELEM(&pattern_reference, struct pat_ref *, list); |
| 6078 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6079 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6080 | appctx->st2 = STAT_ST_LIST; |
| 6081 | /* fall through */ |
| 6082 | |
| 6083 | case STAT_ST_LIST: |
| 6084 | while (appctx->ctx.map.ref) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6085 | chunk_reset(&trash); |
| 6086 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6087 | /* Build messages. If the reference is used by another category than |
| 6088 | * the listed categorie, display the information in the massage. |
| 6089 | */ |
Thierry FOURNIER | f7e04e9 | 2014-03-20 11:45:47 +0100 | [diff] [blame] | 6090 | 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] | 6091 | appctx->ctx.map.ref->reference ? appctx->ctx.map.ref->reference : "", |
| 6092 | appctx->ctx.map.ref->display); |
Thierry FOURNIER | af5a29d | 2014-03-11 14:29:22 +0100 | [diff] [blame] | 6093 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6094 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6095 | /* let's try again later from this stream. We add ourselves into |
| 6096 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6097 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6098 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6099 | return 0; |
| 6100 | } |
| 6101 | |
| 6102 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6103 | appctx->ctx.map.ref = pat_list_get_next(appctx->ctx.map.ref, &pattern_reference, |
| 6104 | appctx->ctx.map.display_flags); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | appctx->st2 = STAT_ST_FIN; |
| 6108 | /* fall through */ |
| 6109 | |
| 6110 | default: |
| 6111 | appctx->st2 = STAT_ST_FIN; |
| 6112 | return 1; |
| 6113 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6114 | return 0; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6115 | } |
| 6116 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6117 | static int stats_map_lookup(struct stream_interface *si) |
| 6118 | { |
| 6119 | struct appctx *appctx = __objt_appctx(si->end); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6120 | struct sample sample; |
| 6121 | struct pattern *pat; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6122 | int match_method; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6123 | |
| 6124 | switch (appctx->st2) { |
| 6125 | case STAT_ST_INIT: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6126 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | c5959fd | 2014-01-20 14:29:33 +0100 | [diff] [blame] | 6127 | 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] | 6128 | 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] | 6129 | appctx->st2 = STAT_ST_LIST; |
| 6130 | /* fall through */ |
| 6131 | |
| 6132 | case STAT_ST_LIST: |
| 6133 | /* for each lookup type */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6134 | while (appctx->ctx.map.expr) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6135 | /* initialise chunk to build new message */ |
| 6136 | chunk_reset(&trash); |
| 6137 | |
| 6138 | /* execute pattern matching */ |
Thierry FOURNIER | 8c542ca | 2015-08-19 09:00:18 +0200 | [diff] [blame] | 6139 | sample.data.type = SMP_T_STR; |
Andreas Seltenreich | 9727cf4 | 2016-03-03 19:32:25 +0100 | [diff] [blame] | 6140 | sample.flags = SMP_F_CONST; |
Thierry FOURNIER | 136f9d3 | 2015-08-19 09:07:19 +0200 | [diff] [blame] | 6141 | sample.data.u.str.len = appctx->ctx.map.chunk.len; |
| 6142 | sample.data.u.str.str = appctx->ctx.map.chunk.str; |
Thierry FOURNIER | 5d34408 | 2014-01-27 14:19:53 +0100 | [diff] [blame] | 6143 | if (appctx->ctx.map.expr->pat_head->match && |
| 6144 | sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6145 | pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); |
| 6146 | else |
| 6147 | pat = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6148 | |
| 6149 | /* build return message: set type of match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6150 | for (match_method=0; match_method<PAT_MATCH_NUM; match_method++) |
| 6151 | if (appctx->ctx.map.expr->pat_head->match == pat_match_fcts[match_method]) |
| 6152 | break; |
| 6153 | if (match_method >= PAT_MATCH_NUM) |
| 6154 | chunk_appendf(&trash, "type=unknown(%p)", appctx->ctx.map.expr->pat_head->match); |
| 6155 | else |
| 6156 | chunk_appendf(&trash, "type=%s", pat_match_names[match_method]); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6157 | |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6158 | /* case sensitive */ |
| 6159 | if (appctx->ctx.map.expr->mflags & PAT_MF_IGNORE_CASE) |
| 6160 | chunk_appendf(&trash, ", case=insensitive"); |
| 6161 | else |
| 6162 | chunk_appendf(&trash, ", case=sensitive"); |
| 6163 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6164 | /* Display no match, and set default value */ |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6165 | if (!pat) { |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6166 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6167 | chunk_appendf(&trash, ", found=no"); |
| 6168 | else |
| 6169 | chunk_appendf(&trash, ", match=no"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | /* Display match and match info */ |
| 6173 | else { |
| 6174 | /* display match */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6175 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) |
| 6176 | chunk_appendf(&trash, ", found=yes"); |
| 6177 | else |
| 6178 | chunk_appendf(&trash, ", match=yes"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6179 | |
Thierry FOURNIER | 1794fdf | 2014-01-17 15:25:13 +0100 | [diff] [blame] | 6180 | /* display index mode */ |
Thierry FOURNIER | e47e4e2 | 2014-04-28 11:18:57 +0200 | [diff] [blame] | 6181 | if (pat->sflags & PAT_SF_TREE) |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6182 | chunk_appendf(&trash, ", idx=tree"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6183 | else |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6184 | chunk_appendf(&trash, ", idx=list"); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6185 | |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6186 | /* display pattern */ |
| 6187 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
| 6188 | if (pat->ref && pat->ref->pattern) |
| 6189 | chunk_appendf(&trash, ", key=\"%s\"", pat->ref->pattern); |
| 6190 | else |
| 6191 | chunk_appendf(&trash, ", key=unknown"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6192 | } |
| 6193 | else { |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6194 | if (pat->ref && pat->ref->pattern) |
| 6195 | chunk_appendf(&trash, ", pattern=\"%s\"", pat->ref->pattern); |
| 6196 | else |
| 6197 | chunk_appendf(&trash, ", pattern=unknown"); |
| 6198 | } |
| 6199 | |
| 6200 | /* display return value */ |
| 6201 | if (appctx->ctx.map.display_flags == PAT_REF_MAP) { |
Thierry FOURNIER | 503bb09 | 2015-08-19 08:35:43 +0200 | [diff] [blame] | 6202 | if (pat->data && pat->ref && pat->ref->sample) |
Thierry FOURNIER | 03d0e45 | 2015-07-23 18:33:41 +0200 | [diff] [blame] | 6203 | chunk_appendf(&trash, ", value=\"%s\", type=\"%s\"", pat->ref->sample, |
Thierry FOURNIER | 7d4335c | 2015-08-19 09:05:25 +0200 | [diff] [blame] | 6204 | smp_to_type[pat->data->type]); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6205 | else |
Thierry FOURNIER | 86db66a | 2014-03-11 18:37:58 +0100 | [diff] [blame] | 6206 | chunk_appendf(&trash, ", value=none"); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6207 | } |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6208 | } |
| 6209 | |
Thierry FOURNIER | b990384 | 2014-03-11 18:48:17 +0100 | [diff] [blame] | 6210 | chunk_appendf(&trash, "\n"); |
| 6211 | |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6212 | /* display response */ |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6213 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6214 | /* let's try again later from this stream. We add ourselves into |
| 6215 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6216 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6217 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6218 | return 0; |
| 6219 | } |
| 6220 | |
| 6221 | /* get next entry */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6222 | appctx->ctx.map.expr = pat_expr_get_next(appctx->ctx.map.expr, |
| 6223 | &appctx->ctx.map.ref->pat); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | appctx->st2 = STAT_ST_FIN; |
| 6227 | /* fall through */ |
| 6228 | |
| 6229 | default: |
| 6230 | appctx->st2 = STAT_ST_FIN; |
| 6231 | free(appctx->ctx.map.chunk.str); |
| 6232 | return 1; |
| 6233 | } |
| 6234 | } |
| 6235 | |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6236 | static int stats_pat_list(struct stream_interface *si) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6237 | { |
| 6238 | struct appctx *appctx = __objt_appctx(si->end); |
| 6239 | |
| 6240 | switch (appctx->st2) { |
| 6241 | |
| 6242 | case STAT_ST_INIT: |
| 6243 | /* Init to the first entry. The list cannot be change */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6244 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.ref->head, |
| 6245 | struct pat_ref_elt *, list); |
| 6246 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
| 6247 | appctx->ctx.map.elt = NULL; |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6248 | appctx->st2 = STAT_ST_LIST; |
| 6249 | /* fall through */ |
| 6250 | |
| 6251 | case STAT_ST_LIST: |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6252 | while (appctx->ctx.map.elt) { |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6253 | chunk_reset(&trash); |
| 6254 | |
| 6255 | /* build messages */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6256 | if (appctx->ctx.map.elt->sample) |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6257 | chunk_appendf(&trash, "%p %s %s\n", |
| 6258 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern, |
| 6259 | appctx->ctx.map.elt->sample); |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6260 | else |
Thierry FOURNIER | 9356c68 | 2014-01-28 15:55:37 +0100 | [diff] [blame] | 6261 | chunk_appendf(&trash, "%p %s\n", |
| 6262 | appctx->ctx.map.elt, appctx->ctx.map.elt->pattern); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6263 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6264 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6265 | /* let's try again later from this stream. We add ourselves into |
| 6266 | * this stream's users so that it can remove us upon termination. |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6267 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6268 | si_applet_cant_put(si); |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6269 | return 0; |
| 6270 | } |
| 6271 | |
| 6272 | /* get next list entry and check the end of the list */ |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6273 | appctx->ctx.map.elt = LIST_NEXT(&appctx->ctx.map.elt->list, |
| 6274 | struct pat_ref_elt *, list); |
| 6275 | if (&appctx->ctx.map.elt->list == &appctx->ctx.map.ref->head) |
Thierry FOURNIER | c0e0d7b | 2013-12-11 16:55:52 +0100 | [diff] [blame] | 6276 | break; |
| 6277 | } |
| 6278 | |
| 6279 | appctx->st2 = STAT_ST_FIN; |
| 6280 | /* fall through */ |
| 6281 | |
| 6282 | default: |
| 6283 | appctx->st2 = STAT_ST_FIN; |
| 6284 | return 1; |
| 6285 | } |
| 6286 | } |
| 6287 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6288 | /* This function dumps all streams' states onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6289 | * 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] | 6290 | * to be called again, otherwise non-zero. It is designed to be called |
| 6291 | * from stats_dump_sess_to_buffer() below. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6292 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6293 | static int stats_dump_sess_to_buffer(struct stream_interface *si) |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6294 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6295 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6296 | struct connection *conn; |
| 6297 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6298 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6299 | /* 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] | 6300 | * reference to the last stream being dumped. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6301 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6302 | if (appctx->st2 == STAT_ST_LIST) { |
| 6303 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6304 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6305 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6306 | } |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6307 | } |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6308 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6309 | } |
| 6310 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6311 | chunk_reset(&trash); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6312 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6313 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6314 | case STAT_ST_INIT: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6315 | /* the function had not been called yet, let's prepare the |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6316 | * buffer for a response. We initialize the current stream |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6317 | * pointer to the first in the global list. When a target |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6318 | * stream is being destroyed, it is responsible for updating |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6319 | * this pointer. We know we have reached the end when this |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6320 | * pointer points back to the head of the streams list. |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6321 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6322 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6323 | appctx->ctx.sess.bref.ref = streams.n; |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6324 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6325 | /* fall through */ |
| 6326 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6327 | case STAT_ST_LIST: |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6328 | /* first, let's detach the back-ref from a possible previous stream */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6329 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) { |
| 6330 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6331 | LIST_INIT(&appctx->ctx.sess.bref.users); |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6332 | } |
| 6333 | |
| 6334 | /* and start from where we stopped */ |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6335 | while (appctx->ctx.sess.bref.ref != &streams) { |
Cyril Bonté | acd7d63 | 2010-11-01 19:26:02 +0100 | [diff] [blame] | 6336 | char pn[INET6_ADDRSTRLEN]; |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6337 | struct stream *curr_sess; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6338 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6339 | curr_sess = LIST_ELEM(appctx->ctx.sess.bref.ref, struct stream *, list); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6340 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6341 | if (appctx->ctx.sess.target) { |
| 6342 | 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] | 6343 | goto next_sess; |
| 6344 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6345 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6346 | /* call the proper dump() function and return if we're missing space */ |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6347 | if (!stats_dump_full_sess_to_buffer(si, curr_sess)) |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6348 | return 0; |
| 6349 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6350 | /* stream dump complete */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6351 | LIST_DEL(&appctx->ctx.sess.bref.users); |
| 6352 | LIST_INIT(&appctx->ctx.sess.bref.users); |
| 6353 | if (appctx->ctx.sess.target != (void *)-1) { |
| 6354 | appctx->ctx.sess.target = NULL; |
Willy Tarreau | 7615366 | 2012-11-26 01:16:39 +0100 | [diff] [blame] | 6355 | break; |
| 6356 | } |
| 6357 | else |
| 6358 | goto next_sess; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6359 | } |
| 6360 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6361 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6362 | "%p: proto=%s", |
| 6363 | curr_sess, |
Willy Tarreau | f1e0212 | 2015-09-23 12:16:43 +0200 | [diff] [blame] | 6364 | strm_li(curr_sess) ? strm_li(curr_sess)->proto->name : "?"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6365 | |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6366 | conn = objt_conn(strm_orig(curr_sess)); |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6367 | 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] | 6368 | case AF_INET: |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6369 | case AF_INET6: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6370 | chunk_appendf(&trash, |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6371 | " src=%s:%d fe=%s be=%s srv=%s", |
| 6372 | pn, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6373 | get_host_port(&conn->addr.from), |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6374 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6375 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6376 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6377 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6378 | break; |
| 6379 | case AF_UNIX: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6380 | chunk_appendf(&trash, |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6381 | " src=unix:%d fe=%s be=%s srv=%s", |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6382 | strm_li(curr_sess)->luid, |
| 6383 | strm_fe(curr_sess)->id, |
Willy Tarreau | 5094333 | 2011-09-02 17:33:05 +0200 | [diff] [blame] | 6384 | (curr_sess->be->cap & PR_CAP_BE) ? curr_sess->be->id : "<NONE>", |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 6385 | objt_server(curr_sess->target) ? objt_server(curr_sess->target)->id : "<none>" |
Emeric Brun | 837ca52 | 2010-10-22 16:19:01 +0200 | [diff] [blame] | 6386 | ); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6387 | break; |
| 6388 | } |
| 6389 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6390 | chunk_appendf(&trash, |
Willy Tarreau | 65671ab | 2009-10-04 14:24:59 +0200 | [diff] [blame] | 6391 | " ts=%02x age=%s calls=%d", |
| 6392 | curr_sess->task->state, |
Willy Tarreau | 3884cba | 2009-03-28 17:54:35 +0100 | [diff] [blame] | 6393 | human_time(now.tv_sec - curr_sess->logs.tv_accept.tv_sec, 1), |
| 6394 | curr_sess->task->calls); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6395 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6396 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6397 | " rq[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6398 | curr_sess->req.flags, |
| 6399 | curr_sess->req.buf->i, |
| 6400 | curr_sess->req.analysers, |
| 6401 | curr_sess->req.rex ? |
| 6402 | human_time(TICKS_TO_MS(curr_sess->req.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6403 | TICKS_TO_MS(1000)) : ""); |
| 6404 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6405 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6406 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6407 | curr_sess->req.wex ? |
| 6408 | human_time(TICKS_TO_MS(curr_sess->req.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6409 | TICKS_TO_MS(1000)) : ""); |
| 6410 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6411 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6412 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6413 | curr_sess->req.analyse_exp ? |
| 6414 | human_time(TICKS_TO_MS(curr_sess->req.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6415 | TICKS_TO_MS(1000)) : ""); |
| 6416 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6417 | chunk_appendf(&trash, |
Willy Tarreau | 02d6cfc | 2012-03-01 18:19:58 +0100 | [diff] [blame] | 6418 | " rp[f=%06xh,i=%d,an=%02xh,rx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6419 | curr_sess->res.flags, |
| 6420 | curr_sess->res.buf->i, |
| 6421 | curr_sess->res.analysers, |
| 6422 | curr_sess->res.rex ? |
| 6423 | human_time(TICKS_TO_MS(curr_sess->res.rex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6424 | TICKS_TO_MS(1000)) : ""); |
| 6425 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6426 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6427 | ",wx=%s", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6428 | curr_sess->res.wex ? |
| 6429 | human_time(TICKS_TO_MS(curr_sess->res.wex - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6430 | TICKS_TO_MS(1000)) : ""); |
| 6431 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6432 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6433 | ",ax=%s]", |
Willy Tarreau | 22ec1ea | 2014-11-27 20:45:39 +0100 | [diff] [blame] | 6434 | curr_sess->res.analyse_exp ? |
| 6435 | human_time(TICKS_TO_MS(curr_sess->res.analyse_exp - now_ms), |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6436 | TICKS_TO_MS(1000)) : ""); |
| 6437 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6438 | conn = objt_conn(curr_sess->si[0].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6439 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6440 | " s0=[%d,%1xh,fd=%d,ex=%s]", |
| 6441 | curr_sess->si[0].state, |
| 6442 | curr_sess->si[0].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6443 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6444 | curr_sess->si[0].exp ? |
| 6445 | human_time(TICKS_TO_MS(curr_sess->si[0].exp - now_ms), |
| 6446 | TICKS_TO_MS(1000)) : ""); |
| 6447 | |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6448 | conn = objt_conn(curr_sess->si[1].end); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6449 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6450 | " s1=[%d,%1xh,fd=%d,ex=%s]", |
| 6451 | curr_sess->si[1].state, |
| 6452 | curr_sess->si[1].flags, |
Willy Tarreau | b363a1f | 2013-10-01 10:45:07 +0200 | [diff] [blame] | 6453 | conn ? conn->t.sock.fd : -1, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6454 | curr_sess->si[1].exp ? |
| 6455 | human_time(TICKS_TO_MS(curr_sess->si[1].exp - now_ms), |
| 6456 | TICKS_TO_MS(1000)) : ""); |
| 6457 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6458 | chunk_appendf(&trash, |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6459 | " exp=%s", |
| 6460 | curr_sess->task->expire ? |
| 6461 | human_time(TICKS_TO_MS(curr_sess->task->expire - now_ms), |
| 6462 | TICKS_TO_MS(1000)) : ""); |
Willy Tarreau | 4726f53 | 2009-03-07 17:25:21 +0100 | [diff] [blame] | 6463 | if (task_in_rq(curr_sess->task)) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6464 | chunk_appendf(&trash, " run(nice=%d)", curr_sess->task->nice); |
Willy Tarreau | c6dcad6 | 2009-03-29 00:18:14 +0100 | [diff] [blame] | 6465 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6466 | chunk_appendf(&trash, "\n"); |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6467 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6468 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6469 | /* let's try again later from this stream. We add ourselves into |
| 6470 | * this stream's users so that it can remove us upon termination. |
Willy Tarreau | fd3828e | 2009-02-22 15:17:24 +0100 | [diff] [blame] | 6471 | */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6472 | si_applet_cant_put(si); |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6473 | LIST_ADDQ(&curr_sess->back_refs, &appctx->ctx.sess.bref.users); |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6474 | return 0; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6475 | } |
| 6476 | |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6477 | next_sess: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6478 | appctx->ctx.sess.bref.ref = curr_sess->list.n; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6479 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6480 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6481 | if (appctx->ctx.sess.target && appctx->ctx.sess.target != (void *)-1) { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6482 | /* specified stream not found */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6483 | if (appctx->ctx.sess.section > 0) |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6484 | chunk_appendf(&trash, " *** session terminated while we were watching it ***\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6485 | else |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6486 | chunk_appendf(&trash, "Session not found.\n"); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6487 | |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6488 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6489 | si_applet_cant_put(si); |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6490 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6491 | } |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6492 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6493 | appctx->ctx.sess.target = NULL; |
| 6494 | appctx->ctx.sess.uid = 0; |
Willy Tarreau | 66dc20a | 2010-03-05 17:53:32 +0100 | [diff] [blame] | 6495 | return 1; |
| 6496 | } |
| 6497 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6498 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6499 | /* fall through */ |
| 6500 | |
| 6501 | default: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6502 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 7e72a8f | 2009-10-03 23:55:14 +0200 | [diff] [blame] | 6503 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6504 | } |
Emeric Brun | 1e029aa | 2010-09-23 18:12:53 +0200 | [diff] [blame] | 6505 | } |
| 6506 | |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6507 | /* This is called when the stream interface is closed. For instance, upon an |
| 6508 | * 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] | 6509 | * remove back references to the stream currently being dumped. |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6510 | */ |
Willy Tarreau | 00a37f0 | 2015-04-13 12:05:19 +0200 | [diff] [blame] | 6511 | static void cli_release_handler(struct appctx *appctx) |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6512 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6513 | if (appctx->st0 == STAT_CLI_O_SESS && appctx->st2 == STAT_ST_LIST) { |
| 6514 | if (!LIST_ISEMPTY(&appctx->ctx.sess.bref.users)) |
| 6515 | LIST_DEL(&appctx->ctx.sess.bref.users); |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6516 | } |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6517 | else if (appctx->st0 == STAT_CLI_PRINT_FREE) { |
| 6518 | free(appctx->ctx.cli.err); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6519 | appctx->ctx.cli.err = NULL; |
Thierry FOURNIER | 364cfdf | 2014-01-29 19:08:49 +0100 | [diff] [blame] | 6520 | } |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6521 | else if (appctx->st0 == STAT_CLI_O_MLOOK) { |
| 6522 | free(appctx->ctx.map.chunk.str); |
Willy Tarreau | 6457d0f | 2015-10-07 20:00:24 +0200 | [diff] [blame] | 6523 | appctx->ctx.map.chunk.str = NULL; |
Thierry FOURNIER | 1e00d38 | 2014-02-11 11:31:40 +0100 | [diff] [blame] | 6524 | } |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 6525 | } |
| 6526 | |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6527 | /* This function is used to either dump tables states (when action is set |
| 6528 | * 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] | 6529 | * It returns 0 if the output buffer is full and it needs to be called |
| 6530 | * again, otherwise non-zero. |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6531 | */ |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6532 | static int stats_table_request(struct stream_interface *si, int action) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6533 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6534 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 6535 | struct stream *s = si_strm(si); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6536 | struct ebmb_node *eb; |
| 6537 | int dt; |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6538 | int skip_entry; |
Willy Tarreau | 20e9932 | 2013-04-13 09:22:25 +0200 | [diff] [blame] | 6539 | int show = action == STAT_CLI_O_TAB; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6540 | |
| 6541 | /* |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6542 | * We have 3 possible states in appctx->st2 : |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6543 | * - STAT_ST_INIT : the first call |
| 6544 | * - STAT_ST_INFO : the proxy pointer points to the next table to |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6545 | * dump, the entry pointer is NULL ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6546 | * - STAT_ST_LIST : the proxy pointer points to the current table |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6547 | * and the entry pointer points to the next entry to be dumped, |
| 6548 | * and the refcount on the next entry is held ; |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6549 | * - STAT_ST_END : nothing left to dump, the buffer may contain some |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6550 | * data though. |
| 6551 | */ |
| 6552 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6553 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6554 | /* 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] | 6555 | if (appctx->st2 == STAT_ST_LIST) { |
| 6556 | appctx->ctx.table.entry->ref_cnt--; |
| 6557 | 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] | 6558 | } |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6559 | return 1; |
| 6560 | } |
| 6561 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6562 | chunk_reset(&trash); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6563 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6564 | while (appctx->st2 != STAT_ST_FIN) { |
| 6565 | switch (appctx->st2) { |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6566 | case STAT_ST_INIT: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6567 | appctx->ctx.table.proxy = appctx->ctx.table.target; |
| 6568 | if (!appctx->ctx.table.proxy) |
| 6569 | appctx->ctx.table.proxy = proxy; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6570 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6571 | appctx->ctx.table.entry = NULL; |
| 6572 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6573 | break; |
| 6574 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6575 | case STAT_ST_INFO: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6576 | if (!appctx->ctx.table.proxy || |
| 6577 | (appctx->ctx.table.target && |
| 6578 | appctx->ctx.table.proxy != appctx->ctx.table.target)) { |
| 6579 | appctx->st2 = STAT_ST_END; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6580 | break; |
| 6581 | } |
| 6582 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6583 | if (appctx->ctx.table.proxy->table.size) { |
| 6584 | if (show && !stats_dump_table_head_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6585 | appctx->ctx.table.target)) |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6586 | return 0; |
| 6587 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6588 | if (appctx->ctx.table.target && |
Willy Tarreau | d0d8da9 | 2015-04-04 02:10:38 +0200 | [diff] [blame] | 6589 | strm_li(s)->bind_conf->level >= ACCESS_LVL_OPER) { |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6590 | /* dump entries only if table explicitly requested */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6591 | eb = ebmb_first(&appctx->ctx.table.proxy->table.keys); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6592 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6593 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
| 6594 | appctx->ctx.table.entry->ref_cnt++; |
| 6595 | appctx->st2 = STAT_ST_LIST; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6596 | break; |
| 6597 | } |
| 6598 | } |
| 6599 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6600 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6601 | break; |
| 6602 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6603 | case STAT_ST_LIST: |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6604 | skip_entry = 0; |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6605 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6606 | if (appctx->ctx.table.data_type >= 0) { |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6607 | /* we're filtering on some data contents */ |
| 6608 | void *ptr; |
| 6609 | long long data; |
| 6610 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6611 | dt = appctx->ctx.table.data_type; |
| 6612 | ptr = stktable_data_ptr(&appctx->ctx.table.proxy->table, |
| 6613 | appctx->ctx.table.entry, |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6614 | dt); |
| 6615 | |
| 6616 | data = 0; |
| 6617 | switch (stktable_data_types[dt].std_type) { |
| 6618 | case STD_T_SINT: |
| 6619 | data = stktable_data_cast(ptr, std_t_sint); |
| 6620 | break; |
| 6621 | case STD_T_UINT: |
| 6622 | data = stktable_data_cast(ptr, std_t_uint); |
| 6623 | break; |
| 6624 | case STD_T_ULL: |
| 6625 | data = stktable_data_cast(ptr, std_t_ull); |
| 6626 | break; |
| 6627 | case STD_T_FRQP: |
| 6628 | data = read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp), |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6629 | appctx->ctx.table.proxy->table.data_arg[dt].u); |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6630 | break; |
| 6631 | } |
| 6632 | |
| 6633 | /* 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] | 6634 | if ((data < appctx->ctx.table.value && |
| 6635 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6636 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6637 | appctx->ctx.table.data_op == STD_OP_GE)) || |
| 6638 | (data == appctx->ctx.table.value && |
| 6639 | (appctx->ctx.table.data_op == STD_OP_NE || |
| 6640 | appctx->ctx.table.data_op == STD_OP_GT || |
| 6641 | appctx->ctx.table.data_op == STD_OP_LT)) || |
| 6642 | (data > appctx->ctx.table.value && |
| 6643 | (appctx->ctx.table.data_op == STD_OP_EQ || |
| 6644 | appctx->ctx.table.data_op == STD_OP_LT || |
| 6645 | appctx->ctx.table.data_op == STD_OP_LE))) |
Willy Tarreau | 4445502 | 2012-12-05 23:01:12 +0100 | [diff] [blame] | 6646 | skip_entry = 1; |
Willy Tarreau | 4f3f01f | 2010-07-18 11:46:20 +0200 | [diff] [blame] | 6647 | } |
| 6648 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6649 | if (show && !skip_entry && |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6650 | !stats_dump_table_entry_to_buffer(&trash, si, appctx->ctx.table.proxy, |
| 6651 | appctx->ctx.table.entry)) |
Simon Horman | d936658 | 2011-06-15 15:18:45 +0900 | [diff] [blame] | 6652 | return 0; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6653 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6654 | appctx->ctx.table.entry->ref_cnt--; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6655 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6656 | eb = ebmb_next(&appctx->ctx.table.entry->key); |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6657 | if (eb) { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6658 | struct stksess *old = appctx->ctx.table.entry; |
| 6659 | appctx->ctx.table.entry = ebmb_entry(eb, struct stksess, key); |
Willy Tarreau | 8fa52f4 | 2012-01-09 11:50:03 +0100 | [diff] [blame] | 6660 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6661 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, old); |
| 6662 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6663 | stksess_kill(&appctx->ctx.table.proxy->table, old); |
| 6664 | appctx->ctx.table.entry->ref_cnt++; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6665 | break; |
| 6666 | } |
| 6667 | |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6668 | |
| 6669 | if (show) |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6670 | stksess_kill_if_expired(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
| 6671 | else if (!skip_entry && !appctx->ctx.table.entry->ref_cnt) |
| 6672 | stksess_kill(&appctx->ctx.table.proxy->table, appctx->ctx.table.entry); |
Simon Horman | c88b887 | 2011-06-15 15:18:49 +0900 | [diff] [blame] | 6673 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6674 | appctx->ctx.table.proxy = appctx->ctx.table.proxy->next; |
| 6675 | appctx->st2 = STAT_ST_INFO; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6676 | break; |
| 6677 | |
Willy Tarreau | 295a837 | 2011-03-10 11:25:07 +0100 | [diff] [blame] | 6678 | case STAT_ST_END: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6679 | appctx->st2 = STAT_ST_FIN; |
Willy Tarreau | 69f58c8 | 2010-07-12 17:55:33 +0200 | [diff] [blame] | 6680 | break; |
| 6681 | } |
| 6682 | } |
| 6683 | return 1; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 6684 | } |
| 6685 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6686 | /* 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] | 6687 | * <2 spaces> <offset=5 digits> <space or plus> <space> <70 chars max> <\n> |
| 6688 | * which is 60 chars per line. Non-printable chars \t, \n, \r and \e are |
| 6689 | * encoded in C format. Other non-printable chars are encoded "\xHH". Original |
| 6690 | * lines are respected within the limit of 70 output chars. Lines that are |
| 6691 | * continuation of a previous truncated line begin with "+" instead of " " |
| 6692 | * after the offset. The new pointer is returned. |
| 6693 | */ |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6694 | static int dump_text_line(struct chunk *out, const char *buf, int bsize, int len, |
| 6695 | int *line, int ptr) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6696 | { |
| 6697 | int end; |
| 6698 | unsigned char c; |
| 6699 | |
| 6700 | end = out->len + 80; |
Krzysztof Piotr Oledzki | 78abe61 | 2009-09-27 13:23:20 +0200 | [diff] [blame] | 6701 | if (end > out->size) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6702 | return ptr; |
| 6703 | |
Willy Tarreau | 7780473 | 2012-10-29 16:14:26 +0100 | [diff] [blame] | 6704 | chunk_appendf(out, " %05d%c ", ptr, (ptr == *line) ? ' ' : '+'); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6705 | |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6706 | while (ptr < len && ptr < bsize) { |
| 6707 | c = buf[ptr]; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6708 | if (isprint(c) && isascii(c) && c != '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6709 | if (out->len > end - 2) |
| 6710 | break; |
| 6711 | out->str[out->len++] = c; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6712 | } else if (c == '\t' || c == '\n' || c == '\r' || c == '\e' || c == '\\') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6713 | if (out->len > end - 3) |
| 6714 | break; |
| 6715 | out->str[out->len++] = '\\'; |
| 6716 | switch (c) { |
| 6717 | case '\t': c = 't'; break; |
| 6718 | case '\n': c = 'n'; break; |
| 6719 | case '\r': c = 'r'; break; |
| 6720 | case '\e': c = 'e'; break; |
Willy Tarreau | 787bbd9 | 2009-03-12 08:18:33 +0100 | [diff] [blame] | 6721 | case '\\': c = '\\'; break; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6722 | } |
| 6723 | out->str[out->len++] = c; |
| 6724 | } else { |
| 6725 | if (out->len > end - 5) |
| 6726 | break; |
| 6727 | out->str[out->len++] = '\\'; |
| 6728 | out->str[out->len++] = 'x'; |
| 6729 | out->str[out->len++] = hextab[(c >> 4) & 0xF]; |
| 6730 | out->str[out->len++] = hextab[c & 0xF]; |
| 6731 | } |
Willy Tarreau | d426a18 | 2010-03-05 14:58:26 +0100 | [diff] [blame] | 6732 | if (buf[ptr++] == '\n') { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6733 | /* we had a line break, let's return now */ |
| 6734 | out->str[out->len++] = '\n'; |
| 6735 | *line = ptr; |
| 6736 | return ptr; |
| 6737 | } |
| 6738 | } |
| 6739 | /* we have an incomplete line, we return it as-is */ |
| 6740 | out->str[out->len++] = '\n'; |
| 6741 | return ptr; |
| 6742 | } |
| 6743 | |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6744 | /* This function dumps counters from all resolvers section and associated name servers. |
| 6745 | * It returns 0 if the output buffer is full and it needs |
| 6746 | * to be called again, otherwise non-zero. |
| 6747 | */ |
| 6748 | static int stats_dump_resolvers_to_buffer(struct stream_interface *si) |
| 6749 | { |
| 6750 | struct appctx *appctx = __objt_appctx(si->end); |
| 6751 | struct dns_resolvers *presolvers; |
| 6752 | struct dns_nameserver *pnameserver; |
| 6753 | |
| 6754 | chunk_reset(&trash); |
| 6755 | |
| 6756 | switch (appctx->st2) { |
| 6757 | case STAT_ST_INIT: |
| 6758 | appctx->st2 = STAT_ST_LIST; /* let's start producing data */ |
| 6759 | /* fall through */ |
| 6760 | |
| 6761 | case STAT_ST_LIST: |
Andrew Hayworth | 68d0534 | 2015-10-02 20:33:01 +0000 | [diff] [blame] | 6762 | if (LIST_ISEMPTY(&dns_resolvers)) { |
| 6763 | chunk_appendf(&trash, "No resolvers found\n"); |
| 6764 | } |
| 6765 | else { |
| 6766 | list_for_each_entry(presolvers, &dns_resolvers, list) { |
| 6767 | if (appctx->ctx.resolvers.ptr != NULL && appctx->ctx.resolvers.ptr != presolvers) |
| 6768 | continue; |
| 6769 | |
| 6770 | chunk_appendf(&trash, "Resolvers section %s\n", presolvers->id); |
| 6771 | list_for_each_entry(pnameserver, &presolvers->nameserver_list, list) { |
| 6772 | chunk_appendf(&trash, " nameserver %s:\n", pnameserver->id); |
| 6773 | chunk_appendf(&trash, " sent: %ld\n", pnameserver->counters.sent); |
| 6774 | chunk_appendf(&trash, " valid: %ld\n", pnameserver->counters.valid); |
| 6775 | chunk_appendf(&trash, " update: %ld\n", pnameserver->counters.update); |
| 6776 | chunk_appendf(&trash, " cname: %ld\n", pnameserver->counters.cname); |
| 6777 | chunk_appendf(&trash, " cname_error: %ld\n", pnameserver->counters.cname_error); |
| 6778 | chunk_appendf(&trash, " any_err: %ld\n", pnameserver->counters.any_err); |
| 6779 | chunk_appendf(&trash, " nx: %ld\n", pnameserver->counters.nx); |
| 6780 | chunk_appendf(&trash, " timeout: %ld\n", pnameserver->counters.timeout); |
| 6781 | chunk_appendf(&trash, " refused: %ld\n", pnameserver->counters.refused); |
| 6782 | chunk_appendf(&trash, " other: %ld\n", pnameserver->counters.other); |
| 6783 | chunk_appendf(&trash, " invalid: %ld\n", pnameserver->counters.invalid); |
| 6784 | chunk_appendf(&trash, " too_big: %ld\n", pnameserver->counters.too_big); |
| 6785 | chunk_appendf(&trash, " truncated: %ld\n", pnameserver->counters.truncated); |
| 6786 | chunk_appendf(&trash, " outdated: %ld\n", pnameserver->counters.outdated); |
| 6787 | } |
| 6788 | } |
Baptiste Assmann | 3863f97 | 2015-05-17 00:33:24 +0200 | [diff] [blame] | 6789 | } |
| 6790 | |
| 6791 | /* display response */ |
| 6792 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6793 | /* let's try again later from this session. We add ourselves into |
| 6794 | * this session's users so that it can remove us upon termination. |
| 6795 | */ |
| 6796 | si->flags |= SI_FL_WAIT_ROOM; |
| 6797 | return 0; |
| 6798 | } |
| 6799 | |
| 6800 | appctx->st2 = STAT_ST_FIN; |
| 6801 | /* fall through */ |
| 6802 | |
| 6803 | default: |
| 6804 | appctx->st2 = STAT_ST_FIN; |
| 6805 | return 1; |
| 6806 | } |
| 6807 | } |
| 6808 | |
Willy Tarreau | f7bc57c | 2012-10-03 00:19:48 +0200 | [diff] [blame] | 6809 | /* This function dumps all captured errors onto the stream interface's |
Willy Tarreau | 306f830 | 2013-07-08 15:53:06 +0200 | [diff] [blame] | 6810 | * 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] | 6811 | * to be called again, otherwise non-zero. |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6812 | */ |
Simon Horman | 9bd2c73 | 2011-06-15 15:18:44 +0900 | [diff] [blame] | 6813 | static int stats_dump_errors_to_buffer(struct stream_interface *si) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6814 | { |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6815 | struct appctx *appctx = __objt_appctx(si->end); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6816 | extern const char *monthname[12]; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6817 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6818 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6819 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6820 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6821 | chunk_reset(&trash); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6822 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6823 | if (!appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6824 | /* the function had not been called yet, let's prepare the |
| 6825 | * buffer for a response. |
| 6826 | */ |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6827 | struct tm tm; |
| 6828 | |
| 6829 | get_localtime(date.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6830 | 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] | 6831 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
| 6832 | tm.tm_hour, tm.tm_min, tm.tm_sec, (int)(date.tv_usec/1000), |
| 6833 | error_snapshot_id); |
| 6834 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6835 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6836 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6837 | si_applet_cant_put(si); |
Willy Tarreau | 10479e4 | 2010-12-12 14:00:34 +0100 | [diff] [blame] | 6838 | return 0; |
| 6839 | } |
| 6840 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6841 | appctx->ctx.errors.px = proxy; |
| 6842 | appctx->ctx.errors.buf = 0; |
| 6843 | appctx->ctx.errors.bol = 0; |
| 6844 | appctx->ctx.errors.ptr = -1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6845 | } |
| 6846 | |
| 6847 | /* we have two inner loops here, one for the proxy, the other one for |
| 6848 | * the buffer. |
| 6849 | */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6850 | while (appctx->ctx.errors.px) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6851 | struct error_snapshot *es; |
| 6852 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6853 | if (appctx->ctx.errors.buf == 0) |
| 6854 | es = &appctx->ctx.errors.px->invalid_req; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6855 | else |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6856 | es = &appctx->ctx.errors.px->invalid_rep; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6857 | |
| 6858 | if (!es->when.tv_sec) |
| 6859 | goto next; |
| 6860 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6861 | if (appctx->ctx.errors.iid >= 0 && |
| 6862 | appctx->ctx.errors.px->uuid != appctx->ctx.errors.iid && |
| 6863 | es->oe->uuid != appctx->ctx.errors.iid) |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6864 | goto next; |
| 6865 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6866 | if (appctx->ctx.errors.ptr < 0) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6867 | /* just print headers now */ |
| 6868 | |
| 6869 | char pn[INET6_ADDRSTRLEN]; |
| 6870 | struct tm tm; |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6871 | int port; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6872 | |
| 6873 | get_localtime(es->when.tv_sec, &tm); |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6874 | chunk_appendf(&trash, " \n[%02d/%s/%04d:%02d:%02d:%02d.%03d]", |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6875 | tm.tm_mday, monthname[tm.tm_mon], tm.tm_year+1900, |
Willy Tarreau | 1772ece | 2009-04-03 14:49:12 +0200 | [diff] [blame] | 6876 | 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] | 6877 | |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6878 | switch (addr_to_str(&es->src, pn, sizeof(pn))) { |
| 6879 | case AF_INET: |
| 6880 | case AF_INET6: |
| 6881 | port = get_host_port(&es->src); |
| 6882 | break; |
| 6883 | default: |
| 6884 | port = 0; |
| 6885 | } |
| 6886 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6887 | switch (appctx->ctx.errors.buf) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6888 | case 0: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6889 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6890 | " frontend %s (#%d): invalid request\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6891 | " backend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6892 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6893 | (es->oe->cap & PR_CAP_BE) ? es->oe->id : "<NONE>", |
| 6894 | (es->oe->cap & PR_CAP_BE) ? es->oe->uuid : -1); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6895 | break; |
| 6896 | case 1: |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6897 | chunk_appendf(&trash, |
Olivier Doucet | 08afdcb | 2014-09-08 11:23:00 +0200 | [diff] [blame] | 6898 | " backend %s (#%d): invalid response\n" |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6899 | " frontend %s (#%d)", |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6900 | appctx->ctx.errors.px->id, appctx->ctx.errors.px->uuid, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6901 | es->oe->id, es->oe->uuid); |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6902 | break; |
| 6903 | } |
| 6904 | |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6905 | chunk_appendf(&trash, |
Willy Tarreau | d04b1bc | 2012-05-08 11:03:10 +0200 | [diff] [blame] | 6906 | ", server %s (#%d), event #%u\n" |
| 6907 | " src %s:%d, session #%d, session flags 0x%08x\n" |
| 6908 | " HTTP msg state %d, msg flags 0x%08x, tx flags 0x%08x\n" |
| 6909 | " HTTP chunk len %lld bytes, HTTP body len %lld bytes\n" |
| 6910 | " buffer flags 0x%08x, out %d bytes, total %lld bytes\n" |
| 6911 | " pending %d bytes, wrapping at %d, error at position %d:\n \n", |
| 6912 | es->srv ? es->srv->id : "<NONE>", es->srv ? es->srv->puid : -1, |
| 6913 | es->ev_id, |
| 6914 | pn, port, es->sid, es->s_flags, |
| 6915 | es->state, es->m_flags, es->t_flags, |
| 6916 | es->m_clen, es->m_blen, |
| 6917 | es->b_flags, es->b_out, es->b_tot, |
| 6918 | es->len, es->b_wrap, es->pos); |
| 6919 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6920 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6921 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6922 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6923 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6924 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6925 | appctx->ctx.errors.ptr = 0; |
| 6926 | appctx->ctx.errors.sid = es->sid; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6927 | } |
| 6928 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6929 | if (appctx->ctx.errors.sid != es->sid) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6930 | /* the snapshot changed while we were dumping it */ |
Willy Tarreau | 19d14ef | 2012-10-29 16:51:55 +0100 | [diff] [blame] | 6931 | chunk_appendf(&trash, |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6932 | " WARNING! update detected on this snapshot, dump interrupted. Please re-check!\n"); |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6933 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6934 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6935 | return 0; |
Willy Tarreau | bc18da1 | 2015-03-13 14:00:47 +0100 | [diff] [blame] | 6936 | } |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6937 | goto next; |
| 6938 | } |
| 6939 | |
| 6940 | /* OK, ptr >= 0, so we have to dump the current line */ |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6941 | 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] | 6942 | int newptr; |
| 6943 | int newline; |
| 6944 | |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6945 | newline = appctx->ctx.errors.bol; |
| 6946 | newptr = dump_text_line(&trash, es->buf, sizeof(es->buf), es->len, &newline, appctx->ctx.errors.ptr); |
| 6947 | if (newptr == appctx->ctx.errors.ptr) |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6948 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6949 | |
Willy Tarreau | 2bb4a96 | 2014-11-28 11:11:05 +0100 | [diff] [blame] | 6950 | if (bi_putchk(si_ic(si), &trash) == -1) { |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6951 | /* Socket buffer full. Let's try again later from the same point */ |
Willy Tarreau | fe12793 | 2015-04-21 19:23:39 +0200 | [diff] [blame] | 6952 | si_applet_cant_put(si); |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 6953 | return 0; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6954 | } |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6955 | appctx->ctx.errors.ptr = newptr; |
| 6956 | appctx->ctx.errors.bol = newline; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6957 | }; |
| 6958 | next: |
Willy Tarreau | 7b4b499 | 2013-12-01 09:15:12 +0100 | [diff] [blame] | 6959 | appctx->ctx.errors.bol = 0; |
| 6960 | appctx->ctx.errors.ptr = -1; |
| 6961 | appctx->ctx.errors.buf++; |
| 6962 | if (appctx->ctx.errors.buf > 1) { |
| 6963 | appctx->ctx.errors.buf = 0; |
| 6964 | appctx->ctx.errors.px = appctx->ctx.errors.px->next; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6965 | } |
Willy Tarreau | ae79572 | 2016-02-16 11:27:28 +0100 | [diff] [blame] | 6966 | } |
| 6967 | |
| 6968 | /* dump complete */ |
| 6969 | return 1; |
| 6970 | } |
| 6971 | |
| 6972 | /* This function dumps all environmnent variables to the buffer. It returns 0 |
| 6973 | * if the output buffer is full and it needs to be called again, otherwise |
| 6974 | * non-zero. Dumps only one entry if st2 == STAT_ST_END. |
| 6975 | */ |
| 6976 | static int stats_dump_env_to_buffer(struct stream_interface *si) |
| 6977 | { |
| 6978 | struct appctx *appctx = __objt_appctx(si->end); |
| 6979 | |
| 6980 | if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) |
| 6981 | return 1; |
| 6982 | |
| 6983 | chunk_reset(&trash); |
| 6984 | |
| 6985 | /* we have two inner loops here, one for the proxy, the other one for |
| 6986 | * the buffer. |
| 6987 | */ |
| 6988 | while (*appctx->ctx.env.var) { |
| 6989 | chunk_printf(&trash, "%s\n", *appctx->ctx.env.var); |
| 6990 | |
| 6991 | if (bi_putchk(si_ic(si), &trash) == -1) { |
| 6992 | si_applet_cant_put(si); |
| 6993 | return 0; |
| 6994 | } |
| 6995 | if (appctx->st2 == STAT_ST_END) |
| 6996 | break; |
| 6997 | appctx->ctx.env.var++; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 6998 | } |
| 6999 | |
| 7000 | /* dump complete */ |
Willy Tarreau | 61b3473 | 2009-10-03 23:49:35 +0200 | [diff] [blame] | 7001 | return 1; |
Willy Tarreau | 74808cb | 2009-03-04 15:53:18 +0100 | [diff] [blame] | 7002 | } |
| 7003 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7004 | /* parse the "level" argument on the bind lines */ |
| 7005 | static int bind_parse_level(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err) |
| 7006 | { |
| 7007 | if (!*args[cur_arg + 1]) { |
| 7008 | memprintf(err, "'%s' : missing level", args[cur_arg]); |
| 7009 | return ERR_ALERT | ERR_FATAL; |
| 7010 | } |
| 7011 | |
| 7012 | if (!strcmp(args[cur_arg+1], "user")) |
| 7013 | conf->level = ACCESS_LVL_USER; |
| 7014 | else if (!strcmp(args[cur_arg+1], "operator")) |
| 7015 | conf->level = ACCESS_LVL_OPER; |
| 7016 | else if (!strcmp(args[cur_arg+1], "admin")) |
| 7017 | conf->level = ACCESS_LVL_ADMIN; |
| 7018 | else { |
| 7019 | memprintf(err, "'%s' only supports 'user', 'operator', and 'admin' (got '%s')", |
| 7020 | args[cur_arg], args[cur_arg+1]); |
| 7021 | return ERR_ALERT | ERR_FATAL; |
| 7022 | } |
| 7023 | |
| 7024 | return 0; |
| 7025 | } |
| 7026 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7027 | struct applet http_stats_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7028 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7029 | .name = "<STATS>", /* used for logging */ |
| 7030 | .fct = http_stats_io_handler, |
Aman Gupta | 9a13e84 | 2012-04-02 18:57:53 -0700 | [diff] [blame] | 7031 | .release = NULL, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7032 | }; |
| 7033 | |
Willy Tarreau | 3057645 | 2015-04-13 13:50:30 +0200 | [diff] [blame] | 7034 | static struct applet cli_applet = { |
Willy Tarreau | 3fdb366 | 2012-11-12 00:42:33 +0100 | [diff] [blame] | 7035 | .obj_type = OBJ_TYPE_APPLET, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7036 | .name = "<CLI>", /* used for logging */ |
| 7037 | .fct = cli_io_handler, |
Willy Tarreau | 5f9a877 | 2012-11-26 02:22:40 +0100 | [diff] [blame] | 7038 | .release = cli_release_handler, |
Willy Tarreau | b24281b | 2011-02-13 13:16:36 +0100 | [diff] [blame] | 7039 | }; |
Willy Tarreau | 3dfe6cd | 2008-12-07 22:29:48 +0100 | [diff] [blame] | 7040 | |
Willy Tarreau | dc13c11 | 2013-06-21 23:16:39 +0200 | [diff] [blame] | 7041 | static struct cfg_kw_list cfg_kws = {ILH, { |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7042 | { CFG_GLOBAL, "stats", stats_parse_global }, |
| 7043 | { 0, NULL, NULL }, |
| 7044 | }}; |
| 7045 | |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7046 | static struct bind_kw_list bind_kws = { "STAT", { }, { |
| 7047 | { "level", bind_parse_level, 1 }, /* set the unix socket admin level */ |
| 7048 | { NULL, NULL, 0 }, |
| 7049 | }}; |
| 7050 | |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7051 | __attribute__((constructor)) |
| 7052 | static void __dumpstats_module_init(void) |
| 7053 | { |
| 7054 | cfg_register_keywords(&cfg_kws); |
Willy Tarreau | d578120 | 2012-09-22 19:32:35 +0200 | [diff] [blame] | 7055 | bind_register_keywords(&bind_kws); |
Willy Tarreau | 10522fd | 2008-07-09 20:12:41 +0200 | [diff] [blame] | 7056 | } |
| 7057 | |
Willy Tarreau | 9186126 | 2007-10-17 17:06:05 +0200 | [diff] [blame] | 7058 | /* |
| 7059 | * Local variables: |
| 7060 | * c-indent-level: 8 |
| 7061 | * c-basic-offset: 8 |
| 7062 | * End: |
| 7063 | */ |